diff options
Diffstat (limited to 'libs/hwui/DeferredLayerUpdater.h')
-rw-r--r-- | libs/hwui/DeferredLayerUpdater.h | 60 |
1 files changed, 43 insertions, 17 deletions
diff --git a/libs/hwui/DeferredLayerUpdater.h b/libs/hwui/DeferredLayerUpdater.h index a91c111933c4..c44c0d537fa7 100644 --- a/libs/hwui/DeferredLayerUpdater.h +++ b/libs/hwui/DeferredLayerUpdater.h @@ -19,24 +19,25 @@ #include <SkColorFilter.h> #include <SkImage.h> #include <SkMatrix.h> +#include <android/hardware_buffer.h> #include <cutils/compiler.h> -#include <map> -#include <system/graphics.h> -#include <utils/StrongPointer.h> +#include <android/surface_texture.h> -#include <GLES2/gl2.h> -#include <GLES2/gl2ext.h> +#include <map> +#include <memory> -#include "renderstate/RenderState.h" -#include "surfacetexture/SurfaceTexture.h" #include "Layer.h" #include "Rect.h" +#include "renderstate/RenderState.h" namespace android { namespace uirenderer { +class AutoBackendTextureRelease; class RenderState; +typedef std::unique_ptr<ASurfaceTexture, decltype(&ASurfaceTexture_release)> AutoTextureRelease; + // Container to hold the properties a layer should be set to at the start // of a render pass class DeferredLayerUpdater : public VirtualLightRefBase, public IGpuContextCallback { @@ -67,15 +68,7 @@ public: return false; } - ANDROID_API void setSurfaceTexture(const sp<SurfaceTexture>& consumer) { - if (consumer.get() != mSurfaceTexture.get()) { - mSurfaceTexture = consumer; - - GLenum target = consumer->getCurrentTextureTarget(); - LOG_ALWAYS_FATAL_IF(target != GL_TEXTURE_2D && target != GL_TEXTURE_EXTERNAL_OES, - "set unsupported SurfaceTexture with target %x", target); - } - } + ANDROID_API void setSurfaceTexture(AutoTextureRelease&& consumer); ANDROID_API void updateTexImage() { mUpdateTexImage = true; } @@ -103,6 +96,39 @@ protected: void onContextDestroyed() override; private: + /** + * ImageSlot contains the information and object references that + * DeferredLayerUpdater maintains about a slot. Slot id comes from + * ASurfaceTexture_dequeueBuffer. Usually there are at most 3 slots active at a time. + */ + class ImageSlot { + public: + ~ImageSlot() { clear(); } + + sk_sp<SkImage> createIfNeeded(AHardwareBuffer* buffer, android_dataspace dataspace, + bool forceCreate, GrContext* context); + + private: + void clear(); + + // the dataspace associated with the current image + android_dataspace mDataspace = HAL_DATASPACE_UNKNOWN; + + AHardwareBuffer* mBuffer = nullptr; + + /** + * mTextureRelease may outlive DeferredLayerUpdater, if the last ref is held by an SkImage. + * DeferredLayerUpdater holds one ref to mTextureRelease, which is decremented by "clear". + */ + AutoBackendTextureRelease* mTextureRelease = nullptr; + }; + + /** + * DeferredLayerUpdater stores the SkImages that have been allocated by the BufferQueue + * for each buffer slot. + */ + std::map<int, ImageSlot> mImageSlots; + RenderState& mRenderState; // Generic properties @@ -112,7 +138,7 @@ private: sk_sp<SkColorFilter> mColorFilter; int mAlpha = 255; SkBlendMode mMode = SkBlendMode::kSrcOver; - sp<SurfaceTexture> mSurfaceTexture; + AutoTextureRelease mSurfaceTexture; SkMatrix* mTransform; bool mGLContextAttached; bool mUpdateTexImage; |