Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(348)

Side by Side Diff: ui/gl/gl_surface_ozone.cc

Issue 750593003: Ozone X11 platform Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/gl/gl_surface.h" 5 #include "ui/gl/gl_surface.h"
6 6
7 #if defined(OZONE_X11)
8 extern "C" {
9 #include <X11/Xlib.h>
10 }
11 #endif
12
7 #include "base/logging.h" 13 #include "base/logging.h"
8 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
9 #include "ui/gfx/native_widget_types.h" 15 #include "ui/gfx/native_widget_types.h"
16 #include "ui/gl/egl_util.h"
10 #include "ui/gl/gl_context.h" 17 #include "ui/gl/gl_context.h"
11 #include "ui/gl/gl_image.h" 18 #include "ui/gl/gl_image.h"
12 #include "ui/gl/gl_implementation.h" 19 #include "ui/gl/gl_implementation.h"
13 #include "ui/gl/gl_surface_egl.h" 20 #include "ui/gl/gl_surface_egl.h"
14 #include "ui/gl/gl_surface_osmesa.h" 21 #include "ui/gl/gl_surface_osmesa.h"
15 #include "ui/gl/gl_surface_stub.h" 22 #include "ui/gl/gl_surface_stub.h"
16 #include "ui/gl/scoped_make_current.h" 23 #include "ui/gl/scoped_make_current.h"
17 #include "ui/ozone/public/surface_factory_ozone.h" 24 #include "ui/ozone/public/surface_factory_ozone.h"
18 #include "ui/ozone/public/surface_ozone_egl.h" 25 #include "ui/ozone/public/surface_ozone_egl.h"
19 26
27 using ui::GetLastEGLErrorString;
28
20 namespace gfx { 29 namespace gfx {
21 30
22 namespace { 31 namespace {
23 32
24 // A thin wrapper around GLSurfaceEGL that owns the EGLNativeWindow 33 // A thin wrapper around GLSurfaceEGL that owns the EGLNativeWindow
25 class GL_EXPORT GLSurfaceOzoneEGL : public NativeViewGLSurfaceEGL { 34 class GL_EXPORT GLSurfaceOzoneEGL : public NativeViewGLSurfaceEGL {
26 public: 35 public:
27 GLSurfaceOzoneEGL(scoped_ptr<ui::SurfaceOzoneEGL> ozone_surface, 36 GLSurfaceOzoneEGL(scoped_ptr<ui::SurfaceOzoneEGL> ozone_surface,
28 AcceleratedWidget widget) 37 AcceleratedWidget widget)
29 : NativeViewGLSurfaceEGL(ozone_surface->GetNativeWindow()), 38 : NativeViewGLSurfaceEGL(ozone_surface->GetNativeWindow()),
(...skipping 19 matching lines...) Expand all
49 return ozone_surface_->OnSwapBuffers(); 58 return ozone_surface_->OnSwapBuffers();
50 } 59 }
51 virtual bool ScheduleOverlayPlane(int z_order, 60 virtual bool ScheduleOverlayPlane(int z_order,
52 OverlayTransform transform, 61 OverlayTransform transform,
53 GLImage* image, 62 GLImage* image,
54 const Rect& bounds_rect, 63 const Rect& bounds_rect,
55 const RectF& crop_rect) override { 64 const RectF& crop_rect) override {
56 return image->ScheduleOverlayPlane( 65 return image->ScheduleOverlayPlane(
57 widget_, z_order, transform, bounds_rect, crop_rect); 66 widget_, z_order, transform, bounds_rect, crop_rect);
58 } 67 }
68 virtual bool SupportsPostSubBuffer() override {
69 return NativeViewGLSurfaceEGL::SupportsPostSubBuffer() &&
70 ozone_surface_->SupportsPartialSwap();
71 }
72
73 #if defined(OZONE_X11)
spang 2014/11/24 18:56:54 please don't use an #ifdef for this, it is very wr
achaulk 2014/11/24 19:28:39 Well it won't work on non-X builds since XGetWindo
74 EGLConfig GetConfig() override {
75 if (!config_) {
76 // Get a config compatible with the window
77 DCHECK(window_);
78 XWindowAttributes win_attribs;
79 if (!XGetWindowAttributes(reinterpret_cast<Display*>(GetNativeDisplay()),
80 window_, &win_attribs)) {
81 return NULL;
82 }
83
84 // Try matching the window depth with an alpha channel,
85 // because we're worried the destination alpha width could
86 // constrain blending precision.
87 const int kBufferSizeOffset = 1;
88 const int kAlphaSizeOffset = 3;
89 EGLint config_attribs[] = {EGL_BUFFER_SIZE,
90 ~0,
91 EGL_ALPHA_SIZE,
92 8,
93 EGL_BLUE_SIZE,
94 8,
95 EGL_GREEN_SIZE,
96 8,
97 EGL_RED_SIZE,
98 8,
99 EGL_RENDERABLE_TYPE,
100 EGL_OPENGL_ES2_BIT,
101 EGL_SURFACE_TYPE,
102 EGL_WINDOW_BIT | EGL_PBUFFER_BIT,
103 EGL_NONE};
104 config_attribs[kBufferSizeOffset] = win_attribs.depth;
105
106 EGLint num_configs;
107 if (!eglChooseConfig(GetDisplay(), config_attribs, &config_, 1,
108 &num_configs)) {
109 LOG(ERROR) << "eglChooseConfig failed with error "
110 << GetLastEGLErrorString();
111 return NULL;
112 }
113
114 if (num_configs) {
115 EGLint config_depth;
116 if (!eglGetConfigAttrib(GetDisplay(), config_, EGL_BUFFER_SIZE,
117 &config_depth)) {
118 LOG(ERROR) << "eglGetConfigAttrib failed with error "
119 << GetLastEGLErrorString();
120 return NULL;
121 }
122
123 if (config_depth == win_attribs.depth) {
124 return config_;
125 }
126 }
127
128 // Try without an alpha channel.
129 config_attribs[kAlphaSizeOffset] = 0;
130 if (!eglChooseConfig(GetDisplay(), config_attribs, &config_, 1,
131 &num_configs)) {
132 LOG(ERROR) << "eglChooseConfig failed with error "
133 << GetLastEGLErrorString();
134 return NULL;
135 }
136
137 if (num_configs == 0) {
138 LOG(ERROR) << "No suitable EGL configs found.";
139 return NULL;
140 }
141 }
142 return config_;
143 }
144 #endif
59 145
60 private: 146 private:
61 using NativeViewGLSurfaceEGL::Initialize; 147 using NativeViewGLSurfaceEGL::Initialize;
62 148
63 virtual ~GLSurfaceOzoneEGL() { 149 virtual ~GLSurfaceOzoneEGL() {
64 Destroy(); // EGL surface must be destroyed before SurfaceOzone 150 Destroy(); // EGL surface must be destroyed before SurfaceOzone
65 } 151 }
66 152
67 bool ReinitializeNativeSurface() { 153 bool ReinitializeNativeSurface() {
68 scoped_ptr<ui::ScopedMakeCurrent> scoped_make_current; 154 scoped_ptr<ui::ScopedMakeCurrent> scoped_make_current;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 GLImage* image, 217 GLImage* image,
132 const Rect& bounds_rect, 218 const Rect& bounds_rect,
133 const RectF& crop_rect) override { 219 const RectF& crop_rect) override {
134 return image->ScheduleOverlayPlane( 220 return image->ScheduleOverlayPlane(
135 widget_, z_order, transform, bounds_rect, crop_rect); 221 widget_, z_order, transform, bounds_rect, crop_rect);
136 } 222 }
137 virtual bool IsOffscreen() override { return false; } 223 virtual bool IsOffscreen() override { return false; }
138 virtual VSyncProvider* GetVSyncProvider() override { 224 virtual VSyncProvider* GetVSyncProvider() override {
139 return vsync_provider_.get(); 225 return vsync_provider_.get();
140 } 226 }
141 virtual bool SupportsPostSubBuffer() override { return true; } 227 virtual bool SupportsPostSubBuffer() override {
228 return ozone_surface_->SupportsPartialSwap();
229 }
142 virtual bool PostSubBuffer(int x, int y, int width, int height) override { 230 virtual bool PostSubBuffer(int x, int y, int width, int height) override {
143 // The actual sub buffer handling is handled at higher layers. 231 // The actual sub buffer handling is handled at higher layers.
144 SwapBuffers(); 232 SwapBuffers();
145 return true; 233 return true;
146 } 234 }
147 235
148 private: 236 private:
149 virtual ~GLSurfaceOzoneSurfaceless() { 237 virtual ~GLSurfaceOzoneSurfaceless() {
150 Destroy(); // EGL surface must be destroyed before SurfaceOzone 238 Destroy(); // EGL surface must be destroyed before SurfaceOzone
151 } 239 }
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 NOTREACHED(); 335 NOTREACHED();
248 return NULL; 336 return NULL;
249 } 337 }
250 } 338 }
251 339
252 EGLNativeDisplayType GetPlatformDefaultEGLNativeDisplay() { 340 EGLNativeDisplayType GetPlatformDefaultEGLNativeDisplay() {
253 return ui::SurfaceFactoryOzone::GetInstance()->GetNativeDisplay(); 341 return ui::SurfaceFactoryOzone::GetInstance()->GetNativeDisplay();
254 } 342 }
255 343
256 } // namespace gfx 344 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698