Flutter Engine
The Flutter Engine
SkGr.h
Go to the documentation of this file.
1/*
2 * Copyright 2017 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#ifndef SkGr_DEFINED
9#define SkGr_DEFINED
10
20#include "src/gpu/Blend.h"
24
25#include <cstdint>
26#include <memory>
27#include <string_view>
28#include <tuple>
29
30class GrColorInfo;
32class GrPaint;
34class GrSurfaceProxy;
36class SkBitmap;
37class SkBlender;
39class SkMatrix;
40class SkPaint;
41class SkSurfaceProps;
42enum class GrColorType;
43enum GrSurfaceOrigin : int;
44struct SkIRect;
45
46namespace skgpu { class UniqueKey; }
47
48////////////////////////////////////////////////////////////////////////////////
49// Color type conversions
50
53 unsigned r = SkGetPackedR32(pm);
54 unsigned g = SkGetPackedG32(pm);
55 unsigned b = SkGetPackedB32(pm);
56 unsigned a = SkGetPackedA32(pm);
57 return GrColorPackRGBA(r, g, b, a);
58}
59
61 unsigned r = SkColorGetR(c);
62 unsigned g = SkColorGetG(c);
63 unsigned b = SkColorGetB(c);
64 unsigned a = SkColorGetA(c);
65 return GrColorPackRGBA(r, g, b, a);
66}
67
68/** Similar, but using SkPMColor4f. */
70
71/** Converts an SkColor4f to the destination color space. */
73
74////////////////////////////////////////////////////////////////////////////////
75// SkTileMode conversion
76
78 switch (tileMode) {
83 }
85}
86
87////////////////////////////////////////////////////////////////////////////////
88// Paint conversion
89
90/** Converts an SkPaint to a GrPaint for a given GrRecordingContext. The matrix is required in order
91 to convert the SkShader (if any) on the SkPaint. The primitive itself has no color. */
93 const GrColorInfo& dstColorInfo,
94 const SkPaint& skPaint,
95 const SkMatrix& ctm,
96 const SkSurfaceProps& surfaceProps,
97 GrPaint* grPaint);
98
99/** Replaces the SkShader (if any) on skPaint with the passed in GrFragmentProcessor, if not null.
100 If null then it is assumed that the geometry processor is implementing a shader replacement.
101 The processor should expect an unpremul input color and produce a premultiplied output color. */
103 const GrColorInfo& dstColorInfo,
104 const SkPaint& skPaint,
105 const SkMatrix& ctm,
106 std::unique_ptr<GrFragmentProcessor> shaderFP,
107 const SkSurfaceProps& surfaceProps,
108 GrPaint* grPaint);
109
110/** Blends the SkPaint's shader (or color if no shader) with the color which specified via a
111 GrOp's GrPrimitiveProcesssor. */
113 const GrColorInfo& dstColorInfo,
114 const SkPaint& skPaint,
115 const SkMatrix& ctm,
116 SkBlender* primColorBlender,
117 const SkSurfaceProps& surfaceProps,
118 GrPaint* grPaint);
119
120////////////////////////////////////////////////////////////////////////////////
121// Misc Sk to Gr type conversions
122
125static_assert((int)skgpu::BlendCoeff::kSC == (int)SkBlendModeCoeff::kSC);
127static_assert((int)skgpu::BlendCoeff::kDC == (int)SkBlendModeCoeff::kDC);
129static_assert((int)skgpu::BlendCoeff::kSA == (int)SkBlendModeCoeff::kSA);
131static_assert((int)skgpu::BlendCoeff::kDA == (int)SkBlendModeCoeff::kDA);
133static_assert((int)SkBlendModeCoeff::kCoeffCount == 10);
134
135////////////////////////////////////////////////////////////////////////////////
136// Texture management
137
138/**
139 * Policies for how to create textures for SkImages (and SkBitmaps).
140 */
141enum class GrImageTexGenPolicy : int {
142 // Choose the cheapest way to generate the texture. Use GrResourceCache if appropriate.
143 kDraw,
144 // Always make a new texture that is uncached and unbudgeted.
146 // Always make a new texture that is uncached and budgeted.
148};
149
150/**
151 * Creates a new texture with mipmap levels and copies the baseProxy into the base layer.
152 */
154 sk_sp<GrSurfaceProxy> baseProxy,
155 GrSurfaceOrigin origin,
156 std::string_view label,
158/**
159 * Same as GrCopyBaseMipMapToTextureProxy but takes the src as a view and returns a view with same
160 * origin and swizzle as the src view.
161 */
165
166/*
167 * Create a texture proxy from the provided bitmap and add it to the texture cache using the key
168 * also extracted from the bitmap. If skgpu::Mipmapped is kYes a non-mipmapped result may be
169 * returned if mipmapping isn't supported or for a 1x1 bitmap. If skgpu::Mipmapped is kNo it
170 * indicates mipmaps aren't required but a previously created mipmapped texture may still be
171 * returned. A color type is returned as color type conversion may be performed if there isn't a
172 * texture format equivalent of the bitmap's color type.
173 */
174std::tuple<GrSurfaceProxyView, GrColorType> GrMakeCachedBitmapProxyView(
176 const SkBitmap&,
177 std::string_view label,
179
180/**
181 * Like above but always uploads the bitmap and never inserts into the cache. Unlike above, the
182 * texture may be approx or scratch and budgeted or not.
183 */
184std::tuple<GrSurfaceProxyView, GrColorType> GrMakeUncachedBitmapProxyView(
186 const SkBitmap&,
190
191/**
192 * Our key includes the offset, width, and height so that bitmaps created by extractSubset()
193 * are unique.
194 *
195 * The imageID is in the shared namespace (see SkNextID::ImageID())
196 * - SkBitmap/SkPixelRef
197 * - SkImage
198 * - SkImageGenerator
199 */
200void GrMakeKeyFromImageID(skgpu::UniqueKey* key, uint32_t imageID, const SkIRect& imageBounds);
201
202/**
203 * Makes a SkIDChangeListener from a skgpu::UniqueKey. The key will be invalidated in the resource
204 * cache if the ID becomes invalid. This also modifies the key so that it will cause the listener
205 * to be deregistered if the key is destroyed (to prevent unbounded listener growth when resources
206 * are purged before listeners trigger).
207 */
209 uint32_t contextID);
210
212 return cubic.B >= 0 && cubic.C >= 0;
213}
214
215#endif
static GrColor GrColorPackRGBA(unsigned r, unsigned g, unsigned b, unsigned a)
Definition: GrColor.h:46
uint32_t GrColor
Definition: GrColor.h:25
GrColorType
Definition: GrTypesPriv.h:540
GrSurfaceOrigin
Definition: GrTypes.h:147
#define SkUNREACHABLE
Definition: SkAssert.h:135
SkBackingFit
Definition: SkBackingFit.h:16
#define SkGetPackedB32(packed)
Definition: SkColorPriv.h:95
#define SkGetPackedR32(packed)
Definition: SkColorPriv.h:93
#define SkGetPackedA32(packed)
Definition: SkColorPriv.h:92
#define SkGetPackedG32(packed)
Definition: SkColorPriv.h:94
#define SkColorGetR(color)
Definition: SkColor.h:65
#define SkColorGetG(color)
Definition: SkColor.h:69
SK_API SkPMColor SkPreMultiplyColor(SkColor c)
Definition: SkColor.cpp:21
uint32_t SkColor
Definition: SkColor.h:37
uint32_t SkPMColor
Definition: SkColor.h:205
#define SkColorGetA(color)
Definition: SkColor.h:61
#define SkColorGetB(color)
Definition: SkColor.h:73
GrImageTexGenPolicy
Definition: SkGr.h:141
bool SkPaintToGrPaintReplaceShader(GrRecordingContext *, const GrColorInfo &dstColorInfo, const SkPaint &skPaint, const SkMatrix &ctm, std::unique_ptr< GrFragmentProcessor > shaderFP, const SkSurfaceProps &surfaceProps, GrPaint *grPaint)
Definition: SkGr.cpp:570
void GrMakeKeyFromImageID(skgpu::UniqueKey *key, uint32_t imageID, const SkIRect &imageBounds)
Definition: SkGr.cpp:60
static GrColor SkColorToUnpremulGrColor(SkColor c)
Definition: SkGr.h:60
SkPMColor4f SkColorToPMColor4f(SkColor, const GrColorInfo &)
Definition: SkGr.cpp:275
static GrColor SkColorToPremulGrColor(SkColor c)
Definition: SkGr.h:51
static constexpr GrSamplerState::WrapMode SkTileModeToWrapMode(SkTileMode tileMode)
Definition: SkGr.h:77
SkColor4f SkColor4fPrepForDst(SkColor4f, const GrColorInfo &)
Definition: SkGr.cpp:283
static bool GrValidCubicResampler(SkCubicResampler cubic)
Definition: SkGr.h:211
bool SkPaintToGrPaintWithBlend(GrRecordingContext *context, const GrColorInfo &dstColorInfo, const SkPaint &skPaint, const SkMatrix &ctm, SkBlender *primColorBlender, const SkSurfaceProps &surfaceProps, GrPaint *grPaint)
Definition: SkGr.cpp:589
std::tuple< GrSurfaceProxyView, GrColorType > GrMakeUncachedBitmapProxyView(GrRecordingContext *, const SkBitmap &, skgpu::Mipmapped=skgpu::Mipmapped::kNo, SkBackingFit=SkBackingFit::kExact, skgpu::Budgeted=skgpu::Budgeted::kYes)
Definition: SkGr.cpp:253
sk_sp< GrSurfaceProxy > GrCopyBaseMipMapToTextureProxy(GrRecordingContext *, sk_sp< GrSurfaceProxy > baseProxy, GrSurfaceOrigin origin, std::string_view label, skgpu::Budgeted=skgpu::Budgeted::kYes)
Definition: SkGr.cpp:107
std::tuple< GrSurfaceProxyView, GrColorType > GrMakeCachedBitmapProxyView(GrRecordingContext *, const SkBitmap &, std::string_view label, skgpu::Mipmapped=skgpu::Mipmapped::kNo)
Definition: SkGr.cpp:188
bool SkPaintToGrPaint(GrRecordingContext *, const GrColorInfo &dstColorInfo, const SkPaint &skPaint, const SkMatrix &ctm, const SkSurfaceProps &surfaceProps, GrPaint *grPaint)
Definition: SkGr.cpp:553
sk_sp< SkIDChangeListener > GrMakeUniqueKeyInvalidationListener(skgpu::UniqueKey *, uint32_t contextID)
Definition: SkGr.cpp:75
GrSurfaceProxyView GrCopyBaseMipMapToView(GrRecordingContext *, GrSurfaceProxyView, skgpu::Budgeted=skgpu::Budgeted::kYes)
Definition: SkGr.cpp:136
SkTileMode
Definition: SkTileMode.h:13
static bool b
struct MyStruct a[10]
AI float cubic(float precision, const SkPoint pts[], const VectorXform &vectorXform=VectorXform())
Definition: WangsFormula.h:195
Definition: GpuTools.h:21
Budgeted
Definition: GpuTypes.h:35
Mipmapped
Definition: GpuTypes.h:53
Definition: SkRect.h:32