Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(155)

Side by Side Diff: content/common/gpu/image_transport_surface.cc

Issue 11195011: Send vsync timebase updates to the browser compositor (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Send vsync timebase updates to the browser compositor Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #if defined(ENABLE_GPU) 5 #if defined(ENABLE_GPU)
6 6
7 #include "content/common/gpu/image_transport_surface.h" 7 #include "content/common/gpu/image_transport_surface.h"
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 return helper_->Initialize(); 260 return helper_->Initialize();
261 } 261 }
262 262
263 void PassThroughImageTransportSurface::Destroy() { 263 void PassThroughImageTransportSurface::Destroy() {
264 helper_->Destroy(); 264 helper_->Destroy();
265 GLSurfaceAdapter::Destroy(); 265 GLSurfaceAdapter::Destroy();
266 } 266 }
267 267
268 bool PassThroughImageTransportSurface::SwapBuffers() { 268 bool PassThroughImageTransportSurface::SwapBuffers() {
269 bool result = gfx::GLSurfaceAdapter::SwapBuffers(); 269 bool result = gfx::GLSurfaceAdapter::SwapBuffers();
270 SendVSyncUpdateIfAvailable();
270 271
271 if (transport_) { 272 if (transport_) {
272 // Round trip to the browser UI thread, for throttling, by sending a dummy 273 // Round trip to the browser UI thread, for throttling, by sending a dummy
273 // SwapBuffers message. 274 // SwapBuffers message.
274 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params; 275 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params;
275 params.surface_handle = 0; 276 params.surface_handle = 0;
276 helper_->SendAcceleratedSurfaceBuffersSwapped(params); 277 helper_->SendAcceleratedSurfaceBuffersSwapped(params);
277 278
278 helper_->SetScheduled(false); 279 helper_->SetScheduled(false);
279 } 280 }
280 return result; 281 return result;
281 } 282 }
282 283
283 bool PassThroughImageTransportSurface::PostSubBuffer( 284 bool PassThroughImageTransportSurface::PostSubBuffer(
284 int x, int y, int width, int height) { 285 int x, int y, int width, int height) {
285 bool result = gfx::GLSurfaceAdapter::PostSubBuffer(x, y, width, height); 286 bool result = gfx::GLSurfaceAdapter::PostSubBuffer(x, y, width, height);
287 SendVSyncUpdateIfAvailable();
286 288
287 if (transport_) { 289 if (transport_) {
288 // Round trip to the browser UI thread, for throttling, by sending a dummy 290 // Round trip to the browser UI thread, for throttling, by sending a dummy
289 // PostSubBuffer message. 291 // PostSubBuffer message.
290 GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params params; 292 GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params params;
291 params.surface_handle = 0; 293 params.surface_handle = 0;
292 params.x = x; 294 params.x = x;
293 params.y = y; 295 params.y = y;
294 params.width = width; 296 params.width = width;
295 params.height = height; 297 params.height = height;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 Resize(new_size_); 332 Resize(new_size_);
331 } 333 }
332 } 334 }
333 335
334 gfx::Size PassThroughImageTransportSurface::GetSize() { 336 gfx::Size PassThroughImageTransportSurface::GetSize() {
335 return GLSurfaceAdapter::GetSize(); 337 return GLSurfaceAdapter::GetSize();
336 } 338 }
337 339
338 PassThroughImageTransportSurface::~PassThroughImageTransportSurface() {} 340 PassThroughImageTransportSurface::~PassThroughImageTransportSurface() {}
339 341
342 void PassThroughImageTransportSurface::SendVSyncUpdateIfAvailable() {
343 int64 systemTime;
344 int64 mediaStreamCounter;
345 int64 swapBufferCounter;
346
347 // GetSyncValues gives us a time from CLOCK_REALTIME, but we need
348 // a time from CLOCK_MONOTONIC, so we convert.
349 static bool conversionComputed = false;
350 static int64 timeDifference = 0;
351
352 // This assumes that the difference between Unix epoch time and system
353 // uptime remains constant throughout the life of this process, but this
354 // may not be true (e.g. the user may adjust the clock). We should either
355 // recompute this periodically, or (if it's cheap enough) recompute this
356 // everytime.
357 if (!conversionComputed) {
358 struct timespec realTime;
359 struct timespec monotonicTime;
360 clock_gettime(CLOCK_REALTIME, &realTime);
361 clock_gettime(CLOCK_MONOTONIC, &monotonicTime);
piman 2012/10/17 17:24:47 PassThroughImageTransportSurface is cross-platform
362
363 int64 realTimeInMicroseconds =
364 realTime.tv_sec * base::Time::kMicrosecondsPerSecond +
365 realTime.tv_nsec / base::Time::kNanosecondsPerMicrosecond;
366
367 int64 monotonicTimeInMicroseconds =
368 monotonicTime.tv_sec * base::Time::kMicrosecondsPerSecond +
369 monotonicTime.tv_nsec / base::Time::kNanosecondsPerMicrosecond;
370
371 timeDifference = realTimeInMicroseconds - monotonicTimeInMicroseconds;
372 conversionComputed = true;
373 }
374
375 if (GetSyncValues(&systemTime, &mediaStreamCounter, &swapBufferCounter)) {
376 int64 monotonicVSyncTime = systemTime - timeDifference;
377 helper_->stub()->SendUpdateVSyncTime(monotonicVSyncTime);
378 }
379 }
380
340 #endif // defined(ENABLE_GPU) 381 #endif // defined(ENABLE_GPU)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698