Flutter Engine
The Flutter Engine
KeyContext.h
Go to the documentation of this file.
1/*
2 * Copyright 2022 Google LLC
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 skgpu_graphite_KeyContext_DEFINED
9#define skgpu_graphite_KeyContext_DEFINED
10
12#include "include/core/SkM44.h"
17
18namespace skgpu::graphite {
19
20class Caps;
21enum class DstReadRequirement;
22class Recorder;
23class RuntimeEffectDictionary;
24class ShaderCodeDictionary;
25
26// The key context must always be able to provide a valid ShaderCodeDictionary and
27// SkRuntimeEffectDictionary. Depending on the calling context it can also supply a
28// backend-specific resource providing object (e.g., a Recorder).
30public:
31 enum class OptimizeSampling : bool { kNo = false, kYes = true };
32 // Constructor for the pre-compile code path (i.e., no Recorder)
42 , fCaps(caps)
43 , fDstTexture(std::move(dstTexture))
44 , fDstOffset(dstOffset) {}
45
46 // Constructor for the ExtractPaintData code path (i.e., with a Recorder)
48 const SkM44& local2Dev,
51 const SkColor4f& paintColor,
54
55 KeyContext(const KeyContext&);
56
57 Recorder* recorder() const { return fRecorder; }
58
59 const Caps* caps() const { return fCaps; }
60
61 const SkM44& local2Dev() const { return fLocal2Dev; }
62 const SkMatrix* localMatrix() const { return fLocalMatrix; }
63
66
67 const SkColorInfo& dstColorInfo() const { return fDstColorInfo; }
68
69 // Proxy to the destination texture, if it needs to be read from, or null otherwise.
70 sk_sp<TextureProxy> dstTexture() const { return fDstTexture; }
71 // Offset within dstTexture to the top-left corner of the area that needs to be read.
72 SkIPoint dstOffset() const { return fDstOffset; }
73
74 const SkPMColor4f& paintColor() const { return fPaintColor; }
75
76 enum class Scope {
78 kRuntimeEffect,
79 };
80
81 Scope scope() const { return fScope; }
83
84protected:
85 Recorder* fRecorder = nullptr;
91 // Although stored as premul the paint color is actually comprised of an opaque RGB portion
92 // and a separate alpha portion. The two portions will never be used together but are stored
93 // together to reduce the number of uniforms.
97
98private:
99 const Caps* fCaps = nullptr;
100 sk_sp<TextureProxy> fDstTexture;
101 SkIPoint fDstOffset;
102};
103
105public:
106 KeyContextWithLocalMatrix(const KeyContext& other, const SkMatrix& childLM)
107 : KeyContext(other) {
108 if (fLocalMatrix) {
109 fStorage = SkMatrix::Concat(childLM, *fLocalMatrix);
110 } else {
111 fStorage = childLM;
112 }
113
114 fLocalMatrix = &fStorage;
115 }
116
117private:
119 KeyContextWithLocalMatrix& operator=(const KeyContextWithLocalMatrix&) = delete;
120
121 SkMatrix fStorage;
122};
123
125public:
127 // We want to keep fPaintColor's alpha value but replace the RGB with values in the new
128 // color space
130 tmp.fA = 1.0f;
132 fPaintColor.fR = tmp.fR;
133 fPaintColor.fG = tmp.fG;
134 fPaintColor.fB = tmp.fB;
136 }
137
138private:
140 KeyContextWithColorInfo& operator=(const KeyContextWithColorInfo&) = delete;
141};
142
144public:
146 fScope = scope;
147 // We skip optimized sampling for runtime effects because these might have arbitrary
148 // coordinate sampling.
151 }
152 }
153
154private:
156 KeyContextWithScope& operator=(const KeyContextWithScope&) = delete;
157};
158
160public:
162 // Subtlies in clampling implmentation can lead to texture samples at non pixel aligned
163 // coordinates.
165 }
166
167private:
169 KeyContextWithCoordClamp& operator=(const KeyContextWithScope&) = delete;
170};
171
172} // namespace skgpu::graphite
173
174#endif // skgpu_graphite_KeyContext_DEFINED
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
constexpr SkPMColor4f SK_PMColor4fBLACK
Definition: SkColorData.h:379
@ kYes
Do pre-clip the geometry before applying the (perspective) matrix.
@ kNo
Don't pre-clip the geometry before applying the (perspective) matrix.
Definition: SkM44.h:150
static SkMatrix Concat(const SkMatrix &a, const SkMatrix &b)
Definition: SkMatrix.h:1775
KeyContextWithColorInfo(const KeyContext &other, const SkColorInfo &info)
Definition: KeyContext.h:126
KeyContextWithCoordClamp(const KeyContext &other)
Definition: KeyContext.h:161
KeyContextWithLocalMatrix(const KeyContext &other, const SkMatrix &childLM)
Definition: KeyContext.h:106
KeyContextWithScope(const KeyContext &other, KeyContext::Scope scope)
Definition: KeyContext.h:145
const SkM44 & local2Dev() const
Definition: KeyContext.h:61
RuntimeEffectDictionary * rtEffectDict() const
Definition: KeyContext.h:65
SkIPoint dstOffset() const
Definition: KeyContext.h:72
Recorder * recorder() const
Definition: KeyContext.h:57
RuntimeEffectDictionary * fRTEffectDict
Definition: KeyContext.h:89
const SkMatrix * localMatrix() const
Definition: KeyContext.h:62
const SkPMColor4f & paintColor() const
Definition: KeyContext.h:74
OptimizeSampling optimizeSampling() const
Definition: KeyContext.h:82
KeyContext(const Caps *caps, ShaderCodeDictionary *dict, RuntimeEffectDictionary *rtEffectDict, const SkColorInfo &dstColorInfo, sk_sp< TextureProxy > dstTexture, SkIPoint dstOffset)
Definition: KeyContext.h:33
sk_sp< TextureProxy > dstTexture() const
Definition: KeyContext.h:70
const SkColorInfo & dstColorInfo() const
Definition: KeyContext.h:67
ShaderCodeDictionary * fDictionary
Definition: KeyContext.h:88
OptimizeSampling fOptimizeSampling
Definition: KeyContext.h:96
ShaderCodeDictionary * dict() const
Definition: KeyContext.h:64
const Caps * caps() const
Definition: KeyContext.h:59
@ kDefault
DstReadRequirement
Definition: Caps.h:64
Definition: ref_ptr.h:256
void apply(float rgba[4]) const
const float * vec() const
Definition: SkColor.h:308
float fB
blue component
Definition: SkColor.h:265
float fR
red component
Definition: SkColor.h:263
float fG
green component
Definition: SkColor.h:264
float fA
alpha component
Definition: SkColor.h:266