| 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/trace_event/trace_event.h" | 10 #include "base/trace_event/trace_event.h" |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 base::TimeTicks swap_time = base::TimeTicks::Now(); | 195 base::TimeTicks swap_time = base::TimeTicks::Now(); |
| 196 for (auto& latency : latency_info_) { | 196 for (auto& latency : latency_info_) { |
| 197 latency.AddLatencyNumberWithTimestamp( | 197 latency.AddLatencyNumberWithTimestamp( |
| 198 ui::INPUT_EVENT_GPU_SWAP_BUFFER_COMPONENT, 0, 0, swap_time, 1); | 198 ui::INPUT_EVENT_GPU_SWAP_BUFFER_COMPONENT, 0, 0, swap_time, 1); |
| 199 } | 199 } |
| 200 | 200 |
| 201 // We use WeakPtr here to avoid manual management of life time of an instance | 201 // We use WeakPtr here to avoid manual management of life time of an instance |
| 202 // of this class. Callback will not be called once the instance of this class | 202 // of this class. Callback will not be called once the instance of this class |
| 203 // is destroyed. However, this also means that the callback can be run on | 203 // is destroyed. However, this also means that the callback can be run on |
| 204 // the calling thread only. | 204 // the calling thread only. |
| 205 return gfx::GLSurfaceAdapter::SwapBuffersAsync( | 205 std::vector<ui::LatencyInfo>* latency_info_ptr = |
| 206 base::Bind(&PassThroughImageTransportSurface::SwapBuffersCallBack, | 206 new std::vector<ui::LatencyInfo>(); |
| 207 weak_ptr_factory_.GetWeakPtr())); | 207 latency_info_ptr->swap(latency_info_); |
| 208 return gfx::GLSurfaceAdapter::SwapBuffersAsync(base::Bind( |
| 209 &PassThroughImageTransportSurface::SwapBuffersCallBack, |
| 210 weak_ptr_factory_.GetWeakPtr(), base::Owned(latency_info_ptr))); |
| 208 } | 211 } |
| 209 | 212 |
| 210 bool PassThroughImageTransportSurface::PostSubBuffer( | 213 bool PassThroughImageTransportSurface::PostSubBuffer( |
| 211 int x, int y, int width, int height) { | 214 int x, int y, int width, int height) { |
| 212 SendVSyncUpdateIfAvailable(); | 215 SendVSyncUpdateIfAvailable(); |
| 213 | 216 |
| 214 base::TimeTicks swap_time = base::TimeTicks::Now(); | 217 base::TimeTicks swap_time = base::TimeTicks::Now(); |
| 215 for (auto& latency : latency_info_) { | 218 for (auto& latency : latency_info_) { |
| 216 latency.AddLatencyNumberWithTimestamp( | 219 latency.AddLatencyNumberWithTimestamp( |
| 217 ui::INPUT_EVENT_GPU_SWAP_BUFFER_COMPONENT, 0, 0, swap_time, 1); | 220 ui::INPUT_EVENT_GPU_SWAP_BUFFER_COMPONENT, 0, 0, swap_time, 1); |
| 218 } | 221 } |
| 219 | 222 |
| 220 // We use WeakPtr here to avoid manual management of life time of an instance | 223 // We use WeakPtr here to avoid manual management of life time of an instance |
| 221 // of this class. Callback will not be called once the instance of this class | 224 // of this class. Callback will not be called once the instance of this class |
| 222 // is destroyed. However, this also means that the callback can be run on | 225 // is destroyed. However, this also means that the callback can be run on |
| 223 // the calling thread only. | 226 // the calling thread only. |
| 224 return gfx::GLSurfaceAdapter::PostSubBufferAsync(x, y, width, height, | 227 std::vector<ui::LatencyInfo>* latency_info_ptr = |
| 228 new std::vector<ui::LatencyInfo>(); |
| 229 latency_info_ptr->swap(latency_info_); |
| 230 return gfx::GLSurfaceAdapter::PostSubBufferAsync( |
| 231 x, y, width, height, |
| 225 base::Bind(&PassThroughImageTransportSurface::SwapBuffersCallBack, | 232 base::Bind(&PassThroughImageTransportSurface::SwapBuffersCallBack, |
| 226 weak_ptr_factory_.GetWeakPtr())); | 233 weak_ptr_factory_.GetWeakPtr(), |
| 234 base::Owned(latency_info_ptr))); |
| 227 } | 235 } |
| 228 | 236 |
| 229 void PassThroughImageTransportSurface::SwapBuffersCallBack() { | 237 void PassThroughImageTransportSurface::SwapBuffersCallBack( |
| 238 std::vector<ui::LatencyInfo>* latency_info_ptr) { |
| 230 base::TimeTicks swap_ack_time = base::TimeTicks::Now(); | 239 base::TimeTicks swap_ack_time = base::TimeTicks::Now(); |
| 231 for (auto& latency : latency_info_) { | 240 for (auto& latency : *latency_info_ptr) { |
| 232 latency.AddLatencyNumberWithTimestamp( | 241 latency.AddLatencyNumberWithTimestamp( |
| 233 ui::INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT, 0, 0, | 242 ui::INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT, 0, 0, |
| 234 swap_ack_time, 1); | 243 swap_ack_time, 1); |
| 235 } | 244 } |
| 236 | 245 |
| 237 helper_->stub()->SendSwapBuffersCompleted(latency_info_); | 246 helper_->stub()->SendSwapBuffersCompleted(*latency_info_ptr); |
| 238 latency_info_.clear(); | |
| 239 } | 247 } |
| 240 | 248 |
| 241 bool PassThroughImageTransportSurface::OnMakeCurrent(gfx::GLContext* context) { | 249 bool PassThroughImageTransportSurface::OnMakeCurrent(gfx::GLContext* context) { |
| 242 if (!did_set_swap_interval_) { | 250 if (!did_set_swap_interval_) { |
| 243 ImageTransportHelper::SetSwapInterval(context); | 251 ImageTransportHelper::SetSwapInterval(context); |
| 244 did_set_swap_interval_ = true; | 252 did_set_swap_interval_ = true; |
| 245 } | 253 } |
| 246 return true; | 254 return true; |
| 247 } | 255 } |
| 248 | 256 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 271 void PassThroughImageTransportSurface::SendVSyncUpdateIfAvailable() { | 279 void PassThroughImageTransportSurface::SendVSyncUpdateIfAvailable() { |
| 272 gfx::VSyncProvider* vsync_provider = GetVSyncProvider(); | 280 gfx::VSyncProvider* vsync_provider = GetVSyncProvider(); |
| 273 if (vsync_provider) { | 281 if (vsync_provider) { |
| 274 vsync_provider->GetVSyncParameters( | 282 vsync_provider->GetVSyncParameters( |
| 275 base::Bind(&GpuCommandBufferStub::SendUpdateVSyncParameters, | 283 base::Bind(&GpuCommandBufferStub::SendUpdateVSyncParameters, |
| 276 helper_->stub()->AsWeakPtr())); | 284 helper_->stub()->AsWeakPtr())); |
| 277 } | 285 } |
| 278 } | 286 } |
| 279 | 287 |
| 280 } // namespace content | 288 } // namespace content |
| OLD | NEW |