[RenderEngine] Strip GLES implementation off Image and Surface.

Image and Surface contain GLES implementation details. This patch moves them to
dedicated classes and move all Surface/Image manipulation methods from
impl::RenderEngine to gl::GLES20RenderEngine.

BUG: 112585051
Test: Build, flash, boot and run some display validation.
Change-Id: I77327f79082dff8e87e0a9472baae0c794f047bf
diff --git a/services/surfaceflinger/RenderEngine/Android.bp b/services/surfaceflinger/RenderEngine/Android.bp
index f62596f..add1b7b 100644
--- a/services/surfaceflinger/RenderEngine/Android.bp
+++ b/services/surfaceflinger/RenderEngine/Android.bp
@@ -41,10 +41,8 @@
     name: "librenderengine_sources",
     srcs: [
         "Description.cpp",
-        "Image.cpp",
         "Mesh.cpp",
         "RenderEngine.cpp",
-        "Surface.cpp",
         "Texture.cpp",
     ],
 }
@@ -54,6 +52,8 @@
     srcs: [
         "gl/GLES20RenderEngine.cpp",
         "gl/GLExtensions.cpp",
+        "gl/GLImage.cpp",
+        "gl/GLSurface.cpp",
         "gl/Program.cpp",
         "gl/ProgramCache.cpp",
     ],
diff --git a/services/surfaceflinger/RenderEngine/RenderEngine.cpp b/services/surfaceflinger/RenderEngine/RenderEngine.cpp
index c843428..ce977b7 100644
--- a/services/surfaceflinger/RenderEngine/RenderEngine.cpp
+++ b/services/surfaceflinger/RenderEngine/RenderEngine.cpp
@@ -184,42 +184,6 @@
     return SyncFeatures::getInstance().useWaitSync();
 }
 
-bool RenderEngine::isCurrent() const {
-    return mEGLDisplay == eglGetCurrentDisplay() && mEGLContext == eglGetCurrentContext();
-}
-
-std::unique_ptr<renderengine::Surface> RenderEngine::createSurface() {
-    return std::make_unique<Surface>(*this);
-}
-
-std::unique_ptr<renderengine::Image> RenderEngine::createImage() {
-    return std::make_unique<Image>(*this);
-}
-
-bool RenderEngine::setCurrentSurface(const android::renderengine::Surface& surface) {
-    // Note: renderengine::Surface is an abstract interface. This implementation only ever
-    // creates renderengine::impl::Surface's, so it is safe to just cast to the actual
-    // type.
-    return setCurrentSurface(static_cast<const android::renderengine::impl::Surface&>(surface));
-}
-
-bool RenderEngine::setCurrentSurface(const android::renderengine::impl::Surface& surface) {
-    bool success = true;
-    EGLSurface eglSurface = surface.getEGLSurface();
-    if (eglSurface != eglGetCurrentSurface(EGL_DRAW)) {
-        success = eglMakeCurrent(mEGLDisplay, eglSurface, eglSurface, mEGLContext) == EGL_TRUE;
-        if (success && surface.getAsync()) {
-            eglSwapInterval(mEGLDisplay, 0);
-        }
-    }
-
-    return success;
-}
-
-void RenderEngine::resetCurrentSurface() {
-    eglMakeCurrent(mEGLDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
-}
-
 base::unique_fd RenderEngine::flush() {
     if (!GLExtensions::getInstance().hasNativeFenceSync()) {
         return base::unique_fd();
@@ -375,24 +339,6 @@
     glDeleteTextures(count, names);
 }
 
-void RenderEngine::bindExternalTextureImage(uint32_t texName,
-                                            const android::renderengine::Image& image) {
-    // Note: renderengine::Image is an abstract interface. This implementation only ever
-    // creates renderengine::impl::Image's, so it is safe to just cast to the actual type.
-    return bindExternalTextureImage(texName,
-                                    static_cast<const android::renderengine::impl::Image&>(image));
-}
-
-void RenderEngine::bindExternalTextureImage(uint32_t texName,
-                                            const android::renderengine::impl::Image& image) {
-    const GLenum target = GL_TEXTURE_EXTERNAL_OES;
-
-    glBindTexture(target, texName);
-    if (image.getEGLImage() != EGL_NO_IMAGE_KHR) {
-        glEGLImageTargetTexture2DOES(target, static_cast<GLeglImageOES>(image.getEGLImage()));
-    }
-}
-
 void RenderEngine::readPixels(size_t l, size_t b, size_t w, size_t h, uint32_t* pixels) {
     glReadPixels(l, b, w, h, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
 }
@@ -597,11 +543,6 @@
     return config;
 }
 
-void RenderEngine::primeCache() const {
-    ProgramCache::getInstance().primeCache(mFeatureFlags & USE_COLOR_MANAGEMENT);
-}
-
-
 }  // namespace impl
 }  // namespace renderengine
 }  // namespace android
diff --git a/services/surfaceflinger/RenderEngine/gl/GLES20RenderEngine.cpp b/services/surfaceflinger/RenderEngine/gl/GLES20RenderEngine.cpp
index e0f1850..f577b333 100644
--- a/services/surfaceflinger/RenderEngine/gl/GLES20RenderEngine.cpp
+++ b/services/surfaceflinger/RenderEngine/gl/GLES20RenderEngine.cpp
@@ -36,6 +36,9 @@
 #include <ui/Rect.h>
 #include <utils/String8.h>
 #include <utils/Trace.h>
+#include "GLExtensions.h"
+#include "GLImage.h"
+#include "GLSurface.h"
 #include "Program.h"
 #include "ProgramCache.h"
 
@@ -151,12 +154,51 @@
 
 GLES20RenderEngine::~GLES20RenderEngine() {}
 
-size_t GLES20RenderEngine::getMaxTextureSize() const {
-    return mMaxTextureSize;
+std::unique_ptr<Surface> GLES20RenderEngine::createSurface() {
+    return std::make_unique<GLSurface>(*this);
 }
 
-size_t GLES20RenderEngine::getMaxViewportDims() const {
-    return mMaxViewportDims[0] < mMaxViewportDims[1] ? mMaxViewportDims[0] : mMaxViewportDims[1];
+std::unique_ptr<Image> GLES20RenderEngine::createImage() {
+    return std::make_unique<GLImage>(*this);
+}
+
+void GLES20RenderEngine::primeCache() const {
+    ProgramCache::getInstance().primeCache(mFeatureFlags & USE_COLOR_MANAGEMENT);
+}
+
+bool GLES20RenderEngine::isCurrent() const {
+    return mEGLDisplay == eglGetCurrentDisplay() && mEGLContext == eglGetCurrentContext();
+}
+
+bool GLES20RenderEngine::setCurrentSurface(const Surface& surface) {
+    // Surface is an abstract interface. GLES20RenderEngine only ever
+    // creates GLSurface's, so it is safe to just cast to the actual
+    // type.
+    bool success = true;
+    const GLSurface& glSurface = static_cast<const GLSurface&>(surface);
+    EGLSurface eglSurface = glSurface.getEGLSurface();
+    if (eglSurface != eglGetCurrentSurface(EGL_DRAW)) {
+        success = eglMakeCurrent(mEGLDisplay, eglSurface, eglSurface, mEGLContext) == EGL_TRUE;
+        if (success && glSurface.getAsync()) {
+            eglSwapInterval(mEGLDisplay, 0);
+        }
+    }
+    return success;
+}
+
+void GLES20RenderEngine::resetCurrentSurface() {
+    eglMakeCurrent(mEGLDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
+}
+
+void GLES20RenderEngine::bindExternalTextureImage(uint32_t texName,
+                                                  const Image& image) {
+    const GLImage& glImage = static_cast<const GLImage&>(image);
+    const GLenum target = GL_TEXTURE_EXTERNAL_OES;
+
+    glBindTexture(target, texName);
+    if (glImage.getEGLImage() != EGL_NO_IMAGE_KHR) {
+        glEGLImageTargetTexture2DOES(target, static_cast<GLeglImageOES>(glImage.getEGLImage()));
+    }
 }
 
 void GLES20RenderEngine::setViewportAndProjection(size_t vpw, size_t vph, Rect sourceCrop,
@@ -425,6 +467,14 @@
     }
 }
 
+size_t GLES20RenderEngine::getMaxTextureSize() const {
+    return mMaxTextureSize;
+}
+
+size_t GLES20RenderEngine::getMaxViewportDims() const {
+    return mMaxViewportDims[0] < mMaxViewportDims[1] ? mMaxViewportDims[0] : mMaxViewportDims[1];
+}
+
 void GLES20RenderEngine::dump(String8& result) {
     RenderEngine::dump(result);
     result.appendFormat("RenderEngine last dataspace conversion: (%s) to (%s)\n",
@@ -462,7 +512,3 @@
 }  // namespace gl
 }  // namespace renderengine
 }  // namespace android
-
-#if defined(__gl_h_)
-#error "don't include gl/gl.h in this file"
-#endif
diff --git a/services/surfaceflinger/RenderEngine/gl/GLES20RenderEngine.h b/services/surfaceflinger/RenderEngine/gl/GLES20RenderEngine.h
index c830184..e256f07 100644
--- a/services/surfaceflinger/RenderEngine/gl/GLES20RenderEngine.h
+++ b/services/surfaceflinger/RenderEngine/gl/GLES20RenderEngine.h
@@ -35,6 +35,9 @@
 
 namespace gl {
 
+class GLImage;
+class GLSurface;
+
 class GLES20RenderEngine : public impl::RenderEngine {
     GLuint mProtectedTexName;
     GLint mMaxViewportDims[2];
@@ -60,6 +63,18 @@
     GLES20RenderEngine(uint32_t featureFlags); // See RenderEngine::FeatureFlag
     virtual ~GLES20RenderEngine();
 
+    std::unique_ptr<renderengine::Surface> createSurface() override;
+    std::unique_ptr<renderengine::Image> createImage() override;
+
+    void primeCache() const override;
+
+    bool isCurrent() const;
+    bool setCurrentSurface(const Surface& surface) override;
+    void resetCurrentSurface() override;
+
+    void bindExternalTextureImage(uint32_t texName, const renderengine::Image& image) override;
+
+
 protected:
     virtual void dump(String8& result);
     virtual void setViewportAndProjection(size_t vpw, size_t vph, Rect sourceCrop, size_t hwh,
diff --git a/services/surfaceflinger/RenderEngine/Image.cpp b/services/surfaceflinger/RenderEngine/gl/GLImage.cpp
similarity index 78%
rename from services/surfaceflinger/RenderEngine/Image.cpp
rename to services/surfaceflinger/RenderEngine/gl/GLImage.cpp
index cabcace..746f3e7 100644
--- a/services/surfaceflinger/RenderEngine/Image.cpp
+++ b/services/surfaceflinger/RenderEngine/gl/GLImage.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright 2017 The Android Open Source Project
+ * Copyright 2018 The Android Open Source Project
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -14,26 +14,17 @@
  * limitations under the License.
  */
 
-#include <renderengine/Image.h>
+#include "GLImage.h"
 
 #include <vector>
 
 #include <log/log.h>
-#include <renderengine/RenderEngine.h>
-#include "gl/GLExtensions.h"
+#include "GLExtensions.h"
+#include "GLES20RenderEngine.h"
 
 namespace android {
 namespace renderengine {
-
-Image::~Image() = default;
-
-namespace impl {
-
-Image::Image(const RenderEngine& engine) : mEGLDisplay(engine.getEGLDisplay()) {}
-
-Image::~Image() {
-    setNativeWindowBuffer(nullptr, false);
-}
+namespace gl {
 
 static std::vector<EGLint> buildAttributeList(bool isProtected) {
     std::vector<EGLint> attrs;
@@ -42,7 +33,7 @@
     attrs.push_back(EGL_IMAGE_PRESERVED_KHR);
     attrs.push_back(EGL_TRUE);
 
-    if (isProtected && gl::GLExtensions::getInstance().hasProtectedContent()) {
+    if (isProtected && GLExtensions::getInstance().hasProtectedContent()) {
         attrs.push_back(EGL_PROTECTED_CONTENT_EXT);
         attrs.push_back(EGL_TRUE);
     }
@@ -52,7 +43,13 @@
     return attrs;
 }
 
-bool Image::setNativeWindowBuffer(ANativeWindowBuffer* buffer, bool isProtected) {
+GLImage::GLImage(const GLES20RenderEngine& engine) : mEGLDisplay(engine.getEGLDisplay()) {}
+
+GLImage::~GLImage() {
+    setNativeWindowBuffer(nullptr, false);
+}
+
+bool GLImage::setNativeWindowBuffer(ANativeWindowBuffer* buffer, bool isProtected) {
     if (mEGLImage != EGL_NO_IMAGE_KHR) {
         if (!eglDestroyImageKHR(mEGLDisplay, mEGLImage)) {
             ALOGE("failed to destroy image: %#x", eglGetError());
@@ -73,6 +70,6 @@
     return true;
 }
 
-}  // namespace impl
+}  // namespace gl
 }  // namespace renderengine
 }  // namespace android
diff --git a/services/surfaceflinger/RenderEngine/gl/GLImage.h b/services/surfaceflinger/RenderEngine/gl/GLImage.h
new file mode 100644
index 0000000..a0f2358
--- /dev/null
+++ b/services/surfaceflinger/RenderEngine/gl/GLImage.h
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <cstdint>
+
+#include <EGL/egl.h>
+#include <EGL/eglext.h>
+#include <android-base/macros.h>
+#include <renderengine/Image.h>
+
+struct ANativeWindowBuffer;
+
+namespace android {
+namespace renderengine {
+namespace gl {
+
+class GLES20RenderEngine;
+
+class GLImage : public renderengine::Image {
+public:
+    explicit GLImage(const GLES20RenderEngine& engine);
+    ~GLImage() override;
+
+    bool setNativeWindowBuffer(ANativeWindowBuffer* buffer, bool isProtected) override;
+
+    EGLSurface getEGLImage() const { return mEGLImage; }
+
+private:
+    EGLDisplay mEGLDisplay;
+    EGLImageKHR mEGLImage = EGL_NO_IMAGE_KHR;
+
+    DISALLOW_COPY_AND_ASSIGN(GLImage);
+};
+
+} // namespace gl
+} // namespace renderengine
+} // namespace android
diff --git a/services/surfaceflinger/RenderEngine/Surface.cpp b/services/surfaceflinger/RenderEngine/gl/GLSurface.cpp
similarity index 71%
rename from services/surfaceflinger/RenderEngine/Surface.cpp
rename to services/surfaceflinger/RenderEngine/gl/GLSurface.cpp
index b9f095b..ff9a252 100644
--- a/services/surfaceflinger/RenderEngine/Surface.cpp
+++ b/services/surfaceflinger/RenderEngine/gl/GLSurface.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright 2017 The Android Open Source Project
+ * Copyright 2018 The Android Open Source Project
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -14,32 +14,30 @@
  * limitations under the License.
  */
 
-#include <renderengine/Surface.h>
+#include "GLSurface.h"
 
 #include <log/log.h>
-#include <renderengine/RenderEngine.h>
 #include <ui/PixelFormat.h>
+#include "GLES20RenderEngine.h"
 
 namespace android {
 namespace renderengine {
+namespace gl {
 
-Surface::~Surface() = default;
-
-namespace impl {
-
-Surface::Surface(const RenderEngine& engine)
+GLSurface::GLSurface(const GLES20RenderEngine& engine)
       : mEGLDisplay(engine.getEGLDisplay()), mEGLConfig(engine.getEGLConfig()) {
     // RE does not assume any config when EGL_KHR_no_config_context is supported
     if (mEGLConfig == EGL_NO_CONFIG_KHR) {
-        mEGLConfig = RenderEngine::chooseEglConfig(mEGLDisplay, PIXEL_FORMAT_RGBA_8888, false);
+        mEGLConfig = GLES20RenderEngine::chooseEglConfig(mEGLDisplay,
+                                                         PIXEL_FORMAT_RGBA_8888, false);
     }
 }
 
-Surface::~Surface() {
+GLSurface::~GLSurface() {
     setNativeWindow(nullptr);
 }
 
-void Surface::setNativeWindow(ANativeWindow* window) {
+void GLSurface::setNativeWindow(ANativeWindow* window) {
     if (mEGLSurface != EGL_NO_SURFACE) {
         eglDestroySurface(mEGLDisplay, mEGLSurface);
         mEGLSurface = EGL_NO_SURFACE;
@@ -51,7 +49,7 @@
     }
 }
 
-void Surface::swapBuffers() const {
+void GLSurface::swapBuffers() const {
     if (!eglSwapBuffers(mEGLDisplay, mEGLSurface)) {
         EGLint error = eglGetError();
 
@@ -64,7 +62,7 @@
     }
 }
 
-EGLint Surface::queryConfig(EGLint attrib) const {
+EGLint GLSurface::queryConfig(EGLint attrib) const {
     EGLint value;
     if (!eglGetConfigAttrib(mEGLDisplay, mEGLConfig, attrib, &value)) {
         value = 0;
@@ -73,7 +71,7 @@
     return value;
 }
 
-EGLint Surface::querySurface(EGLint attrib) const {
+EGLint GLSurface::querySurface(EGLint attrib) const {
     EGLint value;
     if (!eglQuerySurface(mEGLDisplay, mEGLSurface, attrib, &value)) {
         value = 0;
@@ -82,30 +80,30 @@
     return value;
 }
 
-int32_t Surface::queryRedSize() const {
+int32_t GLSurface::queryRedSize() const {
     return queryConfig(EGL_RED_SIZE);
 }
 
-int32_t Surface::queryGreenSize() const {
+int32_t GLSurface::queryGreenSize() const {
     return queryConfig(EGL_GREEN_SIZE);
 }
 
-int32_t Surface::queryBlueSize() const {
+int32_t GLSurface::queryBlueSize() const {
     return queryConfig(EGL_BLUE_SIZE);
 }
 
-int32_t Surface::queryAlphaSize() const {
+int32_t GLSurface::queryAlphaSize() const {
     return queryConfig(EGL_ALPHA_SIZE);
 }
 
-int32_t Surface::queryWidth() const {
+int32_t GLSurface::queryWidth() const {
     return querySurface(EGL_WIDTH);
 }
 
-int32_t Surface::queryHeight() const {
+int32_t GLSurface::queryHeight() const {
     return querySurface(EGL_HEIGHT);
 }
 
-}  // namespace impl
+}  // namespace gl
 }  // namespace renderengine
 }  // namespace android
diff --git a/services/surfaceflinger/RenderEngine/gl/GLSurface.h b/services/surfaceflinger/RenderEngine/gl/GLSurface.h
new file mode 100644
index 0000000..0b89c70
--- /dev/null
+++ b/services/surfaceflinger/RenderEngine/gl/GLSurface.h
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <cstdint>
+
+#include <EGL/egl.h>
+#include <android-base/macros.h>
+#include <renderengine/Surface.h>
+
+struct ANativeWindow;
+
+namespace android {
+namespace renderengine {
+namespace gl {
+
+class GLES20RenderEngine;
+
+class GLSurface final : public renderengine::Surface {
+public:
+    GLSurface(const GLES20RenderEngine& engine);
+    ~GLSurface() override;
+
+    // renderengine::Surface implementation
+    void setCritical(bool enable) override { mCritical = enable; }
+    void setAsync(bool enable) override { mAsync = enable; }
+
+    void setNativeWindow(ANativeWindow* window) override;
+    void swapBuffers() const override;
+
+    int32_t queryRedSize() const override;
+    int32_t queryGreenSize() const override;
+    int32_t queryBlueSize() const override;
+    int32_t queryAlphaSize() const override;
+
+    int32_t queryWidth() const override;
+    int32_t queryHeight() const override;
+
+    bool getAsync() const { return mAsync; }
+    EGLSurface getEGLSurface() const { return mEGLSurface; }
+
+private:
+    EGLint queryConfig(EGLint attrib) const;
+    EGLint querySurface(EGLint attrib) const;
+
+    EGLDisplay mEGLDisplay;
+    EGLConfig mEGLConfig;
+
+    bool mCritical = false;
+    bool mAsync = false;
+
+    ANativeWindow* mWindow = nullptr;
+    EGLSurface mEGLSurface = EGL_NO_SURFACE;
+
+    DISALLOW_COPY_AND_ASSIGN(GLSurface);
+};
+
+}  // namespace gl
+}  // namespace renderengine
+}  // namespace android
diff --git a/services/surfaceflinger/RenderEngine/include/renderengine/Image.h b/services/surfaceflinger/RenderEngine/include/renderengine/Image.h
index 9b34b68..85ec91a 100644
--- a/services/surfaceflinger/RenderEngine/include/renderengine/Image.h
+++ b/services/surfaceflinger/RenderEngine/include/renderengine/Image.h
@@ -16,11 +16,6 @@
 
 #pragma once
 
-#include <cstdint>
-
-#include <EGL/egl.h>
-#include <EGL/eglext.h>
-
 struct ANativeWindowBuffer;
 
 namespace android {
@@ -28,33 +23,10 @@
 
 class Image {
 public:
-    virtual ~Image() = 0;
+    virtual ~Image() = default;
     virtual bool setNativeWindowBuffer(ANativeWindowBuffer* buffer, bool isProtected) = 0;
 };
 
-namespace impl {
-
-class RenderEngine;
-
-class Image : public renderengine::Image {
-public:
-    explicit Image(const RenderEngine& engine);
-    ~Image() override;
-
-    Image(const Image&) = delete;
-    Image& operator=(const Image&) = delete;
-
-    bool setNativeWindowBuffer(ANativeWindowBuffer* buffer, bool isProtected) override;
-
-private:
-    // methods internal to RenderEngine
-    friend class RenderEngine;
-    EGLSurface getEGLImage() const { return mEGLImage; }
-
-    EGLDisplay mEGLDisplay;
-    EGLImageKHR mEGLImage = EGL_NO_IMAGE_KHR;
-};
-
-}  // namespace impl
 }  // namespace renderengine
 }  // namespace android
+
diff --git a/services/surfaceflinger/RenderEngine/include/renderengine/RenderEngine.h b/services/surfaceflinger/RenderEngine/include/renderengine/RenderEngine.h
index c532adc..6206b4c 100644
--- a/services/surfaceflinger/RenderEngine/include/renderengine/RenderEngine.h
+++ b/services/surfaceflinger/RenderEngine/include/renderengine/RenderEngine.h
@@ -58,8 +58,8 @@
 
     virtual ~RenderEngine() = 0;
 
-    virtual std::unique_ptr<renderengine::Surface> createSurface() = 0;
-    virtual std::unique_ptr<renderengine::Image> createImage() = 0;
+    virtual std::unique_ptr<Surface> createSurface() = 0;
+    virtual std::unique_ptr<Image> createImage() = 0;
 
     virtual void primeCache() const = 0;
 
@@ -70,7 +70,7 @@
     virtual bool useWaitSync() const = 0;
 
     virtual bool isCurrent() const = 0;
-    virtual bool setCurrentSurface(const renderengine::Surface& surface) = 0;
+    virtual bool setCurrentSurface(const Surface& surface) = 0;
     virtual void resetCurrentSurface() = 0;
 
     // helpers
@@ -149,10 +149,8 @@
 
 namespace impl {
 
-class Image;
-class Surface;
-
 class RenderEngine : public renderengine::RenderEngine {
+protected:
     enum GlesVersion {
         GLES_VERSION_1_0 = 0x10000,
         GLES_VERSION_1_1 = 0x10001,
@@ -168,7 +166,6 @@
 
     static bool overrideUseContextPriorityFromConfig(bool useContextPriority);
 
-protected:
     RenderEngine(uint32_t featureFlags);
 
     const uint32_t mFeatureFlags;
@@ -180,23 +177,12 @@
 
     static EGLConfig chooseEglConfig(EGLDisplay display, int format, bool logConfig);
 
-    // RenderEngine interface implementation
-
-    std::unique_ptr<renderengine::Surface> createSurface() override;
-    std::unique_ptr<renderengine::Image> createImage() override;
-
-    void primeCache() const override;
-
     // dump the extension strings. always call the base class.
     void dump(String8& result) override;
 
     bool useNativeFenceSync() const override;
     bool useWaitSync() const override;
 
-    bool isCurrent() const;
-    bool setCurrentSurface(const renderengine::Surface& surface) override;
-    void resetCurrentSurface() override;
-
     // synchronization
 
     // flush submits RenderEngine command stream for execution and returns a
@@ -220,7 +206,6 @@
     void disableScissor() override;
     void genTextures(size_t count, uint32_t* names) override;
     void deleteTextures(size_t count, uint32_t const* names) override;
-    void bindExternalTextureImage(uint32_t texName, const renderengine::Image& image) override;
     void readPixels(size_t l, size_t b, size_t w, size_t h, uint32_t* pixels) override;
 
     void checkErrors() const override;
@@ -232,9 +217,6 @@
     EGLConfig getEGLConfig() const;
 
     // Common implementation
-    bool setCurrentSurface(const renderengine::impl::Surface& surface);
-    void bindExternalTextureImage(uint32_t texName, const renderengine::impl::Image& image);
-
     void bindNativeBufferAsFrameBuffer(
             ANativeWindowBuffer* buffer,
             renderengine::BindNativeBufferAsFramebuffer* bindHelper) override;
diff --git a/services/surfaceflinger/RenderEngine/include/renderengine/Surface.h b/services/surfaceflinger/RenderEngine/include/renderengine/Surface.h
index aaa9c7b..3343e1f 100644
--- a/services/surfaceflinger/RenderEngine/include/renderengine/Surface.h
+++ b/services/surfaceflinger/RenderEngine/include/renderengine/Surface.h
@@ -18,8 +18,6 @@
 
 #include <cstdint>
 
-#include <EGL/egl.h>
-
 struct ANativeWindow;
 
 namespace android {
@@ -27,7 +25,7 @@
 
 class Surface {
 public:
-    virtual ~Surface() = 0;
+    virtual ~Surface() = default;
 
     virtual void setCritical(bool enable) = 0;
     virtual void setAsync(bool enable) = 0;
@@ -44,52 +42,5 @@
     virtual int32_t queryHeight() const = 0;
 };
 
-namespace impl {
-
-class RenderEngine;
-
-class Surface final : public renderengine::Surface {
-public:
-    Surface(const RenderEngine& engine);
-    ~Surface();
-
-    Surface(const Surface&) = delete;
-    Surface& operator=(const Surface&) = delete;
-
-    // renderengine::Surface implementation
-    void setCritical(bool enable) override { mCritical = enable; }
-    void setAsync(bool enable) override { mAsync = enable; }
-
-    void setNativeWindow(ANativeWindow* window) override;
-    void swapBuffers() const override;
-
-    int32_t queryRedSize() const override;
-    int32_t queryGreenSize() const override;
-    int32_t queryBlueSize() const override;
-    int32_t queryAlphaSize() const override;
-
-    int32_t queryWidth() const override;
-    int32_t queryHeight() const override;
-
-private:
-    EGLint queryConfig(EGLint attrib) const;
-    EGLint querySurface(EGLint attrib) const;
-
-    // methods internal to RenderEngine
-    friend class RenderEngine;
-    bool getAsync() const { return mAsync; }
-    EGLSurface getEGLSurface() const { return mEGLSurface; }
-
-    EGLDisplay mEGLDisplay;
-    EGLConfig mEGLConfig;
-
-    bool mCritical = false;
-    bool mAsync = false;
-
-    ANativeWindow* mWindow = nullptr;
-    EGLSurface mEGLSurface = EGL_NO_SURFACE;
-};
-
-}  // namespace impl
 }  // namespace renderengine
 }  // namespace android