Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Unified Diff: tools/PictureRenderer.cpp

Issue 1181633005: Convert PictureRenderer to SkPaintFilterCanvas (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: missing 'override' Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/PictureRenderer.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/PictureRenderer.cpp
diff --git a/tools/PictureRenderer.cpp b/tools/PictureRenderer.cpp
index 0875c5ab65c31aba3ef21f1c8228d07f1b3178b2..270b61fd2832624aa146e5f116caf614d71521c3 100644
--- a/tools/PictureRenderer.cpp
+++ b/tools/PictureRenderer.cpp
@@ -24,6 +24,7 @@
#include "SkMatrix.h"
#include "SkMultiPictureDraw.h"
#include "SkOSFile.h"
+#include "SkPaintFilterCanvas.h"
#include "SkPicture.h"
#include "SkPictureRecorder.h"
#include "SkPictureUtils.h"
@@ -87,12 +88,16 @@ void PictureRenderer::CopyString(SkString* dest, const SkString* src) {
}
}
-class FlagsDrawFilter : public SkDrawFilter {
+class FlagsFilterCanvas : public SkPaintFilterCanvas {
public:
- FlagsDrawFilter(PictureRenderer::DrawFilterFlags* flags) :
- fFlags(flags) {}
+ FlagsFilterCanvas(SkCanvas* canvas, PictureRenderer::DrawFilterFlags* flags)
+ : INHERITED(canvas->imageInfo().width(), canvas->imageInfo().height())
+ , fFlags(flags) {
+ this->addCanvas(canvas);
+ }
- virtual bool filter(SkPaint* paint, Type t) {
+protected:
+ void onFilterPaint(SkPaint* paint, Type t) const override {
paint->setFlags(paint->getFlags() & ~fFlags[t] & SkPaint::kAllFlags);
if (PictureRenderer::kMaskFilter_DrawFilterFlag & fFlags[t]) {
SkMaskFilter* maskFilter = paint->getMaskFilter();
@@ -105,21 +110,13 @@ public:
} else if (PictureRenderer::kSlightHinting_DrawFilterFlag & fFlags[t]) {
paint->setHinting(SkPaint::kSlight_Hinting);
}
- return true;
}
private:
- PictureRenderer::DrawFilterFlags* fFlags;
-};
+ const PictureRenderer::DrawFilterFlags* fFlags;
-static void setUpFilter(SkCanvas* canvas, PictureRenderer::DrawFilterFlags* drawFilters) {
- if (drawFilters && !canvas->getDrawFilter()) {
- canvas->setDrawFilter(SkNEW_ARGS(FlagsDrawFilter, (drawFilters)))->unref();
- if (drawFilters[0] & PictureRenderer::kAAClip_DrawFilterFlag) {
- canvas->setAllowSoftClip(false);
- }
- }
-}
+ typedef SkPaintFilterCanvas INHERITED;
+};
SkCanvas* PictureRenderer::setupCanvas() {
const int width = this->getViewWidth();
@@ -128,12 +125,13 @@ SkCanvas* PictureRenderer::setupCanvas() {
}
SkCanvas* PictureRenderer::setupCanvas(int width, int height) {
- SkCanvas* canvas;
+ SkAutoTUnref<SkCanvas> canvas;
+
switch(fDeviceType) {
case kBitmap_DeviceType: {
SkBitmap bitmap;
sk_tools::setup_bitmap(&bitmap, width, height);
- canvas = SkNEW_ARGS(SkCanvas, (bitmap));
+ canvas.reset(SkNEW_ARGS(SkCanvas, (bitmap)));
}
break;
#if SK_SUPPORT_GPU
@@ -165,7 +163,7 @@ SkCanvas* PictureRenderer::setupCanvas(int width, int height) {
if (!device) {
return NULL;
}
- canvas = SkNEW_ARGS(SkCanvas, (device));
+ canvas.reset(SkNEW_ARGS(SkCanvas, (device)));
break;
}
#endif
@@ -173,14 +171,22 @@ SkCanvas* PictureRenderer::setupCanvas(int width, int height) {
SkASSERT(0);
return NULL;
}
- setUpFilter(canvas, fDrawFilters);
+
+ if (fHasDrawFilters) {
+ if (fDrawFilters[0] & PictureRenderer::kAAClip_DrawFilterFlag) {
+ canvas->setAllowSoftClip(false);
+ }
+
+ canvas.reset(SkNEW_ARGS(FlagsFilterCanvas, (canvas.get(), fDrawFilters)));
+ }
+
this->scaleToScaleFactor(canvas);
// Pictures often lie about their extent (i.e., claim to be 100x100 but
// only ever draw to 90x100). Clear here so the undrawn portion will have
// a consistent color
canvas->clear(SK_ColorTRANSPARENT);
- return canvas;
+ return canvas.detach();
}
void PictureRenderer::scaleToScaleFactor(SkCanvas* canvas) {
« no previous file with comments | « tools/PictureRenderer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698