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/gl/gl_context.h" | 10 #include "ui/gl/gl_context.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 | 23 |
24 // A thin wrapper around GLSurfaceEGL that owns the EGLNativeWindow | 24 // A thin wrapper around GLSurfaceEGL that owns the EGLNativeWindow |
25 class GL_EXPORT GLSurfaceOzoneEGL : public NativeViewGLSurfaceEGL { | 25 class GL_EXPORT GLSurfaceOzoneEGL : public NativeViewGLSurfaceEGL { |
26 public: | 26 public: |
27 GLSurfaceOzoneEGL(scoped_ptr<ui::SurfaceOzoneEGL> ozone_surface, | 27 GLSurfaceOzoneEGL(scoped_ptr<ui::SurfaceOzoneEGL> ozone_surface, |
28 AcceleratedWidget widget) | 28 AcceleratedWidget widget) |
29 : NativeViewGLSurfaceEGL(ozone_surface->GetNativeWindow()), | 29 : NativeViewGLSurfaceEGL(ozone_surface->GetNativeWindow()), |
30 ozone_surface_(ozone_surface.Pass()), | 30 ozone_surface_(ozone_surface.Pass()), |
31 widget_(widget) {} | 31 widget_(widget) {} |
32 | 32 |
| 33 virtual bool Initialize() OVERRIDE { |
| 34 return Initialize(ozone_surface_->CreateVSyncProvider()); |
| 35 } |
33 virtual bool Resize(const gfx::Size& size) OVERRIDE { | 36 virtual bool Resize(const gfx::Size& size) OVERRIDE { |
34 if (!ozone_surface_->ResizeNativeWindow(size)) { | 37 if (!ozone_surface_->ResizeNativeWindow(size)) { |
35 if (!ReinitializeNativeSurface() || | 38 if (!ReinitializeNativeSurface() || |
36 !ozone_surface_->ResizeNativeWindow(size)) | 39 !ozone_surface_->ResizeNativeWindow(size)) |
37 return false; | 40 return false; |
38 } | 41 } |
39 | 42 |
40 return NativeViewGLSurfaceEGL::Resize(size); | 43 return NativeViewGLSurfaceEGL::Resize(size); |
41 } | 44 } |
42 virtual bool SwapBuffers() OVERRIDE { | 45 virtual bool SwapBuffers() OVERRIDE { |
43 if (!NativeViewGLSurfaceEGL::SwapBuffers()) | 46 if (!NativeViewGLSurfaceEGL::SwapBuffers()) |
44 return false; | 47 return false; |
45 | 48 |
46 return ozone_surface_->OnSwapBuffers(); | 49 return ozone_surface_->OnSwapBuffers(); |
47 } | 50 } |
48 virtual bool ScheduleOverlayPlane(int z_order, | 51 virtual bool ScheduleOverlayPlane(int z_order, |
49 OverlayTransform transform, | 52 OverlayTransform transform, |
50 GLImage* image, | 53 GLImage* image, |
51 const Rect& bounds_rect, | 54 const Rect& bounds_rect, |
52 const RectF& crop_rect) OVERRIDE { | 55 const RectF& crop_rect) OVERRIDE { |
53 return image->ScheduleOverlayPlane( | 56 return image->ScheduleOverlayPlane( |
54 widget_, z_order, transform, bounds_rect, crop_rect); | 57 widget_, z_order, transform, bounds_rect, crop_rect); |
55 } | 58 } |
56 | 59 |
57 private: | 60 private: |
| 61 using NativeViewGLSurfaceEGL::Initialize; |
| 62 |
58 virtual ~GLSurfaceOzoneEGL() { | 63 virtual ~GLSurfaceOzoneEGL() { |
59 Destroy(); // EGL surface must be destroyed before SurfaceOzone | 64 Destroy(); // EGL surface must be destroyed before SurfaceOzone |
60 } | 65 } |
61 | 66 |
62 bool ReinitializeNativeSurface() { | 67 bool ReinitializeNativeSurface() { |
63 scoped_ptr<ui::ScopedMakeCurrent> scoped_make_current; | 68 scoped_ptr<ui::ScopedMakeCurrent> scoped_make_current; |
64 GLContext* current_context = GLContext::GetCurrent(); | 69 GLContext* current_context = GLContext::GetCurrent(); |
65 bool was_current = | 70 bool was_current = |
66 current_context && current_context->IsCurrent(this); | 71 current_context && current_context->IsCurrent(this); |
67 if (was_current) { | 72 if (was_current) { |
68 scoped_make_current.reset( | 73 scoped_make_current.reset( |
69 new ui::ScopedMakeCurrent(current_context, this)); | 74 new ui::ScopedMakeCurrent(current_context, this)); |
70 } | 75 } |
71 | 76 |
72 Destroy(); | 77 Destroy(); |
73 ozone_surface_ = | 78 ozone_surface_ = |
74 ui::SurfaceFactoryOzone::GetInstance()->CreateEGLSurfaceForWidget( | 79 ui::SurfaceFactoryOzone::GetInstance()->CreateEGLSurfaceForWidget( |
75 widget_).Pass(); | 80 widget_).Pass(); |
76 if (!ozone_surface_) { | 81 if (!ozone_surface_) { |
77 LOG(ERROR) << "Failed to create native surface."; | 82 LOG(ERROR) << "Failed to create native surface."; |
78 return false; | 83 return false; |
79 } | 84 } |
80 | 85 |
81 window_ = ozone_surface_->GetNativeWindow(); | 86 window_ = ozone_surface_->GetNativeWindow(); |
82 scoped_ptr<VSyncProvider> vsync_provider = | 87 if (!Initialize()) { |
83 ozone_surface_->CreateVSyncProvider(); | |
84 if (!Initialize(vsync_provider.Pass())) { | |
85 LOG(ERROR) << "Failed to initialize."; | 88 LOG(ERROR) << "Failed to initialize."; |
86 return false; | 89 return false; |
87 } | 90 } |
88 | 91 |
89 return true; | 92 return true; |
90 } | 93 } |
91 | 94 |
92 | |
93 // The native surface. Deleting this is allowed to free the EGLNativeWindow. | 95 // The native surface. Deleting this is allowed to free the EGLNativeWindow. |
94 scoped_ptr<ui::SurfaceOzoneEGL> ozone_surface_; | 96 scoped_ptr<ui::SurfaceOzoneEGL> ozone_surface_; |
95 AcceleratedWidget widget_; | 97 AcceleratedWidget widget_; |
96 | 98 |
97 DISALLOW_COPY_AND_ASSIGN(GLSurfaceOzoneEGL); | 99 DISALLOW_COPY_AND_ASSIGN(GLSurfaceOzoneEGL); |
98 }; | 100 }; |
99 | 101 |
| 102 class GL_EXPORT GLSurfaceOzoneSurfaceless : public SurfacelessEGL { |
| 103 public: |
| 104 GLSurfaceOzoneSurfaceless(scoped_ptr<ui::SurfaceOzoneEGL> ozone_surface, |
| 105 AcceleratedWidget widget) |
| 106 : SurfacelessEGL(gfx::Size()), |
| 107 ozone_surface_(ozone_surface.Pass()), |
| 108 widget_(widget) {} |
| 109 |
| 110 virtual bool Initialize() OVERRIDE { |
| 111 if (!SurfacelessEGL::Initialize()) |
| 112 return false; |
| 113 vsync_provider_ = ozone_surface_->CreateVSyncProvider(); |
| 114 if (!vsync_provider_) |
| 115 return false; |
| 116 return true; |
| 117 } |
| 118 virtual bool Resize(const gfx::Size& size) OVERRIDE { |
| 119 if (!ozone_surface_->ResizeNativeWindow(size)) |
| 120 return false; |
| 121 |
| 122 return SurfacelessEGL::Resize(size); |
| 123 } |
| 124 virtual bool SwapBuffers() OVERRIDE { |
| 125 return ozone_surface_->OnSwapBuffers(); |
| 126 } |
| 127 virtual bool ScheduleOverlayPlane(int z_order, |
| 128 OverlayTransform transform, |
| 129 GLImage* image, |
| 130 const Rect& bounds_rect, |
| 131 const RectF& crop_rect) OVERRIDE { |
| 132 return image->ScheduleOverlayPlane( |
| 133 widget_, z_order, transform, bounds_rect, crop_rect); |
| 134 } |
| 135 virtual bool IsOffscreen() OVERRIDE { return false; } |
| 136 virtual VSyncProvider* GetVSyncProvider() OVERRIDE { |
| 137 return vsync_provider_.get(); |
| 138 } |
| 139 |
| 140 private: |
| 141 virtual ~GLSurfaceOzoneSurfaceless() { |
| 142 Destroy(); // EGL surface must be destroyed before SurfaceOzone |
| 143 } |
| 144 |
| 145 // The native surface. Deleting this is allowed to free the EGLNativeWindow. |
| 146 scoped_ptr<ui::SurfaceOzoneEGL> ozone_surface_; |
| 147 AcceleratedWidget widget_; |
| 148 scoped_ptr<VSyncProvider> vsync_provider_; |
| 149 |
| 150 DISALLOW_COPY_AND_ASSIGN(GLSurfaceOzoneSurfaceless); |
| 151 }; |
| 152 |
100 } // namespace | 153 } // namespace |
101 | 154 |
102 // static | 155 // static |
103 bool GLSurface::InitializeOneOffInternal() { | 156 bool GLSurface::InitializeOneOffInternal() { |
104 switch (GetGLImplementation()) { | 157 switch (GetGLImplementation()) { |
105 case kGLImplementationEGLGLES2: | 158 case kGLImplementationEGLGLES2: |
106 if (!GLSurfaceEGL::InitializeOneOff()) { | 159 if (!GLSurfaceEGL::InitializeOneOff()) { |
107 LOG(ERROR) << "GLSurfaceEGL::InitializeOneOff failed."; | 160 LOG(ERROR) << "GLSurfaceEGL::InitializeOneOff failed."; |
108 return false; | 161 return false; |
109 } | 162 } |
(...skipping 11 matching lines...) Expand all Loading... |
121 scoped_refptr<GLSurface> GLSurface::CreateViewGLSurface( | 174 scoped_refptr<GLSurface> GLSurface::CreateViewGLSurface( |
122 gfx::AcceleratedWidget window) { | 175 gfx::AcceleratedWidget window) { |
123 if (GetGLImplementation() == kGLImplementationOSMesaGL) { | 176 if (GetGLImplementation() == kGLImplementationOSMesaGL) { |
124 scoped_refptr<GLSurface> surface(new GLSurfaceOSMesaHeadless()); | 177 scoped_refptr<GLSurface> surface(new GLSurfaceOSMesaHeadless()); |
125 if (!surface->Initialize()) | 178 if (!surface->Initialize()) |
126 return NULL; | 179 return NULL; |
127 return surface; | 180 return surface; |
128 } | 181 } |
129 DCHECK(GetGLImplementation() == kGLImplementationEGLGLES2); | 182 DCHECK(GetGLImplementation() == kGLImplementationEGLGLES2); |
130 if (window != kNullAcceleratedWidget) { | 183 if (window != kNullAcceleratedWidget) { |
131 scoped_ptr<ui::SurfaceOzoneEGL> surface_ozone = | 184 scoped_refptr<GLSurface> surface; |
132 ui::SurfaceFactoryOzone::GetInstance()->CreateEGLSurfaceForWidget( | 185 if (GLSurfaceEGL::IsEGLSurfacelessContextSupported() && |
133 window); | 186 ui::SurfaceFactoryOzone::GetInstance() |
134 if (!surface_ozone) | 187 ->CanShowPrimaryPlaneAsOverlay()) { |
135 return NULL; | 188 scoped_ptr<ui::SurfaceOzoneEGL> surface_ozone = |
| 189 ui::SurfaceFactoryOzone::GetInstance() |
| 190 ->CreateSurfacelessEGLSurfaceForWidget(window); |
| 191 if (!surface_ozone) |
| 192 return NULL; |
| 193 surface = new GLSurfaceOzoneSurfaceless(surface_ozone.Pass(), window); |
| 194 } else { |
| 195 scoped_ptr<ui::SurfaceOzoneEGL> surface_ozone = |
| 196 ui::SurfaceFactoryOzone::GetInstance()->CreateEGLSurfaceForWidget( |
| 197 window); |
| 198 if (!surface_ozone) |
| 199 return NULL; |
136 | 200 |
137 scoped_ptr<VSyncProvider> vsync_provider = | 201 surface = new GLSurfaceOzoneEGL(surface_ozone.Pass(), window); |
138 surface_ozone->CreateVSyncProvider(); | 202 } |
139 scoped_refptr<GLSurfaceOzoneEGL> surface = | 203 if (!surface->Initialize()) |
140 new GLSurfaceOzoneEGL(surface_ozone.Pass(), window); | |
141 if (!surface->Initialize(vsync_provider.Pass())) | |
142 return NULL; | 204 return NULL; |
143 return surface; | 205 return surface; |
144 } else { | 206 } else { |
145 scoped_refptr<GLSurface> surface = new GLSurfaceStub(); | 207 scoped_refptr<GLSurface> surface = new GLSurfaceStub(); |
146 if (surface->Initialize()) | 208 if (surface->Initialize()) |
147 return surface; | 209 return surface; |
148 } | 210 } |
149 return NULL; | 211 return NULL; |
150 } | 212 } |
151 | 213 |
(...skipping 25 matching lines...) Expand all Loading... |
177 NOTREACHED(); | 239 NOTREACHED(); |
178 return NULL; | 240 return NULL; |
179 } | 241 } |
180 } | 242 } |
181 | 243 |
182 EGLNativeDisplayType GetPlatformDefaultEGLNativeDisplay() { | 244 EGLNativeDisplayType GetPlatformDefaultEGLNativeDisplay() { |
183 return ui::SurfaceFactoryOzone::GetInstance()->GetNativeDisplay(); | 245 return ui::SurfaceFactoryOzone::GetInstance()->GetNativeDisplay(); |
184 } | 246 } |
185 | 247 |
186 } // namespace gfx | 248 } // namespace gfx |
OLD | NEW |