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

#include <GrProxyProvider.h>

Classes

struct  TextureInfo
 

Public Types

enum class  InvalidateGPUResource : bool { kNo = false , kYes = true }
 
using UseAllocator = GrSurfaceProxy::UseAllocator
 
typedef void * ReleaseContext
 
typedef void(* ReleaseProc) (ReleaseContext)
 
using LazyInstantiationKeyMode = GrSurfaceProxy::LazyInstantiationKeyMode
 
using LazySurfaceDesc = GrSurfaceProxy::LazySurfaceDesc
 
using LazyCallbackResult = GrSurfaceProxy::LazyCallbackResult
 
using LazyInstantiateCallback = GrSurfaceProxy::LazyInstantiateCallback
 

Public Member Functions

 GrProxyProvider (GrImageContext *)
 
 ~GrProxyProvider ()
 
bool assignUniqueKeyToProxy (const skgpu::UniqueKey &, GrTextureProxy *)
 
void adoptUniqueKeyFromSurface (GrTextureProxy *proxy, const GrSurface *)
 
void removeUniqueKeyFromProxy (GrTextureProxy *)
 
sk_sp< GrTextureProxyfindProxyByUniqueKey (const skgpu::UniqueKey &)
 
sk_sp< GrTextureProxyfindOrCreateProxyByUniqueKey (const skgpu::UniqueKey &, UseAllocator=UseAllocator::kYes)
 
GrSurfaceProxyView findCachedProxyWithColorTypeFallback (const skgpu::UniqueKey &, GrSurfaceOrigin, GrColorType, int sampleCnt)
 
sk_sp< GrTextureProxycreateProxyFromBitmap (const SkBitmap &, skgpu::Mipmapped, SkBackingFit, skgpu::Budgeted)
 
sk_sp< GrTextureProxycreateProxy (const GrBackendFormat &, SkISize dimensions, GrRenderable, int renderTargetSampleCnt, skgpu::Mipmapped, SkBackingFit, skgpu::Budgeted, GrProtected, std::string_view label, GrInternalSurfaceFlags=GrInternalSurfaceFlags::kNone, UseAllocator useAllocator=UseAllocator::kYes)
 
sk_sp< GrTextureProxycreateCompressedTextureProxy (SkISize dimensions, skgpu::Budgeted, skgpu::Mipmapped, GrProtected, SkTextureCompressionType, sk_sp< SkData > data)
 
sk_sp< GrTextureProxywrapBackendTexture (const GrBackendTexture &, GrWrapOwnership, GrWrapCacheable, GrIOType, sk_sp< skgpu::RefCntedCallback >=nullptr)
 
sk_sp< GrTextureProxywrapCompressedBackendTexture (const GrBackendTexture &, GrWrapOwnership, GrWrapCacheable, sk_sp< skgpu::RefCntedCallback >)
 
sk_sp< GrTextureProxywrapRenderableBackendTexture (const GrBackendTexture &, int sampleCnt, GrWrapOwnership, GrWrapCacheable, sk_sp< skgpu::RefCntedCallback > releaseHelper)
 
sk_sp< GrSurfaceProxywrapBackendRenderTarget (const GrBackendRenderTarget &, sk_sp< skgpu::RefCntedCallback > releaseHelper)
 
sk_sp< GrTextureProxycreateLazyProxy (LazyInstantiateCallback &&, const GrBackendFormat &, SkISize dimensions, skgpu::Mipmapped, GrMipmapStatus, GrInternalSurfaceFlags, SkBackingFit, skgpu::Budgeted, GrProtected, UseAllocator, std::string_view label)
 
sk_sp< GrRenderTargetProxycreateLazyRenderTargetProxy (LazyInstantiateCallback &&, const GrBackendFormat &, SkISize dimensions, int renderTargetSampleCnt, GrInternalSurfaceFlags, const TextureInfo *, GrMipmapStatus, SkBackingFit, skgpu::Budgeted, GrProtected, bool wrapsVkSecondaryCB, UseAllocator useAllocator)
 
void processInvalidUniqueKey (const skgpu::UniqueKey &, GrTextureProxy *, InvalidateGPUResource)
 
GrDDLProvider isDDLProvider () const
 
uint32_t contextID () const
 
const GrCapscaps () const
 
sk_sp< const GrCapsrefCaps () const
 
GrResourceProviderresourceProvider () const
 
int numUniqueKeyProxies_TestOnly () const
 
void orphanAllUniqueKeys ()
 
void removeAllUniqueKeys ()
 
bool renderingDirectly () const
 
bool isAbandoned () const
 

Static Public Member Functions

static sk_sp< GrTextureProxyCreatePromiseProxy (GrContextThreadSafeProxy *, LazyInstantiateCallback &&, const GrBackendFormat &, SkISize dimensions, skgpu::Mipmapped)
 
static sk_sp< GrTextureProxyMakeFullyLazyProxy (LazyInstantiateCallback &&, const GrBackendFormat &, GrRenderable, int renderTargetSampleCnt, GrProtected, const GrCaps &, UseAllocator)
 

Friends

class GrAHardwareBufferImageGenerator
 
class GrResourceProvider
 

Detailed Description

Definition at line 28 of file GrProxyProvider.h.

Member Typedef Documentation

◆ LazyCallbackResult

Definition at line 147 of file GrProxyProvider.h.

◆ LazyInstantiateCallback

Definition at line 148 of file GrProxyProvider.h.

◆ LazyInstantiationKeyMode

Definition at line 145 of file GrProxyProvider.h.

◆ LazySurfaceDesc

Definition at line 146 of file GrProxyProvider.h.

◆ ReleaseContext

Definition at line 112 of file GrProxyProvider.h.

◆ ReleaseProc

typedef void(* GrProxyProvider::ReleaseProc) (ReleaseContext)

Definition at line 113 of file GrProxyProvider.h.

◆ UseAllocator

Definition at line 30 of file GrProxyProvider.h.

Member Enumeration Documentation

◆ InvalidateGPUResource

enum class GrProxyProvider::InvalidateGPUResource : bool
strong
Enumerator
kNo 
kYes 

Definition at line 213 of file GrProxyProvider.h.

Constructor & Destructor Documentation

◆ GrProxyProvider()

GrProxyProvider::GrProxyProvider ( GrImageContext imageContext)

Definition at line 38 of file GrProxyProvider.cpp.

38: fImageContext(imageContext) {}

◆ ~GrProxyProvider()

GrProxyProvider::~GrProxyProvider ( )

Definition at line 40 of file GrProxyProvider.cpp.

40 {
41 if (this->renderingDirectly()) {
42 // In DDL-mode a proxy provider can still have extant uniquely keyed proxies (since
43 // they need their unique keys to, potentially, find a cached resource when the
44 // DDL is played) but, in non-DDL-mode they should all have been cleaned up by this point.
45 SkASSERT(!fUniquelyKeyedProxies.count());
46 }
47}
#define SkASSERT(cond)
Definition SkAssert.h:116
bool renderingDirectly() const
int count() const

Member Function Documentation

◆ adoptUniqueKeyFromSurface()

void GrProxyProvider::adoptUniqueKeyFromSurface ( GrTextureProxy proxy,
const GrSurface surf 
)

Definition at line 80 of file GrProxyProvider.cpp.

80 {
81 SkASSERT(surf->getUniqueKey().isValid());
82 proxy->cacheAccess().setUniqueKey(this, surf->getUniqueKey());
83 SkASSERT(proxy->getUniqueKey() == surf->getUniqueKey());
84 // multiple proxies can't get the same key
85 SkASSERT(!fUniquelyKeyedProxies.find(surf->getUniqueKey()));
86 fUniquelyKeyedProxies.add(proxy);
87}
const skgpu::UniqueKey & getUniqueKey() const
const skgpu::UniqueKey & getUniqueKey() const override
T * find(const Key &key) const
void add(T *entry)
bool isValid() const
Definition ResourceKey.h:55

◆ assignUniqueKeyToProxy()

bool GrProxyProvider::assignUniqueKeyToProxy ( const skgpu::UniqueKey key,
GrTextureProxy proxy 
)

Definition at line 49 of file GrProxyProvider.cpp.

49 {
51 SkASSERT(key.isValid());
52 if (this->isAbandoned() || !proxy) {
53 return false;
54 }
55
56 // Only the proxyProvider that created a proxy should be assigning unique keys to it.
57 SkASSERT(this->isDDLProvider() == proxy->creatingProvider());
58
59#ifdef SK_DEBUG
60 {
61 auto direct = fImageContext->asDirectContext();
62 if (direct) {
63 GrResourceCache* resourceCache = direct->priv().getResourceCache();
64 // If there is already a GrResource with this key then the caller has violated the
65 // normal usage pattern of uniquely keyed resources (e.g., they have created one w/o
66 // first seeing if it already existed in the cache).
67 SkASSERT(!resourceCache->findAndRefUniqueResource(key));
68 }
69 }
70#endif
71
72 SkASSERT(!fUniquelyKeyedProxies.find(key)); // multiple proxies can't get the same key
73
74 proxy->cacheAccess().setUniqueKey(this, key);
75 SkASSERT(proxy->getUniqueKey() == key);
76 fUniquelyKeyedProxies.add(proxy);
77 return true;
78}
virtual GrDirectContext * asDirectContext()
bool isAbandoned() const
GrDDLProvider isDDLProvider() const
GrGpuResource * findAndRefUniqueResource(const skgpu::UniqueKey &key)
#define ASSERT_SINGLE_OWNER
Definition Device.cpp:120

◆ caps()

const GrCaps * GrProxyProvider::caps ( ) const

Definition at line 998 of file GrProxyProvider.cpp.

998 {
999 return fImageContext->priv().caps();
1000}
const GrCaps * caps() const
GrImageContextPriv priv()

◆ contextID()

uint32_t GrProxyProvider::contextID ( ) const

Definition at line 994 of file GrProxyProvider.cpp.

994 {
995 return fImageContext->priv().contextID();
996}
uint32_t contextID() const

◆ createCompressedTextureProxy()

sk_sp< GrTextureProxy > GrProxyProvider::createCompressedTextureProxy ( SkISize  dimensions,
skgpu::Budgeted  budgeted,
skgpu::Mipmapped  mipmapped,
GrProtected  isProtected,
SkTextureCompressionType  compressionType,
sk_sp< SkData data 
)

Definition at line 532 of file GrProxyProvider.cpp.

538 {
540 if (this->isAbandoned()) {
541 return nullptr;
542 }
543
545
546 if (!this->caps()->isFormatTexturable(format, GrTextureType::k2D)) {
547 return nullptr;
548 }
549
550 GrMipmapStatus mipmapStatus = (skgpu::Mipmapped::kYes == mipmapped)
553
556 return LazyCallbackResult(
558 desc.fFormat,
559 desc.fBudgeted,
560 desc.fMipmapped,
561 desc.fProtected,
562 data.get(),
563 desc.fLabel));
564 },
565 format,
566 dimensions,
567 mipmapped,
568 mipmapStatus,
572 GrProtected::kNo,
573 UseAllocator::kYes,
574 "ProxyProvider_CreateCompressedTextureProxy");
575
576 if (!proxy) {
577 return nullptr;
578 }
579
580 auto direct = fImageContext->asDirectContext();
581 if (direct) {
582 GrResourceProvider* resourceProvider = direct->priv().resourceProvider();
583 // In order to reuse code we always create a lazy proxy. When we aren't in DDL mode however
584 // we're better off instantiating the proxy immediately here.
585 if (!proxy->priv().doLazyInstantiation(resourceProvider)) {
586 return nullptr;
587 }
588 }
589 return proxy;
590}
GrMipmapStatus
virtual GrBackendFormat getBackendFormatFromCompressionType(SkTextureCompressionType) const =0
GrResourceProvider * resourceProvider() const
sk_sp< GrTextureProxy > createLazyProxy(LazyInstantiateCallback &&, const GrBackendFormat &, SkISize dimensions, skgpu::Mipmapped, GrMipmapStatus, GrInternalSurfaceFlags, SkBackingFit, skgpu::Budgeted, GrProtected, UseAllocator, std::string_view label)
GrSurfaceProxy::LazyCallbackResult LazyCallbackResult
GrSurfaceProxy::LazySurfaceDesc LazySurfaceDesc
const GrCaps * caps() const
GrResourceProviderPriv priv()
sk_sp< GrTexture > createCompressedTexture(SkISize dimensions, const GrBackendFormat &, skgpu::Budgeted, skgpu::Mipmapped, skgpu::Protected, SkData *data, std::string_view label)
uint32_t uint32_t * format
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

◆ createLazyProxy()

sk_sp< GrTextureProxy > GrProxyProvider::createLazyProxy ( LazyInstantiateCallback &&  callback,
const GrBackendFormat format,
SkISize  dimensions,
skgpu::Mipmapped  mipmapped,
GrMipmapStatus  mipmapStatus,
GrInternalSurfaceFlags  surfaceFlags,
SkBackingFit  fit,
skgpu::Budgeted  budgeted,
GrProtected  isProtected,
GrSurfaceProxy::UseAllocator  useAllocator,
std::string_view  label 
)

Creates a texture proxy that will be instantiated by a user-supplied callback during flush. The width and height must either both be greater than 0 or both less than or equal to zero. A non-positive value is a signal that the width height are currently unknown. The texture will not be renderable.

When called, the callback must be able to cleanup any resources that it captured at creation. It also must support being passed in a null GrResourceProvider. When this happens, the callback should cleanup any resources it captured and return an empty sk_sp<GrTextureProxy>.

Definition at line 790 of file GrProxyProvider.cpp.

800 {
802 if (this->isAbandoned()) {
803 return nullptr;
804 }
805 SkASSERT((dimensions.fWidth <= 0 && dimensions.fHeight <= 0) ||
806 (dimensions.fWidth > 0 && dimensions.fHeight > 0));
807
808 if (!format.isValid() || format.backend() != fImageContext->backend()) {
809 return nullptr;
810 }
811
812 if (dimensions.fWidth > this->caps()->maxTextureSize() ||
813 dimensions.fHeight > this->caps()->maxTextureSize()) {
814 return nullptr;
815 }
816
817 return sk_sp<GrTextureProxy>(new GrTextureProxy(std::move(callback),
818 format,
819 dimensions,
820 mipmapped,
821 mipmapStatus,
822 fit,
823 budgeted,
824 isProtected,
825 surfaceFlags,
826 useAllocator,
827 this->isDDLProvider(),
828 label));
829}
SK_API GrBackendApi backend() const
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
int32_t fHeight
Definition SkSize.h:18
int32_t fWidth
Definition SkSize.h:17

◆ createLazyRenderTargetProxy()

sk_sp< GrRenderTargetProxy > GrProxyProvider::createLazyRenderTargetProxy ( LazyInstantiateCallback &&  callback,
const GrBackendFormat format,
SkISize  dimensions,
int  renderTargetSampleCnt,
GrInternalSurfaceFlags  surfaceFlags,
const TextureInfo textureInfo,
GrMipmapStatus  mipmapStatus,
SkBackingFit  fit,
skgpu::Budgeted  budgeted,
GrProtected  isProtected,
bool  wrapsVkSecondaryCB,
UseAllocator  useAllocator 
)

A null TextureInfo indicates a non-textureable render target.

Definition at line 831 of file GrProxyProvider.cpp.

843 {
845 if (this->isAbandoned()) {
846 return nullptr;
847 }
848 SkASSERT((dimensions.fWidth <= 0 && dimensions.fHeight <= 0) ||
849 (dimensions.fWidth > 0 && dimensions.fHeight > 0));
850
851 if (dimensions.fWidth > this->caps()->maxRenderTargetSize() ||
852 dimensions.fHeight > this->caps()->maxRenderTargetSize()) {
853 return nullptr;
854 }
855
856 if (textureInfo) {
857 // Wrapped vulkan secondary command buffers don't support texturing since we won't have an
858 // actual VkImage to texture from.
859 SkASSERT(!wrapsVkSecondaryCB);
861 *this->caps(),
862 std::move(callback),
863 format,
864 dimensions,
865 sampleCnt,
866 textureInfo->fMipmapped,
867 mipmapStatus,
868 fit,
869 budgeted,
870 isProtected,
871 surfaceFlags,
872 useAllocator,
873 this->isDDLProvider(),
874 /*label=*/"TextureRenderTarget_LazyRenderTargetProxy"));
875 }
876
880
882 new GrRenderTargetProxy(std::move(callback),
883 format,
884 dimensions,
885 sampleCnt,
886 fit,
887 budgeted,
888 isProtected,
889 surfaceFlags,
890 useAllocator,
891 vkSCB,
892 /*label=*/"RenderTargetProxy_LazyRenderTargetProxy"));
893}

◆ CreatePromiseProxy()

sk_sp< GrTextureProxy > GrProxyProvider::CreatePromiseProxy ( GrContextThreadSafeProxy threadSafeProxy,
LazyInstantiateCallback &&  callback,
const GrBackendFormat format,
SkISize  dimensions,
skgpu::Mipmapped  mipmapped 
)
static

Similar to createLazyProxy below, except narrowed to the use case of shared promise images i.e. static so it doesn't have access to mutable state. Used by MakePromiseImageLazyProxy().

Definition at line 748 of file GrProxyProvider.cpp.

752 {
753 if (threadSafeProxy->priv().abandoned()) {
754 return nullptr;
755 }
756 SkASSERT((dimensions.fWidth <= 0 && dimensions.fHeight <= 0) ||
757 (dimensions.fWidth > 0 && dimensions.fHeight > 0));
758
759 if (dimensions.fWidth > threadSafeProxy->priv().caps()->maxTextureSize() ||
760 dimensions.fHeight > threadSafeProxy->priv().caps()->maxTextureSize()) {
761 return nullptr;
762 }
763 if (!threadSafeProxy->priv().caps()->isFormatTexturable(format, format.textureType())) {
764 return nullptr;
765 }
766 // Ganesh assumes that, when wrapping a mipmapped backend texture from a client, that its
767 // mipmaps are fully fleshed out.
768 GrMipmapStatus mipmapStatus = (skgpu::Mipmapped::kYes == mipmapped)
771
772 // We pass kReadOnly here since we should treat content of the client's texture as immutable.
773 // The promise API provides no way for the client to indicate that the texture is protected.
774 auto proxy = sk_sp<GrTextureProxy>(new GrTextureProxy(std::move(callback),
775 format,
776 dimensions,
777 mipmapped,
778 mipmapStatus,
781 GrProtected::kNo,
785 /*label=*/"PromiseProxy"));
786 proxy->priv().setIsPromiseProxy();
787 return proxy;
788}
virtual bool isFormatTexturable(const GrBackendFormat &, GrTextureType) const =0
int maxTextureSize() const
Definition GrCaps.h:229
GrContextThreadSafeProxyPriv priv()

◆ createProxy()

sk_sp< GrTextureProxy > GrProxyProvider::createProxy ( const GrBackendFormat format,
SkISize  dimensions,
GrRenderable  renderable,
int  renderTargetSampleCnt,
skgpu::Mipmapped  mipmapped,
SkBackingFit  fit,
skgpu::Budgeted  budgeted,
GrProtected  isProtected,
std::string_view  label,
GrInternalSurfaceFlags  surfaceFlags = GrInternalSurfaceFlags::kNone,
GrSurfaceProxy::UseAllocator  useAllocator = UseAllocator::kYes 
)

Definition at line 456 of file GrProxyProvider.cpp.

466 {
468 if (this->isAbandoned()) {
469 return nullptr;
470 }
471
472 const GrCaps* caps = this->caps();
473
474 if (caps->isFormatCompressed(format)) {
475 // Deferred proxies for compressed textures are not supported.
476 return nullptr;
477 }
478
479 if (skgpu::Mipmapped::kYes == mipmapped) {
480 // SkMipmap doesn't include the base level in the level count so we have to add 1
481 int mipCount = SkMipmap::ComputeLevelCount(dimensions.fWidth, dimensions.fHeight) + 1;
482 if (1 == mipCount) {
483 mipmapped = skgpu::Mipmapped::kNo;
484 }
485 }
486
487 if (!caps->validateSurfaceParams(dimensions,
488 format,
489 renderable,
490 renderTargetSampleCnt,
491 mipmapped,
493 return nullptr;
494 }
495 GrMipmapStatus mipmapStatus = (skgpu::Mipmapped::kYes == mipmapped)
498 if (renderable == GrRenderable::kYes) {
499 renderTargetSampleCnt = caps->getRenderTargetSampleCount(renderTargetSampleCnt, format);
500 SkASSERT(renderTargetSampleCnt);
502 // We know anything we instantiate later from this deferred path will be
503 // both texturable and renderable
505 format,
506 dimensions,
507 renderTargetSampleCnt,
508 mipmapped,
509 mipmapStatus,
510 fit,
511 budgeted,
512 isProtected,
513 surfaceFlags | extraFlags,
514 useAllocator,
515 this->isDDLProvider(),
516 label));
517 }
518
520 dimensions,
521 mipmapped,
522 mipmapStatus,
523 fit,
524 budgeted,
525 isProtected,
526 surfaceFlags,
527 useAllocator,
528 this->isDDLProvider(),
529 label));
530}
GrInternalSurfaceFlags
virtual GrInternalSurfaceFlags getExtraSurfaceFlagsForDeferredRT() const
Definition GrCaps.h:533
bool isFormatCompressed(const GrBackendFormat &format) const
Definition GrCaps.cpp:457
bool validateSurfaceParams(const SkISize &, const GrBackendFormat &, GrRenderable renderable, int renderTargetSampleCnt, skgpu::Mipmapped, GrTextureType) const
Definition GrCaps.cpp:327
virtual int getRenderTargetSampleCount(int requestedCount, const GrBackendFormat &) const =0
static int ComputeLevelCount(int baseWidth, int baseHeight)
Definition SkMipmap.cpp:134

◆ createProxyFromBitmap()

sk_sp< GrTextureProxy > GrProxyProvider::createProxyFromBitmap ( const SkBitmap bitmap,
skgpu::Mipmapped  mipmapped,
SkBackingFit  fit,
skgpu::Budgeted  budgeted 
)

Definition at line 271 of file GrProxyProvider.cpp.

274 {
276 SkASSERT(fit == SkBackingFit::kExact || mipmapped == skgpu::Mipmapped::kNo);
277
278 if (this->isAbandoned()) {
279 return nullptr;
280 }
281
282 if (!SkImageInfoIsValid(bitmap.info())) {
283 return nullptr;
284 }
285
286 ATRACE_ANDROID_FRAMEWORK("Upload %sTexture [%dx%d]",
287 skgpu::Mipmapped::kYes == mipmapped ? "MipMap " : "",
288 bitmap.width(),
289 bitmap.height());
290
291 // In non-ddl we will always instantiate right away. Thus we never want to copy the SkBitmap
292 // even if its mutable. In ddl, if the bitmap is mutable then we must make a copy since the
293 // upload of the data to the gpu can happen at anytime and the bitmap may change by then.
294 SkBitmap copyBitmap = bitmap;
295 if (!this->renderingDirectly() && !bitmap.isImmutable()) {
296 copyBitmap.allocPixels();
297 if (!bitmap.readPixels(copyBitmap.pixmap())) {
298 return nullptr;
299 }
300 if (mipmapped == skgpu::Mipmapped::kYes && bitmap.fMips) {
301 copyBitmap.fMips = sk_sp<SkMipmap>(SkMipmap::Build(copyBitmap.pixmap(),
302 /* factoryProc= */ nullptr,
303 /* computeContents= */ false));
304 if (copyBitmap.fMips) {
305 for (int i = 0; i < copyBitmap.fMips->countLevels(); ++i) {
307 bitmap.fMips->getLevel(i, &src);
308 copyBitmap.fMips->getLevel(i, &dst);
309 src.fPixmap.readPixels(dst.fPixmap);
310 }
311 }
312 }
313 copyBitmap.setImmutable();
314 }
315
317 if (mipmapped == skgpu::Mipmapped::kNo ||
319 proxy = this->createNonMippedProxyFromBitmap(copyBitmap, fit, budgeted);
320 } else {
321 proxy = this->createMippedProxyFromBitmap(copyBitmap, budgeted);
322 }
323
324 if (!proxy) {
325 return nullptr;
326 }
327
328 auto direct = fImageContext->asDirectContext();
329 if (direct) {
330 GrResourceProvider* resourceProvider = direct->priv().resourceProvider();
331
332 // In order to reuse code we always create a lazy proxy. When we aren't in DDL mode however
333 // we're better off instantiating the proxy immediately here.
334 if (!proxy->priv().doLazyInstantiation(resourceProvider)) {
335 return nullptr;
336 }
337 }
338 return proxy;
339}
static bool SkImageInfoIsValid(const SkImageInfo &info)
#define ATRACE_ANDROID_FRAMEWORK(fmt,...)
void allocPixels(const SkImageInfo &info, size_t rowBytes)
Definition SkBitmap.cpp:258
void setImmutable()
Definition SkBitmap.cpp:400
SkISize dimensions() const
Definition SkBitmap.h:388
const SkPixmap & pixmap() const
Definition SkBitmap.h:133
bool isImmutable() const
Definition SkBitmap.cpp:396
const SkImageInfo & info() const
Definition SkBitmap.h:139
static SkMipmap * Build(const SkPixmap &src, SkDiscardableFactoryProc, bool computeContents=true)
Definition SkMipmap.cpp:45
int countLevels() const
Definition SkMipmap.cpp:276
bool getLevel(int index, Level *) const
Definition SkMipmap.cpp:280
dst
Definition cp.py:12
int32_t height
int32_t width

◆ findCachedProxyWithColorTypeFallback()

GrSurfaceProxyView GrProxyProvider::findCachedProxyWithColorTypeFallback ( const skgpu::UniqueKey key,
GrSurfaceOrigin  origin,
GrColorType  ct,
int  sampleCnt 
)

A helper that uses findOrCreateProxyByUniqueKey() to find a proxy and, if found, creates a view for the found proxy using the passed in origin and color type. It is assumed that if the proxy is renderable then it was created via a fallback code path so the fallback color type will be used to create the view.

Definition at line 250 of file GrProxyProvider.cpp.

254 {
255 auto proxy = this->findOrCreateProxyByUniqueKey(key);
256 if (!proxy) {
257 return {};
258 }
259 const GrCaps* caps = fImageContext->priv().caps();
260
261 // Assume that we used a fallback color type if and only if the proxy is renderable.
262 if (proxy->asRenderTargetProxy()) {
263 GrBackendFormat expectedFormat;
264 std::tie(ct, expectedFormat) = caps->getFallbackColorTypeAndFormat(ct, sampleCnt);
265 SkASSERT(expectedFormat == proxy->backendFormat());
266 }
267 skgpu::Swizzle swizzle = caps->getReadSwizzle(proxy->backendFormat(), ct);
268 return {std::move(proxy), origin, swizzle};
269}
std::tuple< GrColorType, GrBackendFormat > getFallbackColorTypeAndFormat(GrColorType, int sampleCount) const
Definition GrCaps.cpp:499
skgpu::Swizzle getReadSwizzle(const GrBackendFormat &format, GrColorType colorType) const
Definition GrCaps.cpp:443
sk_sp< GrTextureProxy > findOrCreateProxyByUniqueKey(const skgpu::UniqueKey &, UseAllocator=UseAllocator::kYes)

◆ findOrCreateProxyByUniqueKey()

sk_sp< GrTextureProxy > GrProxyProvider::findOrCreateProxyByUniqueKey ( const skgpu::UniqueKey key,
UseAllocator  useAllocator = UseAllocator::kYes 
)

Definition at line 215 of file GrProxyProvider.cpp.

216 {
218
219 if (this->isAbandoned()) {
220 return nullptr;
221 }
222
224 if (result) {
225 return result;
226 }
227
228 auto direct = fImageContext->asDirectContext();
229 if (!direct) {
230 return nullptr;
231 }
232
233 GrResourceCache* resourceCache = direct->priv().getResourceCache();
234
235 GrGpuResource* resource = resourceCache->findAndRefUniqueResource(key);
236 if (!resource) {
237 return nullptr;
238 }
239
240 sk_sp<GrTexture> texture(static_cast<GrSurface*>(resource)->asTexture());
242
243 result = this->createWrapped(std::move(texture), useAllocator);
244 SkASSERT(result->getUniqueKey() == key);
245 // createWrapped should've added this for us
246 SkASSERT(fUniquelyKeyedProxies.find(key));
247 return result;
248}
sk_sp< GrTextureProxy > findProxyByUniqueKey(const skgpu::UniqueKey &)
GAsyncResult * result
FlTexture * texture

◆ findProxyByUniqueKey()

sk_sp< GrTextureProxy > GrProxyProvider::findProxyByUniqueKey ( const skgpu::UniqueKey key)

Definition at line 101 of file GrProxyProvider.cpp.

101 {
103
104 if (this->isAbandoned()) {
105 return nullptr;
106 }
107
108 GrTextureProxy* proxy = fUniquelyKeyedProxies.find(key);
109 if (proxy) {
110 return sk_ref_sp(proxy);
111 }
112 return nullptr;
113}
sk_sp< T > sk_ref_sp(T *obj)
Definition SkRefCnt.h:381

◆ isAbandoned()

bool GrProxyProvider::isAbandoned ( ) const

Definition at line 1006 of file GrProxyProvider.cpp.

1006 {
1007 return fImageContext->priv().abandoned();
1008}

◆ isDDLProvider()

GrDDLProvider GrProxyProvider::isDDLProvider ( ) const

Definition at line 990 of file GrProxyProvider.cpp.

990 {
991 return fImageContext->asDirectContext() ? GrDDLProvider::kNo : GrDDLProvider::kYes;
992}

◆ MakeFullyLazyProxy()

sk_sp< GrTextureProxy > GrProxyProvider::MakeFullyLazyProxy ( LazyInstantiateCallback &&  callback,
const GrBackendFormat format,
GrRenderable  renderable,
int  renderTargetSampleCnt,
GrProtected  isProtected,
const GrCaps caps,
UseAllocator  useAllocator 
)
static

Fully lazy proxies have unspecified width and height. Methods that rely on those values (e.g., width, height, getBoundsRect) should be avoided.

Definition at line 895 of file GrProxyProvider.cpp.

901 {
902 if (!format.isValid()) {
903 return nullptr;
904 }
905
906 SkASSERT(renderTargetSampleCnt == 1 || renderable == GrRenderable::kYes);
907 // TODO: If we ever have callers requesting specific surface flags then we shouldn't use the
908 // extra deferred flags here. Instead those callers should all pass in exactly what they want.
909 // However, as of today all uses of this essentially create a deferred proxy in the end.
911
912 // MakeFullyLazyProxy is only called at flush time so we know these texture proxies are
913 // not being created by a DDL provider.
914 static constexpr SkISize kLazyDims = {-1, -1};
915 if (GrRenderable::kYes == renderable) {
918 std::move(callback),
919 format,
920 kLazyDims,
921 renderTargetSampleCnt,
922 skgpu::Mipmapped::kNo,
926 isProtected,
927 surfaceFlags,
928 useAllocator,
930 /*label=*/"TextureRenderTarget_FullyLazyProxy"));
931 } else {
932 return sk_sp<GrTextureProxy>(new GrTextureProxy(std::move(callback),
933 format,
934 kLazyDims,
935 skgpu::Mipmapped::kNo,
939 isProtected,
940 surfaceFlags,
941 useAllocator,
943 /*label=*/"Texture_FullyLazyProxy"));
944 }
945}

◆ numUniqueKeyProxies_TestOnly()

int GrProxyProvider::numUniqueKeyProxies_TestOnly ( ) const

Definition at line 50 of file TextureProxyTest.cpp.

50 {
51 return fUniquelyKeyedProxies.count();
52}

◆ orphanAllUniqueKeys()

void GrProxyProvider::orphanAllUniqueKeys ( )

Definition at line 1010 of file GrProxyProvider.cpp.

1010 {
1011 fUniquelyKeyedProxies.foreach([&](GrTextureProxy* proxy){
1012 proxy->fProxyProvider = nullptr;
1013 });
1014}
void foreach(Fn &&fn)

◆ processInvalidUniqueKey()

void GrProxyProvider::processInvalidUniqueKey ( const skgpu::UniqueKey key,
GrTextureProxy proxy,
InvalidateGPUResource  invalidateGPUResource 
)

Definition at line 947 of file GrProxyProvider.cpp.

949 {
950 this->processInvalidUniqueKeyImpl(key, proxy, invalidateGPUResource, RemoveTableEntry::kYes);
951}

◆ refCaps()

sk_sp< const GrCaps > GrProxyProvider::refCaps ( ) const

Definition at line 1002 of file GrProxyProvider.cpp.

1002 {
1003 return fImageContext->priv().refCaps();
1004}
sk_sp< const GrCaps > refCaps() const

◆ removeAllUniqueKeys()

void GrProxyProvider::removeAllUniqueKeys ( )

Definition at line 1016 of file GrProxyProvider.cpp.

1016 {
1017 fUniquelyKeyedProxies.foreach([&](GrTextureProxy* proxy){
1018 // It's not safe to remove table entries while iterating with foreach(),
1019 // but since we're going to remove them all anyway, simply save that for the end.
1020 this->processInvalidUniqueKeyImpl(proxy->getUniqueKey(), proxy,
1022 RemoveTableEntry::kNo);
1023 });
1024 // Removing all those table entries is safe now.
1025 fUniquelyKeyedProxies.reset();
1026}

◆ removeUniqueKeyFromProxy()

void GrProxyProvider::removeUniqueKeyFromProxy ( GrTextureProxy proxy)

Definition at line 89 of file GrProxyProvider.cpp.

89 {
91 SkASSERT(proxy);
92 SkASSERT(proxy->getUniqueKey().isValid());
93
94 if (this->isAbandoned()) {
95 return;
96 }
97
99}
void processInvalidUniqueKey(const skgpu::UniqueKey &, GrTextureProxy *, InvalidateGPUResource)

◆ renderingDirectly()

bool GrProxyProvider::renderingDirectly ( ) const

Does the proxy provider have access to a GrDirectContext? If so, proxies will be instantiated immediately.

Definition at line 1028 of file GrProxyProvider.cpp.

1028 {
1029 return fImageContext->asDirectContext();
1030}

◆ resourceProvider()

GrResourceProvider * GrProxyProvider::resourceProvider ( ) const

Definition at line 706 of file GrProxyProvider.cpp.

706 {
707 GrDirectContext* direct = fImageContext->asDirectContext();
708 if (!direct) {
709 return nullptr;
710 }
711
712 return direct->priv().resourceProvider();
713}
GrResourceProvider * resourceProvider()
GrDirectContextPriv priv()

◆ wrapBackendRenderTarget()

sk_sp< GrSurfaceProxy > GrProxyProvider::wrapBackendRenderTarget ( const GrBackendRenderTarget backendRT,
sk_sp< skgpu::RefCntedCallback releaseHelper 
)

Definition at line 715 of file GrProxyProvider.cpp.

717 {
718 if (this->isAbandoned()) {
719 return nullptr;
720 }
721
722 // This is only supported on a direct GrContext.
723 auto direct = fImageContext->asDirectContext();
724 if (!direct) {
725 return nullptr;
726 }
727
728 GrResourceProvider* resourceProvider = direct->priv().resourceProvider();
729
731 if (!rt) {
732 return nullptr;
733 }
734
735 if (releaseHelper) {
736 rt->setRelease(std::move(releaseHelper));
737 }
738
739 SkASSERT(!rt->asTexture()); // A GrRenderTarget that's not textureable
740 SkASSERT(!rt->getUniqueKey().isValid());
741 // Make sure we match how we created the proxy with skgpu::Budgeted::kNo
742 SkASSERT(GrBudgetedType::kBudgeted != rt->resourcePriv().budgetedType());
743
745 new GrRenderTargetProxy(std::move(rt), UseAllocator::kNo, {}));
746}
sk_sp< GrRenderTarget > wrapBackendRenderTarget(const GrBackendRenderTarget &)

◆ wrapBackendTexture()

sk_sp< GrTextureProxy > GrProxyProvider::wrapBackendTexture ( const GrBackendTexture backendTex,
GrWrapOwnership  ownership,
GrWrapCacheable  cacheable,
GrIOType  ioType,
sk_sp< skgpu::RefCntedCallback releaseHelper = nullptr 
)

Definition at line 592 of file GrProxyProvider.cpp.

597 {
598 SkASSERT(ioType != kWrite_GrIOType);
599
600 if (this->isAbandoned()) {
601 return nullptr;
602 }
603
604 // This is only supported on a direct GrContext.
605 auto direct = fImageContext->asDirectContext();
606 if (!direct) {
607 return nullptr;
608 }
609
610 GrResourceProvider* resourceProvider = direct->priv().resourceProvider();
611
612 sk_sp<GrTexture> tex =
613 resourceProvider->wrapBackendTexture(backendTex, ownership, cacheable, ioType);
614 if (!tex) {
615 return nullptr;
616 }
617
618 if (releaseHelper) {
619 tex->setRelease(std::move(releaseHelper));
620 }
621
622 SkASSERT(!tex->asRenderTarget()); // Strictly a GrTexture
623 // Make sure we match how we created the proxy with skgpu::Budgeted::kNo
624 SkASSERT(GrBudgetedType::kBudgeted != tex->resourcePriv().budgetedType());
625
627 new GrTextureProxy(std::move(tex), UseAllocator::kNo, this->isDDLProvider()));
628}
@ kWrite_GrIOType
sk_sp< GrTexture > wrapBackendTexture(const GrBackendTexture &tex, GrWrapOwnership, GrWrapCacheable, GrIOType)

◆ wrapCompressedBackendTexture()

sk_sp< GrTextureProxy > GrProxyProvider::wrapCompressedBackendTexture ( const GrBackendTexture beTex,
GrWrapOwnership  ownership,
GrWrapCacheable  cacheable,
sk_sp< skgpu::RefCntedCallback releaseHelper 
)

Definition at line 630 of file GrProxyProvider.cpp.

634 {
635 if (this->isAbandoned()) {
636 return nullptr;
637 }
638
639 // This is only supported on a direct GrContext.
640 auto direct = fImageContext->asDirectContext();
641 if (!direct) {
642 return nullptr;
643 }
644
645 GrResourceProvider* resourceProvider = direct->priv().resourceProvider();
646
648 cacheable);
649 if (!tex) {
650 return nullptr;
651 }
652
653 if (releaseHelper) {
654 tex->setRelease(std::move(releaseHelper));
655 }
656
657 SkASSERT(!tex->asRenderTarget()); // Strictly a GrTexture
658 // Make sure we match how we created the proxy with skgpu::Budgeted::kNo
659 SkASSERT(GrBudgetedType::kBudgeted != tex->resourcePriv().budgetedType());
660
662 new GrTextureProxy(std::move(tex), UseAllocator::kNo, this->isDDLProvider()));
663}
sk_sp< GrTexture > wrapCompressedBackendTexture(const GrBackendTexture &tex, GrWrapOwnership, GrWrapCacheable)

◆ wrapRenderableBackendTexture()

sk_sp< GrTextureProxy > GrProxyProvider::wrapRenderableBackendTexture ( const GrBackendTexture backendTex,
int  sampleCnt,
GrWrapOwnership  ownership,
GrWrapCacheable  cacheable,
sk_sp< skgpu::RefCntedCallback releaseHelper 
)

Definition at line 665 of file GrProxyProvider.cpp.

670 {
671 if (this->isAbandoned()) {
672 return nullptr;
673 }
674
675 // This is only supported on a direct GrContext.
676 auto direct = fImageContext->asDirectContext();
677 if (!direct) {
678 return nullptr;
679 }
680
681 const GrCaps* caps = this->caps();
682
683 GrResourceProvider* resourceProvider = direct->priv().resourceProvider();
684
685 sampleCnt = caps->getRenderTargetSampleCount(sampleCnt, backendTex.getBackendFormat());
686 SkASSERT(sampleCnt);
687
689 backendTex, sampleCnt, ownership, cacheable);
690 if (!tex) {
691 return nullptr;
692 }
693
694 if (releaseHelper) {
695 tex->setRelease(std::move(releaseHelper));
696 }
697
698 SkASSERT(tex->asRenderTarget()); // A GrTextureRenderTarget
699 // Make sure we match how we created the proxy with skgpu::Budgeted::kNo
700 SkASSERT(GrBudgetedType::kBudgeted != tex->resourcePriv().budgetedType());
701
703 std::move(tex), UseAllocator::kNo, this->isDDLProvider()));
704}
GrBackendFormat getBackendFormat() const
sk_sp< GrTexture > wrapRenderableBackendTexture(const GrBackendTexture &tex, int sampleCnt, GrWrapOwnership, GrWrapCacheable)

Friends And Related Symbol Documentation

◆ GrAHardwareBufferImageGenerator

friend class GrAHardwareBufferImageGenerator
friend

Definition at line 280 of file GrProxyProvider.h.

◆ GrResourceProvider

friend class GrResourceProvider
friend

Definition at line 281 of file GrProxyProvider.h.


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