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