diff options
Diffstat (limited to 'chromium/ui')
-rw-r--r-- | chromium/ui/gl/gl_angle_util_win.cc | 8 | ||||
-rw-r--r-- | chromium/ui/gl/gl_display.cc | 151 | ||||
-rw-r--r-- | chromium/ui/gl/gl_display.h | 30 | ||||
-rw-r--r-- | chromium/ui/gl/gl_display_manager.cc | 5 | ||||
-rw-r--r-- | chromium/ui/gl/gl_display_manager.h | 7 | ||||
-rw-r--r-- | chromium/ui/gl/gl_surface_wgl.cc | 165 | ||||
-rw-r--r-- | chromium/ui/gl/gl_surface_wgl.h | 4 |
7 files changed, 223 insertions, 147 deletions
diff --git a/chromium/ui/gl/gl_angle_util_win.cc b/chromium/ui/gl/gl_angle_util_win.cc index c6d795265ff..e573fc32269 100644 --- a/chromium/ui/gl/gl_angle_util_win.cc +++ b/chromium/ui/gl/gl_angle_util_win.cc @@ -17,7 +17,13 @@ namespace gl { void* QueryDeviceObjectFromANGLE(int object_type) { TRACE_EVENT0("gpu", "QueryDeviceObjectFromANGLE"); - EGLDisplay egl_display = gl::GLSurfaceEGL::GetGLDisplayEGL()->GetDisplay(); + GLDisplayEGL *gl_display = gl::GLSurfaceEGL::GetGLDisplayEGL(); + if (!gl_display) { + DVLOG(1) << "Failed to retrieve GLDisplayEGL"; + return nullptr; + } + + EGLDisplay egl_display = gl_display->GetDisplay(); if (egl_display == EGL_NO_DISPLAY) { DVLOG(1) << "Failed to retrieve EGLDisplay"; return nullptr; diff --git a/chromium/ui/gl/gl_display.cc b/chromium/ui/gl/gl_display.cc index d1761467570..57cd20bae9e 100644 --- a/chromium/ui/gl/gl_display.cc +++ b/chromium/ui/gl/gl_display.cc @@ -1038,4 +1038,155 @@ bool GLDisplayX11::IsInitialized() { } #endif // defined(USE_GLX) +#if BUILDFLAG(IS_WIN) + +namespace { +const PIXELFORMATDESCRIPTOR kPixelFormatDescriptor = { + sizeof(kPixelFormatDescriptor), // Size of structure. + 1, // Default version. + PFD_DRAW_TO_WINDOW | // Window drawing support. + PFD_SUPPORT_OPENGL | // OpenGL support. + PFD_DOUBLEBUFFER, // Double buffering support (not stereo). + PFD_TYPE_RGBA, // RGBA color mode (not indexed). + 24, // 24 bit color mode. + 0, 0, 0, 0, 0, 0, // Don't set RGB bits & shifts. + 8, 0, // 8 bit alpha + 0, // No accumulation buffer. + 0, 0, 0, 0, // Ignore accumulation bits. + 0, // no z-buffer. + 0, // no stencil buffer. + 0, // No aux buffer. + PFD_MAIN_PLANE, // Main drawing plane (not overlay). + 0, // Reserved. + 0, 0, 0, // Layer masks ignored. +}; + +LRESULT CALLBACK IntermediateWindowProc(HWND window, + UINT message, + WPARAM w_param, + LPARAM l_param) { + switch (message) { + case WM_ERASEBKGND: + // Prevent windows from erasing the background. + return 1; + case WM_PAINT: + // Do not paint anything. + PAINTSTRUCT paint; + if (BeginPaint(window, &paint)) + EndPaint(window, &paint); + return 0; + default: + return DefWindowProc(window, message, w_param, l_param); + } +} +} // namespace + +GLDisplayWGL::GLDisplayWGL(uint64_t system_device_id) + : GLDisplay(system_device_id, WGL), + module_handle_(0), + window_class_(0), + window_handle_(0), + device_context_(0), + pixel_format_(0) {} + +GLDisplayWGL::~GLDisplayWGL() { + if (window_handle_) + DestroyWindow(window_handle_); + if (window_class_) + UnregisterClass(reinterpret_cast<wchar_t*>(window_class_), + module_handle_); +} + +bool GLDisplayWGL::Init(bool software_rendering) { + // We must initialize a GL context before we can bind to extension entry + // points. This requires the device context for a window. + if (!GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT | + GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, + reinterpret_cast<wchar_t*>(IntermediateWindowProc), + &module_handle_)) { + LOG(ERROR) << "GetModuleHandleEx failed."; + return false; + } + + WNDCLASS intermediate_class; + intermediate_class.style = CS_OWNDC; + intermediate_class.lpfnWndProc = IntermediateWindowProc; + intermediate_class.cbClsExtra = 0; + intermediate_class.cbWndExtra = 0; + intermediate_class.hInstance = module_handle_; + intermediate_class.hIcon = LoadIcon(NULL, IDI_APPLICATION); + intermediate_class.hCursor = LoadCursor(NULL, IDC_ARROW); + intermediate_class.hbrBackground = NULL; + intermediate_class.lpszMenuName = NULL; + intermediate_class.lpszClassName = L"Intermediate GL Window"; + window_class_ = RegisterClass(&intermediate_class); + if (!window_class_) { + LOG(ERROR) << "RegisterClass failed."; + return false; + } + + window_handle_ = CreateWindowEx(WS_EX_NOPARENTNOTIFY, + reinterpret_cast<wchar_t*>(window_class_), + L"", + WS_OVERLAPPEDWINDOW, + 0, + 0, + 100, + 100, + NULL, + NULL, + NULL, + NULL); + if (!window_handle_) { + LOG(ERROR) << "CreateWindow failed."; + return false; + } + + device_context_ = GetDC(window_handle_); + pixel_format_ = ChoosePixelFormat(device_context_, + &kPixelFormatDescriptor); + if (pixel_format_ == 0) { + LOG(ERROR) << "Unable to get the pixel format for GL context."; + return false; + } + + bool result = false; + if (software_rendering) { + // wglSetPixelFormat needs to be called instead of SetPixelFormat to allow + // a differently named software GL implementation library to set up its + // internal data. The windows gdi.dll SetPixelFormat call directly calls + // into the stock opengl32.dll, instead of opengl32sw.dll for example. + typedef BOOL(WINAPI * wglSetPixelFormatProc)( + HDC, int, const PIXELFORMATDESCRIPTOR*); + wglSetPixelFormatProc wglSetPixelFormatFn = + reinterpret_cast<wglSetPixelFormatProc>( + GetGLProcAddress("wglSetPixelFormat")); + + result = wglSetPixelFormatFn(device_context_, pixel_format_, + &kPixelFormatDescriptor); + } else { + result = SetPixelFormat(device_context_, pixel_format_, + &kPixelFormatDescriptor); + } + if (!result) { + LOG(ERROR) << "Unable to set the pixel format for temporary GL context."; + return false; + } + return true; +} + +void* GLDisplayWGL::GetDisplay() +{ + return device_context(); +} + +bool GLDisplayWGL::IsInitialized() +{ + return true; +} +void GLDisplayWGL::Shutdown() +{ +} +#endif // BUILDFLAG(IS_WIN) + } // namespace gl diff --git a/chromium/ui/gl/gl_display.h b/chromium/ui/gl/gl_display.h index b44710c0fd7..5d92d569967 100644 --- a/chromium/ui/gl/gl_display.h +++ b/chromium/ui/gl/gl_display.h @@ -75,6 +75,7 @@ enum DisplayPlatform { NONE = 0, EGL = 1, X11 = 2, + WGL = 3, }; GL_EXPORT void GetEGLInitDisplaysForTesting( @@ -140,6 +141,7 @@ class GL_EXPORT GLDisplayEGL : public GLDisplay { std::unique_ptr<DisplayExtensionsEGL> ext; + explicit GLDisplayEGL(uint64_t system_device_id); private: friend class GLDisplayManager<GLDisplayEGL>; friend class EGLApiTest; @@ -154,7 +156,6 @@ class GL_EXPORT GLDisplayEGL : public GLDisplay { EGLDisplay display_ = EGL_NO_DISPLAY; }; - explicit GLDisplayEGL(uint64_t system_device_id); bool InitializeDisplay(EGLDisplayPlatform native_display); void InitializeCommon(); @@ -183,13 +184,38 @@ class GL_EXPORT GLDisplayX11 : public GLDisplay { void Shutdown() override; bool IsInitialized() override; + explicit GLDisplayX11(uint64_t system_device_id); private: friend class GLDisplayManager<GLDisplayX11>; - explicit GLDisplayX11(uint64_t system_device_id); }; #endif // defined(USE_GLX) +#if BUILDFLAG(IS_WIN) +class GLDisplayWGL : public GLDisplay { + public: + ~GLDisplayWGL() override; + + void* GetDisplay() override; + bool IsInitialized() override; + void Shutdown() override; + + bool Init(bool software_rendering); + + ATOM window_class() const { return window_class_; } + HDC device_context() const { return device_context_; } + int pixel_format() const { return pixel_format_; } + + explicit GLDisplayWGL(uint64_t system_device_id); + private: + HINSTANCE module_handle_; + ATOM window_class_; + HWND window_handle_; + HDC device_context_; + int pixel_format_; +}; +#endif // BUILDFLAG(IS_WIN) + } // namespace gl #endif // UI_GL_GL_DISPLAY_H_ diff --git a/chromium/ui/gl/gl_display_manager.cc b/chromium/ui/gl/gl_display_manager.cc index c1cb2a0a3eb..6722875269f 100644 --- a/chromium/ui/gl/gl_display_manager.cc +++ b/chromium/ui/gl/gl_display_manager.cc @@ -12,4 +12,9 @@ template class EXPORT_TEMPLATE_DEFINE(GL_EXPORT) GLDisplayManager<GLDisplayEGL>; #if defined(USE_GLX) template class EXPORT_TEMPLATE_DEFINE(GL_EXPORT) GLDisplayManager<GLDisplayX11>; #endif + +#if BUILDFLAG(IS_WIN) +template class EXPORT_TEMPLATE_DEFINE(GL_EXPORT) GLDisplayManager<GLDisplayWGL>; +#endif + } // namespace gl diff --git a/chromium/ui/gl/gl_display_manager.h b/chromium/ui/gl/gl_display_manager.h index 54a908f3f4d..59646cc82d9 100644 --- a/chromium/ui/gl/gl_display_manager.h +++ b/chromium/ui/gl/gl_display_manager.h @@ -109,6 +109,13 @@ extern template class EXPORT_TEMPLATE_DECLARE(GL_EXPORT) GLDisplayManager<GLDisplayX11>; #endif +#if BUILDFLAG(IS_WIN) +using GLDisplayManagerWGL = GLDisplayManager<GLDisplayWGL>; + +extern template class EXPORT_TEMPLATE_DECLARE(GL_EXPORT) + GLDisplayManager<GLDisplayWGL>; +#endif + } // namespace gl #endif // UI_GL_GL_DISPLAY_MANAGER_H_ diff --git a/chromium/ui/gl/gl_surface_wgl.cc b/chromium/ui/gl/gl_surface_wgl.cc index 26e7c341551..62ffb19e2cd 100644 --- a/chromium/ui/gl/gl_surface_wgl.cc +++ b/chromium/ui/gl/gl_surface_wgl.cc @@ -11,6 +11,8 @@ #include "base/trace_event/trace_event.h" #include "ui/gl/gl_bindings.h" #include "ui/gl/gl_context.h" +#include "ui/gl/gl_display.h" +#include "ui/gl/gl_display_manager.h" #include "ui/gl/gl_gl_api_implementation.h" #include "ui/gl/gl_wgl_api_implementation.h" #include "ui/gl/init/gl_initializer.h" @@ -37,148 +39,21 @@ const PIXELFORMATDESCRIPTOR kPixelFormatDescriptor = { 0, // Reserved. 0, 0, 0, // Layer masks ignored. }; - -LRESULT CALLBACK IntermediateWindowProc(HWND window, - UINT message, - WPARAM w_param, - LPARAM l_param) { - switch (message) { - case WM_ERASEBKGND: - // Prevent windows from erasing the background. - return 1; - case WM_PAINT: - // Do not paint anything. - PAINTSTRUCT paint; - if (BeginPaint(window, &paint)) - EndPaint(window, &paint); - return 0; - default: - return DefWindowProc(window, message, w_param, l_param); - } -} - -class DisplayWGL : public GLDisplay { - public: - DisplayWGL() - : module_handle_(0), - window_class_(0), - window_handle_(0), - device_context_(0), - pixel_format_(0) { - } - - ~DisplayWGL() { - if (window_handle_) - DestroyWindow(window_handle_); - if (window_class_) - UnregisterClass(reinterpret_cast<wchar_t*>(window_class_), - module_handle_); - } - - bool Init(bool software_rendering) { - // We must initialize a GL context before we can bind to extension entry - // points. This requires the device context for a window. - if (!GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT | - GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, - reinterpret_cast<wchar_t*>(IntermediateWindowProc), - &module_handle_)) { - LOG(ERROR) << "GetModuleHandleEx failed."; - return false; - } - - WNDCLASS intermediate_class; - intermediate_class.style = CS_OWNDC; - intermediate_class.lpfnWndProc = IntermediateWindowProc; - intermediate_class.cbClsExtra = 0; - intermediate_class.cbWndExtra = 0; - intermediate_class.hInstance = module_handle_; - intermediate_class.hIcon = LoadIcon(NULL, IDI_APPLICATION); - intermediate_class.hCursor = LoadCursor(NULL, IDC_ARROW); - intermediate_class.hbrBackground = NULL; - intermediate_class.lpszMenuName = NULL; - intermediate_class.lpszClassName = L"Intermediate GL Window"; - window_class_ = RegisterClass(&intermediate_class); - if (!window_class_) { - LOG(ERROR) << "RegisterClass failed."; - return false; - } - - window_handle_ = CreateWindowEx(WS_EX_NOPARENTNOTIFY, - reinterpret_cast<wchar_t*>(window_class_), - L"", - WS_OVERLAPPEDWINDOW, - 0, - 0, - 100, - 100, - NULL, - NULL, - NULL, - NULL); - if (!window_handle_) { - LOG(ERROR) << "CreateWindow failed."; - return false; - } - - device_context_ = GetDC(window_handle_); - pixel_format_ = ChoosePixelFormat(device_context_, - &kPixelFormatDescriptor); - if (pixel_format_ == 0) { - LOG(ERROR) << "Unable to get the pixel format for GL context."; - return false; - } - - bool result = false; - if (software_rendering) { - // wglSetPixelFormat needs to be called instead of SetPixelFormat to allow - // a differently named software GL implementation library to set up its - // internal data. The windows gdi.dll SetPixelFormat call directly calls - // into the stock opengl32.dll, instead of opengl32sw.dll for example. - typedef BOOL(WINAPI * wglSetPixelFormatProc)( - HDC, int, const PIXELFORMATDESCRIPTOR*); - wglSetPixelFormatProc wglSetPixelFormatFn = - reinterpret_cast<wglSetPixelFormatProc>( - GetGLProcAddress("wglSetPixelFormat")); - - result = wglSetPixelFormatFn(device_context_, pixel_format_, - &kPixelFormatDescriptor); - } else { - result = SetPixelFormat(device_context_, pixel_format_, - &kPixelFormatDescriptor); - } - if (!result) { - LOG(ERROR) << "Unable to set the pixel format for temporary GL context."; - return false; - } - return true; - } - - ATOM window_class() const { return window_class_; } - HDC device_context() const { return device_context_; } - int pixel_format() const { return pixel_format_; } - void* GetDisplay() override { return device_context(); } - - private: - HINSTANCE module_handle_; - ATOM window_class_; - HWND window_handle_; - HDC device_context_; - int pixel_format_; -}; -DisplayWGL* g_wgl_display = NULL; } // namespace // static bool GLSurfaceWGL::initialized_ = false; GLSurfaceWGL::GLSurfaceWGL() { + display_ = + GLDisplayManagerWGL::GetInstance()->GetDisplay(GpuPreference::kDefault); } GLSurfaceWGL::~GLSurfaceWGL() { } GLDisplay* GLSurfaceWGL::GetGLDisplay() { - return g_wgl_display; + return display_; } // static @@ -186,12 +61,16 @@ bool GLSurfaceWGL::InitializeOneOff() { if (initialized_) return true; - DCHECK(g_wgl_display == NULL); - std::unique_ptr<DisplayWGL> wgl_display(new DisplayWGL); - if (!wgl_display->Init(init::usingSoftwareDynamicGL())) - return false; + auto wgl_display = GLDisplayManagerWGL::GetInstance()->GetDisplay(GpuPreference::kDefault); + if (!wgl_display->Init(init::usingSoftwareDynamicGL())) + return false; - g_wgl_display = wgl_display.release(); + // DCHECK(g_wgl_display == NULL); + // std::unique_ptr<DisplayWGL> wgl_display(new DisplayWGL); + // if (!wgl_display->Init(init::usingSoftwareDynamicGL())) + // return false; + // + // g_wgl_display = wgl_display.release(); initialized_ = true; return true; } @@ -205,13 +84,13 @@ bool GLSurfaceWGL::InitializeExtensionSettingsOneOff() { } void GLSurfaceWGL::InitializeOneOffForTesting() { - if (g_wgl_display == NULL) { - g_wgl_display = new DisplayWGL; - } + // if (g_wgl_display == NULL) { + // g_wgl_display = new DisplayWGL; + // } } HDC GLSurfaceWGL::GetDisplayDC() { - return g_wgl_display->device_context(); + return GLDisplayManagerWGL::GetInstance()->GetDisplay(GpuPreference::kDefault)->device_context(); } NativeViewGLSurfaceWGL::NativeViewGLSurfaceWGL(gfx::AcceleratedWidget window) @@ -237,7 +116,7 @@ bool NativeViewGLSurfaceWGL::Initialize(GLSurfaceFormat format) { // another process. child_window_ = CreateWindowEx( WS_EX_NOPARENTNOTIFY, - reinterpret_cast<wchar_t*>(g_wgl_display->window_class()), L"", + reinterpret_cast<wchar_t*>(display_->window_class()), L"", WS_CHILDWINDOW | WS_DISABLED | WS_VISIBLE, 0, 0, rect.right - rect.left, rect.bottom - rect.top, window_, NULL, NULL, NULL); if (!child_window_) { @@ -254,7 +133,7 @@ bool NativeViewGLSurfaceWGL::Initialize(GLSurfaceFormat format) { return false; } - if (!SetPixelFormat(device_context_, g_wgl_display->pixel_format(), + if (!SetPixelFormat(device_context_, display_->pixel_format(), &kPixelFormatDescriptor)) { LOG(ERROR) << "Unable to set the pixel format for GL context."; Destroy(); @@ -394,8 +273,8 @@ bool PbufferGLSurfaceWGL::Initialize(GLSurfaceFormat format) { } const int kNoAttributes[] = { 0 }; - pbuffer_ = wglCreatePbufferARB(g_wgl_display->device_context(), - g_wgl_display->pixel_format(), size_.width(), + pbuffer_ = wglCreatePbufferARB(display_->device_context(), + display_->pixel_format(), size_.width(), size_.height(), kNoAttributes); if (!pbuffer_) { diff --git a/chromium/ui/gl/gl_surface_wgl.h b/chromium/ui/gl/gl_surface_wgl.h index 755ab3bb6dc..32748d9c2a2 100644 --- a/chromium/ui/gl/gl_surface_wgl.h +++ b/chromium/ui/gl/gl_surface_wgl.h @@ -10,6 +10,7 @@ #include "ui/gl/gl_surface.h" namespace gl { +class GLDisplayWGL; // Base interface for WGL surfaces. class GL_EXPORT GLSurfaceWGL : public GLSurface { @@ -27,8 +28,9 @@ class GL_EXPORT GLSurfaceWGL : public GLSurface { protected: ~GLSurfaceWGL() override; - private: + protected: static bool initialized_; + GLDisplayWGL* display_; }; // A surface used to render to a view. |