compositortest: Decouple platform from API This allows us to select platform (e.g. glx, x11_egl, null) independently of API (e.g. OpenGL or OpenGL ES). It also simplifies the addition of another EGL-based waffle backend in the next patch. BUG=none TEST=none Change-Id: I670f823a0f38565668f3e4bb24f6b33813420ba7 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/glbench/+/5416277 Tested-by: Matt Turner <msturner@google.com> Reviewed-by: Ilja Friedel <ihf@chromium.org> Auto-Submit: Matt Turner <msturner@google.com> Commit-Queue: ChromeOS Auto Retry <chromeos-auto-retry@chromeos-bot.iam.gserviceaccount.com>
diff --git a/src/compositortest.cc b/src/compositortest.cc index 7453f07..0cdf703 100644 --- a/src/compositortest.cc +++ b/src/compositortest.cc
@@ -12,31 +12,29 @@ #include <thread> #include <vector> #include <waffle.h> + +#include "platform.h" +#include "workload.h" + +#if THIS_IS(PLATFORM_GLX) #include <X11/Xatom.h> #include <X11/Xlib.h> #include <X11/Xutil.h> -#include "workload.h" - -#if defined(USE_OPENGLES) -#include <epoxy/gl.h> -#include <epoxy/egl.h> -#include "waffle_null.h" - -#elif defined(USE_OPENGL) -#include <epoxy/gl.h> -#include <epoxy/glx.h> #include "waffle_glx.h" - -#else -#error bad graphics backend +#define PLATFORM_TYPE WAFFLE_PLATFORM_GLX +#elif THIS_IS(PLATFORM_NULL) +#include "waffle_null.h" +#define PLATFORM_TYPE WAFFLE_PLATFORM_NULL +#elif THIS_IS(PLATFORM_X11_EGL) +#include "waffle_x11_egl.h" +#define PLATFORM_TYPE WAFFLE_PLATFORM_X11_EGL #endif using namespace std::chrono; #if defined(USE_OPENGLES) #define PLATFORM_API WAFFLE_CONTEXT_OPENGL_ES2 -#define PLATFORM_TYPE WAFFLE_PLATFORM_NULL const std::string kVertexHeader = R"STRING( #version 320 es @@ -53,7 +51,6 @@ #define _NET_WM_STATE_TOGGLE 2 #define PLATFORM_API WAFFLE_CONTEXT_OPENGL -#define PLATFORM_TYPE WAFFLE_PLATFORM_GLX const std::string kVertexHeader = R"STRING( #version 430 core @@ -188,7 +185,7 @@ const intptr_t attrib[] = {WAFFLE_WINDOW_FULLSCREEN, 1, 0}; *window = waffle_window_create2(*config, attrib); -#if defined(USE_OPENGL) +#if THIS_IS(PLATFORM_GLX) struct waffle_glx_window *window_glx = waffle_window_get_native(*window)->glx; Display *display_x11 = window_glx->xlib_display; @@ -218,12 +215,15 @@ *ctx = waffle_context_create(*config, NULL); waffle_make_current(*display, *window, *ctx); -#if defined (USE_OPENGLES) - eglSwapInterval(waffle_display_get_native(*display)->null->egl_display, - swap_interval); -#elif defined (USE_OPENGL) - glXSwapIntervalEXT(waffle_display_get_native(*display)->glx->xlib_display, + union waffle_native_display *native_display = + waffle_display_get_native(*display); +#if THIS_IS(PLATFORM_GLX) + glXSwapIntervalEXT(native_display->glx->xlib_display, glXGetCurrentDrawable(), swap_interval); +#elif THIS_IS(PLATFORM_NULL) + eglSwapInterval(native_display->null->egl_display, swap_interval); +#elif THIS_IS(PLATFORM_X11_EGL) + eglSwapInterval(native_display->x11_egl->egl_display, swap_interval); #endif }
diff --git a/src/workload.h b/src/workload.h index d6d2cbc..dd20de5 100644 --- a/src/workload.h +++ b/src/workload.h
@@ -5,18 +5,14 @@ #ifndef COMPOSITOR_GL_WORKLOAD_H_ #define COMPOSITOR_GL_WORKLOAD_H_ -#if defined(USE_OPENGLES) -#include <epoxy/gl.h> -#include <epoxy/egl.h> -#include "waffle_null.h" +#include "platform.h" -#elif defined(USE_OPENGL) #include <epoxy/gl.h> + +#if THIS_IS(PLATFORM_GLX) #include <epoxy/glx.h> -#include "waffle_glx.h" - -#else -#error bad graphics backend +#else // EGL platforms +#include <epoxy/egl.h> #endif #define NS_TO_MS(x) x / 1000000.0