/src/skia/src/image/SkPictureImageGenerator.cpp
Line | Count | Source (jump to first uncovered line) |
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 "src/image/SkPictureImageGenerator.h" |
9 | | |
10 | | #include "include/core/SkAlphaType.h" |
11 | | #include "include/core/SkCanvas.h" |
12 | | #include "include/core/SkColorSpace.h" |
13 | | #include "include/core/SkColorType.h" |
14 | | #include "include/core/SkImage.h" |
15 | | #include "include/core/SkImageGenerator.h" |
16 | | #include "include/core/SkImageInfo.h" |
17 | | #include "include/core/SkMatrix.h" |
18 | | #include "include/core/SkPaint.h" |
19 | | #include "include/core/SkPicture.h" |
20 | | #include "include/core/SkSize.h" |
21 | | #include "src/base/SkTLazy.h" |
22 | | #include "src/image/SkImageGeneratorPriv.h" |
23 | | |
24 | | #include <memory> |
25 | | #include <utility> |
26 | | |
27 | | namespace SkImageGenerators { |
28 | | std::unique_ptr<SkImageGenerator> MakeFromPicture( |
29 | | const SkISize& size, |
30 | | sk_sp<SkPicture> picture, |
31 | | const SkMatrix* matrix, |
32 | | const SkPaint* paint, |
33 | | SkImages::BitDepth bitDepth, |
34 | 0 | sk_sp<SkColorSpace> colorSpace) { |
35 | 0 | return MakeFromPicture(size, picture, matrix, paint, bitDepth, colorSpace, {}); |
36 | 0 | } |
37 | | |
38 | | std::unique_ptr<SkImageGenerator> MakeFromPicture(const SkISize& size, |
39 | | sk_sp<SkPicture> picture, |
40 | | const SkMatrix* matrix, |
41 | | const SkPaint* paint, |
42 | | SkImages::BitDepth bitDepth, |
43 | | sk_sp<SkColorSpace> colorSpace, |
44 | 0 | SkSurfaceProps props) { |
45 | 0 | if (!picture || !colorSpace || size.isEmpty()) { |
46 | 0 | return nullptr; |
47 | 0 | } |
48 | | |
49 | 0 | SkColorType colorType = kN32_SkColorType; |
50 | 0 | if (SkImages::BitDepth::kF16 == bitDepth) { |
51 | 0 | colorType = kRGBA_F16_SkColorType; |
52 | 0 | } |
53 | |
|
54 | 0 | SkImageInfo info = |
55 | 0 | SkImageInfo::Make(size, colorType, kPremul_SkAlphaType, std::move(colorSpace)); |
56 | 0 | return std::unique_ptr<SkImageGenerator>( |
57 | 0 | new SkPictureImageGenerator(info, std::move(picture), matrix, paint, props)); |
58 | 0 | } |
59 | | } // SkImageGenerators |
60 | | |
61 | | /////////////////////////////////////////////////////////////////////////////////////////////////// |
62 | | |
63 | | SkPictureImageGenerator::SkPictureImageGenerator(const SkImageInfo& info, sk_sp<SkPicture> picture, |
64 | | const SkMatrix* matrix, const SkPaint* paint, |
65 | | const SkSurfaceProps& props) |
66 | | : SkImageGenerator(info) |
67 | | , fPicture(std::move(picture)) |
68 | 0 | , fProps(props) { |
69 | |
|
70 | 0 | if (matrix) { |
71 | 0 | fMatrix = *matrix; |
72 | 0 | } else { |
73 | 0 | fMatrix.reset(); |
74 | 0 | } |
75 | |
|
76 | 0 | if (paint) { |
77 | 0 | fPaint.set(*paint); |
78 | 0 | } |
79 | 0 | } |
80 | | |
81 | | bool SkPictureImageGenerator::onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, |
82 | 0 | const Options& opts) { |
83 | 0 | std::unique_ptr<SkCanvas> canvas = SkCanvas::MakeRasterDirect(info, pixels, rowBytes, &fProps); |
84 | 0 | if (!canvas) { |
85 | 0 | return false; |
86 | 0 | } |
87 | 0 | canvas->clear(0); |
88 | 0 | canvas->drawPicture(fPicture, &fMatrix, fPaint.getMaybeNull()); |
89 | 0 | return true; |
90 | 0 | } |