| 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/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "ui/gfx/native_widget_types.h" | 9 #include "ui/gfx/native_widget_types.h" |
| 10 #include "ui/gfx/ozone/surface_factory_ozone.h" | |
| 11 #include "ui/gfx/ozone/surface_ozone_egl.h" | |
| 12 #include "ui/gl/gl_implementation.h" | 10 #include "ui/gl/gl_implementation.h" |
| 13 #include "ui/gl/gl_surface_egl.h" | 11 #include "ui/gl/gl_surface_egl.h" |
| 14 #include "ui/gl/gl_surface_osmesa.h" | 12 #include "ui/gl/gl_surface_osmesa.h" |
| 15 #include "ui/gl/gl_surface_stub.h" | 13 #include "ui/gl/gl_surface_stub.h" |
| 14 #include "ui/ozone/factories/surface_factory_ozone.h" |
| 15 #include "ui/ozone/factories/surface_ozone_egl.h" |
| 16 | 16 |
| 17 namespace gfx { | 17 namespace gfx { |
| 18 | 18 |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 // A thin wrapper around GLSurfaceEGL that owns the EGLNativeWindow | 21 // A thin wrapper around GLSurfaceEGL that owns the EGLNativeWindow |
| 22 class GL_EXPORT GLSurfaceOzoneEGL : public NativeViewGLSurfaceEGL { | 22 class GL_EXPORT GLSurfaceOzoneEGL : public NativeViewGLSurfaceEGL { |
| 23 public: | 23 public: |
| 24 GLSurfaceOzoneEGL(scoped_ptr<SurfaceOzoneEGL> ozone_surface) | 24 GLSurfaceOzoneEGL(scoped_ptr<ui::SurfaceOzoneEGL> ozone_surface) |
| 25 : NativeViewGLSurfaceEGL(ozone_surface->GetNativeWindow()), | 25 : NativeViewGLSurfaceEGL(ozone_surface->GetNativeWindow()), |
| 26 ozone_surface_(ozone_surface.Pass()) {} | 26 ozone_surface_(ozone_surface.Pass()) {} |
| 27 | 27 |
| 28 virtual bool Resize(const gfx::Size& size) OVERRIDE { | 28 virtual bool Resize(const gfx::Size& size) OVERRIDE { |
| 29 if (!ozone_surface_->ResizeNativeWindow(size)) | 29 if (!ozone_surface_->ResizeNativeWindow(size)) |
| 30 return false; | 30 return false; |
| 31 | 31 |
| 32 return NativeViewGLSurfaceEGL::Resize(size); | 32 return NativeViewGLSurfaceEGL::Resize(size); |
| 33 } | 33 } |
| 34 virtual bool SwapBuffers() OVERRIDE { | 34 virtual bool SwapBuffers() OVERRIDE { |
| 35 if (!NativeViewGLSurfaceEGL::SwapBuffers()) | 35 if (!NativeViewGLSurfaceEGL::SwapBuffers()) |
| 36 return false; | 36 return false; |
| 37 | 37 |
| 38 return ozone_surface_->OnSwapBuffers(); | 38 return ozone_surface_->OnSwapBuffers(); |
| 39 } | 39 } |
| 40 | 40 |
| 41 private: | 41 private: |
| 42 virtual ~GLSurfaceOzoneEGL() { | 42 virtual ~GLSurfaceOzoneEGL() { |
| 43 Destroy(); // EGL surface must be destroyed before SurfaceOzone | 43 Destroy(); // EGL surface must be destroyed before SurfaceOzone |
| 44 } | 44 } |
| 45 | 45 |
| 46 // The native surface. Deleting this is allowed to free the EGLNativeWindow. | 46 // The native surface. Deleting this is allowed to free the EGLNativeWindow. |
| 47 scoped_ptr<SurfaceOzoneEGL> ozone_surface_; | 47 scoped_ptr<ui::SurfaceOzoneEGL> ozone_surface_; |
| 48 | 48 |
| 49 DISALLOW_COPY_AND_ASSIGN(GLSurfaceOzoneEGL); | 49 DISALLOW_COPY_AND_ASSIGN(GLSurfaceOzoneEGL); |
| 50 }; | 50 }; |
| 51 | 51 |
| 52 } // namespace | 52 } // namespace |
| 53 | 53 |
| 54 // static | 54 // static |
| 55 bool GLSurface::InitializeOneOffInternal() { | 55 bool GLSurface::InitializeOneOffInternal() { |
| 56 switch (GetGLImplementation()) { | 56 switch (GetGLImplementation()) { |
| 57 case kGLImplementationEGLGLES2: | 57 case kGLImplementationEGLGLES2: |
| 58 if (gfx::SurfaceFactoryOzone::GetInstance()->InitializeHardware() != | 58 if (ui::SurfaceFactoryOzone::GetInstance()->InitializeHardware() != |
| 59 gfx::SurfaceFactoryOzone::INITIALIZED) { | 59 ui::SurfaceFactoryOzone::INITIALIZED) { |
| 60 LOG(ERROR) << "Ozone failed to initialize hardware"; | 60 LOG(ERROR) << "Ozone failed to initialize hardware"; |
| 61 return false; | 61 return false; |
| 62 } | 62 } |
| 63 | 63 |
| 64 if (!GLSurfaceEGL::InitializeOneOff()) { | 64 if (!GLSurfaceEGL::InitializeOneOff()) { |
| 65 LOG(ERROR) << "GLSurfaceEGL::InitializeOneOff failed."; | 65 LOG(ERROR) << "GLSurfaceEGL::InitializeOneOff failed."; |
| 66 return false; | 66 return false; |
| 67 } | 67 } |
| 68 | 68 |
| 69 return true; | 69 return true; |
| 70 case kGLImplementationOSMesaGL: | 70 case kGLImplementationOSMesaGL: |
| 71 case kGLImplementationMockGL: | 71 case kGLImplementationMockGL: |
| 72 return true; | 72 return true; |
| 73 default: | 73 default: |
| 74 return false; | 74 return false; |
| 75 } | 75 } |
| 76 } | 76 } |
| 77 | 77 |
| 78 // static | 78 // static |
| 79 scoped_refptr<GLSurface> GLSurface::CreateViewGLSurface( | 79 scoped_refptr<GLSurface> GLSurface::CreateViewGLSurface( |
| 80 gfx::AcceleratedWidget window) { | 80 gfx::AcceleratedWidget window) { |
| 81 if (GetGLImplementation() == kGLImplementationOSMesaGL) { | 81 if (GetGLImplementation() == kGLImplementationOSMesaGL) { |
| 82 scoped_refptr<GLSurface> surface(new GLSurfaceOSMesaHeadless()); | 82 scoped_refptr<GLSurface> surface(new GLSurfaceOSMesaHeadless()); |
| 83 if (!surface->Initialize()) | 83 if (!surface->Initialize()) |
| 84 return NULL; | 84 return NULL; |
| 85 return surface; | 85 return surface; |
| 86 } | 86 } |
| 87 DCHECK(GetGLImplementation() == kGLImplementationEGLGLES2); | 87 DCHECK(GetGLImplementation() == kGLImplementationEGLGLES2); |
| 88 if (window != kNullAcceleratedWidget) { | 88 if (window != kNullAcceleratedWidget) { |
| 89 scoped_ptr<SurfaceOzoneEGL> surface_ozone = | 89 scoped_ptr<ui::SurfaceOzoneEGL> surface_ozone = |
| 90 SurfaceFactoryOzone::GetInstance()->CreateEGLSurfaceForWidget(window); | 90 ui::SurfaceFactoryOzone::GetInstance()->CreateEGLSurfaceForWidget( |
| 91 window); |
| 91 if (!surface_ozone) | 92 if (!surface_ozone) |
| 92 return NULL; | 93 return NULL; |
| 93 | 94 |
| 94 scoped_ptr<VSyncProvider> vsync_provider = | 95 scoped_ptr<VSyncProvider> vsync_provider = |
| 95 surface_ozone->CreateVSyncProvider(); | 96 surface_ozone->CreateVSyncProvider(); |
| 96 scoped_refptr<GLSurfaceOzoneEGL> surface = | 97 scoped_refptr<GLSurfaceOzoneEGL> surface = |
| 97 new GLSurfaceOzoneEGL(surface_ozone.Pass()); | 98 new GLSurfaceOzoneEGL(surface_ozone.Pass()); |
| 98 if (!surface->Initialize(vsync_provider.Pass())) | 99 if (!surface->Initialize(vsync_provider.Pass())) |
| 99 return NULL; | 100 return NULL; |
| 100 return surface; | 101 return surface; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 129 return NULL; | 130 return NULL; |
| 130 return surface; | 131 return surface; |
| 131 } | 132 } |
| 132 default: | 133 default: |
| 133 NOTREACHED(); | 134 NOTREACHED(); |
| 134 return NULL; | 135 return NULL; |
| 135 } | 136 } |
| 136 } | 137 } |
| 137 | 138 |
| 138 EGLNativeDisplayType GetPlatformDefaultEGLNativeDisplay() { | 139 EGLNativeDisplayType GetPlatformDefaultEGLNativeDisplay() { |
| 139 return SurfaceFactoryOzone::GetInstance()->GetNativeDisplay(); | 140 return ui::SurfaceFactoryOzone::GetInstance()->GetNativeDisplay(); |
| 140 } | 141 } |
| 141 | 142 |
| 142 } // namespace gfx | 143 } // namespace gfx |
| OLD | NEW |