Flutter Engine
The Flutter Engine
SkShader.h
Go to the documentation of this file.
1/*
2 * Copyright 2006 The Android Open Source Project
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#ifndef SkShader_DEFINED
9#define SkShader_DEFINED
10
15
16class SkBlender;
17class SkColorFilter;
18class SkColorSpace;
19class SkImage;
20class SkMatrix;
21enum class SkBlendMode;
22enum class SkTileMode;
23struct SkRect;
25
26/** \class SkShader
27 *
28 * Shaders specify the source color(s) for what is being drawn. If a paint
29 * has no shader, then the paint's color is used. If the paint has a
30 * shader, then the shader's color(s) are use instead, but they are
31 * modulated by the paint's alpha. This makes it easy to create a shader
32 * once (e.g. bitmap tiling or gradient) and then change its transparency
33 * w/o having to modify the original shader... only the paint's alpha needs
34 * to be modified.
35 */
37public:
38 /**
39 * Returns true if the shader is guaranteed to produce only opaque
40 * colors, subject to the SkPaint using the shader to apply an opaque
41 * alpha value. Subclasses should override this to allow some
42 * optimizations.
43 */
44 virtual bool isOpaque() const { return false; }
45
46 /**
47 * Iff this shader is backed by a single SkImage, return its ptr (the caller must ref this
48 * if they want to keep it longer than the lifetime of the shader). If not, return nullptr.
49 */
50 SkImage* isAImage(SkMatrix* localMatrix, SkTileMode xy[2]) const;
51
52 bool isAImage() const {
53 return this->isAImage(nullptr, (SkTileMode*)nullptr) != nullptr;
54 }
55
56 //////////////////////////////////////////////////////////////////////////
57 // Methods to create combinations or variants of shaders
58
59 /**
60 * Return a shader that will apply the specified localMatrix to this shader.
61 * The specified matrix will be applied before any matrix associated with this shader.
62 */
63 sk_sp<SkShader> makeWithLocalMatrix(const SkMatrix&) const;
64
65 /**
66 * Create a new shader that produces the same colors as invoking this shader and then applying
67 * the colorfilter.
68 */
69 sk_sp<SkShader> makeWithColorFilter(sk_sp<SkColorFilter>) const;
70
71 /**
72 * Return a shader that will compute this shader in a specific color space.
73 * By default, all shaders operate in the destination (surface) color space.
74 * The results of a shader are still always converted to the destination - this
75 * API has no impact on simple shaders or images. Primarily, it impacts shaders
76 * that perform mathematical operations, like Blend shaders, or runtime shaders.
77 */
78 sk_sp<SkShader> makeWithWorkingColorSpace(sk_sp<SkColorSpace>) const;
79
80private:
81 SkShader() = default;
82 friend class SkShaderBase;
83
85};
86
87namespace SkShaders {
94
95/*
96 * Create an SkShader that will sample the 'image'. This is equivalent to SkImage::makeShader.
97 */
101 const SkMatrix* localMatrix = nullptr);
102/*
103 * Create an SkShader that will sample 'image' with minimal processing. This is equivalent to
104 * SkImage::makeRawShader.
105 */
109 const SkMatrix* localMatrix = nullptr);
110}
111
112#endif
const char * options
#define SK_API
Definition: SkAPI.h:35
SkBlendMode
Definition: SkBlendMode.h:38
uint32_t SkColor
Definition: SkColor.h:37
SkTileMode
Definition: SkTileMode.h:13
bool isAImage() const
Definition: SkShader.h:52
virtual bool isOpaque() const
Definition: SkShader.h:44
sk_sp< const SkImage > image
Definition: SkRecords.h:269
SK_API sk_sp< SkShader > Blend(SkBlendMode mode, sk_sp< SkShader > dst, sk_sp< SkShader > src)
SK_API sk_sp< SkShader > Color(SkColor)
SK_API sk_sp< SkShader > CoordClamp(sk_sp< SkShader >, const SkRect &subset)
SK_API sk_sp< SkShader > RawImage(sk_sp< SkImage > image, SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions &options, const SkMatrix *localMatrix=nullptr)
SK_API sk_sp< SkShader > Image(sk_sp< SkImage > image, SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions &options, const SkMatrix *localMatrix=nullptr)
SK_API sk_sp< SkShader > Empty()
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive mode
Definition: switches.h:228
dst
Definition: cp.py:12
SkTileMode tmy
SkTileMode tmx