Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 #include "base/command_line.h" | |
| 7 #include "base/logging.h" | 8 #include "base/logging.h" |
| 8 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 9 #include "ui/gfx/native_widget_types.h" | 10 #include "ui/gfx/native_widget_types.h" |
| 11 #include "ui/gl/egl_util.h" | |
| 10 #include "ui/gl/gl_context.h" | 12 #include "ui/gl/gl_context.h" |
| 11 #include "ui/gl/gl_image.h" | 13 #include "ui/gl/gl_image.h" |
| 12 #include "ui/gl/gl_implementation.h" | 14 #include "ui/gl/gl_implementation.h" |
| 13 #include "ui/gl/gl_surface_egl.h" | 15 #include "ui/gl/gl_surface_egl.h" |
| 14 #include "ui/gl/gl_surface_osmesa.h" | 16 #include "ui/gl/gl_surface_osmesa.h" |
| 15 #include "ui/gl/gl_surface_stub.h" | 17 #include "ui/gl/gl_surface_stub.h" |
| 16 #include "ui/gl/scoped_make_current.h" | 18 #include "ui/gl/scoped_make_current.h" |
| 19 #include "ui/ozone/public/ozone_switches.h" | |
| 17 #include "ui/ozone/public/surface_factory_ozone.h" | 20 #include "ui/ozone/public/surface_factory_ozone.h" |
| 18 #include "ui/ozone/public/surface_ozone_egl.h" | 21 #include "ui/ozone/public/surface_ozone_egl.h" |
| 19 | 22 |
| 23 using ui::GetLastEGLErrorString; | |
| 24 | |
| 20 namespace gfx { | 25 namespace gfx { |
| 21 | 26 |
| 22 namespace { | 27 namespace { |
| 23 | 28 |
| 24 // A thin wrapper around GLSurfaceEGL that owns the EGLNativeWindow | 29 // A thin wrapper around GLSurfaceEGL that owns the EGLNativeWindow |
| 25 class GL_EXPORT GLSurfaceOzoneEGL : public NativeViewGLSurfaceEGL { | 30 class GL_EXPORT GLSurfaceOzoneEGL : public NativeViewGLSurfaceEGL { |
| 26 public: | 31 public: |
| 27 GLSurfaceOzoneEGL(scoped_ptr<ui::SurfaceOzoneEGL> ozone_surface, | 32 GLSurfaceOzoneEGL(scoped_ptr<ui::SurfaceOzoneEGL> ozone_surface, |
| 28 AcceleratedWidget widget) | 33 AcceleratedWidget widget) |
| 29 : NativeViewGLSurfaceEGL(ozone_surface->GetNativeWindow()), | 34 : NativeViewGLSurfaceEGL(ozone_surface->GetNativeWindow()), |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 49 return ozone_surface_->OnSwapBuffers(); | 54 return ozone_surface_->OnSwapBuffers(); |
| 50 } | 55 } |
| 51 virtual bool ScheduleOverlayPlane(int z_order, | 56 virtual bool ScheduleOverlayPlane(int z_order, |
| 52 OverlayTransform transform, | 57 OverlayTransform transform, |
| 53 GLImage* image, | 58 GLImage* image, |
| 54 const Rect& bounds_rect, | 59 const Rect& bounds_rect, |
| 55 const RectF& crop_rect) override { | 60 const RectF& crop_rect) override { |
| 56 return image->ScheduleOverlayPlane( | 61 return image->ScheduleOverlayPlane( |
| 57 widget_, z_order, transform, bounds_rect, crop_rect); | 62 widget_, z_order, transform, bounds_rect, crop_rect); |
| 58 } | 63 } |
| 64 virtual bool SupportsPostSubBuffer() override { | |
| 65 return NativeViewGLSurfaceEGL::SupportsPostSubBuffer() && | |
| 66 ozone_surface_->SupportsPartialSwap(); | |
| 67 } | |
| 68 | |
| 69 EGLConfig GetConfig() override { | |
| 70 if (!config_) { | |
|
spang
2014/12/06 00:31:23
We may want to delegate this whole config-choosing
achaulk
2014/12/08 16:44:41
It is, but it involves calling egl from within ozo
spang
2014/12/09 19:47:33
We were mostly worried about #incuding chrome's ve
| |
| 71 // Try matching the window depth with an alpha channel, | |
| 72 // because we're worried the destination alpha width could | |
| 73 // constrain blending precision. | |
| 74 const int kBufferSizeOffset = 1; | |
| 75 const int kAlphaSizeOffset = 3; | |
| 76 EGLint config_attribs[] = {EGL_BUFFER_SIZE, | |
| 77 ~0, | |
|
spang
2014/12/06 00:31:23
I think this was overridden in the old code? Proba
achaulk
2014/12/08 16:44:41
It's not, but GetEGLSurfaceProperties is doing the
| |
| 78 EGL_ALPHA_SIZE, | |
| 79 8, | |
| 80 EGL_BLUE_SIZE, | |
| 81 8, | |
| 82 EGL_GREEN_SIZE, | |
| 83 8, | |
| 84 EGL_RED_SIZE, | |
| 85 8, | |
| 86 EGL_RENDERABLE_TYPE, | |
| 87 EGL_OPENGL_ES2_BIT, | |
| 88 EGL_SURFACE_TYPE, | |
| 89 EGL_WINDOW_BIT, | |
| 90 EGL_NONE}; | |
| 91 const int32* chosen_attribs = | |
| 92 ui::SurfaceFactoryOzone::GetInstance()->GetEGLSurfaceProperties( | |
| 93 config_attribs, ozone_surface_.get()); | |
| 94 | |
| 95 EGLint num_configs; | |
| 96 if (!eglChooseConfig(GetDisplay(), chosen_attribs, &config_, 1, | |
| 97 &num_configs)) { | |
| 98 LOG(ERROR) << "eglChooseConfig failed with error " | |
| 99 << GetLastEGLErrorString(); | |
| 100 return NULL; | |
| 101 } | |
| 102 | |
| 103 if (num_configs) { | |
| 104 EGLint config_depth; | |
| 105 if (!eglGetConfigAttrib(GetDisplay(), config_, EGL_BUFFER_SIZE, | |
| 106 &config_depth)) { | |
| 107 LOG(ERROR) << "eglGetConfigAttrib failed with error " | |
| 108 << GetLastEGLErrorString(); | |
| 109 return NULL; | |
| 110 } | |
| 111 | |
| 112 if (config_depth == chosen_attribs[kBufferSizeOffset]) { | |
| 113 return config_; | |
| 114 } | |
| 115 } | |
| 116 | |
| 117 // Try without an alpha channel. | |
| 118 config_attribs[kAlphaSizeOffset] = 0; | |
| 119 chosen_attribs = | |
| 120 ui::SurfaceFactoryOzone::GetInstance()->GetEGLSurfaceProperties( | |
| 121 config_attribs, ozone_surface_.get()); | |
| 122 if (!eglChooseConfig(GetDisplay(), chosen_attribs, &config_, 1, | |
| 123 &num_configs)) { | |
| 124 LOG(ERROR) << "eglChooseConfig failed with error " | |
| 125 << GetLastEGLErrorString(); | |
| 126 return NULL; | |
| 127 } | |
| 128 | |
| 129 if (num_configs == 0) { | |
| 130 LOG(ERROR) << "No suitable EGL configs found."; | |
| 131 return NULL; | |
| 132 } | |
| 133 } | |
| 134 return config_; | |
| 135 } | |
| 59 | 136 |
| 60 private: | 137 private: |
| 61 using NativeViewGLSurfaceEGL::Initialize; | 138 using NativeViewGLSurfaceEGL::Initialize; |
| 62 | 139 |
| 63 virtual ~GLSurfaceOzoneEGL() { | 140 virtual ~GLSurfaceOzoneEGL() { |
| 64 Destroy(); // EGL surface must be destroyed before SurfaceOzone | 141 Destroy(); // EGL surface must be destroyed before SurfaceOzone |
| 65 } | 142 } |
| 66 | 143 |
| 67 bool ReinitializeNativeSurface() { | 144 bool ReinitializeNativeSurface() { |
| 68 scoped_ptr<ui::ScopedMakeCurrent> scoped_make_current; | 145 scoped_ptr<ui::ScopedMakeCurrent> scoped_make_current; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 131 GLImage* image, | 208 GLImage* image, |
| 132 const Rect& bounds_rect, | 209 const Rect& bounds_rect, |
| 133 const RectF& crop_rect) override { | 210 const RectF& crop_rect) override { |
| 134 return image->ScheduleOverlayPlane( | 211 return image->ScheduleOverlayPlane( |
| 135 widget_, z_order, transform, bounds_rect, crop_rect); | 212 widget_, z_order, transform, bounds_rect, crop_rect); |
| 136 } | 213 } |
| 137 virtual bool IsOffscreen() override { return false; } | 214 virtual bool IsOffscreen() override { return false; } |
| 138 virtual VSyncProvider* GetVSyncProvider() override { | 215 virtual VSyncProvider* GetVSyncProvider() override { |
| 139 return vsync_provider_.get(); | 216 return vsync_provider_.get(); |
| 140 } | 217 } |
| 141 virtual bool SupportsPostSubBuffer() override { return true; } | 218 virtual bool SupportsPostSubBuffer() override { |
| 219 return ozone_surface_->SupportsPartialSwap(); | |
| 220 } | |
| 142 virtual bool PostSubBuffer(int x, int y, int width, int height) override { | 221 virtual bool PostSubBuffer(int x, int y, int width, int height) override { |
| 143 // The actual sub buffer handling is handled at higher layers. | 222 // The actual sub buffer handling is handled at higher layers. |
| 144 SwapBuffers(); | 223 SwapBuffers(); |
| 145 return true; | 224 return true; |
| 146 } | 225 } |
| 147 | 226 |
| 148 private: | 227 private: |
| 149 virtual ~GLSurfaceOzoneSurfaceless() { | 228 virtual ~GLSurfaceOzoneSurfaceless() { |
| 150 Destroy(); // EGL surface must be destroyed before SurfaceOzone | 229 Destroy(); // EGL surface must be destroyed before SurfaceOzone |
| 151 } | 230 } |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 247 NOTREACHED(); | 326 NOTREACHED(); |
| 248 return NULL; | 327 return NULL; |
| 249 } | 328 } |
| 250 } | 329 } |
| 251 | 330 |
| 252 EGLNativeDisplayType GetPlatformDefaultEGLNativeDisplay() { | 331 EGLNativeDisplayType GetPlatformDefaultEGLNativeDisplay() { |
| 253 return ui::SurfaceFactoryOzone::GetInstance()->GetNativeDisplay(); | 332 return ui::SurfaceFactoryOzone::GetInstance()->GetNativeDisplay(); |
| 254 } | 333 } |
| 255 | 334 |
| 256 } // namespace gfx | 335 } // namespace gfx |
| OLD | NEW |