| 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 14 matching lines...) Expand all Loading... |
| 25 #include "ui/gl/gl_surface_osmesa.h" | 25 #include "ui/gl/gl_surface_osmesa.h" |
| 26 #include "ui/gl/gl_surface_overlay.h" | 26 #include "ui/gl/gl_surface_overlay.h" |
| 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; | |
| 36 | |
| 37 namespace gl { | 35 namespace gl { |
| 38 | 36 |
| 39 namespace { | 37 namespace { |
| 40 | 38 |
| 41 // Helper function for base::Bind to create callback to eglChooseConfig. | 39 // Helper function for base::Bind to create callback to eglChooseConfig. |
| 42 bool EglChooseConfig(EGLDisplay display, | 40 bool EglChooseConfig(EGLDisplay display, |
| 43 const int32_t* attribs, | 41 const int32_t* attribs, |
| 44 EGLConfig* configs, | 42 EGLConfig* configs, |
| 45 int32_t config_size, | 43 int32_t config_size, |
| 46 int32_t* num_configs) { | 44 int32_t* num_configs) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 69 EGL_FOREVER_KHR); | 67 EGL_FOREVER_KHR); |
| 70 } | 68 } |
| 71 | 69 |
| 72 // A thin wrapper around GLSurfaceEGL that owns the EGLNativeWindow. | 70 // A thin wrapper around GLSurfaceEGL that owns the EGLNativeWindow. |
| 73 class GL_EXPORT GLSurfaceOzoneEGL : public NativeViewGLSurfaceEGL { | 71 class GL_EXPORT GLSurfaceOzoneEGL : public NativeViewGLSurfaceEGL { |
| 74 public: | 72 public: |
| 75 GLSurfaceOzoneEGL(std::unique_ptr<ui::SurfaceOzoneEGL> ozone_surface, | 73 GLSurfaceOzoneEGL(std::unique_ptr<ui::SurfaceOzoneEGL> ozone_surface, |
| 76 gfx::AcceleratedWidget widget); | 74 gfx::AcceleratedWidget widget); |
| 77 | 75 |
| 78 // GLSurface: | 76 // GLSurface: |
| 79 bool Initialize(gl::GLSurface::Format format) override; | 77 bool Initialize(GLSurface::Format format) override; |
| 80 bool Resize(const gfx::Size& size, | 78 bool Resize(const gfx::Size& size, |
| 81 float scale_factor, | 79 float scale_factor, |
| 82 bool has_alpha) override; | 80 bool has_alpha) override; |
| 83 gfx::SwapResult SwapBuffers() override; | 81 gfx::SwapResult SwapBuffers() override; |
| 84 bool ScheduleOverlayPlane(int z_order, | 82 bool ScheduleOverlayPlane(int z_order, |
| 85 gfx::OverlayTransform transform, | 83 gfx::OverlayTransform transform, |
| 86 GLImage* image, | 84 GLImage* image, |
| 87 const gfx::Rect& bounds_rect, | 85 const gfx::Rect& bounds_rect, |
| 88 const gfx::RectF& crop_rect) override; | 86 const gfx::RectF& crop_rect) override; |
| 89 EGLConfig GetConfig() override; | 87 EGLConfig GetConfig() override; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 102 DISALLOW_COPY_AND_ASSIGN(GLSurfaceOzoneEGL); | 100 DISALLOW_COPY_AND_ASSIGN(GLSurfaceOzoneEGL); |
| 103 }; | 101 }; |
| 104 | 102 |
| 105 GLSurfaceOzoneEGL::GLSurfaceOzoneEGL( | 103 GLSurfaceOzoneEGL::GLSurfaceOzoneEGL( |
| 106 std::unique_ptr<ui::SurfaceOzoneEGL> ozone_surface, | 104 std::unique_ptr<ui::SurfaceOzoneEGL> ozone_surface, |
| 107 gfx::AcceleratedWidget widget) | 105 gfx::AcceleratedWidget widget) |
| 108 : NativeViewGLSurfaceEGL(ozone_surface->GetNativeWindow()), | 106 : NativeViewGLSurfaceEGL(ozone_surface->GetNativeWindow()), |
| 109 ozone_surface_(std::move(ozone_surface)), | 107 ozone_surface_(std::move(ozone_surface)), |
| 110 widget_(widget) {} | 108 widget_(widget) {} |
| 111 | 109 |
| 112 bool GLSurfaceOzoneEGL::Initialize(gl::GLSurface::Format format) { | 110 bool GLSurfaceOzoneEGL::Initialize(GLSurface::Format format) { |
| 113 format_ = format; | 111 format_ = format; |
| 114 return Initialize(ozone_surface_->CreateVSyncProvider()); | 112 return Initialize(ozone_surface_->CreateVSyncProvider()); |
| 115 } | 113 } |
| 116 | 114 |
| 117 bool GLSurfaceOzoneEGL::Resize(const gfx::Size& size, | 115 bool GLSurfaceOzoneEGL::Resize(const gfx::Size& size, |
| 118 float scale_factor, | 116 float scale_factor, |
| 119 bool has_alpha) { | 117 bool has_alpha) { |
| 120 if (!ozone_surface_->ResizeNativeWindow(size)) { | 118 if (!ozone_surface_->ResizeNativeWindow(size)) { |
| 121 if (!ReinitializeNativeSurface() || | 119 if (!ReinitializeNativeSurface() || |
| 122 !ozone_surface_->ResizeNativeWindow(size)) | 120 !ozone_surface_->ResizeNativeWindow(size)) |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 | 181 |
| 184 return true; | 182 return true; |
| 185 } | 183 } |
| 186 | 184 |
| 187 class GL_EXPORT GLSurfaceOzoneSurfaceless : public SurfacelessEGL { | 185 class GL_EXPORT GLSurfaceOzoneSurfaceless : public SurfacelessEGL { |
| 188 public: | 186 public: |
| 189 GLSurfaceOzoneSurfaceless(std::unique_ptr<ui::SurfaceOzoneEGL> ozone_surface, | 187 GLSurfaceOzoneSurfaceless(std::unique_ptr<ui::SurfaceOzoneEGL> ozone_surface, |
| 190 gfx::AcceleratedWidget widget); | 188 gfx::AcceleratedWidget widget); |
| 191 | 189 |
| 192 // GLSurface: | 190 // GLSurface: |
| 193 bool Initialize(gl::GLSurface::Format format) override; | 191 bool Initialize(GLSurface::Format format) override; |
| 194 bool Resize(const gfx::Size& size, | 192 bool Resize(const gfx::Size& size, |
| 195 float scale_factor, | 193 float scale_factor, |
| 196 bool has_alpha) override; | 194 bool has_alpha) override; |
| 197 gfx::SwapResult SwapBuffers() override; | 195 gfx::SwapResult SwapBuffers() override; |
| 198 bool ScheduleOverlayPlane(int z_order, | 196 bool ScheduleOverlayPlane(int z_order, |
| 199 gfx::OverlayTransform transform, | 197 gfx::OverlayTransform transform, |
| 200 GLImage* image, | 198 GLImage* image, |
| 201 const gfx::Rect& bounds_rect, | 199 const gfx::Rect& bounds_rect, |
| 202 const gfx::RectF& crop_rect) override; | 200 const gfx::RectF& crop_rect) override; |
| 203 bool IsOffscreen() override; | 201 bool IsOffscreen() override; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 ozone_surface_(std::move(ozone_surface)), | 264 ozone_surface_(std::move(ozone_surface)), |
| 267 widget_(widget), | 265 widget_(widget), |
| 268 has_implicit_external_sync_( | 266 has_implicit_external_sync_( |
| 269 HasEGLExtension("EGL_ARM_implicit_external_sync")), | 267 HasEGLExtension("EGL_ARM_implicit_external_sync")), |
| 270 last_swap_buffers_result_(true), | 268 last_swap_buffers_result_(true), |
| 271 swap_buffers_pending_(false), | 269 swap_buffers_pending_(false), |
| 272 weak_factory_(this) { | 270 weak_factory_(this) { |
| 273 unsubmitted_frames_.push_back(new PendingFrame()); | 271 unsubmitted_frames_.push_back(new PendingFrame()); |
| 274 } | 272 } |
| 275 | 273 |
| 276 bool GLSurfaceOzoneSurfaceless::Initialize(gl::GLSurface::Format format) { | 274 bool GLSurfaceOzoneSurfaceless::Initialize(GLSurface::Format format) { |
| 277 if (!SurfacelessEGL::Initialize(format)) | 275 if (!SurfacelessEGL::Initialize(format)) |
| 278 return false; | 276 return false; |
| 279 vsync_provider_ = ozone_surface_->CreateVSyncProvider(); | 277 vsync_provider_ = ozone_surface_->CreateVSyncProvider(); |
| 280 if (!vsync_provider_) | 278 if (!vsync_provider_) |
| 281 return false; | 279 return false; |
| 282 return true; | 280 return true; |
| 283 } | 281 } |
| 284 | 282 |
| 285 bool GLSurfaceOzoneSurfaceless::Resize(const gfx::Size& size, | 283 bool GLSurfaceOzoneSurfaceless::Resize(const gfx::Size& size, |
| 286 float scale_factor, | 284 float scale_factor, |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 571 return; | 569 return; |
| 572 } | 570 } |
| 573 GLSurfaceOzoneSurfaceless::SwapBuffersAsync(callback); | 571 GLSurfaceOzoneSurfaceless::SwapBuffersAsync(callback); |
| 574 current_surface_ ^= 1; | 572 current_surface_ ^= 1; |
| 575 BindFramebuffer(); | 573 BindFramebuffer(); |
| 576 } | 574 } |
| 577 | 575 |
| 578 void GLSurfaceOzoneSurfacelessSurfaceImpl::Destroy() { | 576 void GLSurfaceOzoneSurfacelessSurfaceImpl::Destroy() { |
| 579 if (!context_) | 577 if (!context_) |
| 580 return; | 578 return; |
| 581 scoped_refptr<gl::GLContext> previous_context = gl::GLContext::GetCurrent(); | 579 scoped_refptr<GLContext> previous_context = GLContext::GetCurrent(); |
| 582 scoped_refptr<gl::GLSurface> previous_surface; | 580 scoped_refptr<GLSurface> previous_surface; |
| 583 | 581 |
| 584 bool was_current = previous_context && previous_context->IsCurrent(nullptr) && | 582 bool was_current = previous_context && previous_context->IsCurrent(nullptr) && |
| 585 gl::GLSurface::GetCurrent() == this; | 583 GLSurface::GetCurrent() == this; |
| 586 if (!was_current) { | 584 if (!was_current) { |
| 587 // Only take a reference to previous surface if it's not |this| | 585 // Only take a reference to previous surface if it's not |this| |
| 588 // because otherwise we can take a self reference from our own dtor. | 586 // because otherwise we can take a self reference from our own dtor. |
| 589 previous_surface = gl::GLSurface::GetCurrent(); | 587 previous_surface = GLSurface::GetCurrent(); |
| 590 context_->MakeCurrent(this); | 588 context_->MakeCurrent(this); |
| 591 } | 589 } |
| 592 | 590 |
| 593 glBindFramebufferEXT(GL_FRAMEBUFFER, 0); | 591 glBindFramebufferEXT(GL_FRAMEBUFFER, 0); |
| 594 if (fbo_) { | 592 if (fbo_) { |
| 595 glDeleteTextures(arraysize(textures_), textures_); | 593 glDeleteTextures(arraysize(textures_), textures_); |
| 596 for (auto& texture : textures_) | 594 for (auto& texture : textures_) |
| 597 texture = 0; | 595 texture = 0; |
| 598 glDeleteFramebuffersEXT(1, &fbo_); | 596 glDeleteFramebuffersEXT(1, &fbo_); |
| 599 fbo_ = 0; | 597 fbo_ = 0; |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 784 } | 782 } |
| 785 } | 783 } |
| 786 | 784 |
| 787 EGLNativeDisplayType GetPlatformDefaultEGLNativeDisplay() { | 785 EGLNativeDisplayType GetPlatformDefaultEGLNativeDisplay() { |
| 788 return ui::OzonePlatform::GetInstance() | 786 return ui::OzonePlatform::GetInstance() |
| 789 ->GetSurfaceFactoryOzone() | 787 ->GetSurfaceFactoryOzone() |
| 790 ->GetNativeDisplay(); | 788 ->GetNativeDisplay(); |
| 791 } | 789 } |
| 792 | 790 |
| 793 } // namespace gl | 791 } // namespace gl |
| OLD | NEW |