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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: content/common/gpu/image_transport_surface.cc
diff --git a/content/common/gpu/image_transport_surface.cc b/content/common/gpu/image_transport_surface.cc
index 1b1428b02f0a82d901616908265aa87c8b2394ca..3b49d775221ae5aee93dc1e81f5fd9896ad2e0b5 100644
--- a/content/common/gpu/image_transport_surface.cc
+++ b/content/common/gpu/image_transport_surface.cc
@@ -267,6 +267,7 @@ void PassThroughImageTransportSurface::Destroy() {
bool PassThroughImageTransportSurface::SwapBuffers() {
bool result = gfx::GLSurfaceAdapter::SwapBuffers();
+ SendVSyncUpdateIfAvailable();
if (transport_) {
// Round trip to the browser UI thread, for throttling, by sending a dummy
@@ -283,6 +284,7 @@ bool PassThroughImageTransportSurface::SwapBuffers() {
bool PassThroughImageTransportSurface::PostSubBuffer(
int x, int y, int width, int height) {
bool result = gfx::GLSurfaceAdapter::PostSubBuffer(x, y, width, height);
+ SendVSyncUpdateIfAvailable();
if (transport_) {
// Round trip to the browser UI thread, for throttling, by sending a dummy
@@ -337,4 +339,43 @@ gfx::Size PassThroughImageTransportSurface::GetSize() {
PassThroughImageTransportSurface::~PassThroughImageTransportSurface() {}
+void PassThroughImageTransportSurface::SendVSyncUpdateIfAvailable() {
+ int64 systemTime;
+ int64 mediaStreamCounter;
+ int64 swapBufferCounter;
+
+ // GetSyncValues gives us a time from CLOCK_REALTIME, but we need
+ // a time from CLOCK_MONOTONIC, so we convert.
+ static bool conversionComputed = false;
+ static int64 timeDifference = 0;
+
+ // This assumes that the difference between Unix epoch time and system
+ // uptime remains constant throughout the life of this process, but this
+ // may not be true (e.g. the user may adjust the clock). We should either
+ // recompute this periodically, or (if it's cheap enough) recompute this
+ // everytime.
+ if (!conversionComputed) {
+ struct timespec realTime;
+ struct timespec monotonicTime;
+ clock_gettime(CLOCK_REALTIME, &realTime);
+ clock_gettime(CLOCK_MONOTONIC, &monotonicTime);
piman 2012/10/17 17:24:47 PassThroughImageTransportSurface is cross-platform
+
+ int64 realTimeInMicroseconds =
+ realTime.tv_sec * base::Time::kMicrosecondsPerSecond +
+ realTime.tv_nsec / base::Time::kNanosecondsPerMicrosecond;
+
+ int64 monotonicTimeInMicroseconds =
+ monotonicTime.tv_sec * base::Time::kMicrosecondsPerSecond +
+ monotonicTime.tv_nsec / base::Time::kNanosecondsPerMicrosecond;
+
+ timeDifference = realTimeInMicroseconds - monotonicTimeInMicroseconds;
+ conversionComputed = true;
+ }
+
+ if (GetSyncValues(&systemTime, &mediaStreamCounter, &swapBufferCounter)) {
+ int64 monotonicVSyncTime = systemTime - timeDifference;
+ helper_->stub()->SendUpdateVSyncTime(monotonicVSyncTime);
+ }
+}
+
#endif // defined(ENABLE_GPU)

Powered by Google App Engine
This is Rietveld 408576698