Chromium Code Reviews| 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/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 45 gfx::PluginWindowHandle handle) | 45 gfx::PluginWindowHandle handle) |
| 46 : surface_(surface), | 46 : surface_(surface), |
| 47 manager_(manager), | 47 manager_(manager), |
| 48 stub_(stub->AsWeakPtr()), | 48 stub_(stub->AsWeakPtr()), |
| 49 handle_(handle) { | 49 handle_(handle) { |
| 50 route_id_ = manager_->GenerateRouteID(); | 50 route_id_ = manager_->GenerateRouteID(); |
| 51 manager_->AddRoute(route_id_, this); | 51 manager_->AddRoute(route_id_, this); |
| 52 } | 52 } |
| 53 | 53 |
| 54 ImageTransportHelper::~ImageTransportHelper() { | 54 ImageTransportHelper::~ImageTransportHelper() { |
| 55 if (stub_) { | |
| 56 stub_->SetLatencyInfoCallback( | |
| 57 base::Callback<void(const cc::LatencyInfo&)>()); | |
| 58 } | |
| 55 manager_->RemoveRoute(route_id_); | 59 manager_->RemoveRoute(route_id_); |
| 56 } | 60 } |
| 57 | 61 |
| 58 bool ImageTransportHelper::Initialize() { | 62 bool ImageTransportHelper::Initialize() { |
| 59 gpu::gles2::GLES2Decoder* decoder = Decoder(); | 63 gpu::gles2::GLES2Decoder* decoder = Decoder(); |
| 60 | 64 |
| 61 if (!decoder) | 65 if (!decoder) |
| 62 return false; | 66 return false; |
| 63 | 67 |
| 64 decoder->SetResizeCallback( | 68 decoder->SetResizeCallback( |
| 65 base::Bind(&ImageTransportHelper::Resize, base::Unretained(this))); | 69 base::Bind(&ImageTransportHelper::Resize, base::Unretained(this))); |
| 66 | 70 |
| 71 if (stub_) { | |
|
piman
2013/04/03 18:05:09
stub_ is !NULL here since decoder != NULL.
| |
| 72 stub_->SetLatencyInfoCallback( | |
| 73 base::Bind(&ImageTransportHelper::SetLatencyInfo, | |
| 74 base::Unretained(this))); | |
| 75 } | |
| 76 | |
| 67 return true; | 77 return true; |
| 68 } | 78 } |
| 69 | 79 |
| 70 void ImageTransportHelper::Destroy() {} | 80 void ImageTransportHelper::Destroy() {} |
| 71 | 81 |
| 72 bool ImageTransportHelper::OnMessageReceived(const IPC::Message& message) { | 82 bool ImageTransportHelper::OnMessageReceived(const IPC::Message& message) { |
| 73 bool handled = true; | 83 bool handled = true; |
| 74 IPC_BEGIN_MESSAGE_MAP(ImageTransportHelper, message) | 84 IPC_BEGIN_MESSAGE_MAP(ImageTransportHelper, message) |
| 75 IPC_MESSAGE_HANDLER(AcceleratedSurfaceMsg_BufferPresented, | 85 IPC_MESSAGE_HANDLER(AcceleratedSurfaceMsg_BufferPresented, |
| 76 OnBufferPresented) | 86 OnBufferPresented) |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 112 size)); | 122 size)); |
| 113 } | 123 } |
| 114 | 124 |
| 115 void ImageTransportHelper::SendUpdateVSyncParameters( | 125 void ImageTransportHelper::SendUpdateVSyncParameters( |
| 116 base::TimeTicks timebase, base::TimeDelta interval) { | 126 base::TimeTicks timebase, base::TimeDelta interval) { |
| 117 manager_->Send(new GpuHostMsg_UpdateVSyncParameters(stub_->surface_id(), | 127 manager_->Send(new GpuHostMsg_UpdateVSyncParameters(stub_->surface_id(), |
| 118 timebase, | 128 timebase, |
| 119 interval)); | 129 interval)); |
| 120 } | 130 } |
| 121 | 131 |
| 132 void ImageTransportHelper::SendLatencyInfo( | |
| 133 const cc::LatencyInfo& latency_info) { | |
| 134 manager_->Send(new GpuHostMsg_FrameDrawn(latency_info)); | |
| 135 } | |
| 136 | |
| 122 void ImageTransportHelper::SetScheduled(bool is_scheduled) { | 137 void ImageTransportHelper::SetScheduled(bool is_scheduled) { |
| 123 gpu::GpuScheduler* scheduler = Scheduler(); | 138 gpu::GpuScheduler* scheduler = Scheduler(); |
| 124 if (!scheduler) | 139 if (!scheduler) |
| 125 return; | 140 return; |
| 126 | 141 |
| 127 scheduler->SetScheduled(is_scheduled); | 142 scheduler->SetScheduled(is_scheduled); |
| 128 } | 143 } |
| 129 | 144 |
| 130 void ImageTransportHelper::DeferToFence(base::Closure task) { | 145 void ImageTransportHelper::DeferToFence(base::Closure task) { |
| 131 gpu::GpuScheduler* scheduler = Scheduler(); | 146 gpu::GpuScheduler* scheduler = Scheduler(); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 180 | 195 |
| 181 void ImageTransportHelper::Resize(gfx::Size size) { | 196 void ImageTransportHelper::Resize(gfx::Size size) { |
| 182 surface_->OnResize(size); | 197 surface_->OnResize(size); |
| 183 | 198 |
| 184 #if defined(OS_ANDROID) | 199 #if defined(OS_ANDROID) |
| 185 manager_->gpu_memory_manager()->ScheduleManage( | 200 manager_->gpu_memory_manager()->ScheduleManage( |
| 186 GpuMemoryManager::kScheduleManageNow); | 201 GpuMemoryManager::kScheduleManageNow); |
| 187 #endif | 202 #endif |
| 188 } | 203 } |
| 189 | 204 |
| 205 void ImageTransportHelper::SetLatencyInfo( | |
| 206 const cc::LatencyInfo& latency_info) { | |
| 207 surface_->SetLatencyInfo(latency_info); | |
| 208 } | |
| 209 | |
| 190 PassThroughImageTransportSurface::PassThroughImageTransportSurface( | 210 PassThroughImageTransportSurface::PassThroughImageTransportSurface( |
| 191 GpuChannelManager* manager, | 211 GpuChannelManager* manager, |
| 192 GpuCommandBufferStub* stub, | 212 GpuCommandBufferStub* stub, |
| 193 gfx::GLSurface* surface, | 213 gfx::GLSurface* surface, |
| 194 bool transport) | 214 bool transport) |
| 195 : GLSurfaceAdapter(surface), | 215 : GLSurfaceAdapter(surface), |
| 196 transport_(transport), | 216 transport_(transport), |
| 197 did_set_swap_interval_(false), | 217 did_set_swap_interval_(false), |
| 198 did_unschedule_(false), | 218 did_unschedule_(false), |
| 199 is_swap_buffers_pending_(false) { | 219 is_swap_buffers_pending_(false) { |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 216 bool PassThroughImageTransportSurface::DeferDraws() { | 236 bool PassThroughImageTransportSurface::DeferDraws() { |
| 217 if (is_swap_buffers_pending_) { | 237 if (is_swap_buffers_pending_) { |
| 218 DCHECK(!did_unschedule_); | 238 DCHECK(!did_unschedule_); |
| 219 did_unschedule_ = true; | 239 did_unschedule_ = true; |
| 220 helper_->SetScheduled(false); | 240 helper_->SetScheduled(false); |
| 221 return true; | 241 return true; |
| 222 } | 242 } |
| 223 return false; | 243 return false; |
| 224 } | 244 } |
| 225 | 245 |
| 246 void PassThroughImageTransportSurface::SetLatencyInfo( | |
| 247 const cc::LatencyInfo& latency_info) { | |
| 248 latency_info_ = latency_info; | |
| 249 } | |
| 250 | |
| 226 bool PassThroughImageTransportSurface::SwapBuffers() { | 251 bool PassThroughImageTransportSurface::SwapBuffers() { |
| 227 // GetVsyncValues before SwapBuffers to work around Mali driver bug: | 252 // GetVsyncValues before SwapBuffers to work around Mali driver bug: |
| 228 // crbug.com/223558. | 253 // crbug.com/223558. |
| 229 SendVSyncUpdateIfAvailable(); | 254 SendVSyncUpdateIfAvailable(); |
| 230 bool result = gfx::GLSurfaceAdapter::SwapBuffers(); | 255 bool result = gfx::GLSurfaceAdapter::SwapBuffers(); |
| 256 latency_info_.swap_timestamp = base::TimeTicks::HighResNow(); | |
| 231 | 257 |
| 232 if (transport_) { | 258 if (transport_) { |
| 233 DCHECK(!is_swap_buffers_pending_); | 259 DCHECK(!is_swap_buffers_pending_); |
| 234 is_swap_buffers_pending_ = true; | 260 is_swap_buffers_pending_ = true; |
| 235 | 261 |
| 236 // Round trip to the browser UI thread, for throttling, by sending a dummy | 262 // Round trip to the browser UI thread, for throttling, by sending a dummy |
| 237 // SwapBuffers message. | 263 // SwapBuffers message. |
| 238 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params; | 264 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params; |
| 239 params.surface_handle = 0; | 265 params.surface_handle = 0; |
| 266 params.latency_info = latency_info_; | |
| 240 params.size = surface()->GetSize(); | 267 params.size = surface()->GetSize(); |
| 241 helper_->SendAcceleratedSurfaceBuffersSwapped(params); | 268 helper_->SendAcceleratedSurfaceBuffersSwapped(params); |
| 269 } else { | |
| 270 helper_->SendLatencyInfo(latency_info_); | |
| 242 } | 271 } |
| 243 return result; | 272 return result; |
| 244 } | 273 } |
| 245 | 274 |
| 246 bool PassThroughImageTransportSurface::PostSubBuffer( | 275 bool PassThroughImageTransportSurface::PostSubBuffer( |
| 247 int x, int y, int width, int height) { | 276 int x, int y, int width, int height) { |
| 248 SendVSyncUpdateIfAvailable(); | 277 SendVSyncUpdateIfAvailable(); |
| 249 bool result = gfx::GLSurfaceAdapter::PostSubBuffer(x, y, width, height); | 278 bool result = gfx::GLSurfaceAdapter::PostSubBuffer(x, y, width, height); |
| 279 latency_info_.swap_timestamp = base::TimeTicks::HighResNow(); | |
| 250 | 280 |
| 251 if (transport_) { | 281 if (transport_) { |
| 252 DCHECK(!is_swap_buffers_pending_); | 282 DCHECK(!is_swap_buffers_pending_); |
| 253 is_swap_buffers_pending_ = true; | 283 is_swap_buffers_pending_ = true; |
| 254 | 284 |
| 255 // Round trip to the browser UI thread, for throttling, by sending a dummy | 285 // Round trip to the browser UI thread, for throttling, by sending a dummy |
| 256 // PostSubBuffer message. | 286 // PostSubBuffer message. |
| 257 GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params params; | 287 GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params params; |
| 258 params.surface_handle = 0; | 288 params.surface_handle = 0; |
| 289 params.latency_info = latency_info_; | |
| 259 params.surface_size = surface()->GetSize(); | 290 params.surface_size = surface()->GetSize(); |
| 260 params.x = x; | 291 params.x = x; |
| 261 params.y = y; | 292 params.y = y; |
| 262 params.width = width; | 293 params.width = width; |
| 263 params.height = height; | 294 params.height = height; |
| 264 helper_->SendAcceleratedSurfacePostSubBuffer(params); | 295 helper_->SendAcceleratedSurfacePostSubBuffer(params); |
| 265 | 296 |
| 266 helper_->SetScheduled(false); | 297 helper_->SetScheduled(false); |
| 298 } else { | |
| 299 helper_->SendLatencyInfo(latency_info_); | |
| 267 } | 300 } |
| 268 return result; | 301 return result; |
| 269 } | 302 } |
| 270 | 303 |
| 271 bool PassThroughImageTransportSurface::OnMakeCurrent(gfx::GLContext* context) { | 304 bool PassThroughImageTransportSurface::OnMakeCurrent(gfx::GLContext* context) { |
| 272 if (!did_set_swap_interval_) { | 305 if (!did_set_swap_interval_) { |
| 273 ImageTransportHelper::SetSwapInterval(context); | 306 ImageTransportHelper::SetSwapInterval(context); |
| 274 did_set_swap_interval_ = true; | 307 did_set_swap_interval_ = true; |
| 275 } | 308 } |
| 276 return true; | 309 return true; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 314 void PassThroughImageTransportSurface::SendVSyncUpdateIfAvailable() { | 347 void PassThroughImageTransportSurface::SendVSyncUpdateIfAvailable() { |
| 315 gfx::VSyncProvider* vsync_provider = GetVSyncProvider(); | 348 gfx::VSyncProvider* vsync_provider = GetVSyncProvider(); |
| 316 if (vsync_provider) { | 349 if (vsync_provider) { |
| 317 vsync_provider->GetVSyncParameters( | 350 vsync_provider->GetVSyncParameters( |
| 318 base::Bind(&ImageTransportHelper::SendUpdateVSyncParameters, | 351 base::Bind(&ImageTransportHelper::SendUpdateVSyncParameters, |
| 319 helper_->AsWeakPtr())); | 352 helper_->AsWeakPtr())); |
| 320 } | 353 } |
| 321 } | 354 } |
| 322 | 355 |
| 323 } // namespace content | 356 } // namespace content |
| OLD | NEW |