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

Side by Side Diff: src/core/SkPictureImageGenerator.cpp

Issue 1240093004: SkPictureImageGenerator (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: build fix Created 5 years, 4 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 unified diff | Download patch
« no previous file with comments | « include/core/SkImageGenerator.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 "SkImageGenerator.h"
9
10 #include "SkCanvas.h"
11 #include "SkMatrix.h"
12 #include "SkPaint.h"
13 #include "SkPicture.h"
14
15 class SkPictureImageGenerator : SkImageGenerator {
16 public:
17 static SkImageGenerator* Create(const SkISize&, const SkPicture*, const SkMa trix*,
18 const SkPaint*);
19
20 protected:
21 bool onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, SkP MColor ctable[],
22 int* ctableCount) override;
23
24 private:
25 SkPictureImageGenerator(const SkISize&, const SkPicture*, const SkMatrix*, c onst SkPaint*);
26
27 SkAutoTUnref<const SkPicture> fPicture;
28 SkMatrix fMatrix;
29 SkTLazy<SkPaint> fPaint;
30
31 typedef SkImageGenerator INHERITED;
32 };
33
34 SkImageGenerator* SkPictureImageGenerator::Create(const SkISize& size, const SkP icture* picture,
35 const SkMatrix* matrix, const SkPaint* paint) {
36 if (!picture || size.isEmpty()) {
37 return nullptr;
38 }
39
40 return SkNEW_ARGS(SkPictureImageGenerator, (size, picture, matrix, paint));
41 }
42
43 SkPictureImageGenerator::SkPictureImageGenerator(const SkISize& size, const SkPi cture* picture,
44 const SkMatrix* matrix, const S kPaint* paint)
45 : INHERITED(SkImageInfo::MakeN32Premul(size))
46 , fPicture(SkRef(picture)) {
47
48 if (matrix) {
49 fMatrix = *matrix;
50 } else {
51 fMatrix.reset();
52 }
53
54 if (paint) {
55 fPaint.set(*paint);
56 }
57 }
58
59 bool SkPictureImageGenerator::onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes,
60 SkPMColor ctable[], int* ctableCount) {
61 if (info != getInfo() || ctable || ctableCount) {
62 return false;
63 }
64
65 SkBitmap bitmap;
66 if (!bitmap.installPixels(info, pixels, rowBytes)) {
67 return false;
68 }
69
70 bitmap.eraseColor(SK_ColorTRANSPARENT);
71 SkCanvas canvas(bitmap, SkSurfaceProps(0, kUnknown_SkPixelGeometry));
72 canvas.drawPicture(fPicture, &fMatrix, fPaint.getMaybeNull());
73
74 return true;
75 }
76
77 SkImageGenerator* SkImageGenerator::NewFromPicture(const SkISize& size, const Sk Picture* picture,
78 const SkMatrix* matrix, const SkPaint* paint) {
79 return SkPictureImageGenerator::Create(size, picture, matrix, paint);
80 }
OLDNEW
« no previous file with comments | « include/core/SkImageGenerator.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698