OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/common/gpu/image_transport_surface.h" | 5 #include "content/common/gpu/image_transport_surface.h" |
6 | 6 |
| 7 #include "base/command_line.h" |
7 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "content/common/gpu/gpu_channel.h" |
| 10 #include "content/common/gpu/gpu_channel_manager.h" |
8 #include "content/common/gpu/gpu_command_buffer_stub.h" | 11 #include "content/common/gpu/gpu_command_buffer_stub.h" |
9 #include "content/common/gpu/gpu_surface_lookup.h" | 12 #include "content/common/gpu/gpu_surface_lookup.h" |
| 13 #include "content/common/gpu/image_transport_surface.h" |
| 14 #include "content/public/common/content_switches.h" |
10 #include "ui/gl/gl_surface_egl.h" | 15 #include "ui/gl/gl_surface_egl.h" |
11 | 16 |
12 namespace content { | 17 namespace content { |
13 | 18 |
| 19 namespace { |
| 20 |
| 21 class ImageTransportSurfaceAndroid : public PassThroughImageTransportSurface { |
| 22 public: |
| 23 ImageTransportSurfaceAndroid(GpuChannelManager* manager, |
| 24 GpuCommandBufferStub* stub, |
| 25 gfx::GLSurface* surface, |
| 26 uint32 parent_client_id); |
| 27 |
| 28 // gfx::GLSurface implementation. |
| 29 virtual bool Initialize() OVERRIDE; |
| 30 virtual bool SwapBuffers() OVERRIDE; |
| 31 virtual std::string GetExtensions() OVERRIDE; |
| 32 virtual void SetFrontbufferAllocation(bool allocated) OVERRIDE; |
| 33 |
| 34 protected: |
| 35 virtual ~ImageTransportSurfaceAndroid(); |
| 36 |
| 37 private: |
| 38 uint32 parent_client_id_; |
| 39 bool frontbuffer_suggested_allocation_; |
| 40 }; |
| 41 |
| 42 ImageTransportSurfaceAndroid::ImageTransportSurfaceAndroid( |
| 43 GpuChannelManager* manager, |
| 44 GpuCommandBufferStub* stub, |
| 45 gfx::GLSurface* surface, |
| 46 uint32 parent_client_id) |
| 47 : PassThroughImageTransportSurface(manager, stub, surface, true), |
| 48 parent_client_id_(parent_client_id), |
| 49 frontbuffer_suggested_allocation_(true) {} |
| 50 |
| 51 ImageTransportSurfaceAndroid::~ImageTransportSurfaceAndroid() {} |
| 52 |
| 53 bool ImageTransportSurfaceAndroid::Initialize() { |
| 54 if (!surface()) |
| 55 return false; |
| 56 |
| 57 if (!PassThroughImageTransportSurface::Initialize()) |
| 58 return false; |
| 59 |
| 60 GpuChannel* parent_channel = |
| 61 GetHelper()->manager()->LookupChannel(parent_client_id_); |
| 62 if (parent_channel) { |
| 63 const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 64 if (command_line->HasSwitch(switches::kUIPrioritizeInGpuProcess)) |
| 65 GetHelper()->SetPreemptByFlag(parent_channel->GetPreemptionFlag()); |
| 66 } |
| 67 |
| 68 return true; |
| 69 } |
| 70 |
| 71 std::string ImageTransportSurfaceAndroid::GetExtensions() { |
| 72 std::string extensions = gfx::GLSurface::GetExtensions(); |
| 73 extensions += extensions.empty() ? "" : " "; |
| 74 extensions += "GL_CHROMIUM_front_buffer_cached "; |
| 75 return extensions; |
| 76 } |
| 77 |
| 78 void ImageTransportSurfaceAndroid::SetFrontbufferAllocation(bool allocation) { |
| 79 if (frontbuffer_suggested_allocation_ == allocation) |
| 80 return; |
| 81 frontbuffer_suggested_allocation_ = allocation; |
| 82 // TODO(sievers): This races with CompositorFrame messages. |
| 83 if (!allocation) |
| 84 GetHelper()->SendAcceleratedSurfaceRelease(); |
| 85 } |
| 86 |
| 87 bool ImageTransportSurfaceAndroid::SwapBuffers() { |
| 88 NOTREACHED(); |
| 89 return false; |
| 90 } |
| 91 |
| 92 } // anonymous namespace |
| 93 |
14 // static | 94 // static |
15 scoped_refptr<gfx::GLSurface> ImageTransportSurface::CreateNativeSurface( | 95 scoped_refptr<gfx::GLSurface> ImageTransportSurface::CreateNativeSurface( |
16 GpuChannelManager* manager, | 96 GpuChannelManager* manager, |
17 GpuCommandBufferStub* stub, | 97 GpuCommandBufferStub* stub, |
18 const gfx::GLSurfaceHandle& handle) { | 98 const gfx::GLSurfaceHandle& handle) { |
| 99 if (handle.transport_type == gfx::NATIVE_TRANSPORT) { |
| 100 return scoped_refptr<gfx::GLSurface>( |
| 101 new ImageTransportSurfaceAndroid(manager, |
| 102 stub, |
| 103 manager->GetDefaultOffscreenSurface(), |
| 104 handle.parent_client_id)); |
| 105 } |
| 106 |
19 DCHECK(GpuSurfaceLookup::GetInstance()); | 107 DCHECK(GpuSurfaceLookup::GetInstance()); |
20 DCHECK_EQ(handle.transport_type, gfx::NATIVE_DIRECT); | 108 DCHECK_EQ(handle.transport_type, gfx::NATIVE_DIRECT); |
21 ANativeWindow* window = | 109 ANativeWindow* window = |
22 GpuSurfaceLookup::GetInstance()->AcquireNativeWidget( | 110 GpuSurfaceLookup::GetInstance()->AcquireNativeWidget( |
23 stub->surface_id()); | 111 stub->surface_id()); |
24 scoped_refptr<gfx::GLSurface> surface = | 112 scoped_refptr<gfx::GLSurface> surface = |
25 new gfx::NativeViewGLSurfaceEGL(window); | 113 new gfx::NativeViewGLSurfaceEGL(window); |
26 bool initialize_success = surface->Initialize(); | 114 bool initialize_success = surface->Initialize(); |
27 if (window) | 115 if (window) |
28 ANativeWindow_release(window); | 116 ANativeWindow_release(window); |
29 if (!initialize_success) | 117 if (!initialize_success) |
30 return scoped_refptr<gfx::GLSurface>(); | 118 return scoped_refptr<gfx::GLSurface>(); |
31 | 119 |
32 return scoped_refptr<gfx::GLSurface>(new PassThroughImageTransportSurface( | 120 return scoped_refptr<gfx::GLSurface>(new PassThroughImageTransportSurface( |
33 manager, stub, surface.get(), false)); | 121 manager, stub, surface.get(), false)); |
34 } | 122 } |
35 | 123 |
36 } // namespace content | 124 } // namespace content |
OLD | NEW |