SF: replicate mActiveBuffer in LayerBE as mBuffer

Replicate mAcitveBuffer in LayerBE as mBuffer

Test: build/run
Change-Id: Iaec4eeddbf4ca1798a47ecbb6c0b6c82ceb1d27c
diff --git a/services/surfaceflinger/BufferLayer.cpp b/services/surfaceflinger/BufferLayer.cpp
index 2fa17e9..0d947b1 100644
--- a/services/surfaceflinger/BufferLayer.cpp
+++ b/services/surfaceflinger/BufferLayer.cpp
@@ -109,13 +109,14 @@
 }
 
 bool BufferLayer::isProtected() const {
-    const sp<GraphicBuffer>& activeBuffer(mActiveBuffer);
-    return (activeBuffer != 0) && (activeBuffer->getUsage() & GRALLOC_USAGE_PROTECTED);
+    const sp<GraphicBuffer>& buffer(getBE().mBuffer);
+    return (buffer != 0) &&
+            (buffer->getUsage() & GRALLOC_USAGE_PROTECTED);
 }
 
 bool BufferLayer::isVisible() const {
     return !(isHiddenByPolicy()) && getAlpha() > 0.0f &&
-            (mActiveBuffer != NULL || getBE().mSidebandStream != NULL);
+            (getBE().mBuffer != NULL || getBE().mSidebandStream != NULL);
 }
 
 bool BufferLayer::isFixedSize() const {
@@ -171,7 +172,7 @@
                          bool useIdentityTransform) const {
     ATRACE_CALL();
 
-    if (CC_UNLIKELY(mActiveBuffer == 0)) {
+    if (CC_UNLIKELY(getBE().mBuffer == 0)) {
         // the texture has not been created yet, this Layer has
         // in fact never been drawn into. This happens frequently with
         // SurfaceView because the WindowManager can't know when the client
@@ -249,8 +250,8 @@
         }
 
         // Set things up for texturing.
-        mTexture.setDimensions(mActiveBuffer->getWidth(),
-                               mActiveBuffer->getHeight());
+        mTexture.setDimensions(getBE().mBuffer->getWidth(),
+                               getBE().mBuffer->getHeight());
         mTexture.setFiltering(useFiltering);
         mTexture.setMatrix(textureMatrix);
 
@@ -421,7 +422,7 @@
     // Capture the old state of the layer for comparisons later
     const State& s(getDrawingState());
     const bool oldOpacity = isOpaque(s);
-    sp<GraphicBuffer> oldActiveBuffer = mActiveBuffer;
+    sp<GraphicBuffer> oldBuffer = getBE().mBuffer;
 
     if (!allTransactionsSignaled()) {
         mFlinger->signalLayerUpdate();
@@ -498,9 +499,11 @@
     }
 
     // update the active buffer
-    mActiveBuffer =
-            mSurfaceFlingerConsumer->getCurrentBuffer(&mActiveBufferSlot);
-    if (mActiveBuffer == NULL) {
+    getBE().mBuffer =
+            mSurfaceFlingerConsumer->getCurrentBuffer(&getBE().mBufferSlot);
+    // replicated in LayerBE until FE/BE is ready to be synchronized
+    mActiveBuffer = getBE().mBuffer;
+    if (getBE().mBuffer == NULL) {
         // this can only happen if the very first buffer was rejected.
         return outDirtyRegion;
     }
@@ -516,7 +519,7 @@
 
     mRefreshPending = true;
     mFrameLatencyNeeded = true;
-    if (oldActiveBuffer == NULL) {
+    if (oldBuffer == NULL) {
         // the first time we receive a buffer, we need to trigger a
         // geometry invalidation.
         recomputeVisibleRegions = true;
@@ -536,16 +539,16 @@
         recomputeVisibleRegions = true;
     }
 
-    if (oldActiveBuffer != NULL) {
-        uint32_t bufWidth = mActiveBuffer->getWidth();
-        uint32_t bufHeight = mActiveBuffer->getHeight();
-        if (bufWidth != uint32_t(oldActiveBuffer->width) ||
-            bufHeight != uint32_t(oldActiveBuffer->height)) {
+    if (oldBuffer != NULL) {
+        uint32_t bufWidth = getBE().mBuffer->getWidth();
+        uint32_t bufHeight = getBE().mBuffer->getHeight();
+        if (bufWidth != uint32_t(oldBuffer->width) ||
+            bufHeight != uint32_t(oldBuffer->height)) {
             recomputeVisibleRegions = true;
         }
     }
 
-    mCurrentOpacity = getOpacityForFormat(mActiveBuffer->format);
+    mCurrentOpacity = getOpacityForFormat(getBE().mBuffer->format);
     if (oldOpacity != isOpaque(s)) {
         recomputeVisibleRegions = true;
     }
@@ -638,14 +641,14 @@
 
     uint32_t hwcSlot = 0;
     sp<GraphicBuffer> hwcBuffer;
-    hwcInfo.bufferCache.getHwcBuffer(mActiveBufferSlot,
-                                     mActiveBuffer, &hwcSlot, &hwcBuffer);
+    hwcInfo.bufferCache.getHwcBuffer(getBE().mBufferSlot,
+                                     getBE().mBuffer, &hwcSlot, &hwcBuffer);
 
     auto acquireFence = mSurfaceFlingerConsumer->getCurrentFence();
     error = hwcLayer->setBuffer(hwcSlot, hwcBuffer, acquireFence);
     if (error != HWC2::Error::None) {
         ALOGE("[%s] Failed to set buffer %p: %s (%d)", mName.string(),
-              mActiveBuffer->handle, to_string(error).c_str(),
+              getBE().mBuffer->handle, to_string(error).c_str(),
               static_cast<int32_t>(error));
     }
 }
@@ -653,7 +656,7 @@
 bool BufferLayer::isOpaque(const Layer::State& s) const {
     // if we don't have a buffer or sidebandStream yet, we're translucent regardless of the
     // layer's opaque flag.
-    if ((getBE().mSidebandStream == nullptr) && (mActiveBuffer == nullptr)) {
+    if ((getBE().mSidebandStream == nullptr) && (getBE().mBuffer == nullptr)) {
         return false;
     }
 
diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp
index 359b64f..2a4abcb 100644
--- a/services/surfaceflinger/Layer.cpp
+++ b/services/surfaceflinger/Layer.cpp
@@ -63,7 +63,9 @@
 namespace android {
 
 LayerBE::LayerBE()
-      : mMesh(Mesh::TRIANGLE_FAN, 4, 2, 2) {
+      : mBufferSlot(BufferQueue::INVALID_BUFFER_SLOT),
+        mBuffer(nullptr),
+        mMesh(Mesh::TRIANGLE_FAN, 4, 2, 2) {
 }
 
 
@@ -255,9 +257,9 @@
     if (!mCurrentCrop.isEmpty()) {
         // if the buffer crop is defined, we use that
         crop = mCurrentCrop;
-    } else if (mActiveBuffer != NULL) {
+    } else if (getBE().mBuffer != NULL) {
         // otherwise we use the whole buffer
-        crop = mActiveBuffer->getBounds();
+        crop = getBE().mBuffer->getBounds();
     } else {
         // if we don't have a buffer yet, we use an empty/invalid crop
         crop.makeInvalid();
@@ -1000,7 +1002,7 @@
     // to the old buffer. However in the state where we don't have an old buffer
     // there is no such concern but we may still be being used as a parent layer.
     const bool resizePending = ((c.requested.w != c.active.w) || (c.requested.h != c.active.h)) &&
-            (mActiveBuffer != nullptr);
+            (getBE().mBuffer != nullptr);
     if (!isFixedSize()) {
         if (resizePending && getBE().mSidebandStream == NULL) {
             flags |= eDontUpdateGeometryState;
@@ -1399,12 +1401,12 @@
     info.mMatrix[1][0] = ds.active.transform[1][0];
     info.mMatrix[1][1] = ds.active.transform[1][1];
     {
-        sp<const GraphicBuffer> activeBuffer = getActiveBuffer();
-        if (activeBuffer != 0) {
-            info.mActiveBufferWidth = activeBuffer->getWidth();
-            info.mActiveBufferHeight = activeBuffer->getHeight();
-            info.mActiveBufferStride = activeBuffer->getStride();
-            info.mActiveBufferFormat = activeBuffer->format;
+        sp<const GraphicBuffer> buffer = getBE().mBuffer;
+        if (buffer != 0) {
+            info.mActiveBufferWidth = buffer->getWidth();
+            info.mActiveBufferHeight = buffer->getHeight();
+            info.mActiveBufferStride = buffer->getStride();
+            info.mActiveBufferFormat = buffer->format;
         } else {
             info.mActiveBufferWidth = 0;
             info.mActiveBufferHeight = 0;
@@ -1718,15 +1720,15 @@
         // for in the transform. We need to mirror this scaling in child surfaces
         // or we will break the contract where WM can treat child surfaces as
         // pixels in the parent surface.
-        if (p->isFixedSize() && p->mActiveBuffer != nullptr) {
+        if (p->isFixedSize() && p->getBE().mBuffer != nullptr) {
             int bufferWidth;
             int bufferHeight;
             if ((p->mCurrentTransform & NATIVE_WINDOW_TRANSFORM_ROT_90) == 0) {
-                bufferWidth = p->mActiveBuffer->getWidth();
-                bufferHeight = p->mActiveBuffer->getHeight();
+                bufferWidth = p->getBE().mBuffer->getWidth();
+                bufferHeight = p->getBE().mBuffer->getHeight();
             } else {
-                bufferHeight = p->mActiveBuffer->getWidth();
-                bufferWidth = p->mActiveBuffer->getHeight();
+                bufferHeight = p->getBE().mBuffer->getWidth();
+                bufferWidth = p->getBE().mBuffer->getHeight();
             }
             float sx = p->getDrawingState().active.w / static_cast<float>(bufferWidth);
             float sy = p->getDrawingState().active.h / static_cast<float>(bufferHeight);
@@ -1826,9 +1828,9 @@
         layerInfo->set_z_order_relative_of(zOrderRelativeOf->sequence);
     }
 
-    auto activeBuffer = getActiveBuffer();
-    if (activeBuffer != nullptr) {
-        LayerProtoHelper::writeToProto(activeBuffer, layerInfo->mutable_active_buffer());
+    auto buffer = getBE().mBuffer;
+    if (buffer != nullptr) {
+        LayerProtoHelper::writeToProto(buffer, layerInfo->mutable_active_buffer());
     }
 
     layerInfo->set_queued_frames(getQueuedFrameCount());
diff --git a/services/surfaceflinger/Layer.h b/services/surfaceflinger/Layer.h
index b12e34f..8ac5094 100644
--- a/services/surfaceflinger/Layer.h
+++ b/services/surfaceflinger/Layer.h
@@ -70,6 +70,9 @@
 public:
     LayerBE();
 
+    // main thread
+    int mBufferSlot;
+    sp<GraphicBuffer> mBuffer;
     sp<NativeHandle> mSidebandStream;
 
     // The mesh used to draw the layer in GLES composition mode
@@ -469,8 +472,6 @@
     void setFiltering(bool filtering);
     bool getFiltering() const;
 
-    // only for debugging
-    inline const sp<GraphicBuffer>& getActiveBuffer() const { return mActiveBuffer; }
 
     inline const State& getDrawingState() const { return mDrawingState; }
     inline const State& getCurrentState() const { return mCurrentState; }