SF: Separate RenderEngine into interface and impl
This allows the RenderEngine to be substituted by a GMock for tests.
RE::RenderEngine is now a pure virtual interface class.
RE::impl::RenderEngine is the normal/base implementation.
Similarly, RE::Image and RE::Surface are pure virtual interfaces.
RE::impl::Image and RE::impl::Surface are the normal implementations.
Test: Builds
Bug: None
Change-Id: Ib5e658df4bb4efc1a9c0ae95feaf0c1e052cdc94
diff --git a/services/surfaceflinger/RenderEngine/RenderEngine.h b/services/surfaceflinger/RenderEngine/RenderEngine.h
index 67c0d1c..eacef38 100644
--- a/services/surfaceflinger/RenderEngine/RenderEngine.h
+++ b/services/surfaceflinger/RenderEngine/RenderEngine.h
@@ -44,91 +44,63 @@
class Texture;
namespace RE {
+
class Image;
class Surface;
-} // namespace RE
+class BindNativeBufferAsFramebuffer;
+
+namespace impl {
+class RenderEngine;
+}
class RenderEngine {
- enum GlesVersion {
- GLES_VERSION_1_0 = 0x10000,
- GLES_VERSION_1_1 = 0x10001,
- GLES_VERSION_2_0 = 0x20000,
- GLES_VERSION_3_0 = 0x30000,
- };
- static GlesVersion parseGlesVersion(const char* str);
-
- EGLDisplay mEGLDisplay;
- EGLConfig mEGLConfig;
- EGLContext mEGLContext;
- void setEGLHandles(EGLDisplay display, EGLConfig config, EGLContext ctxt);
-
- virtual void bindImageAsFramebuffer(EGLImageKHR image, uint32_t* texName, uint32_t* fbName,
- uint32_t* status) = 0;
- virtual void unbindFramebuffer(uint32_t texName, uint32_t fbName) = 0;
-
- static bool overrideUseContextPriorityFromConfig(bool useContextPriority);
-
-protected:
- RenderEngine();
-
public:
- virtual ~RenderEngine() = 0;
-
enum FeatureFlag {
WIDE_COLOR_SUPPORT = 1 << 0 // Platform has a wide color display
};
- static std::unique_ptr<RenderEngine> create(int hwcFormat, uint32_t featureFlags);
- static EGLConfig chooseEglConfig(EGLDisplay display, int format, bool logConfig);
+ virtual ~RenderEngine() = 0;
- void primeCache() const;
+ virtual std::unique_ptr<RE::Surface> createSurface() = 0;
+ virtual std::unique_ptr<RE::Image> createImage() = 0;
+
+ virtual void primeCache() const = 0;
// dump the extension strings. always call the base class.
- virtual void dump(String8& result);
+ virtual void dump(String8& result) = 0;
- bool supportsImageCrop() const;
+ virtual bool supportsImageCrop() const = 0;
- bool isCurrent() const;
- bool setCurrentSurface(const RE::Surface& surface);
- void resetCurrentSurface();
+ virtual bool isCurrent() const = 0;
+ virtual bool setCurrentSurface(const RE::Surface& surface) = 0;
+ virtual void resetCurrentSurface() = 0;
- // synchronization
-
+ // helpers
// flush submits RenderEngine command stream for execution and returns a
// native fence fd that is signaled when the execution has completed. It
// returns -1 on errors.
- base::unique_fd flush();
+ virtual base::unique_fd flush() = 0;
// finish waits until RenderEngine command stream has been executed. It
// returns false on errors.
- bool finish();
+ virtual bool finish() = 0;
// waitFence inserts a wait on an external fence fd to RenderEngine
// command stream. It returns false on errors.
- bool waitFence(base::unique_fd fenceFd);
+ virtual bool waitFence(base::unique_fd fenceFd) = 0;
- // helpers
- void clearWithColor(float red, float green, float blue, float alpha);
- void fillRegionWithColor(const Region& region, uint32_t height, float red, float green,
- float blue, float alpha);
+ virtual void clearWithColor(float red, float green, float blue, float alpha) = 0;
+ virtual void fillRegionWithColor(const Region& region, uint32_t height, float red, float green,
+ float blue, float alpha) = 0;
// common to all GL versions
- void setScissor(uint32_t left, uint32_t bottom, uint32_t right, uint32_t top);
- void disableScissor();
- void genTextures(size_t count, uint32_t* names);
- void deleteTextures(size_t count, uint32_t const* names);
- void bindExternalTextureImage(uint32_t texName, const RE::Image& image);
- void readPixels(size_t l, size_t b, size_t w, size_t h, uint32_t* pixels);
-
- class BindNativeBufferAsFramebuffer {
- RenderEngine& mEngine;
- EGLImageKHR mImage;
- uint32_t mTexName, mFbName;
- uint32_t mStatus;
-
- public:
- BindNativeBufferAsFramebuffer(RenderEngine& engine, ANativeWindowBuffer* buffer);
- ~BindNativeBufferAsFramebuffer();
- int getStatus() const;
- };
+ virtual void setScissor(uint32_t left, uint32_t bottom, uint32_t right, uint32_t top) = 0;
+ virtual void disableScissor() = 0;
+ virtual void genTextures(size_t count, uint32_t* names) = 0;
+ virtual void deleteTextures(size_t count, uint32_t const* names) = 0;
+ virtual void bindExternalTextureImage(uint32_t texName, const RE::Image& image) = 0;
+ virtual void readPixels(size_t l, size_t b, size_t w, size_t h, uint32_t* pixels) = 0;
+ virtual void bindNativeBufferAsFrameBuffer(ANativeWindowBuffer* buffer,
+ RE::BindNativeBufferAsFramebuffer* bindHelper) = 0;
+ virtual void unbindNativeBufferAsFrameBuffer(RE::BindNativeBufferAsFramebuffer* bindHelper) = 0;
// set-up
virtual void checkErrors() const;
@@ -145,7 +117,7 @@
virtual void setupLayerBlackedOut() = 0;
virtual void setupFillWithColor(float r, float g, float b, float a) = 0;
- virtual mat4 setupColorTransform(const mat4& /* colorTransform */) { return mat4(); }
+ virtual mat4 setupColorTransform(const mat4& /* colorTransform */) = 0;
virtual void disableTexturing() = 0;
virtual void disableBlending() = 0;
@@ -156,14 +128,123 @@
// queries
virtual size_t getMaxTextureSize() const = 0;
virtual size_t getMaxViewportDims() const = 0;
+};
+
+class BindNativeBufferAsFramebuffer {
+public:
+ BindNativeBufferAsFramebuffer(RenderEngine& engine, ANativeWindowBuffer* buffer)
+ : mEngine(engine) {
+ mEngine.bindNativeBufferAsFrameBuffer(buffer, this);
+ }
+ ~BindNativeBufferAsFramebuffer() { mEngine.unbindNativeBufferAsFrameBuffer(this); }
+ status_t getStatus() const { return mStatus; }
+
+protected:
+ friend impl::RenderEngine;
+
+ RenderEngine& mEngine;
+ EGLImageKHR mImage;
+ uint32_t mTexName, mFbName;
+ status_t mStatus;
+};
+
+namespace impl {
+
+class Image;
+class Surface;
+
+class RenderEngine : public RE::RenderEngine {
+ enum GlesVersion {
+ GLES_VERSION_1_0 = 0x10000,
+ GLES_VERSION_1_1 = 0x10001,
+ GLES_VERSION_2_0 = 0x20000,
+ GLES_VERSION_3_0 = 0x30000,
+ };
+ static GlesVersion parseGlesVersion(const char* str);
+
+ EGLDisplay mEGLDisplay;
+ EGLConfig mEGLConfig;
+ EGLContext mEGLContext;
+ void setEGLHandles(EGLDisplay display, EGLConfig config, EGLContext ctxt);
+
+ static bool overrideUseContextPriorityFromConfig(bool useContextPriority);
+
+protected:
+ RenderEngine();
+
+public:
+ virtual ~RenderEngine() = 0;
+
+ static std::unique_ptr<RenderEngine> create(int hwcFormat, uint32_t featureFlags);
+
+ static EGLConfig chooseEglConfig(EGLDisplay display, int format, bool logConfig);
+
+ // RenderEngine interface implementation
+
+ std::unique_ptr<RE::Surface> createSurface() override;
+ std::unique_ptr<RE::Image> createImage() override;
+
+ void primeCache() const override;
+
+ // dump the extension strings. always call the base class.
+ void dump(String8& result) override;
+
+ bool supportsImageCrop() const override;
+
+ bool isCurrent() const;
+ bool setCurrentSurface(const RE::Surface& surface) override;
+ void resetCurrentSurface() override;
+
+ // synchronization
+
+ // flush submits RenderEngine command stream for execution and returns a
+ // native fence fd that is signaled when the execution has completed. It
+ // returns -1 on errors.
+ base::unique_fd flush() override;
+ // finish waits until RenderEngine command stream has been executed. It
+ // returns false on errors.
+ bool finish() override;
+ // waitFence inserts a wait on an external fence fd to RenderEngine
+ // command stream. It returns false on errors.
+ bool waitFence(base::unique_fd fenceFd) override;
+
+ // helpers
+ void clearWithColor(float red, float green, float blue, float alpha) override;
+ void fillRegionWithColor(const Region& region, uint32_t height, float red, float green,
+ float blue, float alpha) override;
+
+ // common to all GL versions
+ void setScissor(uint32_t left, uint32_t bottom, uint32_t right, uint32_t top) override;
+ 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 RE::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;
+
+ mat4 setupColorTransform(const mat4& /* colorTransform */) override { return mat4(); }
// internal to RenderEngine
EGLDisplay getEGLDisplay() const;
EGLConfig getEGLConfig() const;
+
+ // Common implementation
+ bool setCurrentSurface(const RE::impl::Surface& surface);
+ void bindExternalTextureImage(uint32_t texName, const RE::impl::Image& image);
+
+ void bindNativeBufferAsFrameBuffer(ANativeWindowBuffer* buffer,
+ RE::BindNativeBufferAsFramebuffer* bindHelper) override;
+ void unbindNativeBufferAsFrameBuffer(RE::BindNativeBufferAsFramebuffer* bindHelper) override;
+
+ // Overriden by each specialization
+ virtual void bindImageAsFramebuffer(EGLImageKHR image, uint32_t* texName, uint32_t* fbName,
+ uint32_t* status) = 0;
+ virtual void unbindFramebuffer(uint32_t texName, uint32_t fbName) = 0;
};
-// ---------------------------------------------------------------------------
-}; // namespace android
-// ---------------------------------------------------------------------------
+} // namespace impl
+} // namespace RE
+} // namespace android
#endif /* SF_RENDERENGINE_H_ */