aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkPictureImageGenerator.cpp
diff options
context:
space:
mode:
authorGravatar fmalita <fmalita@chromium.org>2015-08-04 13:53:14 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-08-04 13:53:14 -0700
commit1dedc3d2c00468d9b4d0f0a8e69cb56acd08698f (patch)
treefa8c7a5cdced8f543c45d67635064c46af4360f6 /src/core/SkPictureImageGenerator.cpp
parent8caa5af92cf91debc1598380cb72c330e8c63efb (diff)
SkPictureImageGenerator
R=reed@google.com Review URL: https://codereview.chromium.org/1240093004
Diffstat (limited to 'src/core/SkPictureImageGenerator.cpp')
-rw-r--r--src/core/SkPictureImageGenerator.cpp80
1 files changed, 80 insertions, 0 deletions
diff --git a/src/core/SkPictureImageGenerator.cpp b/src/core/SkPictureImageGenerator.cpp
new file mode 100644
index 0000000000..0dea60dfd9
--- /dev/null
+++ b/src/core/SkPictureImageGenerator.cpp
@@ -0,0 +1,80 @@
+/*
+ * Copyright 2015 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "SkImageGenerator.h"
+
+#include "SkCanvas.h"
+#include "SkMatrix.h"
+#include "SkPaint.h"
+#include "SkPicture.h"
+
+class SkPictureImageGenerator : SkImageGenerator {
+public:
+ static SkImageGenerator* Create(const SkISize&, const SkPicture*, const SkMatrix*,
+ const SkPaint*);
+
+protected:
+ bool onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, SkPMColor ctable[],
+ int* ctableCount) override;
+
+private:
+ SkPictureImageGenerator(const SkISize&, const SkPicture*, const SkMatrix*, const SkPaint*);
+
+ SkAutoTUnref<const SkPicture> fPicture;
+ SkMatrix fMatrix;
+ SkTLazy<SkPaint> fPaint;
+
+ typedef SkImageGenerator INHERITED;
+};
+
+SkImageGenerator* SkPictureImageGenerator::Create(const SkISize& size, const SkPicture* picture,
+ const SkMatrix* matrix, const SkPaint* paint) {
+ if (!picture || size.isEmpty()) {
+ return nullptr;
+ }
+
+ return SkNEW_ARGS(SkPictureImageGenerator, (size, picture, matrix, paint));
+}
+
+SkPictureImageGenerator::SkPictureImageGenerator(const SkISize& size, const SkPicture* picture,
+ const SkMatrix* matrix, const SkPaint* paint)
+ : INHERITED(SkImageInfo::MakeN32Premul(size))
+ , fPicture(SkRef(picture)) {
+
+ if (matrix) {
+ fMatrix = *matrix;
+ } else {
+ fMatrix.reset();
+ }
+
+ if (paint) {
+ fPaint.set(*paint);
+ }
+}
+
+bool SkPictureImageGenerator::onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes,
+ SkPMColor ctable[], int* ctableCount) {
+ if (info != getInfo() || ctable || ctableCount) {
+ return false;
+ }
+
+ SkBitmap bitmap;
+ if (!bitmap.installPixels(info, pixels, rowBytes)) {
+ return false;
+ }
+
+ bitmap.eraseColor(SK_ColorTRANSPARENT);
+ SkCanvas canvas(bitmap, SkSurfaceProps(0, kUnknown_SkPixelGeometry));
+ canvas.drawPicture(fPicture, &fMatrix, fPaint.getMaybeNull());
+
+ return true;
+}
+
+SkImageGenerator* SkImageGenerator::NewFromPicture(const SkISize& size, const SkPicture* picture,
+ const SkMatrix* matrix, const SkPaint* paint) {
+ return SkPictureImageGenerator::Create(size, picture, matrix, paint);
+}