OSDN Git Service

Fix janky pose
authorJiwen 'Steve' Cai <jwcai@google.com>
Tue, 21 Mar 2017 22:43:31 +0000 (15:43 -0700)
committerMark Urbanus <urbanus@google.com>
Wed, 22 Mar 2017 16:26:46 +0000 (09:26 -0700)
It's introduced through ag/1980993, where render_buffer_index_ was not
managed after the refactor.

Bug: 36194745
Test: Build and flash, pose is no longer janky.
Change-Id: I6ef86625dbc1c1afd2725614062f5e40e1b7f60a

libs/vr/libvrflinger/display_surface.cpp
libs/vr/libvrflinger/display_surface.h

index 66808ca..66e9925 100644 (file)
@@ -40,7 +40,8 @@ DisplaySurface::DisplaySurface(DisplayService* service, int surface_id,
       manager_visible_(false),
       manager_z_order_(0),
       manager_blur_(0.0f),
-      layer_order_(0) {}
+      layer_order_(0),
+      allocated_buffer_index_(0) {}
 
 DisplaySurface::~DisplaySurface() {
   ALOGD_IF(LOCAL_TRACE,
@@ -104,6 +105,14 @@ void DisplaySurface::DequeueBuffersLocked() {
       return;
     }
 
+    // Save buffer index, associated with the buffer id so that it can be looked
+    // up later.
+    int buffer_id = buffer_consumer->id();
+    if (buffer_id_to_index_.find(buffer_id) == buffer_id_to_index_.end()) {
+      buffer_id_to_index_[buffer_id] = allocated_buffer_index_;
+      ++allocated_buffer_index_;
+    }
+
     if (!IsVisible()) {
       ATRACE_NAME("DropFrameOnInvisibleSurface");
       ALOGD_IF(TRACE,
@@ -171,6 +180,17 @@ AcquiredBuffer DisplaySurface::AcquireNewestAvailableBuffer(
   return buffer;
 }
 
+uint32_t DisplaySurface::GetRenderBufferIndex(int buffer_id) {
+  std::lock_guard<std::mutex> autolock(lock_);
+
+  if (buffer_id_to_index_.find(buffer_id) == buffer_id_to_index_.end()) {
+    ALOGW("DisplaySurface::GetRenderBufferIndex: unknown buffer_id %d.",
+          buffer_id);
+    return 0;
+  }
+  return buffer_id_to_index_[buffer_id];
+}
+
 bool DisplaySurface::IsBufferAvailable() {
   std::lock_guard<std::mutex> autolock(lock_);
   DequeueBuffersLocked();
index feb173e..d31a3a9 100644 (file)
@@ -60,10 +60,7 @@ class DisplaySurface : public SurfaceChannel {
     }
   }
 
-  uint32_t GetRenderBufferIndex(int buffer_id) {
-    return buffer_id_to_index_[buffer_id];
-  }
-
+  uint32_t GetRenderBufferIndex(int buffer_id);
   bool IsBufferAvailable();
   bool IsBufferPosted();
   AcquiredBuffer AcquireCurrentBuffer();
@@ -172,6 +169,8 @@ class DisplaySurface : public SurfaceChannel {
   float manager_blur_;
   int layer_order_;
 
+  // The monotonically increasing index for allocated buffers in this surface.
+  uint32_t allocated_buffer_index_;
   // Maps from the buffer id to the corresponding allocated buffer index.
   std::unordered_map<int, uint32_t> buffer_id_to_index_;
 };