Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Friends | List of all members
GrResourceProvider Class Reference

#include <GrResourceProvider.h>

Public Types

enum class  ZeroInit : bool { kNo = false , kYes = true }
 
using InitializeBufferFn = void(*)(skgpu::VertexWriter, size_t bufferSize)
 

Public Member Functions

 GrResourceProvider (GrGpu *, GrResourceCache *, skgpu::SingleOwner *)
 
template<typename T = GrGpuResource>
std::enable_if< std::is_base_of< GrGpuResource, T >::value, sk_sp< T > >::type findByUniqueKey (const skgpu::UniqueKey &key)
 
sk_sp< GrTexturecreateApproxTexture (SkISize dimensions, const GrBackendFormat &format, GrTextureType textureType, skgpu::Renderable renderable, int renderTargetSampleCnt, skgpu::Protected isProtected, std::string_view label)
 
sk_sp< GrTexturecreateTexture (SkISize dimensions, const GrBackendFormat &format, GrTextureType textureType, skgpu::Renderable renderable, int renderTargetSampleCnt, skgpu::Mipmapped mipmapped, skgpu::Budgeted budgeted, skgpu::Protected isProtected, std::string_view label)
 
sk_sp< GrTexturecreateTexture (SkISize dimensions, const GrBackendFormat &format, GrTextureType textureType, GrColorType colorType, skgpu::Renderable renderable, int renderTargetSampleCnt, skgpu::Budgeted budgeted, skgpu::Mipmapped mipmapped, skgpu::Protected isProtected, const GrMipLevel texels[], std::string_view label)
 
sk_sp< GrTexturecreateTexture (SkISize dimensions, const GrBackendFormat &, GrTextureType textureType, GrColorType srcColorType, skgpu::Renderable, int renderTargetSampleCnt, skgpu::Budgeted, SkBackingFit, skgpu::Protected, const GrMipLevel &mipLevel, std::string_view label)
 
sk_sp< GrTexturefindAndRefScratchTexture (const skgpu::ScratchKey &, std::string_view label)
 
sk_sp< GrTexturefindAndRefScratchTexture (SkISize dimensions, const GrBackendFormat &, GrTextureType textureType, skgpu::Renderable, int renderTargetSampleCnt, skgpu::Mipmapped, skgpu::Protected, std::string_view label)
 
sk_sp< GrTexturecreateCompressedTexture (SkISize dimensions, const GrBackendFormat &, skgpu::Budgeted, skgpu::Mipmapped, skgpu::Protected, SkData *data, std::string_view label)
 
sk_sp< GrTexturewrapBackendTexture (const GrBackendTexture &tex, GrWrapOwnership, GrWrapCacheable, GrIOType)
 
sk_sp< GrTexturewrapCompressedBackendTexture (const GrBackendTexture &tex, GrWrapOwnership, GrWrapCacheable)
 
sk_sp< GrTexturewrapRenderableBackendTexture (const GrBackendTexture &tex, int sampleCnt, GrWrapOwnership, GrWrapCacheable)
 
sk_sp< GrRenderTargetwrapBackendRenderTarget (const GrBackendRenderTarget &)
 
sk_sp< GrRenderTargetwrapVulkanSecondaryCBAsRenderTarget (const SkImageInfo &, const GrVkDrawableInfo &)
 
sk_sp< const GrGpuBufferfindOrMakeStaticBuffer (GrGpuBufferType intendedType, size_t size, const skgpu::UniqueKey &key, InitializeBufferFn)
 
sk_sp< const GrGpuBufferfindOrMakeStaticBuffer (GrGpuBufferType intendedType, size_t size, const void *staticData, const skgpu::UniqueKey &key)
 
sk_sp< const GrGpuBufferfindOrCreatePatternedIndexBuffer (const uint16_t *pattern, int patternSize, int reps, int vertCount, const skgpu::UniqueKey &key)
 
sk_sp< const GrGpuBufferrefNonAAQuadIndexBuffer ()
 
sk_sp< const GrGpuBufferrefAAQuadIndexBuffer ()
 
sk_sp< GrGpuBuffercreateBuffer (size_t size, GrGpuBufferType, GrAccessPattern, ZeroInit)
 
sk_sp< GrGpuBuffercreateBuffer (const void *data, size_t size, GrGpuBufferType type, GrAccessPattern pattern)
 
bool attachStencilAttachment (GrRenderTarget *rt, bool useMSAASurface)
 
sk_sp< GrAttachmentmakeMSAAAttachment (SkISize dimensions, const GrBackendFormat &format, int sampleCnt, skgpu::Protected isProtected, GrMemoryless isMemoryless)
 
sk_sp< GrAttachmentgetDiscardableMSAAAttachment (SkISize dimensions, const GrBackendFormat &format, int sampleCnt, skgpu::Protected isProtected, GrMemoryless memoryless)
 
void assignUniqueKeyToResource (const skgpu::UniqueKey &, GrGpuResource *)
 
std::unique_ptr< GrSemaphoremakeSemaphore (bool isOwned=true)
 
std::unique_ptr< GrSemaphorewrapBackendSemaphore (const GrBackendSemaphore &, GrSemaphoreWrapType, GrWrapOwnership=kBorrow_GrWrapOwnership)
 
void abandon ()
 
uint32_t contextUniqueID () const
 
const GrCapscaps () const
 
bool overBudget () const
 
GrResourceProviderPriv priv ()
 
const GrResourceProviderPriv priv () const
 

Static Public Member Functions

static int MaxNumNonAAQuads ()
 
static int NumVertsPerNonAAQuad ()
 
static int NumIndicesPerNonAAQuad ()
 
static int MaxNumAAQuads ()
 
static int NumVertsPerAAQuad ()
 
static int NumIndicesPerAAQuad ()
 

Friends

class GrResourceProviderPriv
 

Detailed Description

A factory for arbitrary resource types.

Definition at line 59 of file GrResourceProvider.h.

Member Typedef Documentation

◆ InitializeBufferFn

using GrResourceProvider::InitializeBufferFn = void(*)(skgpu::VertexWriter, size_t bufferSize)

Either finds and refs a buffer with the given unique key, or creates a new new, fills its contents with the InitializeBufferDataFn() callback, and assigns it the unique key.

Parameters
intendedTypehint to the graphics subsystem about how the buffer will be used.
sizeminimum size of buffer to return.
keyKey to be assigned to the buffer.
InitializeBufferFncallback with which to initialize the buffer.
Returns
The buffer if successful, otherwise nullptr.

Definition at line 220 of file GrResourceProvider.h.

Member Enumeration Documentation

◆ ZeroInit

enum class GrResourceProvider::ZeroInit : bool
strong
Enumerator
kNo 
kYes 

Definition at line 301 of file GrResourceProvider.h.

Constructor & Destructor Documentation

◆ GrResourceProvider()

GrResourceProvider::GrResourceProvider ( GrGpu gpu,
GrResourceCache cache,
skgpu::SingleOwner owner 
)

Definition at line 48 of file GrResourceProvider.cpp.

51 : fCache(cache)
52 , fGpu(gpu)
53#ifdef SK_DEBUG
54 , fSingleOwner(owner)
55#endif
56{
57 fCaps = sk_ref_sp(fGpu->caps());
58}
sk_sp< T > sk_ref_sp(T *obj)
Definition SkRefCnt.h:381
const GrCaps * caps() const
Definition GrGpu.h:73

Member Function Documentation

◆ abandon()

void GrResourceProvider::abandon ( )
inline

Definition at line 357 of file GrResourceProvider.h.

357 {
358 fCache = nullptr;
359 fGpu = nullptr;
360 }

◆ assignUniqueKeyToResource()

void GrResourceProvider::assignUniqueKeyToResource ( const skgpu::UniqueKey key,
GrGpuResource resource 
)

Assigns a unique key to a resource. If the key is associated with another resource that association is removed and replaced by this resource.

Definition at line 423 of file GrResourceProvider.cpp.

424 {
426 if (this->isAbandoned() || !resource) {
427 return;
428 }
429 resource->resourcePriv().setUniqueKey(key);
430}
void setUniqueKey(const skgpu::UniqueKey &key)
ResourcePriv resourcePriv()
#define ASSERT_SINGLE_OWNER
Definition Device.cpp:120

◆ attachStencilAttachment()

bool GrResourceProvider::attachStencilAttachment ( GrRenderTarget rt,
bool  useMSAASurface 
)

If passed in render target already has a stencil buffer on the specified surface, return true. Otherwise attempt to attach one and return true on success.

Definition at line 664 of file GrResourceProvider.cpp.

664 {
665 SkASSERT(rt);
666 SkASSERT(!this->caps()->avoidStencilBuffers());
667
668 GrAttachment* stencil = rt->getStencilAttachment(useMSAASurface);
669 if (stencil) {
670 SkASSERT(stencil->numSamples() == num_stencil_samples(rt, useMSAASurface, *this->caps()));
671 return true;
672 }
673
674 if (!rt->wasDestroyed() && rt->canAttemptStencilAttachment(useMSAASurface)) {
675 skgpu::UniqueKey sbKey;
676
677#if 0
678 if (this->caps()->oversizedStencilSupport()) {
681 }
682#endif
683 GrBackendFormat stencilFormat = this->gpu()->getPreferredStencilFormat(rt->backendFormat());
684 if (!stencilFormat.isValid()) {
685 return false;
686 }
687 GrProtected isProtected = rt->isProtected() ? GrProtected::kYes : GrProtected::kNo;
688 int numStencilSamples = num_stencil_samples(rt, useMSAASurface, *this->caps());
690 stencilFormat,
691 rt->dimensions(),
693 numStencilSamples,
694 skgpu::Mipmapped::kNo,
695 isProtected,
697 &sbKey);
698 auto keyedStencil = this->findByUniqueKey<GrAttachment>(sbKey);
699 if (!keyedStencil) {
700 // Need to try and create a new stencil
701 keyedStencil = this->gpu()->makeStencilAttachment(rt->backendFormat(), rt->dimensions(),
702 numStencilSamples);
703 if (!keyedStencil) {
704 return false;
705 }
706 this->assignUniqueKeyToResource(sbKey, keyedStencil.get());
707 }
708 rt->attachStencilAttachment(std::move(keyedStencil), useMSAASurface);
709 }
710 stencil = rt->getStencilAttachment(useMSAASurface);
711 SkASSERT(!stencil ||
712 stencil->numSamples() == num_stencil_samples(rt, useMSAASurface, *this->caps()));
713 return stencil != nullptr;
714}
static int num_stencil_samples(const GrRenderTarget *rt, bool useMSAASurface, const GrCaps &caps)
#define SkASSERT(cond)
Definition SkAssert.h:116
static int SkNextPow2(int value)
Definition SkMathPriv.h:272
int numSamples() const
static void ComputeSharedAttachmentUniqueKey(const GrCaps &caps, const GrBackendFormat &format, SkISize dimensions, UsageFlags requiredUsage, int sampleCnt, skgpu::Mipmapped mipmapped, GrProtected isProtected, GrMemoryless memoryless, skgpu::UniqueKey *key)
bool isValid() const
bool wasDestroyed() const
virtual sk_sp< GrAttachment > makeStencilAttachment(const GrBackendFormat &colorFormat, SkISize dimensions, int numStencilSamples)=0
virtual GrBackendFormat getPreferredStencilFormat(const GrBackendFormat &)=0
void attachStencilAttachment(sk_sp< GrAttachment > stencil, bool useMSAASurface)
GrAttachment * getStencilAttachment(bool useMSAASurface) const
virtual bool canAttemptStencilAttachment(bool useMSAASurface) const =0
void assignUniqueKeyToResource(const skgpu::UniqueKey &, GrGpuResource *)
const GrCaps * caps() const
virtual GrBackendFormat backendFormat() const =0
SkISize dimensions() const
Definition GrSurface.h:27
bool isProtected() const
Definition GrSurface.h:87
Protected
Definition GpuTypes.h:61
int32_t height
int32_t width

◆ caps()

const GrCaps * GrResourceProvider::caps ( ) const
inline

Definition at line 363 of file GrResourceProvider.h.

363{ return fCaps.get(); }
T * get() const
Definition SkRefCnt.h:303

◆ contextUniqueID()

uint32_t GrResourceProvider::contextUniqueID ( ) const
inline

Definition at line 362 of file GrResourceProvider.h.

362{ return fCache->contextUniqueID(); }
uint32_t contextUniqueID() const

◆ createApproxTexture()

sk_sp< GrTexture > GrResourceProvider::createApproxTexture ( SkISize  dimensions,
const GrBackendFormat format,
GrTextureType  textureType,
skgpu::Renderable  renderable,
int  renderTargetSampleCnt,
skgpu::Protected  isProtected,
std::string_view  label 
)

Finds a texture that approximately matches the descriptor. Will be at least as large in width and height as desc specifies. If renderable is kYes then the GrTexture will also be a GrRenderTarget. The texture's format and sample count will always match the request. The contents of the texture are undefined.

Definition at line 280 of file GrResourceProvider.cpp.

286 {
288
289 if (this->isAbandoned()) {
290 return nullptr;
291 }
292
293 // Currently we don't recycle compressed textures as scratch. Additionally all compressed
294 // textures should be created through the createCompressedTexture function.
295 SkASSERT(!this->caps()->isFormatCompressed(format));
296
297 if (!fCaps->validateSurfaceParams(dimensions,
298 format,
299 renderable,
300 renderTargetSampleCnt,
301 skgpu::Mipmapped::kNo,
302 textureType)) {
303 return nullptr;
304 }
305
306 auto copyDimensions = skgpu::GetApproxSize(dimensions);
307
308 if (auto tex = this->findAndRefScratchTexture(copyDimensions,
309 format,
310 textureType,
311 renderable,
312 renderTargetSampleCnt,
313 skgpu::Mipmapped::kNo,
314 isProtected,
315 label)) {
316 return tex;
317 }
318
319 return fGpu->createTexture(copyDimensions,
320 format,
321 textureType,
322 renderable,
323 renderTargetSampleCnt,
324 skgpu::Mipmapped::kNo,
326 isProtected,
327 label);
328}
bool validateSurfaceParams(const SkISize &, const GrBackendFormat &, GrRenderable renderable, int renderTargetSampleCnt, skgpu::Mipmapped, GrTextureType) const
Definition GrCaps.cpp:327
sk_sp< GrTexture > createTexture(SkISize dimensions, const GrBackendFormat &format, GrTextureType textureType, GrRenderable renderable, int renderTargetSampleCnt, skgpu::Budgeted budgeted, GrProtected isProtected, GrColorType textureColorType, GrColorType srcColorType, const GrMipLevel texels[], int texelLevelCount, std::string_view label)
Definition GrGpu.cpp:189
sk_sp< GrTexture > findAndRefScratchTexture(const skgpu::ScratchKey &, std::string_view label)
uint32_t uint32_t * format
SkISize GetApproxSize(SkISize size)

◆ createBuffer() [1/2]

sk_sp< GrGpuBuffer > GrResourceProvider::createBuffer ( const void *  data,
size_t  size,
GrGpuBufferType  type,
GrAccessPattern  pattern 
)

Same as above but also fills the buffer from data.

Definition at line 640 of file GrResourceProvider.cpp.

643 {
644 SkASSERT(data);
645 auto buffer = this->createBuffer(size, type, pattern, ZeroInit::kNo);
646 if (!buffer) {
647 return nullptr;
648 }
649 if (!buffer->updateData(data, /*offset=*/0, size, /*preserve=*/false)) {
650 return nullptr;
651 }
652 return buffer;
653}
sk_sp< GrGpuBuffer > createBuffer(size_t size, GrGpuBufferType, GrAccessPattern, ZeroInit)
static const uint8_t buffer[]

◆ createBuffer() [2/2]

sk_sp< GrGpuBuffer > GrResourceProvider::createBuffer ( size_t  size,
GrGpuBufferType  intendedType,
GrAccessPattern  accessPattern,
ZeroInit  zeroInit 
)

Returns a buffer.

Parameters
sizeminimum size of buffer to return.
GrGpuBufferTypehint to the graphics subsystem about what the buffer will be used for.
GrAccessPatternhint to the graphics subsystem about how the data will be accessed.
ZeroInitif kYes zero-initialize the buffer. Otherwise, contents are undefined.
Returns
the buffer if successful, otherwise nullptr.

Definition at line 596 of file GrResourceProvider.cpp.

599 {
600 if (this->isAbandoned()) {
601 return nullptr;
602 }
603 if (kDynamic_GrAccessPattern != accessPattern) {
604 if (this->caps()->buffersAreInitiallyZero()) {
605 zeroInit = ZeroInit::kNo;
606 }
607 sk_sp<GrGpuBuffer> buffer = this->gpu()->createBuffer(size, intendedType, accessPattern);
608 if (buffer && zeroInit == ZeroInit::kYes && !buffer->clearToZero()) {
609 return nullptr;
610 }
611 return buffer;
612 }
613 // bin by pow2+midpoint with a reasonable min
614 static const size_t MIN_SIZE = 1 << 12;
615 static const size_t MIN_UNIFORM_SIZE = 1 << 7;
616 size_t allocSize = intendedType == GrGpuBufferType::kUniform ? std::max(size, MIN_UNIFORM_SIZE)
617 : std::max(size, MIN_SIZE);
618 size_t ceilPow2 = GrNextSizePow2(allocSize);
619 size_t floorPow2 = ceilPow2 >> 1;
620 size_t mid = floorPow2 + (floorPow2 >> 1);
621 allocSize = (allocSize <= mid) ? mid : ceilPow2;
622
624 GrGpuBuffer::ComputeScratchKeyForDynamicBuffer(allocSize, intendedType, &key);
625 auto buffer =
626 sk_sp<GrGpuBuffer>(static_cast<GrGpuBuffer*>(this->cache()->findAndRefScratchResource(
627 key)));
628 if (!buffer) {
629 if (this->caps()->buffersAreInitiallyZero()) {
630 zeroInit = ZeroInit::kNo;
631 }
632 buffer = this->gpu()->createBuffer(allocSize, intendedType, kDynamic_GrAccessPattern);
633 }
634 if (buffer && zeroInit == ZeroInit::kYes && !buffer->clearToZero()) {
635 return nullptr;
636 }
637 return buffer;
638}
@ kDynamic_GrAccessPattern
static size_t GrNextSizePow2(size_t n)
Definition SkMathPriv.h:309
static void ComputeScratchKeyForDynamicBuffer(size_t size, GrGpuBufferType, skgpu::ScratchKey *)
sk_sp< GrGpuBuffer > createBuffer(size_t size, GrGpuBufferType intendedType, GrAccessPattern accessPattern)
Definition GrGpu.cpp:393
static float max(float r, float g, float b)
Definition hsl.cpp:49
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 keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition switches.h:259
Definition ref_ptr.h:256

◆ createCompressedTexture()

sk_sp< GrTexture > GrResourceProvider::createCompressedTexture ( SkISize  dimensions,
const GrBackendFormat format,
skgpu::Budgeted  budgeted,
skgpu::Mipmapped  mipmapped,
skgpu::Protected  isProtected,
SkData data,
std::string_view  label 
)

Creates a compressed texture. The GrGpu must support the SkImageImage::Compression type. It will not be renderable.

Definition at line 211 of file GrResourceProvider.cpp.

217 {
219 if (this->isAbandoned()) {
220 return nullptr;
221 }
222 return fGpu->createCompressedTexture(dimensions,
223 format,
224 budgeted,
225 mipmapped,
226 isProtected,
227 data->data(),
228 data->size());
229}
sk_sp< GrTexture > createCompressedTexture(SkISize dimensions, const GrBackendFormat &format, skgpu::Budgeted budgeted, skgpu::Mipmapped mipmapped, GrProtected isProtected, const void *data, size_t dataSize)
Definition GrGpu.cpp:260
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

◆ createTexture() [1/3]

sk_sp< GrTexture > GrResourceProvider::createTexture ( SkISize  dimensions,
const GrBackendFormat format,
GrTextureType  textureType,
GrColorType  srcColorType,
skgpu::Renderable  renderable,
int  renderTargetSampleCnt,
skgpu::Budgeted  budgeted,
SkBackingFit  fit,
skgpu::Protected  isProtected,
const GrMipLevel mipLevel,
std::string_view  label 
)

Create a potentially loose fit texture with the provided data. The color type must be valid for the format and also describe the texel data. This will ensure any conversions that need to get applied to the data before upload are applied.

Definition at line 155 of file GrResourceProvider.cpp.

165 {
167
168 if (!mipLevel.fPixels) {
169 return nullptr;
170 }
171
172 if (SkBackingFit::kApprox == fit) {
173 if (this->isAbandoned()) {
174 return nullptr;
175 }
176 if (!fCaps->validateSurfaceParams(dimensions,
177 format,
178 renderable,
179 renderTargetSampleCnt,
180 skgpu::Mipmapped::kNo,
181 textureType)) {
182 return nullptr;
183 }
184
185 auto tex = this->createApproxTexture(dimensions,
186 format,
187 textureType,
188 renderable,
189 renderTargetSampleCnt,
190 isProtected,
191 label);
192 if (!tex) {
193 return nullptr;
194 }
195 return this->writePixels(std::move(tex), colorType, dimensions, &mipLevel, 1);
196 } else {
197 return this->createTexture(dimensions,
198 format,
199 textureType,
200 colorType,
201 renderable,
202 renderTargetSampleCnt,
203 budgeted,
204 skgpu::Mipmapped::kNo,
205 isProtected,
206 &mipLevel,
207 label);
208 }
209}
static SkColorType colorType(AImageDecoder *decoder, const AImageDecoderHeaderInfo *headerInfo)
sk_sp< GrTexture > createApproxTexture(SkISize dimensions, const GrBackendFormat &format, GrTextureType textureType, skgpu::Renderable renderable, int renderTargetSampleCnt, skgpu::Protected isProtected, std::string_view label)
sk_sp< GrTexture > createTexture(SkISize dimensions, const GrBackendFormat &format, GrTextureType textureType, skgpu::Renderable renderable, int renderTargetSampleCnt, skgpu::Mipmapped mipmapped, skgpu::Budgeted budgeted, skgpu::Protected isProtected, std::string_view label)
const void * fPixels

◆ createTexture() [2/3]

sk_sp< GrTexture > GrResourceProvider::createTexture ( SkISize  dimensions,
const GrBackendFormat format,
GrTextureType  textureType,
GrColorType  colorType,
skgpu::Renderable  renderable,
int  renderTargetSampleCnt,
skgpu::Budgeted  budgeted,
skgpu::Mipmapped  mipmapped,
skgpu::Protected  isProtected,
const GrMipLevel  texels[],
std::string_view  label 
)

Create an exact fit texture with initial data to upload. The color type must be valid for the format and also describe the texel data. This will ensure any conversions that need to get applied to the data before upload are applied.

Definition at line 60 of file GrResourceProvider.cpp.

70 {
72
73 if (this->isAbandoned()) {
74 return nullptr;
75 }
76
77 int numMipLevels = 1;
78 if (mipmapped == skgpu::Mipmapped::kYes) {
79 numMipLevels = SkMipmap::ComputeLevelCount(dimensions.fWidth, dimensions.fHeight) + 1;
80 }
81
82 if (!fCaps->validateSurfaceParams(dimensions,
83 format,
84 renderable,
85 renderTargetSampleCnt,
86 mipmapped,
87 textureType)) {
88 return nullptr;
89 }
90 // Current rule is that you can provide no level data, just the base, or all the levels.
91 bool hasPixels = texels[0].fPixels;
92 auto scratch = this->getExactScratch(dimensions,
93 format,
94 textureType,
95 renderable,
96 renderTargetSampleCnt,
97 budgeted,
98 mipmapped,
99 isProtected,
100 label);
101 if (scratch) {
102 if (!hasPixels) {
103 return scratch;
104 }
105 return this->writePixels(std::move(scratch), colorType, dimensions, texels, numMipLevels);
106 }
109 GrColorType tempColorType = GrColorType::kUnknown;
110 if (hasPixels) {
111 tempColorType = this->prepareLevels(format, colorType, dimensions, texels, numMipLevels,
112 &tmpTexels, &tmpDatas);
113 if (tempColorType == GrColorType::kUnknown) {
114 return nullptr;
115 }
116 }
117 return fGpu->createTexture(dimensions,
118 format,
119 textureType,
120 renderable,
121 renderTargetSampleCnt,
122 budgeted,
123 isProtected,
124 colorType,
125 tempColorType,
126 tmpTexels.get(),
127 numMipLevels,
128 label);
129}
GrColorType
static int ComputeLevelCount(int baseWidth, int baseHeight)
Definition SkMipmap.cpp:134
int32_t fHeight
Definition SkSize.h:18
int32_t fWidth
Definition SkSize.h:17

◆ createTexture() [3/3]

sk_sp< GrTexture > GrResourceProvider::createTexture ( SkISize  dimensions,
const GrBackendFormat format,
GrTextureType  textureType,
skgpu::Renderable  renderable,
int  renderTargetSampleCnt,
skgpu::Mipmapped  mipmapped,
skgpu::Budgeted  budgeted,
skgpu::Protected  isProtected,
std::string_view  label 
)

Create an exact fit texture with no initial data to upload.

Definition at line 231 of file GrResourceProvider.cpp.

239 {
241 if (this->isAbandoned()) {
242 return nullptr;
243 }
244
245 if (!fCaps->validateSurfaceParams(dimensions, format, renderable, renderTargetSampleCnt,
246 mipmapped, textureType)) {
247 return nullptr;
248 }
249
250 // Currently we don't recycle compressed textures as scratch. Additionally all compressed
251 // textures should be created through the createCompressedTexture function.
252 SkASSERT(!this->caps()->isFormatCompressed(format));
253
254 // TODO: Support skgpu::Mipmapped::kYes in scratch texture lookup here.
255 sk_sp<GrTexture> tex =
256 this->getExactScratch(dimensions,
257 format,
258 textureType,
259 renderable,
260 renderTargetSampleCnt,
261 budgeted,
262 mipmapped,
263 isProtected,
264 label);
265 if (tex) {
266 return tex;
267 }
268
269 return fGpu->createTexture(dimensions,
270 format,
271 textureType,
272 renderable,
273 renderTargetSampleCnt,
274 mipmapped,
275 budgeted,
276 isProtected,
277 label);
278}

◆ findAndRefScratchTexture() [1/2]

sk_sp< GrTexture > GrResourceProvider::findAndRefScratchTexture ( const skgpu::ScratchKey key,
std::string_view  label 
)

Search the cache for a scratch texture matching the provided arguments. Failing that it returns null. If non-null, the resulting texture is always budgeted.

Definition at line 330 of file GrResourceProvider.cpp.

331 {
333 SkASSERT(!this->isAbandoned());
334 SkASSERT(key.isValid());
335
336 if (GrGpuResource* resource = fCache->findAndRefScratchResource(key)) {
338 GrSurface* surface = static_cast<GrSurface*>(resource);
339 resource->setLabel(std::move(label));
340 return sk_sp<GrTexture>(surface->asTexture());
341 }
342 return nullptr;
343}
void setLabel(std::string_view label)
void incNumScratchTexturesReused()
Definition GrGpu.h:544
Stats * stats()
Definition GrGpu.h:551
GrGpuResource * findAndRefScratchResource(const skgpu::ScratchKey &scratchKey)
VkSurfaceKHR surface
Definition main.cc:49

◆ findAndRefScratchTexture() [2/2]

sk_sp< GrTexture > GrResourceProvider::findAndRefScratchTexture ( SkISize  dimensions,
const GrBackendFormat format,
GrTextureType  textureType,
skgpu::Renderable  renderable,
int  renderTargetSampleCnt,
skgpu::Mipmapped  mipmapped,
skgpu::Protected  isProtected,
std::string_view  label 
)

Definition at line 345 of file GrResourceProvider.cpp.

352 {
354 SkASSERT(!this->isAbandoned());
355 SkASSERT(!this->caps()->isFormatCompressed(format));
356 SkASSERT(fCaps->validateSurfaceParams(dimensions,
357 format,
358 renderable,
359 renderTargetSampleCnt,
360 skgpu::Mipmapped::kNo,
361 textureType));
362
363 // We could make initial clears work with scratch textures but it is a rare case so we just opt
364 // to fall back to making a new texture.
365 if (fGpu->caps()->reuseScratchTextures() || renderable == GrRenderable::kYes) {
367 GrTexture::ComputeScratchKey(*this->caps(), format, dimensions, renderable,
368 renderTargetSampleCnt, mipmapped, isProtected, &key);
369 return this->findAndRefScratchTexture(key, label);
370 }
371
372 return nullptr;
373}
bool reuseScratchTextures() const
Definition GrCaps.h:217
static void ComputeScratchKey(const GrCaps &caps, const GrBackendFormat &format, SkISize dimensions, GrRenderable, int sampleCnt, skgpu::Mipmapped, GrProtected, skgpu::ScratchKey *key)

◆ findByUniqueKey()

template<typename T = GrGpuResource>
std::enable_if< std::is_base_of< GrGpuResource, T >::value, sk_sp< T > >::type GrResourceProvider::findByUniqueKey ( const skgpu::UniqueKey key)
inline

Finds a resource in the cache, based on the specified key. Prior to calling this, the caller must be sure that if a resource of exists in the cache with the given unique key then it is of type T.

Definition at line 70 of file GrResourceProvider.h.

70 {
71 return sk_sp<T>(static_cast<T*>(this->findResourceByUniqueKey(key).release()));
72 }
#define T

◆ findOrCreatePatternedIndexBuffer()

sk_sp< const GrGpuBuffer > GrResourceProvider::findOrCreatePatternedIndexBuffer ( const uint16_t *  pattern,
int  patternSize,
int  reps,
int  vertCount,
const skgpu::UniqueKey key 
)
inline

Either finds and refs, or creates an index buffer with a repeating pattern for drawing contiguous vertices of a repeated mesh. If the return is non-null, the caller owns a ref on the returned GrBuffer.

Parameters
patternthe pattern of indices to repeat
patternSizesize in bytes of the pattern
repsnumber of times to repeat the pattern
vertCountnumber of vertices the pattern references
keyKey to be assigned to the index buffer.
Returns
The index buffer if successful, otherwise nullptr.

Definition at line 254 of file GrResourceProvider.h.

258 {
259 if (auto buffer = this->findByUniqueKey<const GrGpuBuffer>(key)) {
260 return buffer;
261 }
262 return this->createPatternedIndexBuffer(pattern, patternSize, reps, vertCount, &key);
263 }

◆ findOrMakeStaticBuffer() [1/2]

sk_sp< const GrGpuBuffer > GrResourceProvider::findOrMakeStaticBuffer ( GrGpuBufferType  intendedType,
size_t  size,
const skgpu::UniqueKey key,
InitializeBufferFn  initializeBufferFn 
)

Definition at line 460 of file GrResourceProvider.cpp.

464 {
465 if (auto buffer = this->findByUniqueKey<GrGpuBuffer>(uniqueKey)) {
466 return buffer;
467 }
468
469 auto buffer = this->createBuffer(size,
470 intendedType,
473 if (!buffer) {
474 return nullptr;
475 }
476
477 // We shouldn't bin and/or cache static buffers.
478 SkASSERT(buffer->size() == size);
479 SkASSERT(!buffer->resourcePriv().getScratchKey().isValid());
480
481 buffer->resourcePriv().setUniqueKey(uniqueKey);
482
483 // Map the buffer. Use a staging buffer on the heap if mapping isn't supported.
484 skgpu::VertexWriter vertexWriter = {buffer->map(), size};
485 AutoTMalloc<char> stagingBuffer;
486 if (!vertexWriter) {
487 SkASSERT(!buffer->isMapped());
488 vertexWriter = {stagingBuffer.reset(size), size};
489 }
490
491 initializeBufferFn(std::move(vertexWriter), size);
492
493 if (buffer->isMapped()) {
494 buffer->unmap();
495 } else {
496 buffer->updateData(stagingBuffer, /*offset=*/0, size, /*preserve=*/false);
497 }
498
499 return buffer;
500}
@ kStatic_GrAccessPattern
T * reset(size_t count=0)

◆ findOrMakeStaticBuffer() [2/2]

sk_sp< const GrGpuBuffer > GrResourceProvider::findOrMakeStaticBuffer ( GrGpuBufferType  intendedType,
size_t  size,
const void *  staticData,
const skgpu::UniqueKey key 
)

Either finds and refs, or creates a static buffer with the given parameters and contents.

Parameters
intendedTypehint to the graphics subsystem about what the buffer will be used for.
sizeminimum size of buffer to return.
dataoptional data with which to initialize the buffer.
keyKey to be assigned to the buffer.
Returns
The buffer if successful, otherwise nullptr.

Definition at line 438 of file GrResourceProvider.cpp.

441 {
442 if (auto buffer = this->findByUniqueKey<GrGpuBuffer>(key)) {
443 return buffer;
444 }
445
446 auto buffer = this->createBuffer(staticData, size, intendedType, kStatic_GrAccessPattern);
447 if (!buffer) {
448 return nullptr;
449 }
450
451 // We shouldn't bin and/or cache static buffers.
452 SkASSERT(buffer->size() == size);
453 SkASSERT(!buffer->resourcePriv().getScratchKey().isValid());
454
455 buffer->resourcePriv().setUniqueKey(key);
456
457 return buffer;
458}

◆ getDiscardableMSAAAttachment()

sk_sp< GrAttachment > GrResourceProvider::getDiscardableMSAAAttachment ( SkISize  dimensions,
const GrBackendFormat format,
int  sampleCnt,
skgpu::Protected  isProtected,
GrMemoryless  memoryless 
)

Gets a GrAttachment that can be used for MSAA rendering. This attachment may be shared by other users. Thus any renderpass that uses the attachment should not assume any specific data at the start and should not try to save written data at the end. Ideally the render pass should discard the data at the end.

Definition at line 716 of file GrResourceProvider.cpp.

720 {
722
723 SkASSERT(sampleCnt > 1);
724
725 if (this->isAbandoned()) {
726 return nullptr;
727 }
728
729 if (!fCaps->validateSurfaceParams(dimensions,
730 format,
731 GrRenderable::kYes,
732 sampleCnt,
733 skgpu::Mipmapped::kNo,
735 return nullptr;
736 }
737
740 format,
741 dimensions,
743 sampleCnt,
744 skgpu::Mipmapped::kNo,
745 isProtected,
746 memoryless,
747 &key);
748 auto msaaAttachment = this->findByUniqueKey<GrAttachment>(key);
749 if (msaaAttachment) {
750 return msaaAttachment;
751 }
752 msaaAttachment = this->makeMSAAAttachment(dimensions, format, sampleCnt, isProtected,
753 memoryless);
754 if (msaaAttachment) {
755 this->assignUniqueKeyToResource(key, msaaAttachment.get());
756 }
757 return msaaAttachment;
758}
sk_sp< GrAttachment > makeMSAAAttachment(SkISize dimensions, const GrBackendFormat &format, int sampleCnt, skgpu::Protected isProtected, GrMemoryless isMemoryless)

◆ makeMSAAAttachment()

sk_sp< GrAttachment > GrResourceProvider::makeMSAAAttachment ( SkISize  dimensions,
const GrBackendFormat format,
int  sampleCnt,
skgpu::Protected  isProtected,
GrMemoryless  isMemoryless 
)

Definition at line 760 of file GrResourceProvider.cpp.

764 {
766
767 SkASSERT(sampleCnt > 1);
768
769 if (this->isAbandoned()) {
770 return nullptr;
771 }
772
773 if (!fCaps->validateSurfaceParams(dimensions,
774 format,
775 GrRenderable::kYes,
776 sampleCnt,
777 skgpu::Mipmapped::kNo,
779 return nullptr;
780 }
781
782 auto scratch = this->refScratchMSAAAttachment(dimensions,
783 format,
784 sampleCnt,
785 isProtected,
786 memoryless,
787 /*label=*/"MakeMSAAAttachment");
788 if (scratch) {
789 return scratch;
790 }
791
792 return fGpu->makeMSAAAttachment(dimensions, format, sampleCnt, isProtected, memoryless);
793}
virtual sk_sp< GrAttachment > makeMSAAAttachment(SkISize dimensions, const GrBackendFormat &format, int numSamples, GrProtected isProtected, GrMemoryless isMemoryless)=0

◆ makeSemaphore()

std::unique_ptr< GrSemaphore > GrResourceProvider::makeSemaphore ( bool  isOwned = true)

Definition at line 832 of file GrResourceProvider.cpp.

832 {
833 return this->isAbandoned() ? nullptr : fGpu->makeSemaphore(isOwned);
834}
virtual std::unique_ptr< GrSemaphore > makeSemaphore(bool isOwned=true)=0

◆ MaxNumAAQuads()

int GrResourceProvider::MaxNumAAQuads ( )
static

Definition at line 590 of file GrResourceProvider.cpp.

590{ return kMaxNumAAQuads; }
static constexpr int kMaxNumAAQuads

◆ MaxNumNonAAQuads()

int GrResourceProvider::MaxNumNonAAQuads ( )
static

Definition at line 562 of file GrResourceProvider.cpp.

562{ return kMaxNumNonAAQuads; }
static constexpr int kMaxNumNonAAQuads

◆ NumIndicesPerAAQuad()

int GrResourceProvider::NumIndicesPerAAQuad ( )
static

Definition at line 592 of file GrResourceProvider.cpp.

592{ return kIndicesPerAAQuad; }
static const int kIndicesPerAAQuad

◆ NumIndicesPerNonAAQuad()

int GrResourceProvider::NumIndicesPerNonAAQuad ( )
static

Definition at line 564 of file GrResourceProvider.cpp.

564{ return kIndicesPerNonAAQuad; }
static const int kIndicesPerNonAAQuad

◆ NumVertsPerAAQuad()

int GrResourceProvider::NumVertsPerAAQuad ( )
static

Definition at line 591 of file GrResourceProvider.cpp.

591{ return kVertsPerAAQuad; }
static const int kVertsPerAAQuad

◆ NumVertsPerNonAAQuad()

int GrResourceProvider::NumVertsPerNonAAQuad ( )
static

Definition at line 563 of file GrResourceProvider.cpp.

563{ return kVertsPerNonAAQuad; }
static const int kVertsPerNonAAQuad

◆ overBudget()

bool GrResourceProvider::overBudget ( ) const
inline

Definition at line 364 of file GrResourceProvider.h.

364{ return fCache->overBudget(); }
bool overBudget() const

◆ priv() [1/2]

GrResourceProviderPriv GrResourceProvider::priv ( )
inline

Definition at line 32 of file GrResourceProviderPriv.h.

32{ return GrResourceProviderPriv(this); }
friend class GrResourceProviderPriv

◆ priv() [2/2]

const GrResourceProviderPriv GrResourceProvider::priv ( ) const
inline

Definition at line 34 of file GrResourceProviderPriv.h.

34 { // NOLINT(readability-const-return-type)
35 return GrResourceProviderPriv(const_cast<GrResourceProvider*>(this));
36}

◆ refAAQuadIndexBuffer()

sk_sp< const GrGpuBuffer > GrResourceProvider::refAAQuadIndexBuffer ( )
inline

Returns an index buffer that can be used to render antialiased quads. Each quad consumes 30 indices and 8 vertices. Call MaxNumAAQuads to get the max allowed number of AA quads. Draw with GrPrimitiveType::kTriangles @ return the AA quad index buffer

Definition at line 290 of file GrResourceProvider.h.

290 {
291 if (!fAAQuadIndexBuffer) {
292 fAAQuadIndexBuffer = this->createAAQuadIndexBuffer();
293 }
294 return fAAQuadIndexBuffer;
295 }

◆ refNonAAQuadIndexBuffer()

sk_sp< const GrGpuBuffer > GrResourceProvider::refNonAAQuadIndexBuffer ( )
inline

Returns an index buffer that can be used to render non-antialiased quads. Each quad consumes 6 indices (0, 1, 2, 2, 1, 3) and 4 vertices. Call MaxNumNonAAQuads to get the max allowed number of non-AA quads. Draw with GrPrimitiveType::kTriangles @ return the non-AA quad index buffer

Definition at line 272 of file GrResourceProvider.h.

272 {
273 if (!fNonAAQuadIndexBuffer) {
274 fNonAAQuadIndexBuffer = this->createNonAAQuadIndexBuffer();
275 }
276 return fNonAAQuadIndexBuffer;
277 }

◆ wrapBackendRenderTarget()

sk_sp< GrRenderTarget > GrResourceProvider::wrapBackendRenderTarget ( const GrBackendRenderTarget backendRT)

Wraps an existing render target with a GrRenderTarget object. It is similar to wrapBackendTexture but can be used to draw into surfaces that are not also textures (e.g. FBO 0 in OpenGL, or an MSAA buffer that the client will resolve to a texture). Currently wrapped render targets always use the kBorrow_GrWrapOwnership and GrWrapCacheable::kNo semantics.

Returns
GrRenderTarget object or NULL on failure.

Definition at line 409 of file GrResourceProvider.cpp.

410 {
412 return this->isAbandoned() ? nullptr : fGpu->wrapBackendRenderTarget(backendRT);
413}
sk_sp< GrRenderTarget > wrapBackendRenderTarget(const GrBackendRenderTarget &)
Definition GrGpu.cpp:366

◆ wrapBackendSemaphore()

std::unique_ptr< GrSemaphore > GrResourceProvider::wrapBackendSemaphore ( const GrBackendSemaphore semaphore,
GrSemaphoreWrapType  wrapType,
GrWrapOwnership  ownership = kBorrow_GrWrapOwnership 
)

Definition at line 836 of file GrResourceProvider.cpp.

839 {
841 return this->isAbandoned() ? nullptr : fGpu->wrapBackendSemaphore(semaphore,
842 wrapType,
843 ownership);
844}
virtual std::unique_ptr< GrSemaphore > wrapBackendSemaphore(const GrBackendSemaphore &, GrSemaphoreWrapType, GrWrapOwnership)=0

◆ wrapBackendTexture()

sk_sp< GrTexture > GrResourceProvider::wrapBackendTexture ( const GrBackendTexture tex,
GrWrapOwnership  ownership,
GrWrapCacheable  cacheable,
GrIOType  ioType 
)

Wraps an existing texture with a GrTexture object.

GrIOType must either be kRead or kRW. kRead blocks any operations that would modify the pixels (e.g. dst for a copy, regenerating MIP levels, write pixels).

OpenGL: if the object is a texture Gr may change its GL texture params when it is drawn.

Returns
GrTexture object or NULL on failure.

Definition at line 375 of file GrResourceProvider.cpp.

378 {
380 if (this->isAbandoned()) {
381 return nullptr;
382 }
383 return fGpu->wrapBackendTexture(tex, ownership, cacheable, ioType);
384}
sk_sp< GrTexture > wrapBackendTexture(const GrBackendTexture &, GrWrapOwnership, GrWrapCacheable, GrIOType)
Definition GrGpu.cpp:297

◆ wrapCompressedBackendTexture()

sk_sp< GrTexture > GrResourceProvider::wrapCompressedBackendTexture ( const GrBackendTexture tex,
GrWrapOwnership  ownership,
GrWrapCacheable  cacheable 
)

Definition at line 386 of file GrResourceProvider.cpp.

388 {
390 if (this->isAbandoned()) {
391 return nullptr;
392 }
393
394 return fGpu->wrapCompressedBackendTexture(tex, ownership, cacheable);
395}
sk_sp< GrTexture > wrapCompressedBackendTexture(const GrBackendTexture &, GrWrapOwnership, GrWrapCacheable)
Definition GrGpu.cpp:318

◆ wrapRenderableBackendTexture()

sk_sp< GrTexture > GrResourceProvider::wrapRenderableBackendTexture ( const GrBackendTexture tex,
int  sampleCnt,
GrWrapOwnership  ownership,
GrWrapCacheable  cacheable 
)

This makes the backend texture be renderable. If sampleCnt is > 1 and the underlying API uses separate MSAA render buffers then a MSAA render buffer is created that resolves to the texture.

Definition at line 398 of file GrResourceProvider.cpp.

401 {
403 if (this->isAbandoned()) {
404 return nullptr;
405 }
406 return fGpu->wrapRenderableBackendTexture(tex, sampleCnt, ownership, cacheable);
407}
sk_sp< GrTexture > wrapRenderableBackendTexture(const GrBackendTexture &, int sampleCnt, GrWrapOwnership, GrWrapCacheable)
Definition GrGpu.cpp:337

◆ wrapVulkanSecondaryCBAsRenderTarget()

sk_sp< GrRenderTarget > GrResourceProvider::wrapVulkanSecondaryCBAsRenderTarget ( const SkImageInfo imageInfo,
const GrVkDrawableInfo vkInfo 
)

Definition at line 415 of file GrResourceProvider.cpp.

416 {
418 return this->isAbandoned() ? nullptr : fGpu->wrapVulkanSecondaryCBAsRenderTarget(imageInfo,
419 vkInfo);
420
421}
sk_sp< GrRenderTarget > wrapVulkanSecondaryCBAsRenderTarget(const SkImageInfo &, const GrVkDrawableInfo &)
Definition GrGpu.cpp:382

Friends And Related Symbol Documentation

◆ GrResourceProviderPriv

friend class GrResourceProviderPriv
friend

Definition at line 421 of file GrResourceProvider.h.


The documentation for this class was generated from the following files: