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 |
18 namespace { | 19 namespace { |
19 | 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 OzoneSurface |
| 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 |
20 EGLNativeDisplayType GetEGLDisplay() { | 39 EGLNativeDisplayType GetEGLDisplay() { |
21 return SurfaceFactoryOzone::GetInstance()->GetNativeDisplay(); | 40 return SurfaceFactoryOzone::GetInstance()->GetNativeDisplay(); |
22 } | 41 } |
23 | 42 |
24 } // namespace | 43 } // namespace |
25 | 44 |
26 // static | 45 // static |
27 bool GLSurface::InitializeOneOffInternal() { | 46 bool GLSurface::InitializeOneOffInternal() { |
28 switch (GetGLImplementation()) { | 47 switch (GetGLImplementation()) { |
29 case kGLImplementationEGLGLES2: | 48 case kGLImplementationEGLGLES2: |
(...skipping 11 matching lines...) Expand all Loading... |
41 scoped_refptr<GLSurface> GLSurface::CreateViewGLSurface( | 60 scoped_refptr<GLSurface> GLSurface::CreateViewGLSurface( |
42 gfx::AcceleratedWidget window) { | 61 gfx::AcceleratedWidget window) { |
43 if (GetGLImplementation() == kGLImplementationOSMesaGL) { | 62 if (GetGLImplementation() == kGLImplementationOSMesaGL) { |
44 scoped_refptr<GLSurface> surface(new GLSurfaceOSMesaHeadless()); | 63 scoped_refptr<GLSurface> surface(new GLSurfaceOSMesaHeadless()); |
45 if (!surface->Initialize()) | 64 if (!surface->Initialize()) |
46 return NULL; | 65 return NULL; |
47 return surface; | 66 return surface; |
48 } | 67 } |
49 DCHECK(GetGLImplementation() == kGLImplementationEGLGLES2); | 68 DCHECK(GetGLImplementation() == kGLImplementationEGLGLES2); |
50 if (window != kNullAcceleratedWidget) { | 69 if (window != kNullAcceleratedWidget) { |
51 EGLNativeWindowType egl_window = | 70 scoped_ptr<SurfaceOzone> surface_ozone = |
52 gfx::SurfaceFactoryOzone::GetInstance()->RealizeAcceleratedWidget( | 71 SurfaceFactoryOzone::GetInstance()->CreateSurfaceForWidget(window); |
53 window); | 72 if (!surface_ozone->InitializeEGL()) |
54 scoped_ptr<VSyncProvider> sync_provider = | 73 return NULL; |
55 gfx::SurfaceFactoryOzone::GetInstance()->CreateVSyncProvider( | 74 scoped_refptr<GLSurfaceOzoneEGL> surface = |
56 egl_window); | 75 new GLSurfaceOzoneEGL(surface_ozone.Pass()); |
57 scoped_refptr<NativeViewGLSurfaceEGL> surface = | 76 if (!surface->Initialize(surface_ozone->CreateVSyncProvider())) |
58 new NativeViewGLSurfaceEGL(egl_window); | 77 return NULL; |
59 if (surface->Initialize(sync_provider.Pass())) | 78 return surface; |
60 return surface; | |
61 } else { | 79 } else { |
62 scoped_refptr<GLSurface> surface = new GLSurfaceStub(); | 80 scoped_refptr<GLSurface> surface = new GLSurfaceStub(); |
63 if (surface->Initialize()) | 81 if (surface->Initialize()) |
64 return surface; | 82 return surface; |
65 } | 83 } |
66 return NULL; | 84 return NULL; |
67 } | 85 } |
68 | 86 |
69 // static | 87 // static |
70 scoped_refptr<GLSurface> GLSurface::CreateOffscreenGLSurface( | 88 scoped_refptr<GLSurface> GLSurface::CreateOffscreenGLSurface( |
(...skipping 18 matching lines...) Expand all Loading... |
89 return NULL; | 107 return NULL; |
90 return surface; | 108 return surface; |
91 } | 109 } |
92 default: | 110 default: |
93 NOTREACHED(); | 111 NOTREACHED(); |
94 return NULL; | 112 return NULL; |
95 } | 113 } |
96 } | 114 } |
97 | 115 |
98 } // namespace gfx | 116 } // namespace gfx |
OLD | NEW |