Revert "Add ExternalTexture class into RenderEngine interface"

Revert submission 14086921-renderengine-external-tex

Reason for revert: Potential culprit for b/185361988
Reverted Changes:
I7796764e2:Update WaylandRenderSurface to accomodate interfac...
I13904eec4:Update Readback VTS to align with RenderEngine int...
I222c71e6e:Add ExternalTexture class into RenderEngine interf...

Change-Id: I1501890f4861a3df7ce273f1fe2ccdb275e2632c
diff --git a/services/surfaceflinger/CompositionEngine/src/RenderSurface.cpp b/services/surfaceflinger/CompositionEngine/src/RenderSurface.cpp
index ef50870..3bef77d 100644
--- a/services/surfaceflinger/CompositionEngine/src/RenderSurface.cpp
+++ b/services/surfaceflinger/CompositionEngine/src/RenderSurface.cpp
@@ -25,8 +25,8 @@
 #include <compositionengine/impl/DumpHelpers.h>
 #include <compositionengine/impl/OutputCompositionState.h>
 #include <compositionengine/impl/RenderSurface.h>
+
 #include <log/log.h>
-#include <renderengine/ExternalTexture.h>
 #include <renderengine/RenderEngine.h>
 #include <system/window.h>
 #include <ui/GraphicBuffer.h>
@@ -63,8 +63,7 @@
         mDisplay(display),
         mNativeWindow(args.nativeWindow),
         mDisplaySurface(args.displaySurface),
-        mSize(args.displayWidth, args.displayHeight),
-        mMaxTextureCacheSize(args.maxTextureCacheSize) {
+        mSize(args.displayWidth, args.displayHeight) {
     LOG_ALWAYS_FATAL_IF(!mNativeWindow);
 }
 
@@ -147,8 +146,7 @@
     }
 }
 
-std::shared_ptr<renderengine::ExternalTexture> RenderSurface::dequeueBuffer(
-        base::unique_fd* bufferFence) {
+sp<GraphicBuffer> RenderSurface::dequeueBuffer(base::unique_fd* bufferFence) {
     ATRACE_CALL();
     int fd = -1;
     ANativeWindowBuffer* buffer = nullptr;
@@ -160,41 +158,16 @@
               mDisplay.getName().c_str(), result);
         // Return fast here as we can't do much more - any rendering we do
         // now will just be wrong.
-        return mTexture;
+        return mGraphicBuffer;
     }
 
-    ALOGW_IF(mTexture != nullptr, "Clobbering a non-null pointer to a buffer [%p].",
-             mTexture->getBuffer()->getNativeBuffer()->handle);
-
-    sp<GraphicBuffer> newBuffer = GraphicBuffer::from(buffer);
-
-    std::shared_ptr<renderengine::ExternalTexture> texture;
-
-    for (auto it = mTextureCache.begin(); it != mTextureCache.end(); it++) {
-        const auto& cachedTexture = *it;
-        if (cachedTexture->getBuffer()->getId() == newBuffer->getId()) {
-            texture = cachedTexture;
-            mTextureCache.erase(it);
-            break;
-        }
-    }
-
-    if (texture) {
-        mTexture = texture;
-    } else {
-        mTexture = std::make_shared<
-                renderengine::ExternalTexture>(GraphicBuffer::from(buffer),
-                                               mCompositionEngine.getRenderEngine(),
-                                               renderengine::ExternalTexture::Usage::WRITEABLE);
-    }
-    mTextureCache.push_back(mTexture);
-    if (mTextureCache.size() > mMaxTextureCacheSize) {
-        mTextureCache.erase(mTextureCache.begin());
-    }
+    ALOGW_IF(mGraphicBuffer != nullptr, "Clobbering a non-null pointer to a buffer [%p].",
+             mGraphicBuffer->getNativeBuffer()->handle);
+    mGraphicBuffer = GraphicBuffer::from(buffer);
 
     *bufferFence = base::unique_fd(fd);
 
-    return mTexture;
+    return mGraphicBuffer;
 }
 
 void RenderSurface::queueBuffer(base::unique_fd readyFence) {
@@ -204,24 +177,24 @@
         // hasFlipClientTargetRequest could return true even if we haven't
         // dequeued a buffer before. Try dequeueing one if we don't have a
         // buffer ready.
-        if (mTexture == nullptr) {
+        if (mGraphicBuffer == nullptr) {
             ALOGI("Attempting to queue a client composited buffer without one "
                   "previously dequeued for display [%s]. Attempting to dequeue "
                   "a scratch buffer now",
                   mDisplay.getName().c_str());
-            // We shouldn't deadlock here, since mTexture == nullptr only
+            // We shouldn't deadlock here, since mGraphicBuffer == nullptr only
             // after a successful call to queueBuffer, or if dequeueBuffer has
             // never been called.
             base::unique_fd unused;
             dequeueBuffer(&unused);
         }
 
-        if (mTexture == nullptr) {
+        if (mGraphicBuffer == nullptr) {
             ALOGE("No buffer is ready for display [%s]", mDisplay.getName().c_str());
         } else {
-            status_t result = mNativeWindow->queueBuffer(mNativeWindow.get(),
-                                                         mTexture->getBuffer()->getNativeBuffer(),
-                                                         dup(readyFence));
+            status_t result =
+                    mNativeWindow->queueBuffer(mNativeWindow.get(),
+                                               mGraphicBuffer->getNativeBuffer(), dup(readyFence));
             if (result != NO_ERROR) {
                 ALOGE("Error when queueing buffer for display [%s]: %d", mDisplay.getName().c_str(),
                       result);
@@ -231,12 +204,11 @@
                     LOG_ALWAYS_FATAL("ANativeWindow::queueBuffer failed with error: %d", result);
                 } else {
                     mNativeWindow->cancelBuffer(mNativeWindow.get(),
-                                                mTexture->getBuffer()->getNativeBuffer(),
-                                                dup(readyFence));
+                                                mGraphicBuffer->getNativeBuffer(), dup(readyFence));
                 }
             }
 
-            mTexture = nullptr;
+            mGraphicBuffer = nullptr;
         }
     }
 
@@ -284,8 +256,8 @@
     mSize = size;
 }
 
-std::shared_ptr<renderengine::ExternalTexture>& RenderSurface::mutableTextureForTest() {
-    return mTexture;
+sp<GraphicBuffer>& RenderSurface::mutableGraphicBufferForTest() {
+    return mGraphicBuffer;
 }
 
 } // namespace impl