Add experimental API to draw a set of SkImages in one SkCanvas call.
The client provides a src and dst rect for each image as well as
a bitfield that indicates whether each edge of the image should be
antialiased. This per-edge AA is useful for tiled compositors.
Rather than take a full SkPaint this API only takes an alpha, a filter
quality (which is pinned to kLow), and a blend mode. This is a likely
point of future evolution.
Currently the API is only fully implemented for kSrcOver on the GPU
backend. With other blend modes or on other backends AA will be ignored
for images that do not have all four edge AA flags set.
BUG: skia:8444
Change-Id: I143998dda8ad6a25f64e18cd600392ba553030ac
Reviewed-on: https://skia-review.googlesource.com/c/159062
Commit-Queue: Brian Salomon <bsalomon@google.com>
Reviewed-by: Mike Klein <mtklein@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
diff --git a/tools/debugger/SkDebugCanvas.cpp b/tools/debugger/SkDebugCanvas.cpp
index 457dbbf..7dabbd3 100644
--- a/tools/debugger/SkDebugCanvas.cpp
+++ b/tools/debugger/SkDebugCanvas.cpp
@@ -357,6 +357,11 @@
this->addDrawCommand(new SkDrawImageNineCommand(image, center, dst, paint));
}
+void SkDebugCanvas::onDrawImageSet(const SkCanvas::ImageSetEntry set[], int count, float alpha,
+ SkFilterQuality filterQuality, SkBlendMode mode) {
+ this->addDrawCommand(new SkDrawImageSetCommand(set, count, alpha, filterQuality, mode));
+}
+
void SkDebugCanvas::onDrawOval(const SkRect& oval, const SkPaint& paint) {
this->addDrawCommand(new SkDrawOvalCommand(oval, paint));
}
diff --git a/tools/debugger/SkDebugCanvas.h b/tools/debugger/SkDebugCanvas.h
index 437aa97..2d5c800 100644
--- a/tools/debugger/SkDebugCanvas.h
+++ b/tools/debugger/SkDebugCanvas.h
@@ -158,6 +158,8 @@
const SkRect& dst, const SkPaint* paint) override;
void onDrawImageRect(const SkImage*, const SkRect* src, const SkRect& dst,
const SkPaint*, SrcRectConstraint) override;
+ void onDrawImageSet(const ImageSetEntry[], int count, float alpha, SkFilterQuality,
+ SkBlendMode) override;
void onDrawBitmapNine(const SkBitmap&, const SkIRect& center, const SkRect& dst,
const SkPaint*) override;
void onDrawImageNine(const SkImage*, const SkIRect& center, const SkRect& dst,
diff --git a/tools/debugger/SkDrawCommand.cpp b/tools/debugger/SkDrawCommand.cpp
index 27b34ef..6bdba38 100644
--- a/tools/debugger/SkDrawCommand.cpp
+++ b/tools/debugger/SkDrawCommand.cpp
@@ -7,12 +7,15 @@
#include "SkDrawCommand.h"
+#include <algorithm>
#include "SkAutoMalloc.h"
+#include "SkClipOpPriv.h"
#include "SkColorFilter.h"
#include "SkDashPathEffect.h"
#include "SkDrawable.h"
#include "SkImageFilter.h"
#include "SkJsonWriteBuffer.h"
+#include "SkLatticeIter.h"
#include "SkMaskFilterBase.h"
#include "SkPaintDefaults.h"
#include "SkPathEffect.h"
@@ -20,13 +23,11 @@
#include "SkPngEncoder.h"
#include "SkReadBuffer.h"
#include "SkRectPriv.h"
-#include "SkTextBlobPriv.h"
+#include "SkShadowFlags.h"
#include "SkTHash.h"
+#include "SkTextBlobPriv.h"
#include "SkTypeface.h"
#include "SkWriteBuffer.h"
-#include "SkClipOpPriv.h"
-#include <SkLatticeIter.h>
-#include <SkShadowFlags.h>
#define SKDEBUGCANVAS_ATTRIBUTE_COMMAND "command"
#define SKDEBUGCANVAS_ATTRIBUTE_VISIBLE "visible"
@@ -227,6 +228,7 @@
case kDrawImageLattice_OpType: return "DrawImageLattice";
case kDrawImageNine_OpType: return "DrawImageNine";
case kDrawImageRect_OpType: return "DrawImageRect";
+ case kDrawImageSet_OpType: return "DrawImageSet";
case kDrawOval_OpType: return "DrawOval";
case kDrawPaint_OpType: return "DrawPaint";
case kDrawPatch_OpType: return "DrawPatch";
@@ -1552,6 +1554,22 @@
return result;
}
+SkDrawImageSetCommand::SkDrawImageSetCommand(const SkCanvas::ImageSetEntry set[], int count,
+ float alpha, SkFilterQuality filterQuality,
+ SkBlendMode mode)
+ : INHERITED(kDrawImageSet_OpType)
+ , fSet(count)
+ , fCount(count)
+ , fAlpha(alpha)
+ , fFilterQuality(filterQuality)
+ , fMode(mode) {
+ std::copy_n(set, count, fSet.get());
+}
+
+void SkDrawImageSetCommand::execute(SkCanvas* canvas) const {
+ canvas->experimental_DrawImageSetV0(fSet.get(), fCount, fAlpha, fFilterQuality, fMode);
+}
+
SkDrawImageNineCommand::SkDrawImageNineCommand(const SkImage* image, const SkIRect& center,
const SkRect& dst, const SkPaint* paint)
: INHERITED(kDrawImageNine_OpType)
diff --git a/tools/debugger/SkDrawCommand.h b/tools/debugger/SkDrawCommand.h
index 2acc504..9a84e9a 100644
--- a/tools/debugger/SkDrawCommand.h
+++ b/tools/debugger/SkDrawCommand.h
@@ -43,6 +43,7 @@
kDrawImageLattice_OpType,
kDrawImageNine_OpType,
kDrawImageRect_OpType,
+ kDrawImageSet_OpType,
kDrawOval_OpType,
kDrawArc_OpType,
kDrawPaint_OpType,
@@ -363,6 +364,22 @@
typedef SkDrawCommand INHERITED;
};
+class SkDrawImageSetCommand : public SkDrawCommand {
+public:
+ SkDrawImageSetCommand(const SkCanvas::ImageSetEntry[], int count, float alpha, SkFilterQuality,
+ SkBlendMode);
+ void execute(SkCanvas* canvas) const override;
+
+private:
+ SkAutoTArray<SkCanvas::ImageSetEntry> fSet;
+ int fCount;
+ float fAlpha;
+ SkFilterQuality fFilterQuality;
+ SkBlendMode fMode;
+
+ typedef SkDrawCommand INHERITED;
+};
+
class SkDrawOvalCommand : public SkDrawCommand {
public:
SkDrawOvalCommand(const SkRect& oval, const SkPaint& paint);