[Android WebView] Fix webview perf bot switchover to use org.chromium.webview_shell...
[chromium-blink-merge.git] / content / common / gpu / image_transport_surface_mac.mm
blob04b6bc3b4d542372e50fe1e7ce02749c4df7af03
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.
5 #include "content/common/gpu/image_transport_surface.h"
7 #include "content/common/gpu/gpu_messages.h"
8 #include "ui/gfx/native_widget_types.h"
9 #include "ui/gl/gl_context.h"
10 #include "ui/gl/gl_implementation.h"
11 #include "ui/gl/gl_surface_osmesa.h"
13 namespace content {
15 scoped_refptr<gfx::GLSurface> ImageTransportSurfaceCreateNativeSurface(
16     GpuChannelManager* manager,
17     GpuCommandBufferStub* stub,
18     gfx::PluginWindowHandle handle);
20 namespace {
22 // A subclass of GLSurfaceOSMesa that doesn't print an error message when
23 // SwapBuffers() is called.
24 class DRTSurfaceOSMesa : public gfx::GLSurfaceOSMesa {
25  public:
26   // Size doesn't matter, the surface is resized to the right size later.
27   DRTSurfaceOSMesa()
28       : GLSurfaceOSMesa(gfx::OSMesaSurfaceFormatRGBA, gfx::Size(1, 1)) {}
30   // Implement a subset of GLSurface.
31   gfx::SwapResult SwapBuffers() override;
33  private:
34   ~DRTSurfaceOSMesa() override {}
35   DISALLOW_COPY_AND_ASSIGN(DRTSurfaceOSMesa);
38 gfx::SwapResult DRTSurfaceOSMesa::SwapBuffers() {
39   return gfx::SwapResult::SWAP_ACK;
42 bool g_allow_os_mesa = false;
44 }  //  namespace
46 // static
47 scoped_refptr<gfx::GLSurface> ImageTransportSurface::CreateNativeSurface(
48     GpuChannelManager* manager,
49     GpuCommandBufferStub* stub,
50     const gfx::GLSurfaceHandle& surface_handle) {
51   DCHECK(surface_handle.transport_type == gfx::NATIVE_DIRECT ||
52          surface_handle.transport_type == gfx::NULL_TRANSPORT);
54   switch (gfx::GetGLImplementation()) {
55     case gfx::kGLImplementationDesktopGL:
56     case gfx::kGLImplementationDesktopGLCoreProfile:
57     case gfx::kGLImplementationAppleGL:
58       return ImageTransportSurfaceCreateNativeSurface(manager, stub,
59                                                       surface_handle.handle);
60     default:
61       // Content shell in DRT mode spins up a gpu process which needs an
62       // image transport surface, but that surface isn't used to read pixel
63       // baselines. So this is mostly a dummy surface.
64       if (!g_allow_os_mesa) {
65         NOTREACHED();
66         return scoped_refptr<gfx::GLSurface>();
67       }
68       scoped_refptr<gfx::GLSurface> surface(new DRTSurfaceOSMesa());
69       if (!surface.get() || !surface->Initialize())
70         return surface;
71       return scoped_refptr<gfx::GLSurface>(new PassThroughImageTransportSurface(
72           manager, stub, surface.get()));
73   }
76 // static
77 void ImageTransportSurface::SetAllowOSMesaForTesting(bool allow) {
78   g_allow_os_mesa = allow;
81 }  // namespace content