| 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/command_line.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "content/common/gpu/gpu_channel.h" | 9 #include "content/common/gpu/gpu_channel.h" |
| 10 #include "content/common/gpu/gpu_channel_manager.h" | 10 #include "content/common/gpu/gpu_channel_manager.h" |
| 11 #include "content/common/gpu/gpu_command_buffer_stub.h" | 11 #include "content/common/gpu/gpu_command_buffer_stub.h" |
| 12 #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" | 13 #include "content/common/gpu/null_transport_surface.h" |
| 14 #include "content/public/common/content_switches.h" | 14 #include "content/public/common/content_switches.h" |
| 15 #include "ui/gl/gl_surface_egl.h" | 15 #include "ui/gl/gl_surface_egl.h" |
| 16 | 16 |
| 17 namespace content { | 17 namespace content { |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 20 // Amount of time the GPU is allowed to idle before it powers down. | 20 // Amount of time the GPU is allowed to idle before it powers down. |
| 21 const int kMaxGpuIdleTimeMs = 40; | 21 const int kMaxGpuIdleTimeMs = 40; |
| 22 // Maximum amount of time we keep pinging the GPU waiting for the client to | 22 // Maximum amount of time we keep pinging the GPU waiting for the client to |
| 23 // draw. | 23 // draw. |
| 24 const int kMaxKeepAliveTimeMs = 200; | 24 const int kMaxKeepAliveTimeMs = 200; |
| 25 // Last time we know the GPU was powered on. Global for tracking across all | 25 // Last time we know the GPU was powered on. Global for tracking across all |
| 26 // transport surfaces. | 26 // transport surfaces. |
| 27 int64 g_last_gpu_access_ticks; | 27 int64 g_last_gpu_access_ticks; |
| 28 | 28 |
| 29 void DidAccessGpu() { | 29 void DidAccessGpu() { |
| 30 g_last_gpu_access_ticks = base::TimeTicks::Now().ToInternalValue(); | 30 g_last_gpu_access_ticks = base::TimeTicks::Now().ToInternalValue(); |
| 31 } | 31 } |
| 32 | 32 |
| 33 class ImageTransportSurfaceAndroid | 33 class ImageTransportSurfaceAndroid |
| 34 : public PassThroughImageTransportSurface, | 34 : public NullTransportSurface, |
| 35 public base::SupportsWeakPtr<ImageTransportSurfaceAndroid> { | 35 public base::SupportsWeakPtr<ImageTransportSurfaceAndroid> { |
| 36 public: | 36 public: |
| 37 ImageTransportSurfaceAndroid(GpuChannelManager* manager, | 37 ImageTransportSurfaceAndroid(GpuChannelManager* manager, |
| 38 GpuCommandBufferStub* stub, | 38 GpuCommandBufferStub* stub, |
| 39 gfx::GLSurface* surface, | 39 const gfx::GLSurfaceHandle& handle); |
| 40 uint32 parent_client_id); | |
| 41 | 40 |
| 42 // gfx::GLSurface implementation. | 41 // gfx::GLSurface implementation. |
| 43 virtual bool Initialize() OVERRIDE; | |
| 44 virtual bool SwapBuffers() OVERRIDE; | |
| 45 virtual bool OnMakeCurrent(gfx::GLContext* context) OVERRIDE; | 42 virtual bool OnMakeCurrent(gfx::GLContext* context) OVERRIDE; |
| 46 virtual void WakeUpGpu() OVERRIDE; | 43 virtual void WakeUpGpu() OVERRIDE; |
| 47 | 44 |
| 48 protected: | 45 protected: |
| 49 virtual ~ImageTransportSurfaceAndroid(); | 46 virtual ~ImageTransportSurfaceAndroid(); |
| 50 | 47 |
| 51 private: | 48 private: |
| 52 void ScheduleWakeUp(); | 49 void ScheduleWakeUp(); |
| 53 void DoWakeUpGpu(); | 50 void DoWakeUpGpu(); |
| 54 | 51 |
| 55 uint32 parent_client_id_; | |
| 56 base::TimeTicks begin_wake_up_time_; | 52 base::TimeTicks begin_wake_up_time_; |
| 57 }; | 53 }; |
| 58 | 54 |
| 59 class DirectSurfaceAndroid : public PassThroughImageTransportSurface { | 55 class DirectSurfaceAndroid : public PassThroughImageTransportSurface { |
| 60 public: | 56 public: |
| 61 DirectSurfaceAndroid(GpuChannelManager* manager, | 57 DirectSurfaceAndroid(GpuChannelManager* manager, |
| 62 GpuCommandBufferStub* stub, | 58 GpuCommandBufferStub* stub, |
| 63 gfx::GLSurface* surface); | 59 gfx::GLSurface* surface); |
| 64 | 60 |
| 65 // gfx::GLSurface implementation. | 61 // gfx::GLSurface implementation. |
| 66 virtual bool SwapBuffers() OVERRIDE; | 62 virtual bool SwapBuffers() OVERRIDE; |
| 67 | 63 |
| 68 protected: | 64 protected: |
| 69 virtual ~DirectSurfaceAndroid(); | 65 virtual ~DirectSurfaceAndroid(); |
| 70 | 66 |
| 71 private: | 67 private: |
| 72 DISALLOW_COPY_AND_ASSIGN(DirectSurfaceAndroid); | 68 DISALLOW_COPY_AND_ASSIGN(DirectSurfaceAndroid); |
| 73 }; | 69 }; |
| 74 | 70 |
| 75 ImageTransportSurfaceAndroid::ImageTransportSurfaceAndroid( | 71 ImageTransportSurfaceAndroid::ImageTransportSurfaceAndroid( |
| 76 GpuChannelManager* manager, | 72 GpuChannelManager* manager, |
| 77 GpuCommandBufferStub* stub, | 73 GpuCommandBufferStub* stub, |
| 78 gfx::GLSurface* surface, | 74 const gfx::GLSurfaceHandle& handle) |
| 79 uint32 parent_client_id) | 75 : NullTransportSurface(manager, stub, handle) {} |
| 80 : PassThroughImageTransportSurface(manager, stub, surface), | |
| 81 parent_client_id_(parent_client_id) {} | |
| 82 | 76 |
| 83 ImageTransportSurfaceAndroid::~ImageTransportSurfaceAndroid() {} | 77 ImageTransportSurfaceAndroid::~ImageTransportSurfaceAndroid() {} |
| 84 | 78 |
| 85 bool ImageTransportSurfaceAndroid::Initialize() { | |
| 86 if (!surface()) | |
| 87 return false; | |
| 88 | |
| 89 if (!PassThroughImageTransportSurface::Initialize()) | |
| 90 return false; | |
| 91 | |
| 92 GpuChannel* parent_channel = | |
| 93 GetHelper()->manager()->LookupChannel(parent_client_id_); | |
| 94 if (parent_channel) { | |
| 95 const base::CommandLine* command_line = | |
| 96 base::CommandLine::ForCurrentProcess(); | |
| 97 if (command_line->HasSwitch(switches::kUIPrioritizeInGpuProcess)) | |
| 98 GetHelper()->SetPreemptByFlag(parent_channel->GetPreemptionFlag()); | |
| 99 } | |
| 100 | |
| 101 return true; | |
| 102 } | |
| 103 | |
| 104 bool ImageTransportSurfaceAndroid::OnMakeCurrent(gfx::GLContext* context) { | 79 bool ImageTransportSurfaceAndroid::OnMakeCurrent(gfx::GLContext* context) { |
| 105 DidAccessGpu(); | 80 DidAccessGpu(); |
| 106 return true; | 81 return true; |
| 107 } | 82 } |
| 108 | 83 |
| 109 bool ImageTransportSurfaceAndroid::SwapBuffers() { | |
| 110 NOTREACHED(); | |
| 111 return false; | |
| 112 } | |
| 113 | |
| 114 void ImageTransportSurfaceAndroid::WakeUpGpu() { | 84 void ImageTransportSurfaceAndroid::WakeUpGpu() { |
| 115 begin_wake_up_time_ = base::TimeTicks::Now(); | 85 begin_wake_up_time_ = base::TimeTicks::Now(); |
| 116 ScheduleWakeUp(); | 86 ScheduleWakeUp(); |
| 117 } | 87 } |
| 118 | 88 |
| 119 void ImageTransportSurfaceAndroid::ScheduleWakeUp() { | 89 void ImageTransportSurfaceAndroid::ScheduleWakeUp() { |
| 120 base::TimeTicks now = base::TimeTicks::Now(); | 90 base::TimeTicks now = base::TimeTicks::Now(); |
| 121 base::TimeTicks last_access_time = | 91 base::TimeTicks last_access_time = |
| 122 base::TimeTicks::FromInternalValue(g_last_gpu_access_ticks); | 92 base::TimeTicks::FromInternalValue(g_last_gpu_access_ticks); |
| 123 TRACE_EVENT2("gpu", "ImageTransportSurfaceAndroid::ScheduleWakeUp", | 93 TRACE_EVENT2("gpu", "ImageTransportSurfaceAndroid::ScheduleWakeUp", |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 return PassThroughImageTransportSurface::SwapBuffers(); | 128 return PassThroughImageTransportSurface::SwapBuffers(); |
| 159 } | 129 } |
| 160 | 130 |
| 161 } // anonymous namespace | 131 } // anonymous namespace |
| 162 | 132 |
| 163 // static | 133 // static |
| 164 scoped_refptr<gfx::GLSurface> ImageTransportSurface::CreateNativeSurface( | 134 scoped_refptr<gfx::GLSurface> ImageTransportSurface::CreateNativeSurface( |
| 165 GpuChannelManager* manager, | 135 GpuChannelManager* manager, |
| 166 GpuCommandBufferStub* stub, | 136 GpuCommandBufferStub* stub, |
| 167 const gfx::GLSurfaceHandle& handle) { | 137 const gfx::GLSurfaceHandle& handle) { |
| 168 if (handle.transport_type == gfx::NATIVE_TRANSPORT) { | 138 if (handle.transport_type == gfx::NULL_TRANSPORT) { |
| 169 return scoped_refptr<gfx::GLSurface>( | 139 return scoped_refptr<gfx::GLSurface>( |
| 170 new ImageTransportSurfaceAndroid(manager, | 140 new ImageTransportSurfaceAndroid(manager, stub, handle)); |
| 171 stub, | |
| 172 manager->GetDefaultOffscreenSurface(), | |
| 173 handle.parent_client_id)); | |
| 174 } | 141 } |
| 175 | 142 |
| 176 DCHECK(GpuSurfaceLookup::GetInstance()); | 143 DCHECK(GpuSurfaceLookup::GetInstance()); |
| 177 DCHECK_EQ(handle.transport_type, gfx::NATIVE_DIRECT); | 144 DCHECK_EQ(handle.transport_type, gfx::NATIVE_DIRECT); |
| 178 ANativeWindow* window = | 145 ANativeWindow* window = |
| 179 GpuSurfaceLookup::GetInstance()->AcquireNativeWidget( | 146 GpuSurfaceLookup::GetInstance()->AcquireNativeWidget( |
| 180 stub->surface_id()); | 147 stub->surface_id()); |
| 181 scoped_refptr<gfx::GLSurface> surface = | 148 scoped_refptr<gfx::GLSurface> surface = |
| 182 new gfx::NativeViewGLSurfaceEGL(window); | 149 new gfx::NativeViewGLSurfaceEGL(window); |
| 183 bool initialize_success = surface->Initialize(); | 150 bool initialize_success = surface->Initialize(); |
| 184 if (window) | 151 if (window) |
| 185 ANativeWindow_release(window); | 152 ANativeWindow_release(window); |
| 186 if (!initialize_success) | 153 if (!initialize_success) |
| 187 return scoped_refptr<gfx::GLSurface>(); | 154 return scoped_refptr<gfx::GLSurface>(); |
| 188 | 155 |
| 189 return scoped_refptr<gfx::GLSurface>( | 156 return scoped_refptr<gfx::GLSurface>( |
| 190 new DirectSurfaceAndroid(manager, stub, surface.get())); | 157 new DirectSurfaceAndroid(manager, stub, surface.get())); |
| 191 } | 158 } |
| 192 | 159 |
| 193 } // namespace content | 160 } // namespace content |
| OLD | NEW |