| 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" | 10 #include "ui/gfx/ozone/surface_factory_ozone.h" |
| 11 #include "ui/gfx/ozone/surface_ozone.h" |
| 11 #include "ui/gl/gl_implementation.h" | 12 #include "ui/gl/gl_implementation.h" |
| 12 #include "ui/gl/gl_surface_egl.h" | 13 #include "ui/gl/gl_surface_egl.h" |
| 13 #include "ui/gl/gl_surface_osmesa.h" | 14 #include "ui/gl/gl_surface_osmesa.h" |
| 14 #include "ui/gl/gl_surface_stub.h" | 15 #include "ui/gl/gl_surface_stub.h" |
| 15 | 16 |
| 16 namespace gfx { | 17 namespace gfx { |
| 17 | 18 |
| 19 namespace { |
| 20 |
| 21 // A thin wrapper around GLSurfaceEGL that owns the EGLNativeWindow |
| 22 class GL_EXPORT GLSurfaceOzoneEGL : public NativeViewGLSurfaceEGL { |
| 23 public: |
| 24 GLSurfaceOzoneEGL(scoped_ptr<SurfaceOzone> ozone_surface) |
| 25 : NativeViewGLSurfaceEGL(ozone_surface->GetEGLNativeWindow()), |
| 26 ozone_surface_(ozone_surface.Pass()) {} |
| 27 |
| 28 virtual ~GLSurfaceOzoneEGL() { |
| 29 Destroy(); // EGL surface must be destroyed before SurfaceOzone |
| 30 } |
| 31 |
| 32 private: |
| 33 // The native surface. Deleting this is allowed to free the EGLNativeWindow. |
| 34 scoped_ptr<SurfaceOzone> ozone_surface_; |
| 35 |
| 36 DISALLOW_COPY_AND_ASSIGN(GLSurfaceOzoneEGL); |
| 37 }; |
| 38 |
| 39 } // namespace |
| 40 |
| 18 // static | 41 // static |
| 19 bool GLSurface::InitializeOneOffInternal() { | 42 bool GLSurface::InitializeOneOffInternal() { |
| 20 switch (GetGLImplementation()) { | 43 switch (GetGLImplementation()) { |
| 21 case kGLImplementationEGLGLES2: | 44 case kGLImplementationEGLGLES2: |
| 22 if (!GLSurfaceEGL::InitializeOneOff()) { | 45 if (!GLSurfaceEGL::InitializeOneOff()) { |
| 23 LOG(ERROR) << "GLSurfaceEGL::InitializeOneOff failed."; | 46 LOG(ERROR) << "GLSurfaceEGL::InitializeOneOff failed."; |
| 24 return false; | 47 return false; |
| 25 } | 48 } |
| 26 default: | 49 default: |
| 27 break; | 50 break; |
| 28 } | 51 } |
| 29 return true; | 52 return true; |
| 30 } | 53 } |
| 31 | 54 |
| 32 // static | 55 // static |
| 33 scoped_refptr<GLSurface> GLSurface::CreateViewGLSurface( | 56 scoped_refptr<GLSurface> GLSurface::CreateViewGLSurface( |
| 34 gfx::AcceleratedWidget window) { | 57 gfx::AcceleratedWidget window) { |
| 35 if (GetGLImplementation() == kGLImplementationOSMesaGL) { | 58 if (GetGLImplementation() == kGLImplementationOSMesaGL) { |
| 36 scoped_refptr<GLSurface> surface(new GLSurfaceOSMesaHeadless()); | 59 scoped_refptr<GLSurface> surface(new GLSurfaceOSMesaHeadless()); |
| 37 if (!surface->Initialize()) | 60 if (!surface->Initialize()) |
| 38 return NULL; | 61 return NULL; |
| 39 return surface; | 62 return surface; |
| 40 } | 63 } |
| 41 DCHECK(GetGLImplementation() == kGLImplementationEGLGLES2); | 64 DCHECK(GetGLImplementation() == kGLImplementationEGLGLES2); |
| 42 if (window != kNullAcceleratedWidget) { | 65 if (window != kNullAcceleratedWidget) { |
| 43 EGLNativeWindowType egl_window = | 66 scoped_ptr<SurfaceOzone> surface_ozone = |
| 44 gfx::SurfaceFactoryOzone::GetInstance()->RealizeAcceleratedWidget( | 67 SurfaceFactoryOzone::GetInstance()->CreateSurfaceForWidget(window); |
| 45 window); | 68 if (!surface_ozone->InitializeEGL()) |
| 46 scoped_ptr<VSyncProvider> sync_provider = | 69 return NULL; |
| 47 gfx::SurfaceFactoryOzone::GetInstance()->CreateVSyncProvider( | 70 scoped_refptr<GLSurfaceOzoneEGL> surface = |
| 48 egl_window); | 71 new GLSurfaceOzoneEGL(surface_ozone.Pass()); |
| 49 scoped_refptr<NativeViewGLSurfaceEGL> surface = | 72 if (!surface->Initialize(surface_ozone->CreateVSyncProvider())) |
| 50 new NativeViewGLSurfaceEGL(egl_window); | 73 return NULL; |
| 51 if (surface->Initialize(sync_provider.Pass())) | 74 return surface; |
| 52 return surface; | |
| 53 } else { | 75 } else { |
| 54 scoped_refptr<GLSurface> surface = new GLSurfaceStub(); | 76 scoped_refptr<GLSurface> surface = new GLSurfaceStub(); |
| 55 if (surface->Initialize()) | 77 if (surface->Initialize()) |
| 56 return surface; | 78 return surface; |
| 57 } | 79 } |
| 58 return NULL; | 80 return NULL; |
| 59 } | 81 } |
| 60 | 82 |
| 61 // static | 83 // static |
| 62 scoped_refptr<GLSurface> GLSurface::CreateOffscreenGLSurface( | 84 scoped_refptr<GLSurface> GLSurface::CreateOffscreenGLSurface( |
| (...skipping 22 matching lines...) Expand all Loading... |
| 85 NOTREACHED(); | 107 NOTREACHED(); |
| 86 return NULL; | 108 return NULL; |
| 87 } | 109 } |
| 88 } | 110 } |
| 89 | 111 |
| 90 EGLNativeDisplayType GetPlatformDefaultEGLNativeDisplay() { | 112 EGLNativeDisplayType GetPlatformDefaultEGLNativeDisplay() { |
| 91 return SurfaceFactoryOzone::GetInstance()->GetNativeDisplay(); | 113 return SurfaceFactoryOzone::GetInstance()->GetNativeDisplay(); |
| 92 } | 114 } |
| 93 | 115 |
| 94 } // namespace gfx | 116 } // namespace gfx |
| OLD | NEW |