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

Unified Diff: src/effects/SkPictureSource.cpp

Issue 114263002: Implement an SkPicture image filter source. This is required for the external-SVG reference feature… (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years 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
« include/effects/SkPictureSource.h ('K') | « include/effects/SkPictureSource.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/effects/SkPictureSource.cpp
diff --git a/src/effects/SkPictureSource.cpp b/src/effects/SkPictureSource.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..d4b312597375f80a50a6f62954eaa431f424040f
--- /dev/null
+++ b/src/effects/SkPictureSource.cpp
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2013 The Android Open Source Project
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "SkPictureSource.h"
+#include "SkDevice.h"
+#include "SkCanvas.h"
+#include "SkFlattenableBuffers.h"
+#include "SkValidationUtils.h"
+
+SkPictureSource::SkPictureSource(const SkPicture& picture)
+ : INHERITED(0, 0),
+ fPicture(picture),
+ fRect(SkRect::MakeWH(picture.width(), picture.height())) {
+}
+
+SkPictureSource::SkPictureSource(const SkPicture& picture, const SkRect& rect)
+ : INHERITED(0, 0),
+ fPicture(picture),
+ fRect(rect) {
+}
+
+SkPictureSource::SkPictureSource(SkFlattenableReadBuffer& buffer)
+ : INHERITED(0, buffer) {
+ // FIXME: unflatten picture here.
+ buffer.readRect(&fRect);
+}
+
+void SkPictureSource::flatten(SkFlattenableWriteBuffer& buffer) const {
+ this->INHERITED::flatten(buffer);
+ // FIXME: flatten picture here.
+ buffer.writeRect(fRect);
+}
+
+bool SkPictureSource::onFilterImage(Proxy* proxy, const SkBitmap&, const SkMatrix& matrix,
+ SkBitmap* result, SkIPoint* offset) {
+ SkRect floatBounds;
+ SkIRect bounds;
+ matrix.mapRect(&floatBounds, fRect);
+ floatBounds.roundOut(&bounds);
+
+ if (bounds.isEmpty()) {
+ return true;
+ }
+
+ SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(bounds.width(), bounds.height()));
+ if (NULL == device.get()) {
+ return false;
+ }
+
+ SkCanvas canvas(device.get());
+ SkPaint paint;
+
+ canvas.translate(-bounds.fLeft, -bounds.fTop);
+ canvas.concat(matrix);
+ canvas.drawPicture(fPicture);
+
+ *result = device.get()->accessBitmap(false);
+ offset->fX += bounds.fLeft;
+ offset->fY += bounds.fTop;
+ return true;
+}
« include/effects/SkPictureSource.h ('K') | « include/effects/SkPictureSource.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698