aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorDerek Sollenberger <djsollen@google.com>2019-04-04 11:49:14 -0400
committerMichele Bono <bono.michele94@gmail.com>2019-08-07 16:13:50 +0200
commit55c3d512b95a8b515b7a6a8542da8c0f28270b2e (patch)
treea6098e8aaafb8daeed174c4c9c784c5cb26e6689 /include
parent1f50aa929088085c6a4fa1c6de435193cbde9ee2 (diff)
Add private save-behind and draw-behind methods to canvas.HEADp9.0
The draw-behind is a variant of drawPaint but is automatically clipped to the bounds of the most recent saveBehind buffer (axis-aligned bounds). No public exposure outside of the Android framework. Impl is pretty simple (its a variant of drawPaint) - find the most recent saveBehind device bounds - if there is none, draw nothing, else - temporarily intersect the device's clip with that bounds - drawPaint - restore the clip This patches did not apply cleanly and have been updated to compile with a previous version of Skia. It was cherry-picked from the following 3 Skia commits: 148b7fd3ad9c29dec0052de624c26ff291ef8f0a d567408362bf7847d6000f6786f9a7b2c9d0b88b 9adc82c73df0ef25b708cae8aa48ef9c39ed4c67 Bug: 129117085 Test: None Change-Id: I291f57885de6e95f749bf5cdb70ac16a5781ffb1
Diffstat (limited to 'include')
-rw-r--r--include/android/SkAndroidFrameworkUtils.h3
-rw-r--r--include/core/SkCanvas.h23
-rw-r--r--include/core/SkOverdrawCanvas.h1
-rw-r--r--include/core/SkPicture.h3
-rw-r--r--include/core/SkRect.h3
-rw-r--r--include/utils/SkLuaCanvas.h1
-rw-r--r--include/utils/SkNWayCanvas.h2
-rw-r--r--include/utils/SkNoDrawCanvas.h2
-rw-r--r--include/utils/SkPaintFilterCanvas.h1
9 files changed, 37 insertions, 2 deletions
diff --git a/include/android/SkAndroidFrameworkUtils.h b/include/android/SkAndroidFrameworkUtils.h
index 46d251626e..c2bf2b2bde 100644
--- a/include/android/SkAndroidFrameworkUtils.h
+++ b/include/android/SkAndroidFrameworkUtils.h
@@ -9,6 +9,7 @@
#define SkAndroidFrameworkUtils_DEFINED
#include "SkTypes.h"
+#include "SkRect.h"
#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
@@ -32,6 +33,8 @@ public:
static bool clipWithStencil(SkCanvas* canvas);
#endif //SK_SUPPORT_GPU
+ static int SaveBehind(SkCanvas* canvas, const SkRect* subset);
+
static void SafetyNetLog(const char*);
};
diff --git a/include/core/SkCanvas.h b/include/core/SkCanvas.h
index 2f83b66fdd..51c285fc08 100644
--- a/include/core/SkCanvas.h
+++ b/include/core/SkCanvas.h
@@ -739,7 +739,7 @@ public:
Call restoreToCount() with returned value to restore this and subsequent saves.
@param layerRec layer state
- @return depth of save state stack
+ @return depth of save state stack before this call was made.
*/
int saveLayer(const SaveLayerRec& layerRec);
@@ -2484,6 +2484,8 @@ protected:
virtual SaveLayerStrategy getSaveLayerStrategy(const SaveLayerRec& ) {
return kFullLayer_SaveLayerStrategy;
}
+ // returns true if we should actually perform the saveBehind, or false if we should just save.
+ virtual bool onDoSaveBehind(const SkRect*) { return true; }
virtual void willRestore() {}
virtual void didRestore() {}
virtual void didConcat(const SkMatrix& ) {}
@@ -2520,6 +2522,7 @@ protected:
virtual void onDrawDrawable(SkDrawable* drawable, const SkMatrix* matrix);
virtual void onDrawPaint(const SkPaint& paint);
+ virtual void onDrawBehind(const SkPaint& paint);
virtual void onDrawRect(const SkRect& rect, const SkPaint& paint);
virtual void onDrawRegion(const SkRegion& region, const SkPaint& paint);
virtual void onDrawOval(const SkRect& rect, const SkPaint& paint);
@@ -2674,6 +2677,7 @@ private:
void internalSetMatrix(const SkMatrix&);
friend class SkAndroidFrameworkUtils;
+ friend class SkCanvasPriv;
friend class SkDrawIter; // needs setupDrawForLayerDevice()
friend class AutoDrawLooper;
friend class SkDebugCanvas; // needs experimental fAllowSimplifyClip
@@ -2694,6 +2698,22 @@ private:
SkCanvas(const SkBitmap&, std::unique_ptr<SkRasterHandleAllocator>,
SkRasterHandleAllocator::Handle);
+ /** Experimental
+ * Saves the specified subset of the current pixels in the current layer,
+ * and then clears those pixels to transparent black.
+ * Restores the pixels on restore() by drawing them in SkBlendMode::kDstOver.
+ *
+ * @param subset conservative bounds of the area to be saved / restored.
+ * @return depth of save state stack before this call was made.
+ */
+ int only_axis_aligned_saveBehind(const SkRect* subset);
+
+ /**
+ * Like drawPaint, but magically clipped to the most recent saveBehind buffer rectangle.
+ * If there is no active saveBehind, then this draws nothing.
+ */
+ void drawClippedToSaveBehind(const SkPaint&);
+
void resetForNextPicture(const SkIRect& bounds);
// needs gettotalclip()
@@ -2717,6 +2737,7 @@ private:
SrcRectConstraint);
void internalDrawPaint(const SkPaint& paint);
void internalSaveLayer(const SaveLayerRec&, SaveLayerStrategy);
+ void internalSaveBehind(const SkRect*);
void internalDrawDevice(SkBaseDevice*, int x, int y, const SkPaint*, SkImage* clipImage,
const SkMatrix& clipMatrix);
diff --git a/include/core/SkOverdrawCanvas.h b/include/core/SkOverdrawCanvas.h
index 284fe6cd97..eda33ddf41 100644
--- a/include/core/SkOverdrawCanvas.h
+++ b/include/core/SkOverdrawCanvas.h
@@ -31,6 +31,7 @@ public:
void onDrawPatch(const SkPoint[12], const SkColor[4], const SkPoint[4], SkBlendMode,
const SkPaint&) override;
void onDrawPaint(const SkPaint&) override;
+ void onDrawBehind(const SkPaint& paint) override;
void onDrawRect(const SkRect&, const SkPaint&) override;
void onDrawRegion(const SkRegion&, const SkPaint&) override;
void onDrawOval(const SkRect&, const SkPaint&) override;
diff --git a/include/core/SkPicture.h b/include/core/SkPicture.h
index b2beb56b86..9452feeda9 100644
--- a/include/core/SkPicture.h
+++ b/include/core/SkPicture.h
@@ -168,10 +168,11 @@ private:
// V59: No more LocalSpace option on PictureImageFilter
// V60: Remove flags in picture header
// V61: Change SkDrawPictureRec to take two colors rather than two alphas
+ // V62: Add saveBehind
// Only SKPs within the min/current picture version range (inclusive) can be read.
static const uint32_t MIN_PICTURE_VERSION = 56; // august 2017
- static const uint32_t CURRENT_PICTURE_VERSION = 61;
+ static const uint32_t CURRENT_PICTURE_VERSION = 62;
static bool IsValidPictInfo(const SkPictInfo& info);
static sk_sp<SkPicture> Forwardport(const SkPictInfo&,
diff --git a/include/core/SkRect.h b/include/core/SkRect.h
index f9a5bff4ff..dd66d75076 100644
--- a/include/core/SkRect.h
+++ b/include/core/SkRect.h
@@ -154,6 +154,9 @@ struct SK_API SkIRect {
*/
int32_t y() const { return fTop; }
+ // Experimental
+ SkIPoint topLeft() const { return {fLeft, fTop}; }
+
/** Returns span on the x-axis. This does not check if SkIRect is sorted, or if
result fits in 32-bit signed integer; result may be negative.
diff --git a/include/utils/SkLuaCanvas.h b/include/utils/SkLuaCanvas.h
index 2fef2c0785..fc2e73d827 100644
--- a/include/utils/SkLuaCanvas.h
+++ b/include/utils/SkLuaCanvas.h
@@ -24,6 +24,7 @@ public:
protected:
void willSave() override;
SaveLayerStrategy getSaveLayerStrategy(const SaveLayerRec&) override;
+ bool onDoSaveBehind(const SkRect*) override;
void willRestore() override;
void didConcat(const SkMatrix&) override;
diff --git a/include/utils/SkNWayCanvas.h b/include/utils/SkNWayCanvas.h
index a3e567ef89..57bd6de1eb 100644
--- a/include/utils/SkNWayCanvas.h
+++ b/include/utils/SkNWayCanvas.h
@@ -33,6 +33,7 @@ protected:
void willSave() override;
SaveLayerStrategy getSaveLayerStrategy(const SaveLayerRec&) override;
+ bool onDoSaveBehind(const SkRect*) override;
void willRestore() override;
void didConcat(const SkMatrix&) override;
@@ -56,6 +57,7 @@ protected:
const SkPaint& paint) override;
void onDrawPaint(const SkPaint&) override;
+ void onDrawBehind(const SkPaint&) override;
void onDrawPoints(PointMode, size_t count, const SkPoint pts[], const SkPaint&) override;
void onDrawRect(const SkRect&, const SkPaint&) override;
void onDrawOval(const SkRect&, const SkPaint&) override;
diff --git a/include/utils/SkNoDrawCanvas.h b/include/utils/SkNoDrawCanvas.h
index 7b3eaf6b18..65d7403194 100644
--- a/include/utils/SkNoDrawCanvas.h
+++ b/include/utils/SkNoDrawCanvas.h
@@ -35,6 +35,7 @@ public:
protected:
SaveLayerStrategy getSaveLayerStrategy(const SaveLayerRec& rec) override;
+ bool onDoSaveBehind(const SkRect*) override;
// No-op overrides for aborting rasterization earlier than SkNullBlitter.
void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) override {}
@@ -51,6 +52,7 @@ protected:
const SkPaint&) override {}
void onDrawPaint(const SkPaint&) override {}
+ void onDrawBehind(const SkPaint&) override {}
void onDrawPoints(PointMode, size_t, const SkPoint[], const SkPaint&) override {}
void onDrawRect(const SkRect&, const SkPaint&) override {}
void onDrawRegion(const SkRegion&, const SkPaint&) override {}
diff --git a/include/utils/SkPaintFilterCanvas.h b/include/utils/SkPaintFilterCanvas.h
index d6689b91bc..4cf29dbd18 100644
--- a/include/utils/SkPaintFilterCanvas.h
+++ b/include/utils/SkPaintFilterCanvas.h
@@ -65,6 +65,7 @@ protected:
virtual bool onFilter(SkTCopyOnFirstWrite<SkPaint>* paint, Type type) const = 0;
void onDrawPaint(const SkPaint&) override;
+ void onDrawBehind(const SkPaint&) override;
void onDrawPoints(PointMode, size_t count, const SkPoint pts[], const SkPaint&) override;
void onDrawRect(const SkRect&, const SkPaint&) override;
void onDrawRRect(const SkRRect&, const SkPaint&) override;