Refactor SkImageFilter usage to cache results.

If an SkImageFilter is used, create an image
snapshot with the filter applied to avoid
re-computing it on each draw invocation

Bug: 188450217
Test: Re-ran CTS tests

Change-Id: Ib790669e14ada9d4ebbfac958d699e2b5242f2d7
diff --git a/libs/hwui/RenderNode.h b/libs/hwui/RenderNode.h
index 6a0b1aa..8595b6e 100644
--- a/libs/hwui/RenderNode.h
+++ b/libs/hwui/RenderNode.h
@@ -345,6 +345,16 @@
         return mSkiaLayer.get() ? mSkiaLayer->layerSurface.get() : nullptr;
     }
 
+    struct SnapshotResult {
+        sk_sp<SkImage> snapshot;
+        SkIRect outSubset;
+        SkIPoint outOffset;
+    };
+
+    std::optional<SnapshotResult> updateSnapshotIfRequired(GrRecordingContext* context,
+                                            const SkImageFilter* imageFilter,
+                                            const SkIRect& clipBounds);
+
     skiapipeline::SkiaLayer* getSkiaLayer() const { return mSkiaLayer.get(); }
 
     /**
@@ -375,6 +385,22 @@
      */
     std::unique_ptr<skiapipeline::SkiaLayer> mSkiaLayer;
 
+    /**
+     * SkImageFilter used to create the mSnapshotResult
+     */
+    sk_sp<SkImageFilter> mTargetImageFilter;
+
+    /**
+     * Clip bounds used to create the mSnapshotResult
+     */
+    SkIRect mImageFilterClipBounds;
+
+    /**
+     * Result of the most recent snapshot with additional metadata used to
+     * determine how to draw the contents
+     */
+    SnapshotResult mSnapshotResult;
+
     struct ClippedOutlineCache {
         // keys
         uint32_t outlineID = 0;