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