Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkPictureImageGenerator.cpp
Go to the documentation of this file.
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
9
20#include "include/core/SkSize.h"
21#include "src/base/SkTLazy.h"
23
24#include <memory>
25#include <utility>
26
27namespace SkImageGenerators {
28std::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 sk_sp<SkColorSpace> colorSpace) {
35 return MakeFromPicture(size, picture, matrix, paint, bitDepth, colorSpace, {});
36}
37
38std::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 SkSurfaceProps props) {
45 if (!picture || !colorSpace || size.isEmpty()) {
46 return nullptr;
47 }
48
49 SkColorType colorType = kN32_SkColorType;
50 if (SkImages::BitDepth::kF16 == bitDepth) {
52 }
53
55 SkImageInfo::Make(size, colorType, kPremul_SkAlphaType, std::move(colorSpace));
56 return std::unique_ptr<SkImageGenerator>(
57 new SkPictureImageGenerator(info, std::move(picture), matrix, paint, props));
58}
59} // SkImageGenerators
60
61///////////////////////////////////////////////////////////////////////////////////////////////////
62
64 const SkMatrix* matrix, const SkPaint* paint,
65 const SkSurfaceProps& props)
67 , fPicture(std::move(picture))
68 , fProps(props) {
69
70 if (matrix) {
71 fMatrix = *matrix;
72 } else {
73 fMatrix.reset();
74 }
75
76 if (paint) {
77 fPaint.set(*paint);
78 }
79}
80
81bool SkPictureImageGenerator::onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes,
82 const Options& opts) {
83 std::unique_ptr<SkCanvas> canvas = SkCanvas::MakeRasterDirect(info, pixels, rowBytes, &fProps);
84 if (!canvas) {
85 return false;
86 }
87 canvas->clear(0);
88 canvas->drawPicture(fPicture, &fMatrix, fPaint.getMaybeNull());
89 return true;
90}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition SkAlphaType.h:29
SkColorType
Definition SkColorType.h:19
@ kRGBA_F16_SkColorType
pixel with half floats for red, green, blue, alpha;
Definition SkColorType.h:38
static SkColorType colorType(AImageDecoder *decoder, const AImageDecoderHeaderInfo *headerInfo)
static std::unique_ptr< SkCanvas > MakeRasterDirect(const SkImageInfo &info, void *pixels, size_t rowBytes, const SkSurfaceProps *props=nullptr)
SkMatrix & reset()
Definition SkMatrix.cpp:49
bool onGetPixels(const SkImageInfo &, void *pixels, size_t rowBytes, const Options &) override
SkPictureImageGenerator(const SkImageInfo &, sk_sp< SkPicture >, const SkMatrix *, const SkPaint *, const SkSurfaceProps &)
const T * getMaybeNull() const
Definition SkTLazy.h:108
T * set(const T &src)
Definition SkTLazy.h:56
const Paint & paint
std::unique_ptr< SkImageGenerator > MakeFromPicture(const SkISize &, sk_sp< SkPicture >, const SkMatrix *, const SkPaint *, SkImages::BitDepth, sk_sp< SkColorSpace >, SkSurfaceProps props)
@ kF16
uses 16-bit float per color component
Definition ref_ptr.h:256
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)