| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 #include "ui/gl/gl_surface_stub.h" | 27 #include "ui/gl/gl_surface_stub.h" |
| 28 #include "ui/gl/scoped_binders.h" | 28 #include "ui/gl/scoped_binders.h" |
| 29 #include "ui/gl/scoped_make_current.h" | 29 #include "ui/gl/scoped_make_current.h" |
| 30 #include "ui/ozone/public/native_pixmap.h" | 30 #include "ui/ozone/public/native_pixmap.h" |
| 31 #include "ui/ozone/public/ozone_platform.h" | 31 #include "ui/ozone/public/ozone_platform.h" |
| 32 #include "ui/ozone/public/surface_factory_ozone.h" | 32 #include "ui/ozone/public/surface_factory_ozone.h" |
| 33 #include "ui/ozone/public/surface_ozone_egl.h" | 33 #include "ui/ozone/public/surface_ozone_egl.h" |
| 34 | 34 |
| 35 using gl::GLImage; | 35 using gl::GLImage; |
| 36 | 36 |
| 37 namespace gfx { | 37 namespace gl { |
| 38 | 38 |
| 39 namespace { | 39 namespace { |
| 40 | 40 |
| 41 // Helper function for base::Bind to create callback to eglChooseConfig. | 41 // Helper function for base::Bind to create callback to eglChooseConfig. |
| 42 bool EglChooseConfig(EGLDisplay display, | 42 bool EglChooseConfig(EGLDisplay display, |
| 43 const int32_t* attribs, | 43 const int32_t* attribs, |
| 44 EGLConfig* configs, | 44 EGLConfig* configs, |
| 45 int32_t config_size, | 45 int32_t config_size, |
| 46 int32_t* num_configs) { | 46 int32_t* num_configs) { |
| 47 return eglChooseConfig(display, attribs, configs, config_size, num_configs); | 47 return eglChooseConfig(display, attribs, configs, config_size, num_configs); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 66 | 66 |
| 67 void WaitForFence(EGLDisplay display, EGLSyncKHR fence) { | 67 void WaitForFence(EGLDisplay display, EGLSyncKHR fence) { |
| 68 eglClientWaitSyncKHR(display, fence, EGL_SYNC_FLUSH_COMMANDS_BIT_KHR, | 68 eglClientWaitSyncKHR(display, fence, EGL_SYNC_FLUSH_COMMANDS_BIT_KHR, |
| 69 EGL_FOREVER_KHR); | 69 EGL_FOREVER_KHR); |
| 70 } | 70 } |
| 71 | 71 |
| 72 // A thin wrapper around GLSurfaceEGL that owns the EGLNativeWindow. | 72 // A thin wrapper around GLSurfaceEGL that owns the EGLNativeWindow. |
| 73 class GL_EXPORT GLSurfaceOzoneEGL : public NativeViewGLSurfaceEGL { | 73 class GL_EXPORT GLSurfaceOzoneEGL : public NativeViewGLSurfaceEGL { |
| 74 public: | 74 public: |
| 75 GLSurfaceOzoneEGL(std::unique_ptr<ui::SurfaceOzoneEGL> ozone_surface, | 75 GLSurfaceOzoneEGL(std::unique_ptr<ui::SurfaceOzoneEGL> ozone_surface, |
| 76 AcceleratedWidget widget); | 76 gfx::AcceleratedWidget widget); |
| 77 | 77 |
| 78 // GLSurface: | 78 // GLSurface: |
| 79 bool Initialize(gfx::GLSurface::Format format) override; | 79 bool Initialize(gl::GLSurface::Format format) override; |
| 80 bool Resize(const gfx::Size& size, | 80 bool Resize(const gfx::Size& size, |
| 81 float scale_factor, | 81 float scale_factor, |
| 82 bool has_alpha) override; | 82 bool has_alpha) override; |
| 83 gfx::SwapResult SwapBuffers() override; | 83 gfx::SwapResult SwapBuffers() override; |
| 84 bool ScheduleOverlayPlane(int z_order, | 84 bool ScheduleOverlayPlane(int z_order, |
| 85 OverlayTransform transform, | 85 gfx::OverlayTransform transform, |
| 86 GLImage* image, | 86 GLImage* image, |
| 87 const Rect& bounds_rect, | 87 const gfx::Rect& bounds_rect, |
| 88 const RectF& crop_rect) override; | 88 const gfx::RectF& crop_rect) override; |
| 89 EGLConfig GetConfig() override; | 89 EGLConfig GetConfig() override; |
| 90 | 90 |
| 91 private: | 91 private: |
| 92 using NativeViewGLSurfaceEGL::Initialize; | 92 using NativeViewGLSurfaceEGL::Initialize; |
| 93 | 93 |
| 94 ~GLSurfaceOzoneEGL() override; | 94 ~GLSurfaceOzoneEGL() override; |
| 95 | 95 |
| 96 bool ReinitializeNativeSurface(); | 96 bool ReinitializeNativeSurface(); |
| 97 | 97 |
| 98 // The native surface. Deleting this is allowed to free the EGLNativeWindow. | 98 // The native surface. Deleting this is allowed to free the EGLNativeWindow. |
| 99 std::unique_ptr<ui::SurfaceOzoneEGL> ozone_surface_; | 99 std::unique_ptr<ui::SurfaceOzoneEGL> ozone_surface_; |
| 100 AcceleratedWidget widget_; | 100 gfx::AcceleratedWidget widget_; |
| 101 | 101 |
| 102 DISALLOW_COPY_AND_ASSIGN(GLSurfaceOzoneEGL); | 102 DISALLOW_COPY_AND_ASSIGN(GLSurfaceOzoneEGL); |
| 103 }; | 103 }; |
| 104 | 104 |
| 105 GLSurfaceOzoneEGL::GLSurfaceOzoneEGL( | 105 GLSurfaceOzoneEGL::GLSurfaceOzoneEGL( |
| 106 std::unique_ptr<ui::SurfaceOzoneEGL> ozone_surface, | 106 std::unique_ptr<ui::SurfaceOzoneEGL> ozone_surface, |
| 107 AcceleratedWidget widget) | 107 gfx::AcceleratedWidget widget) |
| 108 : NativeViewGLSurfaceEGL(ozone_surface->GetNativeWindow()), | 108 : NativeViewGLSurfaceEGL(ozone_surface->GetNativeWindow()), |
| 109 ozone_surface_(std::move(ozone_surface)), | 109 ozone_surface_(std::move(ozone_surface)), |
| 110 widget_(widget) {} | 110 widget_(widget) {} |
| 111 | 111 |
| 112 bool GLSurfaceOzoneEGL::Initialize(gfx::GLSurface::Format format) { | 112 bool GLSurfaceOzoneEGL::Initialize(gl::GLSurface::Format format) { |
| 113 format_ = format; | 113 format_ = format; |
| 114 return Initialize(ozone_surface_->CreateVSyncProvider()); | 114 return Initialize(ozone_surface_->CreateVSyncProvider()); |
| 115 } | 115 } |
| 116 | 116 |
| 117 bool GLSurfaceOzoneEGL::Resize(const gfx::Size& size, | 117 bool GLSurfaceOzoneEGL::Resize(const gfx::Size& size, |
| 118 float scale_factor, | 118 float scale_factor, |
| 119 bool has_alpha) { | 119 bool has_alpha) { |
| 120 if (!ozone_surface_->ResizeNativeWindow(size)) { | 120 if (!ozone_surface_->ResizeNativeWindow(size)) { |
| 121 if (!ReinitializeNativeSurface() || | 121 if (!ReinitializeNativeSurface() || |
| 122 !ozone_surface_->ResizeNativeWindow(size)) | 122 !ozone_surface_->ResizeNativeWindow(size)) |
| 123 return false; | 123 return false; |
| 124 } | 124 } |
| 125 | 125 |
| 126 return NativeViewGLSurfaceEGL::Resize(size, scale_factor, has_alpha); | 126 return NativeViewGLSurfaceEGL::Resize(size, scale_factor, has_alpha); |
| 127 } | 127 } |
| 128 | 128 |
| 129 gfx::SwapResult GLSurfaceOzoneEGL::SwapBuffers() { | 129 gfx::SwapResult GLSurfaceOzoneEGL::SwapBuffers() { |
| 130 gfx::SwapResult result = NativeViewGLSurfaceEGL::SwapBuffers(); | 130 gfx::SwapResult result = NativeViewGLSurfaceEGL::SwapBuffers(); |
| 131 if (result != gfx::SwapResult::SWAP_ACK) | 131 if (result != gfx::SwapResult::SWAP_ACK) |
| 132 return result; | 132 return result; |
| 133 | 133 |
| 134 return ozone_surface_->OnSwapBuffers() ? gfx::SwapResult::SWAP_ACK | 134 return ozone_surface_->OnSwapBuffers() ? gfx::SwapResult::SWAP_ACK |
| 135 : gfx::SwapResult::SWAP_FAILED; | 135 : gfx::SwapResult::SWAP_FAILED; |
| 136 } | 136 } |
| 137 | 137 |
| 138 bool GLSurfaceOzoneEGL::ScheduleOverlayPlane(int z_order, | 138 bool GLSurfaceOzoneEGL::ScheduleOverlayPlane(int z_order, |
| 139 OverlayTransform transform, | 139 gfx::OverlayTransform transform, |
| 140 GLImage* image, | 140 GLImage* image, |
| 141 const Rect& bounds_rect, | 141 const gfx::Rect& bounds_rect, |
| 142 const RectF& crop_rect) { | 142 const gfx::RectF& crop_rect) { |
| 143 return image->ScheduleOverlayPlane(widget_, z_order, transform, bounds_rect, | 143 return image->ScheduleOverlayPlane(widget_, z_order, transform, bounds_rect, |
| 144 crop_rect); | 144 crop_rect); |
| 145 } | 145 } |
| 146 | 146 |
| 147 EGLConfig GLSurfaceOzoneEGL::GetConfig() { | 147 EGLConfig GLSurfaceOzoneEGL::GetConfig() { |
| 148 if (!config_) { | 148 if (!config_) { |
| 149 ui::EglConfigCallbacks callbacks = GetEglConfigCallbacks(GetDisplay()); | 149 ui::EglConfigCallbacks callbacks = GetEglConfigCallbacks(GetDisplay()); |
| 150 config_ = ozone_surface_->GetEGLSurfaceConfig(callbacks); | 150 config_ = ozone_surface_->GetEGLSurfaceConfig(callbacks); |
| 151 } | 151 } |
| 152 if (config_) | 152 if (config_) |
| (...skipping 27 matching lines...) Expand all Loading... |
| 180 LOG(ERROR) << "Failed to initialize."; | 180 LOG(ERROR) << "Failed to initialize."; |
| 181 return false; | 181 return false; |
| 182 } | 182 } |
| 183 | 183 |
| 184 return true; | 184 return true; |
| 185 } | 185 } |
| 186 | 186 |
| 187 class GL_EXPORT GLSurfaceOzoneSurfaceless : public SurfacelessEGL { | 187 class GL_EXPORT GLSurfaceOzoneSurfaceless : public SurfacelessEGL { |
| 188 public: | 188 public: |
| 189 GLSurfaceOzoneSurfaceless(std::unique_ptr<ui::SurfaceOzoneEGL> ozone_surface, | 189 GLSurfaceOzoneSurfaceless(std::unique_ptr<ui::SurfaceOzoneEGL> ozone_surface, |
| 190 AcceleratedWidget widget); | 190 gfx::AcceleratedWidget widget); |
| 191 | 191 |
| 192 // GLSurface: | 192 // GLSurface: |
| 193 bool Initialize(gfx::GLSurface::Format format) override; | 193 bool Initialize(gl::GLSurface::Format format) override; |
| 194 bool Resize(const gfx::Size& size, | 194 bool Resize(const gfx::Size& size, |
| 195 float scale_factor, | 195 float scale_factor, |
| 196 bool has_alpha) override; | 196 bool has_alpha) override; |
| 197 gfx::SwapResult SwapBuffers() override; | 197 gfx::SwapResult SwapBuffers() override; |
| 198 bool ScheduleOverlayPlane(int z_order, | 198 bool ScheduleOverlayPlane(int z_order, |
| 199 OverlayTransform transform, | 199 gfx::OverlayTransform transform, |
| 200 GLImage* image, | 200 GLImage* image, |
| 201 const Rect& bounds_rect, | 201 const gfx::Rect& bounds_rect, |
| 202 const RectF& crop_rect) override; | 202 const gfx::RectF& crop_rect) override; |
| 203 bool IsOffscreen() override; | 203 bool IsOffscreen() override; |
| 204 VSyncProvider* GetVSyncProvider() override; | 204 gfx::VSyncProvider* GetVSyncProvider() override; |
| 205 bool SupportsAsyncSwap() override; | 205 bool SupportsAsyncSwap() override; |
| 206 bool SupportsPostSubBuffer() override; | 206 bool SupportsPostSubBuffer() override; |
| 207 gfx::SwapResult PostSubBuffer(int x, int y, int width, int height) override; | 207 gfx::SwapResult PostSubBuffer(int x, int y, int width, int height) override; |
| 208 void SwapBuffersAsync(const SwapCompletionCallback& callback) override; | 208 void SwapBuffersAsync(const SwapCompletionCallback& callback) override; |
| 209 void PostSubBufferAsync(int x, | 209 void PostSubBufferAsync(int x, |
| 210 int y, | 210 int y, |
| 211 int width, | 211 int width, |
| 212 int height, | 212 int height, |
| 213 const SwapCompletionCallback& callback) override; | 213 const SwapCompletionCallback& callback) override; |
| 214 EGLConfig GetConfig() override; | 214 EGLConfig GetConfig() override; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 229 void SubmitFrame(); | 229 void SubmitFrame(); |
| 230 | 230 |
| 231 EGLSyncKHR InsertFence(); | 231 EGLSyncKHR InsertFence(); |
| 232 void FenceRetired(EGLSyncKHR fence, PendingFrame* frame); | 232 void FenceRetired(EGLSyncKHR fence, PendingFrame* frame); |
| 233 | 233 |
| 234 void SwapCompleted(const SwapCompletionCallback& callback, | 234 void SwapCompleted(const SwapCompletionCallback& callback, |
| 235 gfx::SwapResult result); | 235 gfx::SwapResult result); |
| 236 | 236 |
| 237 // The native surface. Deleting this is allowed to free the EGLNativeWindow. | 237 // The native surface. Deleting this is allowed to free the EGLNativeWindow. |
| 238 std::unique_ptr<ui::SurfaceOzoneEGL> ozone_surface_; | 238 std::unique_ptr<ui::SurfaceOzoneEGL> ozone_surface_; |
| 239 AcceleratedWidget widget_; | 239 gfx::AcceleratedWidget widget_; |
| 240 std::unique_ptr<VSyncProvider> vsync_provider_; | 240 std::unique_ptr<gfx::VSyncProvider> vsync_provider_; |
| 241 ScopedVector<PendingFrame> unsubmitted_frames_; | 241 ScopedVector<PendingFrame> unsubmitted_frames_; |
| 242 bool has_implicit_external_sync_; | 242 bool has_implicit_external_sync_; |
| 243 bool last_swap_buffers_result_; | 243 bool last_swap_buffers_result_; |
| 244 bool swap_buffers_pending_; | 244 bool swap_buffers_pending_; |
| 245 | 245 |
| 246 base::WeakPtrFactory<GLSurfaceOzoneSurfaceless> weak_factory_; | 246 base::WeakPtrFactory<GLSurfaceOzoneSurfaceless> weak_factory_; |
| 247 | 247 |
| 248 private: | 248 private: |
| 249 DISALLOW_COPY_AND_ASSIGN(GLSurfaceOzoneSurfaceless); | 249 DISALLOW_COPY_AND_ASSIGN(GLSurfaceOzoneSurfaceless); |
| 250 }; | 250 }; |
| 251 | 251 |
| 252 GLSurfaceOzoneSurfaceless::PendingFrame::PendingFrame() : ready(false) {} | 252 GLSurfaceOzoneSurfaceless::PendingFrame::PendingFrame() : ready(false) {} |
| 253 | 253 |
| 254 bool GLSurfaceOzoneSurfaceless::PendingFrame::ScheduleOverlayPlanes( | 254 bool GLSurfaceOzoneSurfaceless::PendingFrame::ScheduleOverlayPlanes( |
| 255 gfx::AcceleratedWidget widget) { | 255 gfx::AcceleratedWidget widget) { |
| 256 for (const auto& overlay : overlays) | 256 for (const auto& overlay : overlays) |
| 257 if (!overlay.ScheduleOverlayPlane(widget)) | 257 if (!overlay.ScheduleOverlayPlane(widget)) |
| 258 return false; | 258 return false; |
| 259 return true; | 259 return true; |
| 260 } | 260 } |
| 261 | 261 |
| 262 GLSurfaceOzoneSurfaceless::GLSurfaceOzoneSurfaceless( | 262 GLSurfaceOzoneSurfaceless::GLSurfaceOzoneSurfaceless( |
| 263 std::unique_ptr<ui::SurfaceOzoneEGL> ozone_surface, | 263 std::unique_ptr<ui::SurfaceOzoneEGL> ozone_surface, |
| 264 AcceleratedWidget widget) | 264 gfx::AcceleratedWidget widget) |
| 265 : SurfacelessEGL(gfx::Size()), | 265 : SurfacelessEGL(gfx::Size()), |
| 266 ozone_surface_(std::move(ozone_surface)), | 266 ozone_surface_(std::move(ozone_surface)), |
| 267 widget_(widget), | 267 widget_(widget), |
| 268 has_implicit_external_sync_( | 268 has_implicit_external_sync_( |
| 269 HasEGLExtension("EGL_ARM_implicit_external_sync")), | 269 HasEGLExtension("EGL_ARM_implicit_external_sync")), |
| 270 last_swap_buffers_result_(true), | 270 last_swap_buffers_result_(true), |
| 271 swap_buffers_pending_(false), | 271 swap_buffers_pending_(false), |
| 272 weak_factory_(this) { | 272 weak_factory_(this) { |
| 273 unsubmitted_frames_.push_back(new PendingFrame()); | 273 unsubmitted_frames_.push_back(new PendingFrame()); |
| 274 } | 274 } |
| 275 | 275 |
| 276 bool GLSurfaceOzoneSurfaceless::Initialize(gfx::GLSurface::Format format) { | 276 bool GLSurfaceOzoneSurfaceless::Initialize(gl::GLSurface::Format format) { |
| 277 if (!SurfacelessEGL::Initialize(format)) | 277 if (!SurfacelessEGL::Initialize(format)) |
| 278 return false; | 278 return false; |
| 279 vsync_provider_ = ozone_surface_->CreateVSyncProvider(); | 279 vsync_provider_ = ozone_surface_->CreateVSyncProvider(); |
| 280 if (!vsync_provider_) | 280 if (!vsync_provider_) |
| 281 return false; | 281 return false; |
| 282 return true; | 282 return true; |
| 283 } | 283 } |
| 284 | 284 |
| 285 bool GLSurfaceOzoneSurfaceless::Resize(const gfx::Size& size, | 285 bool GLSurfaceOzoneSurfaceless::Resize(const gfx::Size& size, |
| 286 float scale_factor, | 286 float scale_factor, |
| 287 bool has_alpha) { | 287 bool has_alpha) { |
| 288 if (!ozone_surface_->ResizeNativeWindow(size)) | 288 if (!ozone_surface_->ResizeNativeWindow(size)) |
| 289 return false; | 289 return false; |
| 290 | 290 |
| 291 return SurfacelessEGL::Resize(size, scale_factor, has_alpha); | 291 return SurfacelessEGL::Resize(size, scale_factor, has_alpha); |
| 292 } | 292 } |
| 293 | 293 |
| 294 gfx::SwapResult GLSurfaceOzoneSurfaceless::SwapBuffers() { | 294 gfx::SwapResult GLSurfaceOzoneSurfaceless::SwapBuffers() { |
| 295 glFlush(); | 295 glFlush(); |
| 296 // TODO: the following should be replaced by a per surface flush as it gets | 296 // TODO: the following should be replaced by a per surface flush as it gets |
| 297 // implemented in GL drivers. | 297 // implemented in GL drivers. |
| 298 if (has_implicit_external_sync_) { | 298 if (has_implicit_external_sync_) { |
| 299 EGLSyncKHR fence = InsertFence(); | 299 EGLSyncKHR fence = InsertFence(); |
| 300 if (!fence) | 300 if (!fence) |
| 301 return SwapResult::SWAP_FAILED; | 301 return gfx::SwapResult::SWAP_FAILED; |
| 302 | 302 |
| 303 EGLDisplay display = GetDisplay(); | 303 EGLDisplay display = GetDisplay(); |
| 304 WaitForFence(display, fence); | 304 WaitForFence(display, fence); |
| 305 eglDestroySyncKHR(display, fence); | 305 eglDestroySyncKHR(display, fence); |
| 306 } | 306 } |
| 307 | 307 |
| 308 unsubmitted_frames_.back()->ScheduleOverlayPlanes(widget_); | 308 unsubmitted_frames_.back()->ScheduleOverlayPlanes(widget_); |
| 309 unsubmitted_frames_.back()->overlays.clear(); | 309 unsubmitted_frames_.back()->overlays.clear(); |
| 310 | 310 |
| 311 if (ozone_surface_->IsUniversalDisplayLinkDevice()) | 311 if (ozone_surface_->IsUniversalDisplayLinkDevice()) |
| 312 glFinish(); | 312 glFinish(); |
| 313 | 313 |
| 314 return ozone_surface_->OnSwapBuffers() ? gfx::SwapResult::SWAP_ACK | 314 return ozone_surface_->OnSwapBuffers() ? gfx::SwapResult::SWAP_ACK |
| 315 : gfx::SwapResult::SWAP_FAILED; | 315 : gfx::SwapResult::SWAP_FAILED; |
| 316 } | 316 } |
| 317 | 317 |
| 318 bool GLSurfaceOzoneSurfaceless::ScheduleOverlayPlane(int z_order, | 318 bool GLSurfaceOzoneSurfaceless::ScheduleOverlayPlane( |
| 319 OverlayTransform transform, | 319 int z_order, |
| 320 GLImage* image, | 320 gfx::OverlayTransform transform, |
| 321 const Rect& bounds_rect, | 321 GLImage* image, |
| 322 const RectF& crop_rect) { | 322 const gfx::Rect& bounds_rect, |
| 323 const gfx::RectF& crop_rect) { |
| 323 unsubmitted_frames_.back()->overlays.push_back( | 324 unsubmitted_frames_.back()->overlays.push_back( |
| 324 GLSurfaceOverlay(z_order, transform, image, bounds_rect, crop_rect)); | 325 GLSurfaceOverlay(z_order, transform, image, bounds_rect, crop_rect)); |
| 325 return true; | 326 return true; |
| 326 } | 327 } |
| 327 | 328 |
| 328 bool GLSurfaceOzoneSurfaceless::IsOffscreen() { | 329 bool GLSurfaceOzoneSurfaceless::IsOffscreen() { |
| 329 return false; | 330 return false; |
| 330 } | 331 } |
| 331 | 332 |
| 332 VSyncProvider* GLSurfaceOzoneSurfaceless::GetVSyncProvider() { | 333 gfx::VSyncProvider* GLSurfaceOzoneSurfaceless::GetVSyncProvider() { |
| 333 return vsync_provider_.get(); | 334 return vsync_provider_.get(); |
| 334 } | 335 } |
| 335 | 336 |
| 336 bool GLSurfaceOzoneSurfaceless::SupportsAsyncSwap() { | 337 bool GLSurfaceOzoneSurfaceless::SupportsAsyncSwap() { |
| 337 return true; | 338 return true; |
| 338 } | 339 } |
| 339 | 340 |
| 340 bool GLSurfaceOzoneSurfaceless::SupportsPostSubBuffer() { | 341 bool GLSurfaceOzoneSurfaceless::SupportsPostSubBuffer() { |
| 341 return true; | 342 return true; |
| 342 } | 343 } |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 SubmitFrame(); | 467 SubmitFrame(); |
| 467 } | 468 } |
| 468 | 469 |
| 469 // This provides surface-like semantics implemented through surfaceless. | 470 // This provides surface-like semantics implemented through surfaceless. |
| 470 // A framebuffer is bound automatically. | 471 // A framebuffer is bound automatically. |
| 471 class GL_EXPORT GLSurfaceOzoneSurfacelessSurfaceImpl | 472 class GL_EXPORT GLSurfaceOzoneSurfacelessSurfaceImpl |
| 472 : public GLSurfaceOzoneSurfaceless { | 473 : public GLSurfaceOzoneSurfaceless { |
| 473 public: | 474 public: |
| 474 GLSurfaceOzoneSurfacelessSurfaceImpl( | 475 GLSurfaceOzoneSurfacelessSurfaceImpl( |
| 475 std::unique_ptr<ui::SurfaceOzoneEGL> ozone_surface, | 476 std::unique_ptr<ui::SurfaceOzoneEGL> ozone_surface, |
| 476 AcceleratedWidget widget); | 477 gfx::AcceleratedWidget widget); |
| 477 | 478 |
| 478 // GLSurface: | 479 // GLSurface: |
| 479 unsigned int GetBackingFrameBufferObject() override; | 480 unsigned int GetBackingFrameBufferObject() override; |
| 480 bool OnMakeCurrent(GLContext* context) override; | 481 bool OnMakeCurrent(GLContext* context) override; |
| 481 bool Resize(const gfx::Size& size, | 482 bool Resize(const gfx::Size& size, |
| 482 float scale_factor, | 483 float scale_factor, |
| 483 bool has_alpha) override; | 484 bool has_alpha) override; |
| 484 bool SupportsPostSubBuffer() override; | 485 bool SupportsPostSubBuffer() override; |
| 485 gfx::SwapResult SwapBuffers() override; | 486 gfx::SwapResult SwapBuffers() override; |
| 486 void SwapBuffersAsync(const SwapCompletionCallback& callback) override; | 487 void SwapBuffersAsync(const SwapCompletionCallback& callback) override; |
| 487 void Destroy() override; | 488 void Destroy() override; |
| 488 bool IsSurfaceless() const override; | 489 bool IsSurfaceless() const override; |
| 489 | 490 |
| 490 private: | 491 private: |
| 491 ~GLSurfaceOzoneSurfacelessSurfaceImpl() override; | 492 ~GLSurfaceOzoneSurfacelessSurfaceImpl() override; |
| 492 | 493 |
| 493 void BindFramebuffer(); | 494 void BindFramebuffer(); |
| 494 bool CreatePixmaps(); | 495 bool CreatePixmaps(); |
| 495 | 496 |
| 496 scoped_refptr<GLContext> context_; | 497 scoped_refptr<GLContext> context_; |
| 497 GLuint fbo_; | 498 GLuint fbo_; |
| 498 GLuint textures_[2]; | 499 GLuint textures_[2]; |
| 499 scoped_refptr<GLImage> images_[2]; | 500 scoped_refptr<GLImage> images_[2]; |
| 500 int current_surface_; | 501 int current_surface_; |
| 501 DISALLOW_COPY_AND_ASSIGN(GLSurfaceOzoneSurfacelessSurfaceImpl); | 502 DISALLOW_COPY_AND_ASSIGN(GLSurfaceOzoneSurfacelessSurfaceImpl); |
| 502 }; | 503 }; |
| 503 | 504 |
| 504 GLSurfaceOzoneSurfacelessSurfaceImpl::GLSurfaceOzoneSurfacelessSurfaceImpl( | 505 GLSurfaceOzoneSurfacelessSurfaceImpl::GLSurfaceOzoneSurfacelessSurfaceImpl( |
| 505 std::unique_ptr<ui::SurfaceOzoneEGL> ozone_surface, | 506 std::unique_ptr<ui::SurfaceOzoneEGL> ozone_surface, |
| 506 AcceleratedWidget widget) | 507 gfx::AcceleratedWidget widget) |
| 507 : GLSurfaceOzoneSurfaceless(std::move(ozone_surface), widget), | 508 : GLSurfaceOzoneSurfaceless(std::move(ozone_surface), widget), |
| 508 context_(nullptr), | 509 context_(nullptr), |
| 509 fbo_(0), | 510 fbo_(0), |
| 510 current_surface_(0) { | 511 current_surface_(0) { |
| 511 for (auto& texture : textures_) | 512 for (auto& texture : textures_) |
| 512 texture = 0; | 513 texture = 0; |
| 513 } | 514 } |
| 514 | 515 |
| 515 unsigned int | 516 unsigned int |
| 516 GLSurfaceOzoneSurfacelessSurfaceImpl::GetBackingFrameBufferObject() { | 517 GLSurfaceOzoneSurfacelessSurfaceImpl::GetBackingFrameBufferObject() { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 543 return GLSurfaceOzoneSurfaceless::Resize(size, scale_factor, true) && | 544 return GLSurfaceOzoneSurfaceless::Resize(size, scale_factor, true) && |
| 544 CreatePixmaps(); | 545 CreatePixmaps(); |
| 545 } | 546 } |
| 546 | 547 |
| 547 bool GLSurfaceOzoneSurfacelessSurfaceImpl::SupportsPostSubBuffer() { | 548 bool GLSurfaceOzoneSurfacelessSurfaceImpl::SupportsPostSubBuffer() { |
| 548 return false; | 549 return false; |
| 549 } | 550 } |
| 550 | 551 |
| 551 gfx::SwapResult GLSurfaceOzoneSurfacelessSurfaceImpl::SwapBuffers() { | 552 gfx::SwapResult GLSurfaceOzoneSurfacelessSurfaceImpl::SwapBuffers() { |
| 552 if (!images_[current_surface_]->ScheduleOverlayPlane( | 553 if (!images_[current_surface_]->ScheduleOverlayPlane( |
| 553 widget_, 0, OverlayTransform::OVERLAY_TRANSFORM_NONE, | 554 widget_, 0, gfx::OverlayTransform::OVERLAY_TRANSFORM_NONE, |
| 554 gfx::Rect(GetSize()), gfx::RectF(1, 1))) | 555 gfx::Rect(GetSize()), gfx::RectF(1, 1))) |
| 555 return gfx::SwapResult::SWAP_FAILED; | 556 return gfx::SwapResult::SWAP_FAILED; |
| 556 gfx::SwapResult result = GLSurfaceOzoneSurfaceless::SwapBuffers(); | 557 gfx::SwapResult result = GLSurfaceOzoneSurfaceless::SwapBuffers(); |
| 557 if (result != gfx::SwapResult::SWAP_ACK) | 558 if (result != gfx::SwapResult::SWAP_ACK) |
| 558 return result; | 559 return result; |
| 559 current_surface_ ^= 1; | 560 current_surface_ ^= 1; |
| 560 BindFramebuffer(); | 561 BindFramebuffer(); |
| 561 return gfx::SwapResult::SWAP_ACK; | 562 return gfx::SwapResult::SWAP_ACK; |
| 562 } | 563 } |
| 563 | 564 |
| 564 void GLSurfaceOzoneSurfacelessSurfaceImpl::SwapBuffersAsync( | 565 void GLSurfaceOzoneSurfacelessSurfaceImpl::SwapBuffersAsync( |
| 565 const SwapCompletionCallback& callback) { | 566 const SwapCompletionCallback& callback) { |
| 566 if (!images_[current_surface_]->ScheduleOverlayPlane( | 567 if (!images_[current_surface_]->ScheduleOverlayPlane( |
| 567 widget_, 0, OverlayTransform::OVERLAY_TRANSFORM_NONE, | 568 widget_, 0, gfx::OverlayTransform::OVERLAY_TRANSFORM_NONE, |
| 568 gfx::Rect(GetSize()), gfx::RectF(1, 1))) { | 569 gfx::Rect(GetSize()), gfx::RectF(1, 1))) { |
| 569 callback.Run(gfx::SwapResult::SWAP_FAILED); | 570 callback.Run(gfx::SwapResult::SWAP_FAILED); |
| 570 return; | 571 return; |
| 571 } | 572 } |
| 572 GLSurfaceOzoneSurfaceless::SwapBuffersAsync(callback); | 573 GLSurfaceOzoneSurfaceless::SwapBuffersAsync(callback); |
| 573 current_surface_ ^= 1; | 574 current_surface_ ^= 1; |
| 574 BindFramebuffer(); | 575 BindFramebuffer(); |
| 575 } | 576 } |
| 576 | 577 |
| 577 void GLSurfaceOzoneSurfacelessSurfaceImpl::Destroy() { | 578 void GLSurfaceOzoneSurfacelessSurfaceImpl::Destroy() { |
| 578 if (!context_) | 579 if (!context_) |
| 579 return; | 580 return; |
| 580 scoped_refptr<gfx::GLContext> previous_context = gfx::GLContext::GetCurrent(); | 581 scoped_refptr<gl::GLContext> previous_context = gl::GLContext::GetCurrent(); |
| 581 scoped_refptr<gfx::GLSurface> previous_surface; | 582 scoped_refptr<gl::GLSurface> previous_surface; |
| 582 | 583 |
| 583 bool was_current = previous_context && previous_context->IsCurrent(nullptr) && | 584 bool was_current = previous_context && previous_context->IsCurrent(nullptr) && |
| 584 gfx::GLSurface::GetCurrent() == this; | 585 gl::GLSurface::GetCurrent() == this; |
| 585 if (!was_current) { | 586 if (!was_current) { |
| 586 // Only take a reference to previous surface if it's not |this| | 587 // Only take a reference to previous surface if it's not |this| |
| 587 // because otherwise we can take a self reference from our own dtor. | 588 // because otherwise we can take a self reference from our own dtor. |
| 588 previous_surface = gfx::GLSurface::GetCurrent(); | 589 previous_surface = gl::GLSurface::GetCurrent(); |
| 589 context_->MakeCurrent(this); | 590 context_->MakeCurrent(this); |
| 590 } | 591 } |
| 591 | 592 |
| 592 glBindFramebufferEXT(GL_FRAMEBUFFER, 0); | 593 glBindFramebufferEXT(GL_FRAMEBUFFER, 0); |
| 593 if (fbo_) { | 594 if (fbo_) { |
| 594 glDeleteTextures(arraysize(textures_), textures_); | 595 glDeleteTextures(arraysize(textures_), textures_); |
| 595 for (auto& texture : textures_) | 596 for (auto& texture : textures_) |
| 596 texture = 0; | 597 texture = 0; |
| 597 glDeleteFramebuffersEXT(1, &fbo_); | 598 glDeleteFramebuffersEXT(1, &fbo_); |
| 598 fbo_ = 0; | 599 fbo_ = 0; |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 700 return true; | 701 return true; |
| 701 default: | 702 default: |
| 702 return false; | 703 return false; |
| 703 } | 704 } |
| 704 } | 705 } |
| 705 | 706 |
| 706 // static | 707 // static |
| 707 scoped_refptr<GLSurface> GLSurface::CreateSurfacelessViewGLSurface( | 708 scoped_refptr<GLSurface> GLSurface::CreateSurfacelessViewGLSurface( |
| 708 gfx::AcceleratedWidget window) { | 709 gfx::AcceleratedWidget window) { |
| 709 if (GetGLImplementation() == kGLImplementationEGLGLES2 && | 710 if (GetGLImplementation() == kGLImplementationEGLGLES2 && |
| 710 window != kNullAcceleratedWidget && | 711 window != gfx::kNullAcceleratedWidget && |
| 711 GLSurfaceEGL::IsEGLSurfacelessContextSupported()) { | 712 GLSurfaceEGL::IsEGLSurfacelessContextSupported()) { |
| 712 std::unique_ptr<ui::SurfaceOzoneEGL> surface_ozone = | 713 std::unique_ptr<ui::SurfaceOzoneEGL> surface_ozone = |
| 713 ui::OzonePlatform::GetInstance() | 714 ui::OzonePlatform::GetInstance() |
| 714 ->GetSurfaceFactoryOzone() | 715 ->GetSurfaceFactoryOzone() |
| 715 ->CreateSurfacelessEGLSurfaceForWidget(window); | 716 ->CreateSurfacelessEGLSurfaceForWidget(window); |
| 716 if (!surface_ozone) | 717 if (!surface_ozone) |
| 717 return nullptr; | 718 return nullptr; |
| 718 scoped_refptr<GLSurface> surface; | 719 scoped_refptr<GLSurface> surface; |
| 719 surface = new GLSurfaceOzoneSurfaceless(std::move(surface_ozone), window); | 720 surface = new GLSurfaceOzoneSurfaceless(std::move(surface_ozone), window); |
| 720 if (surface->Initialize()) | 721 if (surface->Initialize()) |
| 721 return surface; | 722 return surface; |
| 722 } | 723 } |
| 723 | 724 |
| 724 return nullptr; | 725 return nullptr; |
| 725 } | 726 } |
| 726 | 727 |
| 727 // static | 728 // static |
| 728 scoped_refptr<GLSurface> GLSurface::CreateViewGLSurface( | 729 scoped_refptr<GLSurface> GLSurface::CreateViewGLSurface( |
| 729 gfx::AcceleratedWidget window) { | 730 gfx::AcceleratedWidget window) { |
| 730 if (GetGLImplementation() == kGLImplementationOSMesaGL) { | 731 if (GetGLImplementation() == kGLImplementationOSMesaGL) { |
| 731 scoped_refptr<GLSurface> surface(new GLSurfaceOSMesaHeadless()); | 732 scoped_refptr<GLSurface> surface(new GLSurfaceOSMesaHeadless()); |
| 732 if (!surface->Initialize()) | 733 if (!surface->Initialize()) |
| 733 return nullptr; | 734 return nullptr; |
| 734 return surface; | 735 return surface; |
| 735 } | 736 } |
| 736 if ((window != kNullAcceleratedWidget) && | 737 if ((window != gfx::kNullAcceleratedWidget) && |
| 737 (GetGLImplementation() == kGLImplementationEGLGLES2)) { | 738 (GetGLImplementation() == kGLImplementationEGLGLES2)) { |
| 738 scoped_refptr<GLSurface> surface; | 739 scoped_refptr<GLSurface> surface; |
| 739 if (GLSurfaceEGL::IsEGLSurfacelessContextSupported()) | 740 if (GLSurfaceEGL::IsEGLSurfacelessContextSupported()) |
| 740 surface = CreateViewGLSurfaceOzoneSurfacelessSurfaceImpl(window); | 741 surface = CreateViewGLSurfaceOzoneSurfacelessSurfaceImpl(window); |
| 741 if (!surface) | 742 if (!surface) |
| 742 surface = CreateViewGLSurfaceOzone(window); | 743 surface = CreateViewGLSurfaceOzone(window); |
| 743 return surface; | 744 return surface; |
| 744 } else { | 745 } else { |
| 745 DCHECK_EQ(GetGLImplementation(), kGLImplementationMockGL); | 746 DCHECK_EQ(GetGLImplementation(), kGLImplementationMockGL); |
| 746 scoped_refptr<GLSurface> surface = new GLSurfaceStub(); | 747 scoped_refptr<GLSurface> surface = new GLSurfaceStub(); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 782 return nullptr; | 783 return nullptr; |
| 783 } | 784 } |
| 784 } | 785 } |
| 785 | 786 |
| 786 EGLNativeDisplayType GetPlatformDefaultEGLNativeDisplay() { | 787 EGLNativeDisplayType GetPlatformDefaultEGLNativeDisplay() { |
| 787 return ui::OzonePlatform::GetInstance() | 788 return ui::OzonePlatform::GetInstance() |
| 788 ->GetSurfaceFactoryOzone() | 789 ->GetSurfaceFactoryOzone() |
| 789 ->GetNativeDisplay(); | 790 ->GetNativeDisplay(); |
| 790 } | 791 } |
| 791 | 792 |
| 792 } // namespace gfx | 793 } // namespace gl |
| OLD | NEW |