[RenderEngine] Make BindNativeBufferAsFramebuffer more generic.

BindNativeBufferAsFramebuffer is a helper class that manages resource of an EGL
image for screenshot capturing. However, as a public API it ties to GLES. This
patch abstracts framebuffer out as Framebuffer and uses it instead of EGL
image. As a result, we can move the most of the implementation of
bindNativeBufferAsFrameBuffer and unbindNativeBufferAsFrameBuffer to
GLFramebuffer so that it manages its own resources, and move the rest of the
implementation to GLES20RenderEngine and get rid off two virtual functions.

Minor: Clean up some coding style.

BUG: 112585051
Test: Build, flash, boot and run some display validation
Change-Id: I787625089f8959cc273d4756baa7135cb004ed2d
diff --git a/services/surfaceflinger/RenderEngine/gl/GLES20RenderEngine.h b/services/surfaceflinger/RenderEngine/gl/GLES20RenderEngine.h
index a6fc03d..3113e53 100644
--- a/services/surfaceflinger/RenderEngine/gl/GLES20RenderEngine.h
+++ b/services/surfaceflinger/RenderEngine/gl/GLES20RenderEngine.h
@@ -39,32 +39,13 @@
 class GLSurface;
 
 class GLES20RenderEngine : public impl::RenderEngine {
-    GLuint mProtectedTexName;
-    GLint mMaxViewportDims[2];
-    GLint mMaxTextureSize;
-    GLuint mVpWidth;
-    GLuint mVpHeight;
-
-    struct Group {
-        GLuint texture;
-        GLuint fbo;
-        GLuint width;
-        GLuint height;
-        mat4 colorTransform;
-    };
-
-    Description mState;
-
-    virtual void bindImageAsFramebuffer(EGLImageKHR image, uint32_t* texName, uint32_t* fbName,
-                                        uint32_t* status);
-    virtual void unbindFramebuffer(uint32_t texName, uint32_t fbName);
-
 public:
     GLES20RenderEngine(uint32_t featureFlags); // See RenderEngine::FeatureFlag
-    virtual ~GLES20RenderEngine();
+    ~GLES20RenderEngine() override;
 
-    std::unique_ptr<renderengine::Surface> createSurface() override;
-    std::unique_ptr<renderengine::Image> createImage() override;
+    std::unique_ptr<Framebuffer> createFramebuffer() override;
+    std::unique_ptr<Surface> createSurface() override;
+    std::unique_ptr<Image> createImage() override;
 
     void primeCache() const override;
 
@@ -72,15 +53,16 @@
     bool setCurrentSurface(const Surface& surface) override;
     void resetCurrentSurface() override;
 
-    void bindExternalTextureImage(uint32_t texName, const renderengine::Image& image) override;
-
+    void bindExternalTextureImage(uint32_t texName, const Image& image) override;
+    status_t bindFrameBuffer(Framebuffer* framebuffer) override;
+    void unbindFrameBuffer(Framebuffer* framebuffer) override;
 
 protected:
-    virtual void dump(String8& result);
-    virtual void setViewportAndProjection(size_t vpw, size_t vph, Rect sourceCrop,
-                                          ui::Transform::orientation_flags rotation);
-    virtual void setupLayerBlending(bool premultipliedAlpha, bool opaque, bool disableTexture,
-                                    const half4& color) override;
+    void dump(String8& result) override;
+    void setViewportAndProjection(size_t vpw, size_t vph, Rect sourceCrop,
+                                  ui::Transform::orientation_flags rotation) override;
+    void setupLayerBlending(bool premultipliedAlpha, bool opaque, bool disableTexture,
+                            const half4& color) override;
 
     // Color management related functions and state
     void setSourceY410BT2020(bool enable) override;
@@ -88,17 +70,41 @@
     void setOutputDataSpace(ui::Dataspace dataspace) override;
     void setDisplayMaxLuminance(const float maxLuminance) override;
 
-    virtual void setupLayerTexturing(const Texture& texture);
-    virtual void setupLayerBlackedOut();
-    virtual void setupFillWithColor(float r, float g, float b, float a);
-    virtual void setupColorTransform(const mat4& colorTransform);
-    virtual void disableTexturing();
-    virtual void disableBlending();
+    void setupLayerTexturing(const Texture& texture) override;
+    void setupLayerBlackedOut() override;
+    void setupFillWithColor(float r, float g, float b, float a) override;
+    void setupColorTransform(const mat4& colorTransform) override;
+    void disableTexturing() override;
+    void disableBlending() override;
 
-    virtual void drawMesh(const Mesh& mesh);
+    void drawMesh(const Mesh& mesh) override;
 
-    virtual size_t getMaxTextureSize() const;
-    virtual size_t getMaxViewportDims() const;
+    size_t getMaxTextureSize() const override;
+    size_t getMaxViewportDims() const override;
+
+private:
+    // A data space is considered HDR data space if it has BT2020 color space
+    // with PQ or HLG transfer function.
+    bool isHdrDataSpace(const ui::Dataspace dataSpace) const;
+    bool needsXYZTransformMatrix() const;
+
+    GLuint mProtectedTexName;
+    GLint mMaxViewportDims[2];
+    GLint mMaxTextureSize;
+    GLuint mVpWidth;
+    GLuint mVpHeight;
+    Description mState;
+
+    mat4 mSrgbToDisplayP3;
+    mat4 mDisplayP3ToSrgb;
+    mat3 mSrgbToXyz;
+    mat3 mBt2020ToXyz;
+    mat3 mDisplayP3ToXyz;
+    mat4 mXyzToSrgb;
+    mat4 mXyzToDisplayP3;
+    mat4 mXyzToBt2020;
+
+    bool mRenderToFbo = false;
 
     // Current dataspace of layer being rendered
     ui::Dataspace mDataSpace = ui::Dataspace::UNKNOWN;
@@ -109,22 +115,6 @@
     // Whether device supports color management, currently color management
     // supports sRGB, DisplayP3 color spaces.
     const bool mUseColorManagement = false;
-    mat4 mSrgbToDisplayP3;
-    mat4 mDisplayP3ToSrgb;
-    mat3 mSrgbToXyz;
-    mat3 mBt2020ToXyz;
-    mat3 mDisplayP3ToXyz;
-    mat4 mXyzToSrgb;
-    mat4 mXyzToDisplayP3;
-    mat4 mXyzToBt2020;
-
-private:
-    // A data space is considered HDR data space if it has BT2020 color space
-    // with PQ or HLG transfer function.
-    bool isHdrDataSpace(const ui::Dataspace dataSpace) const;
-    bool needsXYZTransformMatrix() const;
-
-    bool mRenderToFbo = false;
 };
 
 }  // namespace gl