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