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/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 std::vector<ui::LatencyInfo> latency_info; | |
| 206 latency_info.swap(latency_info_); | |
| 205 return gfx::GLSurfaceAdapter::SwapBuffersAsync( | 207 return gfx::GLSurfaceAdapter::SwapBuffersAsync( |
| 206 base::Bind(&PassThroughImageTransportSurface::SwapBuffersCallBack, | 208 base::Bind(&PassThroughImageTransportSurface::SwapBuffersCallBack, |
| 207 weak_ptr_factory_.GetWeakPtr())); | 209 weak_ptr_factory_.GetWeakPtr(), latency_info)); |
| 208 } | 210 } |
| 209 | 211 |
| 210 bool PassThroughImageTransportSurface::PostSubBuffer( | 212 bool PassThroughImageTransportSurface::PostSubBuffer( |
| 211 int x, int y, int width, int height) { | 213 int x, int y, int width, int height) { |
| 212 SendVSyncUpdateIfAvailable(); | 214 SendVSyncUpdateIfAvailable(); |
| 213 | 215 |
| 214 base::TimeTicks swap_time = base::TimeTicks::Now(); | 216 base::TimeTicks swap_time = base::TimeTicks::Now(); |
| 215 for (auto& latency : latency_info_) { | 217 for (auto& latency : latency_info_) { |
| 216 latency.AddLatencyNumberWithTimestamp( | 218 latency.AddLatencyNumberWithTimestamp( |
| 217 ui::INPUT_EVENT_GPU_SWAP_BUFFER_COMPONENT, 0, 0, swap_time, 1); | 219 ui::INPUT_EVENT_GPU_SWAP_BUFFER_COMPONENT, 0, 0, swap_time, 1); |
| 218 } | 220 } |
| 219 | 221 |
| 220 // We use WeakPtr here to avoid manual management of life time of an instance | 222 // 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 | 223 // 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 | 224 // is destroyed. However, this also means that the callback can be run on |
| 223 // the calling thread only. | 225 // the calling thread only. |
| 224 return gfx::GLSurfaceAdapter::PostSubBufferAsync(x, y, width, height, | 226 std::vector<ui::LatencyInfo> latency_info; |
| 227 latency_info.swap(latency_info_); | |
|
brianderson
2015/05/14 19:06:12
Although this swap avoids one copy, I think there
alexst (slow to review)
2015/05/14 19:32:41
Sounds good, done.
| |
| 228 return gfx::GLSurfaceAdapter::PostSubBufferAsync( | |
| 229 x, y, width, height, | |
| 225 base::Bind(&PassThroughImageTransportSurface::SwapBuffersCallBack, | 230 base::Bind(&PassThroughImageTransportSurface::SwapBuffersCallBack, |
| 226 weak_ptr_factory_.GetWeakPtr())); | 231 weak_ptr_factory_.GetWeakPtr(), latency_info)); |
| 227 } | 232 } |
| 228 | 233 |
| 229 void PassThroughImageTransportSurface::SwapBuffersCallBack() { | 234 void PassThroughImageTransportSurface::SwapBuffersCallBack( |
| 235 std::vector<ui::LatencyInfo> latency_info) { | |
| 230 base::TimeTicks swap_ack_time = base::TimeTicks::Now(); | 236 base::TimeTicks swap_ack_time = base::TimeTicks::Now(); |
| 231 for (auto& latency : latency_info_) { | 237 for (auto& latency : latency_info) { |
| 232 latency.AddLatencyNumberWithTimestamp( | 238 latency.AddLatencyNumberWithTimestamp( |
| 233 ui::INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT, 0, 0, | 239 ui::INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT, 0, 0, |
| 234 swap_ack_time, 1); | 240 swap_ack_time, 1); |
| 235 } | 241 } |
| 236 | 242 |
| 237 helper_->stub()->SendSwapBuffersCompleted(latency_info_); | 243 helper_->stub()->SendSwapBuffersCompleted(latency_info); |
| 238 latency_info_.clear(); | |
| 239 } | 244 } |
| 240 | 245 |
| 241 bool PassThroughImageTransportSurface::OnMakeCurrent(gfx::GLContext* context) { | 246 bool PassThroughImageTransportSurface::OnMakeCurrent(gfx::GLContext* context) { |
| 242 if (!did_set_swap_interval_) { | 247 if (!did_set_swap_interval_) { |
| 243 ImageTransportHelper::SetSwapInterval(context); | 248 ImageTransportHelper::SetSwapInterval(context); |
| 244 did_set_swap_interval_ = true; | 249 did_set_swap_interval_ = true; |
| 245 } | 250 } |
| 246 return true; | 251 return true; |
| 247 } | 252 } |
| 248 | 253 |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 271 void PassThroughImageTransportSurface::SendVSyncUpdateIfAvailable() { | 276 void PassThroughImageTransportSurface::SendVSyncUpdateIfAvailable() { |
| 272 gfx::VSyncProvider* vsync_provider = GetVSyncProvider(); | 277 gfx::VSyncProvider* vsync_provider = GetVSyncProvider(); |
| 273 if (vsync_provider) { | 278 if (vsync_provider) { |
| 274 vsync_provider->GetVSyncParameters( | 279 vsync_provider->GetVSyncParameters( |
| 275 base::Bind(&GpuCommandBufferStub::SendUpdateVSyncParameters, | 280 base::Bind(&GpuCommandBufferStub::SendUpdateVSyncParameters, |
| 276 helper_->stub()->AsWeakPtr())); | 281 helper_->stub()->AsWeakPtr())); |
| 277 } | 282 } |
| 278 } | 283 } |
| 279 | 284 |
| 280 } // namespace content | 285 } // namespace content |
| OLD | NEW |