Index: ui/ozone/platform/x11/x11_surface_factory.cc |
diff --git a/ui/ozone/platform/x11/x11_surface_factory.cc b/ui/ozone/platform/x11/x11_surface_factory.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..3c316e33782d2257ee136107320425a9d373129a |
--- /dev/null |
+++ b/ui/ozone/platform/x11/x11_surface_factory.cc |
@@ -0,0 +1,130 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "ui/ozone/platform/x11/x11_surface_factory.h" |
+ |
+#include "third_party/khronos/EGL/egl.h" |
+#include "ui/gfx/vsync_provider.h" |
+#include "ui/ozone/common/egl_util.h" |
+#include "ui/ozone/public/surface_ozone_egl.h" |
+#include "ui/platform_window/x11/x11_window.h" |
+ |
+namespace ui { |
+ |
+class X11SurfaceEGL : public SurfaceOzoneEGL { |
+ public: |
+ X11SurfaceEGL(gfx::AcceleratedWidget widget) : widget_(widget) {} |
+ ~X11SurfaceEGL() {} |
+ |
+ intptr_t GetNativeWindow() override { return widget_; } |
+ |
+ bool OnSwapBuffers() override { return true; } |
+ |
+ bool ResizeNativeWindow(const gfx::Size& viewport_size) override { |
+ return true; |
+ } |
+ |
+ scoped_ptr<gfx::VSyncProvider> CreateVSyncProvider() override { |
+ return scoped_ptr<gfx::VSyncProvider>(); |
+ } |
+ |
+ private: |
+ gfx::AcceleratedWidget widget_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(X11SurfaceEGL); |
+}; |
+ |
+X11SurfaceFactory::X11SurfaceFactory( |
+ scoped_refptr<X11WindowManager> window_manager) |
+ : window_manager_(window_manager) { |
+} |
+ |
+X11SurfaceFactory::~X11SurfaceFactory() { |
+} |
+ |
+// SurfaceFactoryOzone: |
+scoped_ptr<SurfaceOzoneEGL> X11SurfaceFactory::CreateEGLSurfaceForWidget( |
+ gfx::AcceleratedWidget widget) { |
+ return scoped_ptr<SurfaceOzoneEGL>(new X11SurfaceEGL(widget)); |
+} |
+ |
+bool X11SurfaceFactory::LoadEGLGLES2Bindings( |
+ AddGLLibraryCallback add_gl_library, |
+ SetGLGetProcAddressProcCallback set_gl_get_proc_address) { |
+ return LoadDefaultEGLGLES2Bindings(add_gl_library, set_gl_get_proc_address); |
+} |
+ |
+intptr_t X11SurfaceFactory::GetNativeDisplay() { |
+ return reinterpret_cast<intptr_t>(gfx::GetXDisplay()); |
+} |
+ |
+void* X11SurfaceFactory::GetEGLSurfaceConfig(const EglConfigInfo& egl, |
+ SurfaceOzoneEGL* surface) { |
+ // Try matching the window depth with an alpha channel, |
+ // because we're worried the destination alpha width could |
+ // constrain blending precision. |
+ EGLConfig config; |
+ const int kBufferSizeOffset = 1; |
+ const int kAlphaSizeOffset = 3; |
+ EGLint config_attribs[] = {EGL_BUFFER_SIZE, |
+ ~0, |
+ EGL_ALPHA_SIZE, |
+ 8, |
+ EGL_BLUE_SIZE, |
+ 8, |
+ EGL_GREEN_SIZE, |
+ 8, |
+ EGL_RED_SIZE, |
+ 8, |
+ EGL_RENDERABLE_TYPE, |
+ EGL_OPENGL_ES2_BIT, |
+ EGL_SURFACE_TYPE, |
+ EGL_WINDOW_BIT, |
+ EGL_NONE}; |
+ XWindowAttributes win_attribs; |
+ if (XGetWindowAttributes(gfx::GetXDisplay(), surface->GetNativeWindow(), |
+ &win_attribs)) { |
+ config_attribs[kBufferSizeOffset] = win_attribs.depth; |
+ } |
+ |
+ EGLint num_configs; |
+ if (!egl.choose_config.Run(config_attribs, &config, 1, &num_configs)) { |
+ LOG(ERROR) << "eglChooseConfig failed with error " |
+ << egl.get_last_error_string.Run(); |
+ return NULL; |
+ } |
+ |
+ if (num_configs) { |
+ EGLint config_depth; |
+ if (!egl.get_config_attribute.Run(config, EGL_BUFFER_SIZE, &config_depth)) { |
+ LOG(ERROR) << "eglGetConfigAttrib failed with error " |
+ << egl.get_last_error_string.Run(); |
+ return NULL; |
+ } |
+ |
+ if (config_depth == config_attribs[kBufferSizeOffset]) { |
+ return config; |
+ } |
+ } |
+ |
+ // Try without an alpha channel. |
+ config_attribs[kAlphaSizeOffset] = 0; |
+ if (!egl.choose_config.Run(config_attribs, &config, 1, &num_configs)) { |
+ LOG(ERROR) << "eglChooseConfig failed with error " |
+ << egl.get_last_error_string.Run(); |
+ return NULL; |
+ } |
+ |
+ if (num_configs == 0) { |
+ LOG(ERROR) << "No suitable EGL configs found."; |
+ return NULL; |
+ } |
+ return config; |
+} |
+ |
+X11Window* X11SurfaceFactory::FindWindow(XID id) { |
+ return window_manager_->FindWindow(id); |
+} |
+ |
+} // namespace ui |