summaryrefslogtreecommitdiff
path: root/libs/hwui/DeferredLayerUpdater.h
diff options
context:
space:
mode:
author Stan Iliev <stani@google.com> 2019-09-17 14:07:23 -0400
committer Stan Iliev <stani@google.com> 2019-11-08 15:37:17 +0000
commitaaa9e834d443a56671eccbe97c755c253fa94afe (patch)
treee67daf0782137e572f6be35e9a24b146c4fd4b57 /libs/hwui/DeferredLayerUpdater.h
parent707ba29a6621220c2713468bf095178dcc1e376e (diff)
Decouple SurfaceTexture from HWUI
Remove all Skia and HWUI types from SurfaceTexture implementation. Move SurfaceTexture to libgui (ag/9578265). Define private C++ API for SurfaceTexture, which is consumed by DeferredLayerUpdater. Move AutoBackendTextureRelease/Skia code from SurfaceTexture to HWUI. Test: pass CtsUiRenderingTestCases and CtsViewTestCases Bug: 136263580 Change-Id: I3f971bb490f64a3ac0b2a66a89ba935bf7f08213
Diffstat (limited to 'libs/hwui/DeferredLayerUpdater.h')
-rw-r--r--libs/hwui/DeferredLayerUpdater.h50
1 files changed, 44 insertions, 6 deletions
diff --git a/libs/hwui/DeferredLayerUpdater.h b/libs/hwui/DeferredLayerUpdater.h
index 1491f99402ba..289f65c22ad3 100644
--- a/libs/hwui/DeferredLayerUpdater.h
+++ b/libs/hwui/DeferredLayerUpdater.h
@@ -19,21 +19,26 @@
#include <SkColorFilter.h>
#include <SkImage.h>
#include <SkMatrix.h>
+#include <android/hardware_buffer.h>
#include <cutils/compiler.h>
+// TODO: Use public SurfaceTexture APIs once available and include public NDK header file instead.
+#include <gui/surfacetexture/surface_texture_platform.h>
+
#include <map>
-#include <system/graphics.h>
-#include <utils/StrongPointer.h>
+#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> 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 {
@@ -64,7 +69,7 @@ public:
return false;
}
- ANDROID_API void setSurfaceTexture(const sp<SurfaceTexture>& consumer);
+ ANDROID_API void setSurfaceTexture(AutoTextureRelease&& consumer);
ANDROID_API void updateTexImage() { mUpdateTexImage = true; }
@@ -92,6 +97,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
@@ -101,7 +139,7 @@ private:
sk_sp<SkColorFilter> mColorFilter;
int mAlpha = 255;
SkBlendMode mMode = SkBlendMode::kSrcOver;
- sp<SurfaceTexture> mSurfaceTexture;
+ AutoTextureRelease mSurfaceTexture;
SkMatrix* mTransform;
bool mGLContextAttached;
bool mUpdateTexImage;