Index: src/core/SkPictureImageGenerator.cpp |
diff --git a/src/core/SkPictureImageGenerator.cpp b/src/core/SkPictureImageGenerator.cpp |
new file mode 100644 |
index 0000000000000000000000000000000000000000..8d60c0afc5b3b4e2e79dd4130e92402dc6f34b65 |
--- /dev/null |
+++ b/src/core/SkPictureImageGenerator.cpp |
@@ -0,0 +1,56 @@ |
+/* |
+ * 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 "SkPictureImageGenerator.h" |
+ |
+#include "SkCanvas.h" |
+#include "SkMatrix.h" |
+#include "SkPaint.h" |
+#include "SkPicture.h" |
+ |
+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)) |
+ , fInfo(SkImageInfo::MakeN32Premul(size)) |
+ , fPicture(SkRef(picture)) { |
+ SkASSERT(picture); |
+ |
+ if (matrix) { |
+ fMatrix.set(*matrix); |
+ } |
+ |
+ if (paint) { |
+ fPaint.set(*paint); |
+ } |
+} |
+ |
+bool SkPictureImageGenerator::onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, |
+ SkPMColor ctable[], int* ctableCount) { |
+ if (info != fInfo || SkToBool(ctable) || SkToBool(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.getMaybeNull(), fPaint.getMaybeNull()); |
+ |
+ return true; |
+} |