OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "content/common/gpu/image_transport_surface.h" |
| 6 |
| 7 #include "base/macros.h" |
| 8 #include "content/common/gpu/pass_through_image_transport_surface.h" |
| 9 #include "ui/gfx/native_widget_types.h" |
| 10 #include "ui/gl/gl_surface_osmesa.h" |
| 11 |
| 12 namespace content { |
| 13 |
| 14 scoped_refptr<gfx::GLSurface> ImageTransportSurfaceCreateNativeSurface( |
| 15 GpuChannelManager* manager, |
| 16 GpuCommandBufferStub* stub, |
| 17 gpu::SurfaceHandle handle); |
| 18 |
| 19 namespace { |
| 20 |
| 21 // A subclass of GLSurfaceOSMesa that doesn't print an error message when |
| 22 // SwapBuffers() is called. |
| 23 class DRTSurfaceOSMesa : public gfx::GLSurfaceOSMesa { |
| 24 public: |
| 25 // Size doesn't matter, the surface is resized to the right size later. |
| 26 DRTSurfaceOSMesa() |
| 27 : GLSurfaceOSMesa(gfx::GLSurface::SURFACE_OSMESA_RGBA, gfx::Size(1, 1)) {} |
| 28 |
| 29 // Implement a subset of GLSurface. |
| 30 gfx::SwapResult SwapBuffers() override; |
| 31 |
| 32 private: |
| 33 ~DRTSurfaceOSMesa() override {} |
| 34 DISALLOW_COPY_AND_ASSIGN(DRTSurfaceOSMesa); |
| 35 }; |
| 36 |
| 37 gfx::SwapResult DRTSurfaceOSMesa::SwapBuffers() { |
| 38 return gfx::SwapResult::SWAP_ACK; |
| 39 } |
| 40 |
| 41 bool g_allow_os_mesa = false; |
| 42 |
| 43 } // namespace |
| 44 |
| 45 // static |
| 46 scoped_refptr<gfx::GLSurface> ImageTransportSurface::CreateNativeSurface( |
| 47 GpuChannelManager* manager, |
| 48 GpuCommandBufferStub* stub, |
| 49 gpu::SurfaceHandle surface_handle, |
| 50 gfx::GLSurface::Format format) { |
| 51 DCHECK_NE(surface_handle, gpu::kNullSurfaceHandle); |
| 52 |
| 53 switch (gfx::GetGLImplementation()) { |
| 54 case gfx::kGLImplementationDesktopGL: |
| 55 case gfx::kGLImplementationDesktopGLCoreProfile: |
| 56 case gfx::kGLImplementationAppleGL: |
| 57 return ImageTransportSurfaceCreateNativeSurface(manager, stub, |
| 58 surface_handle); |
| 59 default: |
| 60 // Content shell in DRT mode spins up a gpu process which needs an |
| 61 // image transport surface, but that surface isn't used to read pixel |
| 62 // baselines. So this is mostly a dummy surface. |
| 63 if (!g_allow_os_mesa) { |
| 64 NOTREACHED(); |
| 65 return nullptr; |
| 66 } |
| 67 scoped_refptr<gfx::GLSurface> surface(new DRTSurfaceOSMesa()); |
| 68 if (!surface.get() || !surface->Initialize(format)) |
| 69 return surface; |
| 70 return scoped_refptr<gfx::GLSurface>(new PassThroughImageTransportSurface( |
| 71 manager, stub, surface.get())); |
| 72 } |
| 73 } |
| 74 |
| 75 // static |
| 76 void ImageTransportSurface::SetAllowOSMesaForTesting(bool allow) { |
| 77 g_allow_os_mesa = allow; |
| 78 } |
| 79 |
| 80 } // namespace content |
OLD | NEW |