Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Namespaces | Enumerations | Functions
SkGr.h File Reference
#include "include/core/SkBlendMode.h"
#include "include/core/SkColor.h"
#include "include/core/SkColorPriv.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkSamplingOptions.h"
#include "include/core/SkTileMode.h"
#include "include/core/SkTypes.h"
#include "include/gpu/GpuTypes.h"
#include "include/private/SkColorData.h"
#include "src/gpu/Blend.h"
#include "src/gpu/SkBackingFit.h"
#include "src/gpu/ganesh/GrColor.h"
#include "src/gpu/ganesh/GrSamplerState.h"
#include <cstdint>
#include <memory>
#include <string_view>
#include <tuple>

Go to the source code of this file.

Namespaces

namespace  skgpu
 

Enumerations

enum class  GrImageTexGenPolicy : int { kDraw , kNew_Uncached_Unbudgeted , kNew_Uncached_Budgeted }
 

Functions

static GrColor SkColorToPremulGrColor (SkColor c)
 
static GrColor SkColorToUnpremulGrColor (SkColor c)
 
SkPMColor4f SkColorToPMColor4f (SkColor, const GrColorInfo &)
 
SkColor4f SkColor4fPrepForDst (SkColor4f, const GrColorInfo &)
 
static constexpr GrSamplerState::WrapMode SkTileModeToWrapMode (SkTileMode tileMode)
 
bool SkPaintToGrPaint (GrRecordingContext *, const GrColorInfo &dstColorInfo, const SkPaint &skPaint, const SkMatrix &ctm, const SkSurfaceProps &surfaceProps, GrPaint *grPaint)
 
bool SkPaintToGrPaintReplaceShader (GrRecordingContext *, const GrColorInfo &dstColorInfo, const SkPaint &skPaint, const SkMatrix &ctm, std::unique_ptr< GrFragmentProcessor > shaderFP, const SkSurfaceProps &surfaceProps, GrPaint *grPaint)
 
bool SkPaintToGrPaintWithBlend (GrRecordingContext *context, const GrColorInfo &dstColorInfo, const SkPaint &skPaint, const SkMatrix &ctm, SkBlender *primColorBlender, const SkSurfaceProps &surfaceProps, GrPaint *grPaint)
 
sk_sp< GrSurfaceProxyGrCopyBaseMipMapToTextureProxy (GrRecordingContext *, sk_sp< GrSurfaceProxy > baseProxy, GrSurfaceOrigin origin, std::string_view label, skgpu::Budgeted=skgpu::Budgeted::kYes)
 
GrSurfaceProxyView GrCopyBaseMipMapToView (GrRecordingContext *, GrSurfaceProxyView, skgpu::Budgeted=skgpu::Budgeted::kYes)
 
std::tuple< GrSurfaceProxyView, GrColorTypeGrMakeCachedBitmapProxyView (GrRecordingContext *, const SkBitmap &, std::string_view label, skgpu::Mipmapped=skgpu::Mipmapped::kNo)
 
std::tuple< GrSurfaceProxyView, GrColorTypeGrMakeUncachedBitmapProxyView (GrRecordingContext *, const SkBitmap &, skgpu::Mipmapped=skgpu::Mipmapped::kNo, SkBackingFit=SkBackingFit::kExact, skgpu::Budgeted=skgpu::Budgeted::kYes)
 
void GrMakeKeyFromImageID (skgpu::UniqueKey *key, uint32_t imageID, const SkIRect &imageBounds)
 
sk_sp< SkIDChangeListenerGrMakeUniqueKeyInvalidationListener (skgpu::UniqueKey *, uint32_t contextID)
 
static bool GrValidCubicResampler (SkCubicResampler cubic)
 

Enumeration Type Documentation

◆ GrImageTexGenPolicy

enum class GrImageTexGenPolicy : int
strong

Policies for how to create textures for SkImages (and SkBitmaps).

Enumerator
kDraw 
kNew_Uncached_Unbudgeted 
kNew_Uncached_Budgeted 

Definition at line 141 of file SkGr.h.

141 : 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};

Function Documentation

◆ GrCopyBaseMipMapToTextureProxy()

sk_sp< GrSurfaceProxy > GrCopyBaseMipMapToTextureProxy ( GrRecordingContext ctx,
sk_sp< GrSurfaceProxy baseProxy,
GrSurfaceOrigin  origin,
std::string_view  label,
skgpu::Budgeted  budgeted = skgpu::Budgeted::kYes 
)

Creates a new texture with mipmap levels and copies the baseProxy into the base layer.

Definition at line 107 of file SkGr.cpp.

111 {
112 SkASSERT(baseProxy);
113
114 // We don't allow this for promise proxies i.e. if they need mips they need to give them
115 // to us upfront.
116 if (baseProxy->isPromiseProxy()) {
117 return nullptr;
118 }
119 if (!ctx->priv().caps()->isFormatCopyable(baseProxy->backendFormat())) {
120 return nullptr;
121 }
122 auto copy = GrSurfaceProxy::Copy(ctx,
123 std::move(baseProxy),
124 origin,
125 skgpu::Mipmapped::kYes,
127 budgeted,
128 label);
129 if (!copy) {
130 return nullptr;
131 }
132 SkASSERT(copy->asTextureProxy());
133 return copy;
134}
#define SkASSERT(cond)
Definition SkAssert.h:116
const GrCaps * caps() const
virtual bool isFormatCopyable(const GrBackendFormat &) const =0
GrRecordingContextPriv priv()
const GrBackendFormat & backendFormat() const
static sk_sp< GrSurfaceProxy > Copy(GrRecordingContext *, sk_sp< GrSurfaceProxy > src, GrSurfaceOrigin, skgpu::Mipmapped, SkIRect srcRect, SkBackingFit, skgpu::Budgeted, std::string_view label, RectsMustMatch=RectsMustMatch::kNo, sk_sp< GrRenderTask > *outTask=nullptr)
Definition copy.py:1

◆ GrCopyBaseMipMapToView()

GrSurfaceProxyView GrCopyBaseMipMapToView ( GrRecordingContext context,
GrSurfaceProxyView  src,
skgpu::Budgeted  budgeted = skgpu::Budgeted::kYes 
)

Same as GrCopyBaseMipMapToTextureProxy but takes the src as a view and returns a view with same origin and swizzle as the src view.

Definition at line 136 of file SkGr.cpp.

138 {
139 auto origin = src.origin();
140 auto swizzle = src.swizzle();
141 auto proxy = src.refProxy();
143 context, proxy, origin, /*label=*/"CopyBaseMipMapToView", budgeted),
144 origin,
145 swizzle};
146}
sk_sp< GrSurfaceProxy > GrCopyBaseMipMapToTextureProxy(GrRecordingContext *ctx, sk_sp< GrSurfaceProxy > baseProxy, GrSurfaceOrigin origin, std::string_view label, skgpu::Budgeted budgeted)
Definition SkGr.cpp:107

◆ GrMakeCachedBitmapProxyView()

std::tuple< GrSurfaceProxyView, GrColorType > GrMakeCachedBitmapProxyView ( GrRecordingContext rContext,
const SkBitmap bitmap,
std::string_view  label,
skgpu::Mipmapped  mipmapped = skgpu::Mipmapped::kNo 
)

Definition at line 188 of file SkGr.cpp.

192 {
193 if (!bitmap.peekPixels(nullptr)) {
194 return {};
195 }
196
197 GrProxyProvider* proxyProvider = rContext->priv().proxyProvider();
198 const GrCaps* caps = rContext->priv().caps();
199
201 SkIPoint origin = bitmap.pixelRefOrigin();
202 SkIRect subset = SkIRect::MakePtSize(origin, bitmap.dimensions());
203 GrMakeKeyFromImageID(&key, bitmap.pixelRef()->getGenerationID(), subset);
204
205 mipmapped = adjust_mipmapped(mipmapped, bitmap, caps);
207
208 auto installKey = [&](GrTextureProxy* proxy) {
209 auto listener = GrMakeUniqueKeyInvalidationListener(&key, proxyProvider->contextID());
210 bitmap.pixelRef()->addGenIDChangeListener(std::move(listener));
211 proxyProvider->assignUniqueKeyToProxy(key, proxy);
212 };
213
215 if (!proxy) {
216 proxy = make_bmp_proxy(
217 proxyProvider, bitmap, ct, mipmapped, SkBackingFit::kExact, skgpu::Budgeted::kYes);
218 if (!proxy) {
219 return {};
220 }
221 SkASSERT(mipmapped == skgpu::Mipmapped::kNo ||
222 proxy->mipmapped() == skgpu::Mipmapped::kYes);
223 installKey(proxy.get());
224 }
225
226 skgpu::Swizzle swizzle = caps->getReadSwizzle(proxy->backendFormat(), ct);
227 if (mipmapped == skgpu::Mipmapped::kNo || proxy->mipmapped() == skgpu::Mipmapped::kYes) {
228 return {{std::move(proxy), kTopLeft_GrSurfaceOrigin, swizzle}, ct};
229 }
230
231 // We need a mipped proxy, but we found a proxy earlier that wasn't mipped. Thus we generate
232 // a new mipped surface and copy the original proxy into the base layer. We will then let
233 // the gpu generate the rest of the mips.
234 auto mippedProxy = GrCopyBaseMipMapToTextureProxy(
235 rContext, proxy, kTopLeft_GrSurfaceOrigin, /*label=*/"MakeCachedBitmapProxyView");
236 if (!mippedProxy) {
237 // We failed to make a mipped proxy with the base copied into it. This could have
238 // been from failure to make the proxy or failure to do the copy. Thus we will fall
239 // back to just using the non mipped proxy; See skbug.com/7094.
240 return {{std::move(proxy), kTopLeft_GrSurfaceOrigin, swizzle}, ct};
241 }
242 // In this case we are stealing the key from the original proxy which should only happen
243 // when we have just generated mipmaps for an originally unmipped proxy/texture. This
244 // means that all future uses of the key will access the mipmapped version. The texture
245 // backing the unmipped version will remain in the resource cache until the last texture
246 // proxy referencing it is deleted at which time it too will be deleted or recycled.
247 SkASSERT(proxy->getUniqueKey() == key);
248 proxyProvider->removeUniqueKeyFromProxy(proxy.get());
249 installKey(mippedProxy->asTextureProxy());
250 return {{std::move(mippedProxy), kTopLeft_GrSurfaceOrigin, swizzle}, ct};
251}
GrColorType
@ kTopLeft_GrSurfaceOrigin
Definition GrTypes.h:148
void GrMakeKeyFromImageID(skgpu::UniqueKey *key, uint32_t imageID, const SkIRect &imageBounds)
Definition SkGr.cpp:60
static sk_sp< GrTextureProxy > make_bmp_proxy(GrProxyProvider *proxyProvider, const SkBitmap &bitmap, GrColorType ct, skgpu::Mipmapped mipmapped, SkBackingFit fit, skgpu::Budgeted budgeted)
Definition SkGr.cpp:165
sk_sp< SkIDChangeListener > GrMakeUniqueKeyInvalidationListener(skgpu::UniqueKey *key, uint32_t contextID)
Definition SkGr.cpp:75
static skgpu::Mipmapped adjust_mipmapped(skgpu::Mipmapped mipmapped, const SkBitmap &bitmap, const GrCaps *caps)
Definition SkGr.cpp:148
static GrColorType choose_bmp_texture_colortype(const GrCaps *caps, const SkBitmap &bitmap)
Definition SkGr.cpp:157
skgpu::Swizzle getReadSwizzle(const GrBackendFormat &format, GrColorType colorType) const
Definition GrCaps.cpp:443
uint32_t contextID() const
void removeUniqueKeyFromProxy(GrTextureProxy *)
bool assignUniqueKeyToProxy(const skgpu::UniqueKey &, GrTextureProxy *)
sk_sp< GrTextureProxy > findOrCreateProxyByUniqueKey(const skgpu::UniqueKey &, UseAllocator=UseAllocator::kYes)
GrProxyProvider * proxyProvider()
T * get() const
Definition SkRefCnt.h:303
static constexpr SkIRect MakePtSize(SkIPoint pt, SkISize size)
Definition SkRect.h:78

◆ GrMakeKeyFromImageID()

void GrMakeKeyFromImageID ( skgpu::UniqueKey key,
uint32_t  imageID,
const SkIRect imageBounds 
)

Our key includes the offset, width, and height so that bitmaps created by extractSubset() are unique.

The imageID is in the shared namespace (see SkNextID::ImageID())

Definition at line 60 of file SkGr.cpp.

60 {
62 SkASSERT(imageID);
63 SkASSERT(!imageBounds.isEmpty());
64 static const skgpu::UniqueKey::Domain kImageIDDomain = skgpu::UniqueKey::GenerateDomain();
65 skgpu::UniqueKey::Builder builder(key, kImageIDDomain, 5, "Image");
66 builder[0] = imageID;
67 builder[1] = imageBounds.fLeft;
68 builder[2] = imageBounds.fTop;
69 builder[3] = imageBounds.fRight;
70 builder[4] = imageBounds.fBottom;
71}
static Domain GenerateDomain()
int32_t fBottom
larger y-axis bounds
Definition SkRect.h:36
int32_t fTop
smaller y-axis bounds
Definition SkRect.h:34
bool isEmpty() const
Definition SkRect.h:202
int32_t fLeft
smaller x-axis bounds
Definition SkRect.h:33
int32_t fRight
larger x-axis bounds
Definition SkRect.h:35

◆ GrMakeUncachedBitmapProxyView()

std::tuple< GrSurfaceProxyView, GrColorType > GrMakeUncachedBitmapProxyView ( GrRecordingContext rContext,
const SkBitmap bitmap,
skgpu::Mipmapped  mipmapped = skgpu::Mipmapped::kNo,
SkBackingFit  fit = SkBackingFit::kExact,
skgpu::Budgeted  budgeted = skgpu::Budgeted::kYes 
)

Like above but always uploads the bitmap and never inserts into the cache. Unlike above, the texture may be approx or scratch and budgeted or not.

Definition at line 253 of file SkGr.cpp.

258 {
259 GrProxyProvider* proxyProvider = rContext->priv().proxyProvider();
260 const GrCaps* caps = rContext->priv().caps();
261
262 mipmapped = adjust_mipmapped(mipmapped, bitmap, caps);
264
265 if (auto proxy = make_bmp_proxy(proxyProvider, bitmap, ct, mipmapped, fit, budgeted)) {
266 skgpu::Swizzle swizzle = caps->getReadSwizzle(proxy->backendFormat(), ct);
267 SkASSERT(mipmapped == skgpu::Mipmapped::kNo ||
268 proxy->mipmapped() == skgpu::Mipmapped::kYes);
269 return {{std::move(proxy), kTopLeft_GrSurfaceOrigin, swizzle}, ct};
270 }
271 return {};
272}

◆ GrMakeUniqueKeyInvalidationListener()

sk_sp< SkIDChangeListener > GrMakeUniqueKeyInvalidationListener ( skgpu::UniqueKey key,
uint32_t  contextID 
)

Makes a SkIDChangeListener from a skgpu::UniqueKey. The key will be invalidated in the resource cache if the ID becomes invalid. This also modifies the key so that it will cause the listener to be deregistered if the key is destroyed (to prevent unbounded listener growth when resources are purged before listeners trigger).

Definition at line 75 of file SkGr.cpp.

76 {
77 class Listener : public SkIDChangeListener {
78 public:
79 Listener(const skgpu::UniqueKey& key, uint32_t contextUniqueID)
80 : fMsg(key, contextUniqueID) {}
81
82 void changed() override {
84 }
85
86 private:
88 };
89
90 auto listener = sk_make_sp<Listener>(*key, contextID);
91
92 // We stick a SkData on the key that calls invalidateListener in its destructor.
93 auto invalidateListener = [](const void* ptr, void* /*context*/) {
94 auto listener = reinterpret_cast<const sk_sp<Listener>*>(ptr);
95 (*listener)->markShouldDeregister();
96 delete listener;
97 };
98 auto data = SkData::MakeWithProc(new sk_sp<Listener>(listener),
99 sizeof(sk_sp<Listener>),
100 invalidateListener,
101 nullptr);
102 SkASSERT(!key->getCustomData());
103 key->setCustomData(std::move(data));
104 return listener;
105}
static sk_sp< SkData > MakeWithProc(const void *ptr, size_t length, ReleaseProc proc, void *ctx)
Definition SkData.cpp:128
virtual void changed()=0
static void Post(Message m)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
Definition switches.h:41

◆ GrValidCubicResampler()

static bool GrValidCubicResampler ( SkCubicResampler  cubic)
inlinestatic

Definition at line 211 of file SkGr.h.

211 {
212 return cubic.B >= 0 && cubic.C >= 0;
213}
AI float cubic(float precision, const SkPoint pts[], const VectorXform &vectorXform=VectorXform())

◆ SkColor4fPrepForDst()

SkColor4f SkColor4fPrepForDst ( SkColor4f  color,
const GrColorInfo colorInfo 
)

Converts an SkColor4f to the destination color space.

Definition at line 283 of file SkGr.cpp.

283 {
284 if (auto* xform = colorInfo.colorSpaceXformFromSRGB()) {
285 color = xform->apply(color);
286 }
287 return color;
288}
SkColor4f color
GrColorSpaceXform * colorSpaceXformFromSRGB() const
Definition GrColorInfo.h:40

◆ SkColorToPMColor4f()

SkPMColor4f SkColorToPMColor4f ( SkColor  c,
const GrColorInfo colorInfo 
)

Similar, but using SkPMColor4f.

Definition at line 275 of file SkGr.cpp.

275 {
277 if (auto* xform = colorInfo.colorSpaceXformFromSRGB()) {
278 color = xform->apply(color);
279 }
280 return color.premul();
281}
static SkRGBA4f FromColor(SkColor color)

◆ SkColorToPremulGrColor()

static GrColor SkColorToPremulGrColor ( SkColor  c)
inlinestatic

Definition at line 51 of file SkGr.h.

51 {
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}
static GrColor GrColorPackRGBA(unsigned r, unsigned g, unsigned b, unsigned a)
Definition GrColor.h:46
#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
SK_API SkPMColor SkPreMultiplyColor(SkColor c)
Definition SkColor.cpp:21
uint32_t SkPMColor
Definition SkColor.h:205
static bool b
struct MyStruct a[10]

◆ SkColorToUnpremulGrColor()

static GrColor SkColorToUnpremulGrColor ( SkColor  c)
inlinestatic

Definition at line 60 of file SkGr.h.

60 {
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}
#define SkColorGetR(color)
Definition SkColor.h:65
#define SkColorGetG(color)
Definition SkColor.h:69
#define SkColorGetA(color)
Definition SkColor.h:61
#define SkColorGetB(color)
Definition SkColor.h:73

◆ SkPaintToGrPaint()

bool SkPaintToGrPaint ( GrRecordingContext context,
const GrColorInfo dstColorInfo,
const SkPaint skPaint,
const SkMatrix ctm,
const SkSurfaceProps surfaceProps,
GrPaint grPaint 
)

Converts an SkPaint to a GrPaint for a given GrRecordingContext. The matrix is required in order to convert the SkShader (if any) on the SkPaint. The primitive itself has no color.

Definition at line 553 of file SkGr.cpp.

558 {
559 return skpaint_to_grpaint_impl(context,
560 dstColorInfo,
561 skPaint,
562 ctm,
563 /*shaderFP=*/std::nullopt,
564 /*primColorBlender=*/nullptr,
565 surfaceProps,
566 grPaint);
567}
static bool skpaint_to_grpaint_impl(GrRecordingContext *context, const GrColorInfo &dstColorInfo, const SkPaint &skPaint, const SkMatrix &ctm, std::optional< std::unique_ptr< GrFragmentProcessor > > shaderFP, SkBlender *primColorBlender, const SkSurfaceProps &surfaceProps, GrPaint *grPaint)
Definition SkGr.cpp:362

◆ SkPaintToGrPaintReplaceShader()

bool SkPaintToGrPaintReplaceShader ( GrRecordingContext context,
const GrColorInfo dstColorInfo,
const SkPaint skPaint,
const SkMatrix ctm,
std::unique_ptr< GrFragmentProcessor shaderFP,
const SkSurfaceProps surfaceProps,
GrPaint grPaint 
)

Replaces the SkShader (if any) on skPaint with the passed in GrFragmentProcessor, if not null. If null then it is assumed that the geometry processor is implementing a shader replacement. The processor should expect an unpremul input color and produce a premultiplied output color.

Replaces the SkShader (if any) on skPaint with the passed in GrFragmentProcessor.

Definition at line 570 of file SkGr.cpp.

576 {
577 return skpaint_to_grpaint_impl(context,
578 dstColorInfo,
579 skPaint,
580 ctm,
581 std::move(shaderFP),
582 /*primColorBlender=*/nullptr,
583 surfaceProps,
584 grPaint);
585}

◆ SkPaintToGrPaintWithBlend()

bool SkPaintToGrPaintWithBlend ( GrRecordingContext context,
const GrColorInfo dstColorInfo,
const SkPaint skPaint,
const SkMatrix ctm,
SkBlender primColorBlender,
const SkSurfaceProps surfaceProps,
GrPaint grPaint 
)

Blends the SkPaint's shader (or color if no shader) with the color which specified via a GrOp's GrPrimitiveProcesssor.

Blends the SkPaint's shader (or color if no shader) with a per-primitive color which must be setup as a vertex attribute using the specified SkBlender.

Definition at line 589 of file SkGr.cpp.

595 {
596 return skpaint_to_grpaint_impl(context,
597 dstColorInfo,
598 skPaint,
599 ctm,
600 /*shaderFP=*/std::nullopt,
601 primColorBlender,
602 surfaceProps,
603 grPaint);
604}

◆ SkTileModeToWrapMode()

static constexpr GrSamplerState::WrapMode SkTileModeToWrapMode ( SkTileMode  tileMode)
staticconstexpr