OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2015 Google Inc. |
| 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. |
| 6 */ |
| 7 |
| 8 #include "SkPictureImageGenerator.h" |
| 9 |
| 10 #include "SkCanvas.h" |
| 11 #include "SkMatrix.h" |
| 12 #include "SkPaint.h" |
| 13 #include "SkPicture.h" |
| 14 |
| 15 SkImageGenerator* SkPictureImageGenerator::create(const SkISize& size, const SkP
icture* picture, |
| 16 const SkMatrix* matrix, const SkPaint* paint) { |
| 17 if (!picture || size.isEmpty()) { |
| 18 return nullptr; |
| 19 } |
| 20 |
| 21 return SkNEW_ARGS(SkPictureImageGenerator, (size, picture, matrix, paint)); |
| 22 } |
| 23 |
| 24 SkPictureImageGenerator::SkPictureImageGenerator(const SkISize& size, const SkPi
cture* picture, |
| 25 const SkMatrix* matrix, const S
kPaint* paint) |
| 26 : INHERITED(SkImageInfo::MakeN32Premul(size)) |
| 27 , fInfo(SkImageInfo::MakeN32Premul(size)) |
| 28 , fPicture(SkRef(picture)) { |
| 29 SkASSERT(picture); |
| 30 |
| 31 if (matrix) { |
| 32 fMatrix.set(*matrix); |
| 33 } |
| 34 |
| 35 if (paint) { |
| 36 fPaint.set(*paint); |
| 37 } |
| 38 } |
| 39 |
| 40 bool SkPictureImageGenerator::onGetPixels(const SkImageInfo& info, void* pixels,
size_t rowBytes, |
| 41 SkPMColor ctable[], int* ctableCount)
{ |
| 42 if (info != fInfo || SkToBool(ctable) || SkToBool(ctableCount)) { |
| 43 return false; |
| 44 } |
| 45 |
| 46 SkBitmap bitmap; |
| 47 if (bitmap.installPixels(info, pixels, rowBytes)) { |
| 48 return false; |
| 49 } |
| 50 |
| 51 bitmap.eraseColor(SK_ColorTRANSPARENT); |
| 52 SkCanvas canvas(bitmap, SkSurfaceProps(0, kUnknown_SkPixelGeometry)); |
| 53 canvas.drawPicture(fPicture, fMatrix.getMaybeNull(), fPaint.getMaybeNull()); |
| 54 |
| 55 return true; |
| 56 } |
OLD | NEW |