Chromium Code Reviews| 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" |
| 11 #include "ui/gl/gl_image.h" | 11 #include "ui/gl/gl_image.h" |
| 12 #include "ui/gl/gl_implementation.h" | 12 #include "ui/gl/gl_implementation.h" |
| 13 #include "ui/gl/gl_surface_egl.h" | 13 #include "ui/gl/gl_surface_egl.h" |
| 14 #include "ui/gl/gl_surface_osmesa.h" | 14 #include "ui/gl/gl_surface_osmesa.h" |
| 15 #include "ui/gl/gl_surface_stub.h" | 15 #include "ui/gl/gl_surface_stub.h" |
| 16 #include "ui/gl/scoped_make_current.h" | 16 #include "ui/gl/scoped_make_current.h" |
| 17 #include "ui/ozone/gpu/gpu_memory_buffer_factory_ozone_native_buffer.h" | |
| 18 #include "ui/ozone/public/native_pixmap.h" | |
| 17 #include "ui/ozone/public/surface_factory_ozone.h" | 19 #include "ui/ozone/public/surface_factory_ozone.h" |
| 18 #include "ui/ozone/public/surface_ozone_egl.h" | 20 #include "ui/ozone/public/surface_ozone_egl.h" |
| 19 | 21 |
| 20 namespace gfx { | 22 namespace gfx { |
| 21 | 23 |
| 22 namespace { | 24 namespace { |
| 23 | 25 |
| 24 // A thin wrapper around GLSurfaceEGL that owns the EGLNativeWindow | 26 // A thin wrapper around GLSurfaceEGL that owns the EGLNativeWindow |
| 25 class GL_EXPORT GLSurfaceOzoneEGL : public NativeViewGLSurfaceEGL { | 27 class GL_EXPORT GLSurfaceOzoneEGL : public NativeViewGLSurfaceEGL { |
| 26 public: | 28 public: |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 150 return ozone_surface_->OnSwapBuffersAsync(callback); | 152 return ozone_surface_->OnSwapBuffersAsync(callback); |
| 151 } | 153 } |
| 152 bool PostSubBufferAsync(int x, | 154 bool PostSubBufferAsync(int x, |
| 153 int y, | 155 int y, |
| 154 int width, | 156 int width, |
| 155 int height, | 157 int height, |
| 156 const SwapCompletionCallback& callback) override { | 158 const SwapCompletionCallback& callback) override { |
| 157 return SwapBuffersAsync(callback); | 159 return SwapBuffersAsync(callback); |
| 158 } | 160 } |
| 159 | 161 |
| 160 private: | 162 protected: |
| 161 ~GLSurfaceOzoneSurfaceless() override { | 163 ~GLSurfaceOzoneSurfaceless() override { |
| 162 Destroy(); // EGL surface must be destroyed before SurfaceOzone | 164 Destroy(); // EGL surface must be destroyed before SurfaceOzone |
| 163 } | 165 } |
| 164 | 166 |
| 165 bool Flush() { | 167 bool Flush() { |
| 166 glFlush(); | 168 glFlush(); |
| 167 // TODO: the following should be replaced by a per surface flush as it gets | 169 // TODO: the following should be replaced by a per surface flush as it gets |
| 168 // implemented in GL drivers. | 170 // implemented in GL drivers. |
| 169 if (has_implicit_external_sync_) { | 171 if (has_implicit_external_sync_) { |
| 170 const EGLint attrib_list[] = { | 172 const EGLint attrib_list[] = { |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 187 } | 189 } |
| 188 | 190 |
| 189 // The native surface. Deleting this is allowed to free the EGLNativeWindow. | 191 // The native surface. Deleting this is allowed to free the EGLNativeWindow. |
| 190 scoped_ptr<ui::SurfaceOzoneEGL> ozone_surface_; | 192 scoped_ptr<ui::SurfaceOzoneEGL> ozone_surface_; |
| 191 AcceleratedWidget widget_; | 193 AcceleratedWidget widget_; |
| 192 scoped_ptr<VSyncProvider> vsync_provider_; | 194 scoped_ptr<VSyncProvider> vsync_provider_; |
| 193 bool has_implicit_external_sync_; | 195 bool has_implicit_external_sync_; |
| 194 DISALLOW_COPY_AND_ASSIGN(GLSurfaceOzoneSurfaceless); | 196 DISALLOW_COPY_AND_ASSIGN(GLSurfaceOzoneSurfaceless); |
| 195 }; | 197 }; |
| 196 | 198 |
| 199 // This provides surface-like semantics implemented through surfaceless. | |
| 200 // A framebuffer is bound automatically and re-bound at each swap. | |
| 201 class GL_EXPORT GLSurfaceOzoneSurfacelessSurfaceImpl | |
| 202 : public GLSurfaceOzoneSurfaceless { | |
| 203 public: | |
| 204 GLSurfaceOzoneSurfacelessSurfaceImpl( | |
| 205 scoped_ptr<ui::SurfaceOzoneEGL> ozone_surface, | |
| 206 AcceleratedWidget widget) | |
| 207 : GLSurfaceOzoneSurfaceless(ozone_surface.Pass(), widget), | |
| 208 fbo_(0), | |
| 209 current_surface_(0) { | |
| 210 textures_[0] = 0; | |
| 211 textures_[1] = 0; | |
| 212 } | |
| 213 | |
| 214 void BindFB() { | |
|
dnicoara
2015/02/19 00:10:13
I think this can be private, right?
Also could yo
achaulk
2015/02/19 00:19:05
Done.
| |
| 215 glBindFramebufferEXT(GL_FRAMEBUFFER, fbo_); | |
| 216 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, | |
| 217 GL_TEXTURE_2D, textures_[current_surface_], 0); | |
| 218 } | |
| 219 | |
| 220 unsigned int GetBackingFrameBufferObject() override { return fbo_; } | |
| 221 | |
| 222 bool OnMakeCurrent(GLContext* context) override { | |
| 223 if (!fbo_) { | |
| 224 glGenFramebuffersEXT(1, &fbo_); | |
| 225 if (!fbo_) | |
| 226 return false; | |
| 227 glGenTextures(2, textures_); | |
| 228 // Create and bind our pixmaps. | |
| 229 ResizePixmaps(); | |
| 230 } | |
| 231 BindFB(); | |
| 232 return SurfacelessEGL::OnMakeCurrent(context); | |
| 233 } | |
| 234 | |
| 235 bool Resize(const gfx::Size& size) override { | |
| 236 return GLSurfaceOzoneSurfaceless::Resize(size) && ResizePixmaps(); | |
| 237 } | |
| 238 | |
| 239 bool SupportsPostSubBuffer() override { return false; } | |
| 240 | |
| 241 bool SwapBuffers() override { | |
| 242 bool ret = images_[current_surface_]->ScheduleOverlayPlane( | |
| 243 widget_, 0, OverlayTransform::OVERLAY_TRANSFORM_NONE, | |
| 244 gfx::Rect(GetSize()), gfx::RectF(1, 1)) && | |
| 245 GLSurfaceOzoneSurfaceless::SwapBuffers(); | |
| 246 current_surface_ ^= 1; | |
| 247 BindFB(); | |
| 248 return ret; | |
| 249 } | |
| 250 | |
| 251 private: | |
| 252 ~GLSurfaceOzoneSurfacelessSurfaceImpl() override {} | |
|
dnicoara
2015/02/19 00:10:13
You'll need to cleanup all the allocated resource
achaulk
2015/02/19 00:19:05
Done.
| |
| 253 | |
| 254 bool ResizePixmaps() { | |
| 255 if (!fbo_) | |
| 256 return true; | |
| 257 for (int i = 0; i < 2; i++) { | |
| 258 scoped_refptr<ui::NativePixmap> pixmap = | |
| 259 ui::SurfaceFactoryOzone::GetInstance()->CreateNativePixmap( | |
| 260 widget_, GetSize(), ui::SurfaceFactoryOzone::RGBA_8888, | |
| 261 ui::SurfaceFactoryOzone::SCANOUT); | |
| 262 if (!pixmap) | |
| 263 return false; | |
| 264 images_[i] = | |
| 265 ui::GpuMemoryBufferFactoryOzoneNativeBuffer::CreateImageForPixmap( | |
| 266 pixmap, GetSize(), GpuMemoryBuffer::Format::RGBA_8888, GL_RGBA); | |
| 267 // Bind image to texture | |
| 268 glBindTexture(GL_TEXTURE_EXTERNAL_OES, textures_[i]); | |
| 269 if (!images_[i]->BindTexImage(GL_TEXTURE_EXTERNAL_OES)) | |
| 270 return false; | |
| 271 } | |
| 272 return true; | |
| 273 } | |
| 274 | |
| 275 GLuint fbo_; | |
| 276 GLuint textures_[2]; | |
| 277 scoped_refptr<GLImage> images_[2]; | |
| 278 int current_surface_; | |
| 279 DISALLOW_COPY_AND_ASSIGN(GLSurfaceOzoneSurfacelessSurfaceImpl); | |
| 280 }; | |
| 281 | |
| 197 } // namespace | 282 } // namespace |
| 198 | 283 |
| 199 // static | 284 // static |
| 200 bool GLSurface::InitializeOneOffInternal() { | 285 bool GLSurface::InitializeOneOffInternal() { |
| 201 switch (GetGLImplementation()) { | 286 switch (GetGLImplementation()) { |
| 202 case kGLImplementationEGLGLES2: | 287 case kGLImplementationEGLGLES2: |
| 203 if (!GLSurfaceEGL::InitializeOneOff()) { | 288 if (!GLSurfaceEGL::InitializeOneOff()) { |
| 204 LOG(ERROR) << "GLSurfaceEGL::InitializeOneOff failed."; | 289 LOG(ERROR) << "GLSurfaceEGL::InitializeOneOff failed."; |
| 205 return false; | 290 return false; |
| 206 } | 291 } |
| 207 | 292 |
| 208 return true; | 293 return true; |
| 209 case kGLImplementationOSMesaGL: | 294 case kGLImplementationOSMesaGL: |
| 210 case kGLImplementationMockGL: | 295 case kGLImplementationMockGL: |
| 211 return true; | 296 return true; |
| 212 default: | 297 default: |
| 213 return false; | 298 return false; |
| 214 } | 299 } |
| 215 } | 300 } |
| 216 | 301 |
| 217 // static | 302 // static |
| 303 scoped_refptr<GLSurface> GLSurface::CreateSurfacelessViewGLSurface( | |
| 304 gfx::AcceleratedWidget window) { | |
| 305 if (GetGLImplementation() == kGLImplementationEGLGLES2 && | |
| 306 window != kNullAcceleratedWidget && | |
| 307 GLSurfaceEGL::IsEGLSurfacelessContextSupported() && | |
| 308 ui::SurfaceFactoryOzone::GetInstance()->CanShowPrimaryPlaneAsOverlay()) { | |
| 309 scoped_ptr<ui::SurfaceOzoneEGL> surface_ozone = | |
| 310 ui::SurfaceFactoryOzone::GetInstance() | |
| 311 ->CreateSurfacelessEGLSurfaceForWidget(window); | |
| 312 if (!surface_ozone) | |
| 313 return NULL; | |
| 314 scoped_refptr<GLSurface> surface; | |
| 315 surface = new GLSurfaceOzoneSurfaceless(surface_ozone.Pass(), window); | |
| 316 if (surface->Initialize()) | |
| 317 return surface; | |
| 318 } | |
| 319 | |
| 320 return nullptr; | |
| 321 } | |
| 322 | |
| 323 // static | |
| 218 scoped_refptr<GLSurface> GLSurface::CreateViewGLSurface( | 324 scoped_refptr<GLSurface> GLSurface::CreateViewGLSurface( |
| 219 gfx::AcceleratedWidget window) { | 325 gfx::AcceleratedWidget window) { |
| 220 if (GetGLImplementation() == kGLImplementationOSMesaGL) { | 326 if (GetGLImplementation() == kGLImplementationOSMesaGL) { |
| 221 scoped_refptr<GLSurface> surface(new GLSurfaceOSMesaHeadless()); | 327 scoped_refptr<GLSurface> surface(new GLSurfaceOSMesaHeadless()); |
| 222 if (!surface->Initialize()) | 328 if (!surface->Initialize()) |
| 223 return NULL; | 329 return NULL; |
| 224 return surface; | 330 return surface; |
| 225 } | 331 } |
| 226 DCHECK(GetGLImplementation() == kGLImplementationEGLGLES2); | 332 DCHECK(GetGLImplementation() == kGLImplementationEGLGLES2); |
| 227 if (window != kNullAcceleratedWidget) { | 333 if (window != kNullAcceleratedWidget) { |
| 228 scoped_refptr<GLSurface> surface; | 334 scoped_refptr<GLSurface> surface; |
| 229 if (GLSurfaceEGL::IsEGLSurfacelessContextSupported() && | 335 if (GLSurfaceEGL::IsEGLSurfacelessContextSupported() && |
| 230 ui::SurfaceFactoryOzone::GetInstance() | 336 ui::SurfaceFactoryOzone::GetInstance() |
| 231 ->CanShowPrimaryPlaneAsOverlay()) { | 337 ->CanShowPrimaryPlaneAsOverlay()) { |
| 232 scoped_ptr<ui::SurfaceOzoneEGL> surface_ozone = | 338 scoped_ptr<ui::SurfaceOzoneEGL> surface_ozone = |
| 233 ui::SurfaceFactoryOzone::GetInstance() | 339 ui::SurfaceFactoryOzone::GetInstance() |
| 234 ->CreateSurfacelessEGLSurfaceForWidget(window); | 340 ->CreateSurfacelessEGLSurfaceForWidget(window); |
| 235 if (!surface_ozone) | 341 if (!surface_ozone) |
| 236 return NULL; | 342 return NULL; |
| 237 surface = new GLSurfaceOzoneSurfaceless(surface_ozone.Pass(), window); | 343 surface = new GLSurfaceOzoneSurfacelessSurfaceImpl(surface_ozone.Pass(), |
| 344 window); | |
| 238 } else { | 345 } else { |
| 239 scoped_ptr<ui::SurfaceOzoneEGL> surface_ozone = | 346 scoped_ptr<ui::SurfaceOzoneEGL> surface_ozone = |
| 240 ui::SurfaceFactoryOzone::GetInstance()->CreateEGLSurfaceForWidget( | 347 ui::SurfaceFactoryOzone::GetInstance()->CreateEGLSurfaceForWidget( |
| 241 window); | 348 window); |
| 242 if (!surface_ozone) | 349 if (!surface_ozone) |
| 243 return NULL; | 350 return NULL; |
| 244 | 351 |
| 245 surface = new GLSurfaceOzoneEGL(surface_ozone.Pass(), window); | 352 surface = new GLSurfaceOzoneEGL(surface_ozone.Pass(), window); |
| 246 } | 353 } |
| 247 if (!surface->Initialize()) | 354 if (!surface->Initialize()) |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 283 NOTREACHED(); | 390 NOTREACHED(); |
| 284 return NULL; | 391 return NULL; |
| 285 } | 392 } |
| 286 } | 393 } |
| 287 | 394 |
| 288 EGLNativeDisplayType GetPlatformDefaultEGLNativeDisplay() { | 395 EGLNativeDisplayType GetPlatformDefaultEGLNativeDisplay() { |
| 289 return ui::SurfaceFactoryOzone::GetInstance()->GetNativeDisplay(); | 396 return ui::SurfaceFactoryOzone::GetInstance()->GetNativeDisplay(); |
| 290 } | 397 } |
| 291 | 398 |
| 292 } // namespace gfx | 399 } // namespace gfx |
| OLD | NEW |