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

#include <GrDirectContext.h>

Inheritance diagram for GrDirectContext:
GrRecordingContext GrImageContext GrContext_Base SkRefCnt SkRefCntBase

Classes

class  DirectContextID
 

Public Member Functions

 ~GrDirectContext () override
 
void resetContext (uint32_t state=kAll_GrBackendState)
 
void resetGLTextureBindings ()
 
void abandonContext () override
 
bool abandoned () override
 
bool isDeviceLost ()
 
sk_sp< GrContextThreadSafeProxythreadSafeProxy ()
 
bool oomed ()
 
void releaseResourcesAndAbandonContext ()
 
void getResourceCacheLimits (int *maxResources, size_t *maxResourceBytes) const
 
size_t getResourceCacheLimit () const
 
void getResourceCacheUsage (int *resourceCount, size_t *resourceBytes) const
 
size_t getResourceCachePurgeableBytes () const
 
void setResourceCacheLimits (int maxResources, size_t maxResourceBytes)
 
void setResourceCacheLimit (size_t maxResourceBytes)
 
void freeGpuResources ()
 
void performDeferredCleanup (std::chrono::milliseconds msNotUsed, GrPurgeResourceOptions opts=GrPurgeResourceOptions::kAllResources)
 
void purgeResourcesNotUsedInMs (std::chrono::milliseconds msNotUsed)
 
void purgeUnlockedResources (size_t bytesToPurge, bool preferScratchResources)
 
void purgeUnlockedResources (GrPurgeResourceOptions opts)
 
bool wait (int numSemaphores, const GrBackendSemaphore *waitSemaphores, bool deleteSemaphoresAfterWait=true)
 
void flushAndSubmit (GrSyncCpu sync=GrSyncCpu::kNo)
 
GrSemaphoresSubmitted flush (const GrFlushInfo &info)
 
void flush ()
 
GrSemaphoresSubmitted flush (const sk_sp< const SkImage > &image, const GrFlushInfo &info)
 
void flush (const sk_sp< const SkImage > &image)
 
void flushAndSubmit (const sk_sp< const SkImage > &image)
 
GrSemaphoresSubmitted flush (SkSurface *surface, SkSurfaces::BackendSurfaceAccess access, const GrFlushInfo &info)
 
GrSemaphoresSubmitted flush (SkSurface *surface, const GrFlushInfo &info, const skgpu::MutableTextureState *newState=nullptr)
 
void flushAndSubmit (SkSurface *surface, GrSyncCpu sync=GrSyncCpu::kNo)
 
void flush (SkSurface *surface)
 
bool submit (GrSyncCpu sync=GrSyncCpu::kNo)
 
void checkAsyncWorkCompletion ()
 
void dumpMemoryStatistics (SkTraceMemoryDump *traceMemoryDump) const
 
bool supportsDistanceFieldText () const
 
void storeVkPipelineCacheData ()
 
GrBackendTexture createBackendTexture (int width, int height, const GrBackendFormat &, skgpu::Mipmapped, GrRenderable, GrProtected=GrProtected::kNo, std::string_view label={})
 
GrBackendTexture createBackendTexture (int width, int height, SkColorType, skgpu::Mipmapped, GrRenderable, GrProtected=GrProtected::kNo, std::string_view label={})
 
GrBackendTexture createBackendTexture (int width, int height, const GrBackendFormat &, const SkColor4f &color, skgpu::Mipmapped, GrRenderable, GrProtected=GrProtected::kNo, GrGpuFinishedProc finishedProc=nullptr, GrGpuFinishedContext finishedContext=nullptr, std::string_view label={})
 
GrBackendTexture createBackendTexture (int width, int height, SkColorType, const SkColor4f &color, skgpu::Mipmapped, GrRenderable, GrProtected=GrProtected::kNo, GrGpuFinishedProc finishedProc=nullptr, GrGpuFinishedContext finishedContext=nullptr, std::string_view label={})
 
GrBackendTexture createBackendTexture (const SkPixmap srcData[], int numLevels, GrSurfaceOrigin, GrRenderable, GrProtected, GrGpuFinishedProc finishedProc=nullptr, GrGpuFinishedContext finishedContext=nullptr, std::string_view label={})
 
GrBackendTexture createBackendTexture (const SkPixmap &srcData, GrSurfaceOrigin textureOrigin, GrRenderable renderable, GrProtected isProtected, GrGpuFinishedProc finishedProc=nullptr, GrGpuFinishedContext finishedContext=nullptr, std::string_view label={})
 
GrBackendTexture createBackendTexture (const SkPixmap srcData[], int numLevels, GrRenderable renderable, GrProtected isProtected, GrGpuFinishedProc finishedProc=nullptr, GrGpuFinishedContext finishedContext=nullptr, std::string_view label={})
 
GrBackendTexture createBackendTexture (const SkPixmap &srcData, GrRenderable renderable, GrProtected isProtected, GrGpuFinishedProc finishedProc=nullptr, GrGpuFinishedContext finishedContext=nullptr, std::string_view label={})
 
bool updateBackendTexture (const GrBackendTexture &, const SkColor4f &color, GrGpuFinishedProc finishedProc, GrGpuFinishedContext finishedContext)
 
bool updateBackendTexture (const GrBackendTexture &, SkColorType skColorType, const SkColor4f &color, GrGpuFinishedProc finishedProc, GrGpuFinishedContext finishedContext)
 
bool updateBackendTexture (const GrBackendTexture &, const SkPixmap srcData[], int numLevels, GrSurfaceOrigin=kTopLeft_GrSurfaceOrigin, GrGpuFinishedProc finishedProc=nullptr, GrGpuFinishedContext finishedContext=nullptr)
 
bool updateBackendTexture (const GrBackendTexture &texture, const SkPixmap &srcData, GrSurfaceOrigin textureOrigin=kTopLeft_GrSurfaceOrigin, GrGpuFinishedProc finishedProc=nullptr, GrGpuFinishedContext finishedContext=nullptr)
 
bool updateBackendTexture (const GrBackendTexture &texture, const SkPixmap srcData[], int numLevels, GrGpuFinishedProc finishedProc, GrGpuFinishedContext finishedContext)
 
GrBackendTexture createCompressedBackendTexture (int width, int height, const GrBackendFormat &, const SkColor4f &color, skgpu::Mipmapped, GrProtected=GrProtected::kNo, GrGpuFinishedProc finishedProc=nullptr, GrGpuFinishedContext finishedContext=nullptr)
 
GrBackendTexture createCompressedBackendTexture (int width, int height, SkTextureCompressionType, const SkColor4f &color, skgpu::Mipmapped, GrProtected=GrProtected::kNo, GrGpuFinishedProc finishedProc=nullptr, GrGpuFinishedContext finishedContext=nullptr)
 
GrBackendTexture createCompressedBackendTexture (int width, int height, const GrBackendFormat &, const void *data, size_t dataSize, skgpu::Mipmapped, GrProtected=GrProtected::kNo, GrGpuFinishedProc finishedProc=nullptr, GrGpuFinishedContext finishedContext=nullptr)
 
GrBackendTexture createCompressedBackendTexture (int width, int height, SkTextureCompressionType, const void *data, size_t dataSize, skgpu::Mipmapped, GrProtected=GrProtected::kNo, GrGpuFinishedProc finishedProc=nullptr, GrGpuFinishedContext finishedContext=nullptr)
 
bool updateCompressedBackendTexture (const GrBackendTexture &, const SkColor4f &color, GrGpuFinishedProc finishedProc, GrGpuFinishedContext finishedContext)
 
bool updateCompressedBackendTexture (const GrBackendTexture &, const void *data, size_t dataSize, GrGpuFinishedProc finishedProc, GrGpuFinishedContext finishedContext)
 
bool setBackendTextureState (const GrBackendTexture &, const skgpu::MutableTextureState &, skgpu::MutableTextureState *previousState=nullptr, GrGpuFinishedProc finishedProc=nullptr, GrGpuFinishedContext finishedContext=nullptr)
 
bool setBackendRenderTargetState (const GrBackendRenderTarget &, const skgpu::MutableTextureState &, skgpu::MutableTextureState *previousState=nullptr, GrGpuFinishedProc finishedProc=nullptr, GrGpuFinishedContext finishedContext=nullptr)
 
void deleteBackendTexture (const GrBackendTexture &)
 
bool precompileShader (const SkData &key, const SkData &data)
 
DirectContextID directContextID () const
 
GrDirectContextPriv priv ()
 
const GrDirectContextPriv priv () const
 
SK_API int maxTextureSize () const
 
SK_API int maxRenderTargetSize () const
 
SK_API bool colorTypeSupportedAsImage (SkColorType) const
 
SK_API bool supportsProtectedContent () const
 
SK_API bool colorTypeSupportedAsSurface (SkColorType colorType) const
 
SK_API int maxSurfaceSampleCountForColorType (SkColorType colorType) const
 
- Public Member Functions inherited from GrRecordingContext
 ~GrRecordingContext () override
 
bool abandoned () override
 
SK_API bool colorTypeSupportedAsSurface (SkColorType colorType) const
 
SK_API int maxTextureSize () const
 
SK_API int maxRenderTargetSize () const
 
SK_API bool colorTypeSupportedAsImage (SkColorType) const
 
SK_API bool supportsProtectedContent () const
 
SK_API int maxSurfaceSampleCountForColorType (SkColorType colorType) const
 
SK_API sk_sp< const SkCapabilitiesskCapabilities () const
 
GrRecordingContextPriv priv ()
 
const GrRecordingContextPriv priv () const
 
- Public Member Functions inherited from GrImageContext
 ~GrImageContext () override
 
GrImageContextPriv priv ()
 
const GrImageContextPriv priv () const
 
- Public Member Functions inherited from GrContext_Base
 ~GrContext_Base () override
 
SK_API GrBackendApi backend () const
 
SK_API GrBackendFormat defaultBackendFormat (SkColorType, GrRenderable) const
 
SK_API GrBackendFormat compressedBackendFormat (SkTextureCompressionType) const
 
SK_API int maxSurfaceSampleCountForColorType (SkColorType colorType) const
 
sk_sp< GrContextThreadSafeProxythreadSafeProxy ()
 
GrBaseContextPriv priv ()
 
const GrBaseContextPriv priv () const
 
- Public Member Functions inherited from SkRefCntBase
 SkRefCntBase ()
 
virtual ~SkRefCntBase ()
 
bool unique () const
 
void ref () const
 
void unref () const
 

Static Public Member Functions

static sk_sp< GrDirectContextMakeMock (const GrMockOptions *, const GrContextOptions &)
 
static sk_sp< GrDirectContextMakeMock (const GrMockOptions *)
 

Protected Member Functions

 GrDirectContext (GrBackendApi backend, const GrContextOptions &options, sk_sp< GrContextThreadSafeProxy > proxy)
 
bool init () override
 
GrAtlasManageronGetAtlasManager ()
 
skgpu::ganesh::SmallPathAtlasMgronGetSmallPathAtlasMgr ()
 
GrDirectContextasDirectContext () override
 
- Protected Member Functions inherited from GrRecordingContext
 GrRecordingContext (sk_sp< GrContextThreadSafeProxy >, bool ddlRecording)
 
bool init () override
 
void abandonContext () override
 
GrDrawingManagerdrawingManager ()
 
void destroyDrawingManager ()
 
Arenas arenas ()
 
OwnedArenas && detachArenas ()
 
GrProxyProviderproxyProvider ()
 
const GrProxyProviderproxyProvider () const
 
virtual void recordProgramInfo (const GrProgramInfo *)
 
virtual void detachProgramData (skia_private::TArray< ProgramData > *)
 
sktext::gpu::TextBlobRedrawCoordinatorgetTextBlobRedrawCoordinator ()
 
const sktext::gpu::TextBlobRedrawCoordinatorgetTextBlobRedrawCoordinator () const
 
GrThreadSafeCachethreadSafeCache ()
 
const GrThreadSafeCachethreadSafeCache () const
 
void addOnFlushCallbackObject (GrOnFlushCallbackObject *)
 
GrRecordingContextasRecordingContext () override
 
Statsstats ()
 
const Statsstats () const
 
void dumpJSON (SkJSONWriter *) const
 
- Protected Member Functions inherited from GrImageContext
 GrImageContext (sk_sp< GrContextThreadSafeProxy >)
 
skgpu::SingleOwnersingleOwner () const
 
GrImageContextasImageContext () override
 
- Protected Member Functions inherited from GrContext_Base
 GrContext_Base (sk_sp< GrContextThreadSafeProxy >)
 
uint32_t contextID () const
 
bool matches (GrContext_Base *candidate) const
 
const GrContextOptionsoptions () const
 
const GrCapscaps () const
 
sk_sp< const GrCapsrefCaps () const
 

Friends

class GrDirectContextPriv
 

Additional Inherited Members

- Protected Attributes inherited from GrRecordingContext
class GrRecordingContext::Stats fStats
 
std::unique_ptr< GrAuditTrailfAuditTrail
 
- Protected Attributes inherited from GrContext_Base
sk_sp< GrContextThreadSafeProxyfThreadSafeProxy
 

Detailed Description

Definition at line 60 of file GrDirectContext.h.

Constructor & Destructor Documentation

◆ ~GrDirectContext()

GrDirectContext::~GrDirectContext ( )
override

Definition at line 96 of file GrDirectContext.cpp.

96 {
98 // this if-test protects against the case where the context is being destroyed
99 // before having been fully created
100 if (fGpu) {
101 this->flushAndSubmit();
102 }
103
104 // We need to make sure all work is finished on the gpu before we start releasing resources.
105 this->syncAllOutstandingGpuWork(/*shouldExecuteWhileAbandoned=*/false);
106
107 this->destroyDrawingManager();
108
109 // Ideally we could just let the ptr drop, but resource cache queries this ptr in releaseAll.
110 if (fResourceCache) {
111 fResourceCache->releaseAll();
112 }
113 // This has to be after GrResourceCache::releaseAll so that other threads that are holding
114 // async pixel result don't try to destroy buffers off thread.
115 fMappedBufferManager.reset();
116}
void flushAndSubmit(GrSyncCpu sync=GrSyncCpu::kNo)
#define ASSERT_SINGLE_OWNER
Definition Device.cpp:120

◆ GrDirectContext()

GrDirectContext::GrDirectContext ( GrBackendApi  backend,
const GrContextOptions options,
sk_sp< GrContextThreadSafeProxy proxy 
)
protected

Definition at line 88 of file GrDirectContext.cpp.

91 : GrRecordingContext(std::move(proxy), false)
92 , fDeleteCallbackHelper(new DeleteCallbackHelper(options.fContextDeleteContext,
94 , fDirectContextID(DirectContextID::Next()) {}
const GrContextOptions & options() const
static GrDirectContext::DirectContextID Next()
GrDirectContextDestroyedProc fContextDeleteProc
GrDirectContextDestroyedContext fContextDeleteContext

Member Function Documentation

◆ abandonContext()

void GrDirectContext::abandonContext ( )
overridevirtual

Abandons all GPU resources and assumes the underlying backend 3D API context is no longer usable. Call this if you have lost the associated GPU context, and thus internal texture, buffer, etc. references/IDs are now invalid. Calling this ensures that the destructors of the context and any of its created resource objects will not make backend 3D API calls. Content rendered but not previously flushed may be lost. After this function is called all subsequent calls on the context will fail or be no-ops.

The typical use case for this function is that the underlying 3D context was lost and further API calls may crash.

This call is not valid to be made inside ReleaseProcs passed into SkSurface or SkImages. The call will simply fail (and assert in debug) if it is called while inside a ReleaseProc.

For Vulkan, even if the device becomes lost, the VkQueue, VkDevice, or VkInstance used to create the context must be kept alive even after abandoning the context. Those objects must live for the lifetime of the context object itself. The reason for this is so that we can continue to delete any outstanding GrBackendTextures/RenderTargets which must be cleaned up even in a device lost state.

Reimplemented from GrImageContext.

Definition at line 134 of file GrDirectContext.cpp.

134 {
136 return;
137 }
138
139 if (fInsideReleaseProcCnt) {
140 SkDEBUGFAIL("Calling GrDirectContext::abandonContext() while inside a ReleaseProc is not "
141 "allowed");
142 return;
143 }
144
146
147 // We need to make sure all work is finished on the gpu before we start releasing resources.
148 this->syncAllOutstandingGpuWork(this->caps()->mustSyncGpuDuringAbandon());
149
150 fStrikeCache->freeAll();
151
152 fMappedBufferManager->abandon();
153
154 fResourceProvider->abandon();
155
156 // abandon first so destructors don't try to free the resources in the API.
157 fResourceCache->abandonAll();
158
159 fGpu->disconnect(GrGpu::DisconnectType::kAbandon);
160
161#if !defined(SK_ENABLE_OPTIMIZE_SIZE)
162 if (fSmallPathAtlasMgr) {
163 fSmallPathAtlasMgr->reset();
164 }
165#endif
166 fAtlasManager->freeAll();
167}
#define SkDEBUGFAIL(message)
Definition SkAssert.h:118
const GrCaps * caps() const
bool abandoned() override
void abandonContext() override

◆ abandoned()

bool GrDirectContext::abandoned ( )
overridevirtual

Returns true if the context was abandoned or if the backend specific context has gotten into an unrecoverarble, lost state (e.g. in Vulkan backend if we've gotten a VK_ERROR_DEVICE_LOST). If the backend context is lost, this call will also abandon this context.

Reimplemented from GrImageContext.

Definition at line 169 of file GrDirectContext.cpp.

169 {
171 return true;
172 }
173
174 if (fGpu && fGpu->isDeviceLost()) {
175 this->abandonContext();
176 return true;
177 }
178 return false;
179}
void abandonContext() override

◆ asDirectContext()

GrDirectContext * GrDirectContext::asDirectContext ( )
inlineoverrideprotectedvirtual

Reimplemented from GrContext_Base.

Definition at line 921 of file GrDirectContext.h.

921{ return this; }

◆ checkAsyncWorkCompletion()

void GrDirectContext::checkAsyncWorkCompletion ( )

Checks whether any asynchronous work is complete and if so calls related callbacks.

Definition at line 531 of file GrDirectContext.cpp.

531 {
532 if (fGpu) {
533 fGpu->checkFinishProcs();
534 }
535}

◆ colorTypeSupportedAsImage()

bool GrRecordingContext::colorTypeSupportedAsImage ( SkColorType  colorType) const

Can a SkImage be created with the given color type.

Definition at line 84 of file GrRecordingContext.cpp.

171 {
174 GrRenderable::kNo);
175 return format.isValid();
176}
static constexpr GrColorType SkColorTypeToGrColorType(SkColorType ct)
static SkColorType colorType(AImageDecoder *decoder, const AImageDecoderHeaderInfo *headerInfo)
bool isValid() const
GrBackendFormat getDefaultBackendFormat(GrColorType, GrRenderable) const
Definition GrCaps.cpp:400
uint32_t uint32_t * format

◆ colorTypeSupportedAsSurface()

SK_API bool GrRecordingContext::colorTypeSupportedAsSurface ( SkColorType  colorType) const
inline

Can a SkSurface be created with the given color type. To check whether MSAA is supported use maxSurfaceSampleCountForColorType().

Definition at line 58 of file GrRecordingContext.h.

58 {
65 return false;
66 }
67
69 }
@ kR16G16B16A16_unorm_SkColorType
pixel with a little endian uint16_t for red, green, blue
Definition SkColorType.h:50
@ kA16_unorm_SkColorType
pixel with a little endian uint16_t for alpha
Definition SkColorType.h:48
@ kGray_8_SkColorType
pixel with grayscale level in 8-bit byte
Definition SkColorType.h:35
@ kA16_float_SkColorType
pixel with a half float for alpha
Definition SkColorType.h:45
@ kR16G16_unorm_SkColorType
pixel with a little endian uint16_t for red and green
Definition SkColorType.h:49
@ kR16G16_float_SkColorType
pixel with a half float for red and green
Definition SkColorType.h:46
SK_API int maxSurfaceSampleCountForColorType(SkColorType colorType) const

◆ createBackendTexture() [1/8]

GrBackendTexture GrDirectContext::createBackendTexture ( const SkPixmap srcData,
GrRenderable  renderable,
GrProtected  isProtected,
GrGpuFinishedProc  finishedProc = nullptr,
GrGpuFinishedContext  finishedContext = nullptr,
std::string_view  label = {} 
)

Definition at line 594 of file GrDirectContext.cpp.

599 {
600 return this->createBackendTexture(&srcData,
601 1,
602 renderable,
603 isProtected,
604 finishedProc,
605 finishedContext,
606 label);
607}
GrBackendTexture createBackendTexture(int width, int height, const GrBackendFormat &, skgpu::Mipmapped, GrRenderable, GrProtected=GrProtected::kNo, std::string_view label={})

◆ createBackendTexture() [2/8]

GrBackendTexture GrDirectContext::createBackendTexture ( const SkPixmap srcData,
GrSurfaceOrigin  textureOrigin,
GrRenderable  renderable,
GrProtected  isProtected,
GrGpuFinishedProc  finishedProc = nullptr,
GrGpuFinishedContext  finishedContext = nullptr,
std::string_view  label = {} 
)

Convenience version createBackendTexture() that takes just a base level pixmap.

Definition at line 583 of file GrDirectContext.cpp.

589 {
590 return this->createBackendTexture(&srcData, 1, textureOrigin, renderable, isProtected,
591 finishedProc, finishedContext, label);
592}

◆ createBackendTexture() [3/8]

GrBackendTexture GrDirectContext::createBackendTexture ( const SkPixmap  srcData[],
int  numLevels,
GrRenderable  renderable,
GrProtected  isProtected,
GrGpuFinishedProc  finishedProc = nullptr,
GrGpuFinishedContext  finishedContext = nullptr,
std::string_view  label = {} 
)

Definition at line 609 of file GrDirectContext.cpp.

615 {
616 return this->createBackendTexture(srcData,
617 numLevels,
619 renderable,
620 isProtected,
621 finishedProc,
622 finishedContext,
623 label);
624}
@ kTopLeft_GrSurfaceOrigin
Definition GrTypes.h:148

◆ createBackendTexture() [4/8]

GrBackendTexture GrDirectContext::createBackendTexture ( const SkPixmap  srcData[],
int  numLevels,
GrSurfaceOrigin  textureOrigin,
GrRenderable  renderable,
GrProtected  isProtected,
GrGpuFinishedProc  finishedProc = nullptr,
GrGpuFinishedContext  finishedContext = nullptr,
std::string_view  label = {} 
)

If possible, create a backend texture initialized with the provided pixmap data. The client should ensure that the returned backend texture is valid. The client can pass in a finishedProc to be notified when the data has been uploaded by the gpu and the texture can be deleted. The client is required to call submit to send the upload work to the gpu. The finishedProc will always get called even if we failed to create the GrBackendTexture. If successful, the created backend texture will be compatible with the provided pixmap(s). Compatible, in this case, means that the backend format will be the result of calling defaultBackendFormat on the base pixmap's colortype. The src data can be deleted when this call returns. If numLevels is 1 a non-mipmapped texture will result. If a mipmapped texture is desired the data for all the mipmap levels must be provided. In the mipmapped case all the colortypes of the provided pixmaps must be the same. Additionally, all the miplevels must be sized correctly (please see SkMipmap::ComputeLevelSize and ComputeLevelCount). The GrSurfaceOrigin controls whether the pixmap data is vertically flipped in the texture. Note: the pixmap's alphatypes and colorspaces are ignored. For the Vulkan backend the layout of the created VkImage will be: VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL

Definition at line 773 of file GrDirectContext.cpp.

780 {
781 TRACE_EVENT0("skia.gpu", TRACE_FUNC);
782
783 auto finishedCallback = skgpu::RefCntedCallback::Make(finishedProc, finishedContext);
784
785 if (this->abandoned()) {
786 return {};
787 }
788
789 if (!srcData || numProvidedLevels <= 0) {
790 return {};
791 }
792
793 SkColorType colorType = srcData[0].colorType();
794
795 skgpu::Mipmapped mipmapped = skgpu::Mipmapped::kNo;
796 if (numProvidedLevels > 1) {
797 mipmapped = skgpu::Mipmapped::kYes;
798 }
799
800 GrBackendFormat backendFormat = this->defaultBackendFormat(colorType, renderable);
801 GrBackendTexture beTex = this->createBackendTexture(srcData[0].width(),
802 srcData[0].height(),
803 backendFormat,
804 mipmapped,
805 renderable,
806 isProtected,
807 label);
808 if (!beTex.isValid()) {
809 return {};
810 }
812 srcData,
813 numProvidedLevels,
814 beTex,
815 textureOrigin,
816 std::move(finishedCallback))) {
817 this->deleteBackendTexture(beTex);
818 return {};
819 }
820 return beTex;
821}
static bool update_texture_with_pixmaps(GrDirectContext *context, const SkPixmap src[], int numLevels, const GrBackendTexture &backendTexture, GrSurfaceOrigin textureOrigin, sk_sp< skgpu::RefCntedCallback > finishedCallback)
SkColorType
Definition SkColorType.h:19
#define TRACE_FUNC
SK_API GrBackendFormat defaultBackendFormat(SkColorType, GrRenderable) const
bool abandoned() override
void deleteBackendTexture(const GrBackendTexture &)
SkColorType colorType() const
Definition SkPixmap.h:173
static sk_sp< RefCntedCallback > Make(Callback proc, Context ctx)
Mipmapped
Definition GpuTypes.h:53
int32_t height
int32_t width
#define TRACE_EVENT0(category_group, name)

◆ createBackendTexture() [5/8]

GrBackendTexture GrDirectContext::createBackendTexture ( int  width,
int  height,
const GrBackendFormat backendFormat,
const SkColor4f color,
skgpu::Mipmapped  mipmapped,
GrRenderable  renderable,
GrProtected  isProtected = GrProtected::kNo,
GrGpuFinishedProc  finishedProc = nullptr,
GrGpuFinishedContext  finishedContext = nullptr,
std::string_view  label = {} 
)

If possible, create a backend texture initialized to a particular color. The client should ensure that the returned backend texture is valid. The client can pass in a finishedProc to be notified when the data has been uploaded by the gpu and the texture can be deleted. The client is required to call submit to send the upload work to the gpu. The finishedProc will always get called even if we failed to create the GrBackendTexture. For the Vulkan backend the layout of the created VkImage will be: VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL

Definition at line 710 of file GrDirectContext.cpp.

719 {
720 auto finishedCallback = skgpu::RefCntedCallback::Make(finishedProc, finishedContext);
721
722 TRACE_EVENT0("skia.gpu", TRACE_FUNC);
723 if (this->abandoned()) {
724 return {};
725 }
726
728 {width, height},
729 backendFormat,
730 mipmapped,
731 renderable,
732 isProtected,
733 std::move(finishedCallback),
734 color.array(),
735 label);
736}
static GrBackendTexture create_and_clear_backend_texture(GrDirectContext *dContext, SkISize dimensions, const GrBackendFormat &backendFormat, skgpu::Mipmapped mipmapped, GrRenderable renderable, GrProtected isProtected, sk_sp< skgpu::RefCntedCallback > finishedCallback, std::array< float, 4 > color, std::string_view label)
SkColor4f color

◆ createBackendTexture() [6/8]

GrBackendTexture GrDirectContext::createBackendTexture ( int  width,
int  height,
const GrBackendFormat backendFormat,
skgpu::Mipmapped  mipmapped,
GrRenderable  renderable,
GrProtected  isProtected = GrProtected::kNo,
std::string_view  label = {} 
)

The explicitly allocated backend texture API allows clients to use Skia to create backend objects outside of Skia proper (i.e., Skia's caching system will not know about them.)

It is the client's responsibility to delete all these objects (using deleteBackendTexture) before deleting the context used to create them. If the backend is Vulkan, the textures must be deleted before abandoning the context as well. Additionally, clients should only delete these objects on the thread for which that context is active.

The client is responsible for ensuring synchronization between different uses of the backend object (i.e., wrapping it in a surface, rendering to it, deleting the surface, rewrapping it in a image and drawing the image will require explicit synchronization on the client's part). If possible, create an uninitialized backend texture. The client should ensure that the returned backend texture is valid. For the Vulkan backend the layout of the created VkImage will be: VK_IMAGE_LAYOUT_UNDEFINED.

Definition at line 567 of file GrDirectContext.cpp.

573 {
574 TRACE_EVENT0("skia.gpu", TRACE_FUNC);
575 if (this->abandoned()) {
576 return GrBackendTexture();
577 }
578
579 return fGpu->createBackendTexture({width, height}, backendFormat, renderable,
580 mipmapped, isProtected, label);
581}

◆ createBackendTexture() [7/8]

GrBackendTexture GrDirectContext::createBackendTexture ( int  width,
int  height,
SkColorType  skColorType,
const SkColor4f color,
skgpu::Mipmapped  mipmapped,
GrRenderable  renderable,
GrProtected  isProtected = GrProtected::kNo,
GrGpuFinishedProc  finishedProc = nullptr,
GrGpuFinishedContext  finishedContext = nullptr,
std::string_view  label = {} 
)

If possible, create a backend texture initialized to a particular color. The client should ensure that the returned backend texture is valid. The client can pass in a finishedProc to be notified when the data has been uploaded by the gpu and the texture can be deleted. The client is required to call submit to send the upload work to the gpu. The finishedProc will always get called even if we failed to create the GrBackendTexture. If successful, the created backend texture will be compatible with the provided SkColorType. For the Vulkan backend the layout of the created VkImage will be: VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL

Definition at line 738 of file GrDirectContext.cpp.

747 {
748 auto finishedCallback = skgpu::RefCntedCallback::Make(finishedProc, finishedContext);
749
750 if (this->abandoned()) {
751 return {};
752 }
753
754 GrBackendFormat format = this->defaultBackendFormat(skColorType, renderable);
755 if (!format.isValid()) {
756 return {};
757 }
758
759 GrColorType grColorType = SkColorTypeToGrColorType(skColorType);
760 SkColor4f swizzledColor = this->caps()->getWriteSwizzle(format, grColorType).applyTo(color);
761
763 {width, height},
764 format,
765 mipmapped,
766 renderable,
767 isProtected,
768 std::move(finishedCallback),
769 swizzledColor.array(),
770 label);
771}
GrColorType
virtual skgpu::Swizzle getWriteSwizzle(const GrBackendFormat &, GrColorType) const =0
constexpr std::array< float, 4 > applyTo(std::array< float, 4 > color) const
Definition Swizzle.h:101

◆ createBackendTexture() [8/8]

GrBackendTexture GrDirectContext::createBackendTexture ( int  width,
int  height,
SkColorType  skColorType,
skgpu::Mipmapped  mipmapped,
GrRenderable  renderable,
GrProtected  isProtected = GrProtected::kNo,
std::string_view  label = {} 
)

If possible, create an uninitialized backend texture. The client should ensure that the returned backend texture is valid. If successful, the created backend texture will be compatible with the provided SkColorType. For the Vulkan backend the layout of the created VkImage will be: VK_IMAGE_LAYOUT_UNDEFINED.

Definition at line 626 of file GrDirectContext.cpp.

632 {
633 if (this->abandoned()) {
634 return GrBackendTexture();
635 }
636
637 const GrBackendFormat format = this->defaultBackendFormat(skColorType, renderable);
638
639 return this->createBackendTexture(
640 width, height, format, mipmapped, renderable, isProtected, label);
641}

◆ createCompressedBackendTexture() [1/4]

GrBackendTexture GrDirectContext::createCompressedBackendTexture ( int  width,
int  height,
const GrBackendFormat backendFormat,
const SkColor4f color,
skgpu::Mipmapped  mipmapped,
GrProtected  isProtected = GrProtected::kNo,
GrGpuFinishedProc  finishedProc = nullptr,
GrGpuFinishedContext  finishedContext = nullptr 
)

If possible, create a compressed backend texture initialized to a particular color. The client should ensure that the returned backend texture is valid. The client can pass in a finishedProc to be notified when the data has been uploaded by the gpu and the texture can be deleted. The client is required to call submit to send the upload work to the gpu. The finishedProc will always get called even if we failed to create the GrBackendTexture. For the Vulkan backend the layout of the created VkImage will be: VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL

Definition at line 935 of file GrDirectContext.cpp.

943 {
944 TRACE_EVENT0("skia.gpu", TRACE_FUNC);
945 auto finishedCallback = skgpu::RefCntedCallback::Make(finishedProc, finishedContext);
946
947 if (this->abandoned()) {
948 return {};
949 }
950
952 if (compression == SkTextureCompressionType::kNone) {
953 return {};
954 }
955
956 size_t size = SkCompressedDataSize(
957 compression, {width, height}, nullptr, mipmapped == skgpu::Mipmapped::kYes);
958 auto storage = std::make_unique<char[]>(size);
959 skgpu::FillInCompressedData(compression, {width, height}, mipmapped, storage.get(), color);
961 {width, height},
962 backendFormat,
963 mipmapped,
964 isProtected,
965 std::move(finishedCallback),
966 storage.get(),
967 size);
968}
SkTextureCompressionType GrBackendFormatToCompressionType(const GrBackendFormat &format)
static GrBackendTexture create_and_update_compressed_backend_texture(GrDirectContext *dContext, SkISize dimensions, const GrBackendFormat &backendFormat, skgpu::Mipmapped mipmapped, GrProtected isProtected, sk_sp< skgpu::RefCntedCallback > finishedCallback, const void *data, size_t size)
size_t SkCompressedDataSize(SkTextureCompressionType type, SkISize dimensions, TArray< size_t > *individualMipOffsets, bool mipmapped)
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
void FillInCompressedData(SkTextureCompressionType type, SkISize dimensions, skgpu::Mipmapped mipmapped, char *dstPixels, const SkColor4f &colorf)

◆ createCompressedBackendTexture() [2/4]

GrBackendTexture GrDirectContext::createCompressedBackendTexture ( int  width,
int  height,
const GrBackendFormat backendFormat,
const void *  data,
size_t  dataSize,
skgpu::Mipmapped  mipmapped,
GrProtected  isProtected = GrProtected::kNo,
GrGpuFinishedProc  finishedProc = nullptr,
GrGpuFinishedContext  finishedContext = nullptr 
)

If possible, create a backend texture initialized with the provided raw data. The client should ensure that the returned backend texture is valid. The client can pass in a finishedProc to be notified when the data has been uploaded by the gpu and the texture can be deleted. The client is required to call submit to send the upload work to the gpu. The finishedProc will always get called even if we failed to create the GrBackendTexture If numLevels is 1 a non-mipmapped texture will result. If a mipmapped texture is desired the data for all the mipmap levels must be provided. Additionally, all the miplevels must be sized correctly (please see SkMipmap::ComputeLevelSize and ComputeLevelCount). For the Vulkan backend the layout of the created VkImage will be: VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL

Definition at line 986 of file GrDirectContext.cpp.

995 {
996 TRACE_EVENT0("skia.gpu", TRACE_FUNC);
997 auto finishedCallback = skgpu::RefCntedCallback::Make(finishedProc, finishedContext);
998
999 if (this->abandoned()) {
1000 return {};
1001 }
1002
1004 {width, height},
1005 backendFormat,
1006 mipmapped,
1007 isProtected,
1008 std::move(finishedCallback),
1009 compressedData,
1010 dataSize);
1011}

◆ createCompressedBackendTexture() [3/4]

GrBackendTexture GrDirectContext::createCompressedBackendTexture ( int  width,
int  height,
SkTextureCompressionType  compression,
const SkColor4f color,
skgpu::Mipmapped  mipmapped,
GrProtected  isProtected = GrProtected::kNo,
GrGpuFinishedProc  finishedProc = nullptr,
GrGpuFinishedContext  finishedContext = nullptr 
)

Definition at line 970 of file GrDirectContext.cpp.

978 {
979 TRACE_EVENT0("skia.gpu", TRACE_FUNC);
981 return this->createCompressedBackendTexture(width, height, format, color,
982 mipmapped, isProtected, finishedProc,
983 finishedContext);
984}
SK_API GrBackendFormat compressedBackendFormat(SkTextureCompressionType) const
GrBackendTexture createCompressedBackendTexture(int width, int height, const GrBackendFormat &, const SkColor4f &color, skgpu::Mipmapped, GrProtected=GrProtected::kNo, GrGpuFinishedProc finishedProc=nullptr, GrGpuFinishedContext finishedContext=nullptr)

◆ createCompressedBackendTexture() [4/4]

GrBackendTexture GrDirectContext::createCompressedBackendTexture ( int  width,
int  height,
SkTextureCompressionType  compression,
const void *  data,
size_t  dataSize,
skgpu::Mipmapped  mipmapped,
GrProtected  isProtected = GrProtected::kNo,
GrGpuFinishedProc  finishedProc = nullptr,
GrGpuFinishedContext  finishedContext = nullptr 
)

Definition at line 1013 of file GrDirectContext.cpp.

1022 {
1023 TRACE_EVENT0("skia.gpu", TRACE_FUNC);
1024 GrBackendFormat format = this->compressedBackendFormat(compression);
1025 return this->createCompressedBackendTexture(width, height, format, data, dataSize, mipmapped,
1026 isProtected, finishedProc, finishedContext);
1027}

◆ deleteBackendTexture()

void GrDirectContext::deleteBackendTexture ( const GrBackendTexture backendTex)

Definition at line 1113 of file GrDirectContext.cpp.

1113 {
1114 TRACE_EVENT0("skia.gpu", TRACE_FUNC);
1115 // For the Vulkan backend we still must destroy the backend texture when the context is
1116 // abandoned.
1117 if ((this->abandoned() && this->backend() != GrBackendApi::kVulkan) || !backendTex.isValid()) {
1118 return;
1119 }
1120
1121 fGpu->deleteBackendTexture(backendTex);
1122}
SK_API GrBackendApi backend() const

◆ directContextID()

DirectContextID GrDirectContext::directContextID ( ) const
inline

Definition at line 903 of file GrDirectContext.h.

903{ return fDirectContextID; }

◆ dumpMemoryStatistics()

void GrDirectContext::dumpMemoryStatistics ( SkTraceMemoryDump traceMemoryDump) const

Enumerates all cached GPU resources and dumps their memory to traceMemoryDump.

Definition at line 560 of file GrDirectContext.cpp.

560 {
562 fResourceCache->dumpMemoryStatistics(traceMemoryDump);
563 traceMemoryDump->dumpNumericValue("skia/gr_text_blob_cache", "size", "bytes",
564 this->getTextBlobRedrawCoordinator()->usedBytes());
565}
sktext::gpu::TextBlobRedrawCoordinator * getTextBlobRedrawCoordinator()
virtual void dumpNumericValue(const char *dumpName, const char *valueName, const char *units, uint64_t value)=0

◆ flush() [1/7]

void GrDirectContext::flush ( )
inline

Definition at line 363 of file GrDirectContext.h.

363{ this->flush(GrFlushInfo()); }

◆ flush() [2/7]

GrSemaphoresSubmitted GrDirectContext::flush ( const GrFlushInfo info)

Call to ensure all drawing to the context has been flushed to underlying 3D API specific objects. A call to submit is always required to ensure work is actually sent to the gpu. Some specific API details: GL: Commands are actually sent to the driver, but glFlush is never called. Thus some sync objects from the flush will not be valid until a submission occurs.

Vulkan/Metal/D3D/Dawn: Commands are recorded to the backend APIs corresponding command buffer or encoder objects. However, these objects are not sent to the gpu until a submission occurs.

If the return is GrSemaphoresSubmitted::kYes, only initialized GrBackendSemaphores will be submitted to the gpu during the next submit call (it is possible Skia failed to create a subset of the semaphores). The client should not wait on these semaphores until after submit has been called, and must keep them alive until then. If this call returns GrSemaphoresSubmitted::kNo, the GPU backend will not submit any semaphores to be signaled on the GPU. Thus the client should not have the GPU wait on any of the semaphores passed in with the GrFlushInfo. Regardless of whether semaphores were submitted to the GPU or not, the client is still responsible for deleting any initialized semaphores. Regardless of semaphore submission the context will still be flushed. It should be emphasized that a return value of GrSemaphoresSubmitted::kNo does not mean the flush did not happen. It simply means there were no semaphores submitted to the GPU. A caller should only take this as a failure if they passed in semaphores to be submitted.

Definition at line 432 of file GrDirectContext.cpp.

432 {
434 if (this->abandoned()) {
435 if (info.fFinishedProc) {
436 info.fFinishedProc(info.fFinishedContext);
437 }
438 if (info.fSubmittedProc) {
439 info.fSubmittedProc(info.fSubmittedContext, false);
440 }
442 }
443
444 return this->drawingManager()->flushSurfaces(
446}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
GrSemaphoresSubmitted flushSurfaces(SkSpan< GrSurfaceProxy * >, SkSurfaces::BackendSurfaceAccess, const GrFlushInfo &, const skgpu::MutableTextureState *newState)
GrDrawingManager * drawingManager()
@ kNoAccess
back-end surface will not be used by client
GrGpuFinishedProc fFinishedProc
Definition GrTypes.h:219

◆ flush() [3/7]

void GrDirectContext::flush ( const sk_sp< const SkImage > &  image)

Definition at line 474 of file GrDirectContext.cpp.

474 {
475 this->flush(image, {});
476}

◆ flush() [4/7]

GrSemaphoresSubmitted GrDirectContext::flush ( const sk_sp< const SkImage > &  image,
const GrFlushInfo info 
)

Flushes any pending uses of texture-backed images in the GPU backend. If the image is not texture-backed (including promise texture images) or if the GrDirectContext does not have the same context ID as the context backing the image then this is a no-op. If the image was not used in any non-culled draws in the current queue of work for the passed GrDirectContext then this is a no-op unless the GrFlushInfo contains semaphores or a finish proc. Those are respected even when the image has not been used.

Parameters
imagethe non-null image to flush.
infoflush options

Definition at line 461 of file GrDirectContext.cpp.

462 {
463 if (!image) {
465 }
466 auto ib = as_IB(image);
467 if (!ib->isGaneshBacked()) {
469 }
470 auto igb = static_cast<const SkImage_GaneshBase*>(image.get());
471 return igb->flush(this, flushInfo);
472}
static SkImage_Base * as_IB(SkImage *image)
virtual GrSemaphoresSubmitted flush(GrDirectContext *, const GrFlushInfo &) const =0
T * get() const
Definition SkRefCnt.h:303
sk_sp< SkImage > image
Definition examples.cpp:29

◆ flush() [5/7]

void GrDirectContext::flush ( SkSurface surface)

Flushes the given surface with the default GrFlushInfo.

Has no effect on a CPU-backed surface.

Definition at line 525 of file GrDirectContext.cpp.

525 {
526 this->flush(surface, GrFlushInfo(), nullptr);
527}

◆ flush() [6/7]

GrSemaphoresSubmitted GrDirectContext::flush ( SkSurface surface,
const GrFlushInfo info,
const skgpu::MutableTextureState newState = nullptr 
)

Same as above except:

If a skgpu::MutableTextureState is passed in, at the end of the flush we will transition the surface to be in the state requested by the skgpu::MutableTextureState. If the surface (or SkImage or GrBackendSurface wrapping the same backend object) is used again after this flush the state may be changed and no longer match what is requested here. This is often used if the surface will be used for presenting or external use and the client wants backend object to be prepped for that use. A finishedProc or semaphore on the GrFlushInfo will also include the work for any requested state change.

If the backend API is Vulkan, the caller can set the skgpu::MutableTextureState's VkImageLayout to VK_IMAGE_LAYOUT_UNDEFINED or queueFamilyIndex to VK_QUEUE_FAMILY_IGNORED to tell Skia to not change those respective states.

Parameters
surfaceThe GPU backed surface to be flushed. Has no effect on a CPU-backed surface.
infoflush options
newStateoptional state change request after flush

Definition at line 501 of file GrDirectContext.cpp.

503 {
504 if (!surface) {
506 }
507 auto sb = asSB(surface);
508 if (!sb->isGaneshBacked()) {
510 }
511
512 auto gs = static_cast<SkSurface_Ganesh*>(surface);
513 SkASSERT(this->priv().matches(gs->getDevice()->recordingContext()->asDirectContext()));
514 GrRenderTargetProxy* rtp = gs->getDevice()->targetProxy();
515
516 return this->priv().flushSurface(
518}
#define SkASSERT(cond)
Definition SkAssert.h:116
static SkSurface_Base * asSB(SkSurface *surface)
bool matches(GrContext_Base *candidate) const
GrSemaphoresSubmitted flushSurface(GrSurfaceProxy *proxy, SkSurfaces::BackendSurfaceAccess access=SkSurfaces::BackendSurfaceAccess::kNoAccess, const GrFlushInfo &info={}, const skgpu::MutableTextureState *newState=nullptr)
GrDirectContextPriv priv()
VkSurfaceKHR surface
Definition main.cc:49

◆ flush() [7/7]

GrSemaphoresSubmitted GrDirectContext::flush ( SkSurface surface,
SkSurfaces::BackendSurfaceAccess  access,
const GrFlushInfo info 
)

Issues pending SkSurface commands to the GPU-backed API objects and resolves any SkSurface MSAA. A call to GrDirectContext::submit is always required to ensure work is actually sent to the gpu. Some specific API details: GL: Commands are actually sent to the driver, but glFlush is never called. Thus some sync objects from the flush will not be valid until a submission occurs.

Vulkan/Metal/D3D/Dawn: Commands are recorded to the backend APIs corresponding command buffer or encoder objects. However, these objects are not sent to the gpu until a submission occurs.

The work that is submitted to the GPU will be dependent on the BackendSurfaceAccess that is passed in.

If BackendSurfaceAccess::kNoAccess is passed in all commands will be issued to the GPU.

If BackendSurfaceAccess::kPresent is passed in and the backend API is not Vulkan, it is treated the same as kNoAccess. If the backend API is Vulkan, the VkImage that backs the SkSurface will be transferred back to its original queue. If the SkSurface was created by wrapping a VkImage, the queue will be set to the queue which was originally passed in on the GrVkImageInfo. Additionally, if the original queue was not external or foreign the layout of the VkImage will be set to VK_IMAGE_LAYOUT_PRESENT_SRC_KHR.

The GrFlushInfo describes additional options to flush. Please see documentation at GrFlushInfo for more info.

If the return is GrSemaphoresSubmitted::kYes, only initialized GrBackendSemaphores will be submitted to the gpu during the next submit call (it is possible Skia failed to create a subset of the semaphores). The client should not wait on these semaphores until after submit has been called, but must keep them alive until then. If a submit flag was passed in with the flush these valid semaphores can we waited on immediately. If this call returns GrSemaphoresSubmitted::kNo, the GPU backend will not submit any semaphores to be signaled on the GPU. Thus the client should not have the GPU wait on any of the semaphores passed in with the GrFlushInfo. Regardless of whether semaphores were submitted to the GPU or not, the client is still responsible for deleting any initialized semaphores. Regardless of semaphore submission the context will still be flushed. It should be emphasized that a return value of GrSemaphoresSubmitted::kNo does not mean the flush did not happen. It simply means there were no semaphores submitted to the GPU. A caller should only take this as a failure if they passed in semaphores to be submitted.

Pending surface commands are flushed regardless of the return result.

Parameters
surfaceThe GPU backed surface to be flushed. Has no effect on a CPU-backed surface.
accesstype of access the call will do on the backend object after flush
infoflush options

Definition at line 483 of file GrDirectContext.cpp.

485 {
486 if (!surface) {
488 }
489 auto sb = asSB(surface);
490 if (!sb->isGaneshBacked()) {
492 }
493
494 auto gs = static_cast<SkSurface_Ganesh*>(surface);
495 SkASSERT(this->priv().matches(gs->getDevice()->recordingContext()->asDirectContext()));
496 GrRenderTargetProxy* rtp = gs->getDevice()->targetProxy();
497
498 return this->priv().flushSurface(rtp, access, info, nullptr);
499}

◆ flushAndSubmit() [1/3]

void GrDirectContext::flushAndSubmit ( const sk_sp< const SkImage > &  image)

Version of flush() that uses a default GrFlushInfo. Also submits the flushed work to the GPU.

Definition at line 478 of file GrDirectContext.cpp.

478 {
479 this->flush(image, {});
480 this->submit();
481}
bool submit(GrSyncCpu sync=GrSyncCpu::kNo)

◆ flushAndSubmit() [2/3]

void GrDirectContext::flushAndSubmit ( GrSyncCpu  sync = GrSyncCpu::kNo)
inline

Call to ensure all drawing to the context has been flushed and submitted to the underlying 3D API. This is equivalent to calling GrContext::flush with a default GrFlushInfo followed by GrContext::submit(sync).

Definition at line 332 of file GrDirectContext.h.

332 {
333 this->flush(GrFlushInfo());
334 this->submit(sync);
335 }

◆ flushAndSubmit() [3/3]

void GrDirectContext::flushAndSubmit ( SkSurface surface,
GrSyncCpu  sync = GrSyncCpu::kNo 
)

Call to ensure all reads/writes of the surface have been issued to the underlying 3D API. Skia will correctly order its own draws and pixel operations. This must to be used to ensure correct ordering when the surface backing store is accessed outside Skia (e.g. direct use of the 3D API or a windowing system). This is equivalent to calling flush with a default GrFlushInfo followed by ::submit(syncCpu).

Has no effect on a CPU-backed surface.

Definition at line 520 of file GrDirectContext.cpp.

520 {
522 this->submit(sync);
523}

◆ freeGpuResources()

void GrDirectContext::freeGpuResources ( )

Frees GPU created by the context. Can be called to reduce GPU memory pressure.

Definition at line 220 of file GrDirectContext.cpp.

220 {
222
223 if (this->abandoned()) {
224 return;
225 }
226
227 this->flushAndSubmit();
228#if !defined(SK_ENABLE_OPTIMIZE_SIZE)
229 if (fSmallPathAtlasMgr) {
230 fSmallPathAtlasMgr->reset();
231 }
232#endif
233 fAtlasManager->freeAll();
234
235 // TODO: the glyph cache doesn't hold any GpuResources so this call should not be needed here.
236 // Some slack in the GrTextBlob's implementation requires it though. That could be fixed.
237 fStrikeCache->freeAll();
238
240
241 fResourceCache->purgeUnlockedResources(GrPurgeResourceOptions::kAllResources);
242}

◆ getResourceCacheLimit()

size_t GrDirectContext::getResourceCacheLimit ( ) const

Return the current GPU resource cache limit in bytes.

Definition at line 330 of file GrDirectContext.cpp.

330 {
332 return fResourceCache->getMaxResourceBytes();
333}

◆ getResourceCacheLimits()

void GrDirectContext::getResourceCacheLimits ( int maxResources,
size_t *  maxResourceBytes 
) const

DEPRECATED Return the current GPU resource cache limits.

Parameters
maxResourcesIf non-null, will be set to -1.
maxResourceBytesIf non-null, returns maximum number of bytes of video memory that can be held in the cache.

Definition at line 320 of file GrDirectContext.cpp.

320 {
322 if (maxResources) {
323 *maxResources = -1;
324 }
325 if (maxResourceBytes) {
326 *maxResourceBytes = this->getResourceCacheLimit();
327 }
328}
size_t getResourceCacheLimit() const

◆ getResourceCachePurgeableBytes()

size_t GrDirectContext::getResourceCachePurgeableBytes ( ) const

Gets the number of bytes in the cache consumed by purgeable (e.g. unlocked) resources.

Definition at line 315 of file GrDirectContext.cpp.

315 {
317 return fResourceCache->getPurgeableBytes();
318}

◆ getResourceCacheUsage()

void GrDirectContext::getResourceCacheUsage ( int resourceCount,
size_t *  resourceBytes 
) const

Gets the current GPU resource cache usage.

Parameters
resourceCountIf non-null, returns the number of resources that are held in the cache.
maxResourceBytesIf non-null, returns the total number of bytes of video memory held in the cache.

Definition at line 304 of file GrDirectContext.cpp.

304 {
306
307 if (resourceCount) {
308 *resourceCount = fResourceCache->getBudgetedResourceCount();
309 }
310 if (resourceBytes) {
311 *resourceBytes = fResourceCache->getBudgetedResourceBytes();
312 }
313}

◆ init()

bool GrDirectContext::init ( )
overrideprotectedvirtual

Reimplemented from GrContext_Base.

Definition at line 244 of file GrDirectContext.cpp.

244 {
246 if (!fGpu) {
247 return false;
248 }
249
250 fThreadSafeProxy->priv().init(fGpu->refCaps(), fGpu->refPipelineBuilder());
252 return false;
253 }
254
256 SkASSERT(this->threadSafeCache());
257
258 fStrikeCache = std::make_unique<StrikeCache>();
259 fResourceCache = std::make_unique<GrResourceCache>(this->singleOwner(),
260 this->directContextID(),
261 this->contextID());
262 fResourceCache->setProxyProvider(this->proxyProvider());
263 fResourceCache->setThreadSafeCache(this->threadSafeCache());
264#if defined(GR_TEST_UTILS)
265 if (this->options().fResourceCacheLimitOverride != -1) {
266 this->setResourceCacheLimit(this->options().fResourceCacheLimitOverride);
267 }
268#endif
269 fResourceProvider = std::make_unique<GrResourceProvider>(fGpu.get(), fResourceCache.get(),
270 this->singleOwner());
271 fMappedBufferManager = std::make_unique<GrClientMappedBufferManager>(this->directContextID());
272
273 fDidTestPMConversions = false;
274
275 // DDL TODO: we need to think through how the task group & persistent cache
276 // get passed on to/shared between all the DDLRecorders created with this context.
277 if (this->options().fExecutor) {
278 fTaskGroup = std::make_unique<SkTaskGroup>(*this->options().fExecutor);
279 }
280
281 fPersistentCache = this->options().fPersistentCache;
282
283 GrDrawOpAtlas::AllowMultitexturing allowMultitexturing;
284 if (GrContextOptions::Enable::kNo == this->options().fAllowMultipleGlyphCacheTextures ||
285 // multitexturing supported only if range can represent the index + texcoords fully
286 !(this->caps()->shaderCaps()->fFloatIs32Bits ||
287 this->caps()->shaderCaps()->fIntegerSupport)) {
288 allowMultitexturing = GrDrawOpAtlas::AllowMultitexturing::kNo;
289 } else {
290 allowMultitexturing = GrDrawOpAtlas::AllowMultitexturing::kYes;
291 }
292
294
295 fAtlasManager = std::make_unique<GrAtlasManager>(proxyProvider,
296 this->options().fGlyphCacheTextureMaximumBytes,
297 allowMultitexturing,
298 this->options().fSupportBilerpFromGlyphAtlas);
299 this->priv().addOnFlushCallbackObject(fAtlasManager.get());
300
301 return true;
302}
void init(sk_sp< const GrCaps >, sk_sp< GrThreadSafePipelineBuilder >) const
GrContextThreadSafeProxyPriv priv()
uint32_t contextID() const
sk_sp< GrContextThreadSafeProxy > fThreadSafeProxy
DirectContextID directContextID() const
void setResourceCacheLimit(size_t maxResourceBytes)
skgpu::SingleOwner * singleOwner() const
void addOnFlushCallbackObject(GrOnFlushCallbackObject *)
GrProxyProvider * proxyProvider()
GrThreadSafeCache * threadSafeCache()
GrProxyProvider * proxyProvider()
PersistentCache * fPersistentCache

◆ isDeviceLost()

bool GrDirectContext::isDeviceLost ( )

Returns true if the backend specific context has gotten into an unrecoverarble, lost state (e.g. in Vulkan backend if we've gotten a VK_ERROR_DEVICE_LOST). If the backend context is lost, this call will also abandon this context.

Definition at line 181 of file GrDirectContext.cpp.

181 {
182 if (fGpu && fGpu->isDeviceLost()) {
184 this->abandonContext();
185 }
186 return true;
187 }
188 return false;
189}

◆ MakeMock() [1/2]

sk_sp< GrDirectContext > GrDirectContext::MakeMock ( const GrMockOptions mockOptions)
static

Definition at line 1164 of file GrDirectContext.cpp.

1164 {
1165 GrContextOptions defaultOptions;
1166 return MakeMock(mockOptions, defaultOptions);
1167}
static sk_sp< GrDirectContext > MakeMock(const GrMockOptions *, const GrContextOptions &)

◆ MakeMock() [2/2]

sk_sp< GrDirectContext > GrDirectContext::MakeMock ( const GrMockOptions mockOptions,
const GrContextOptions options 
)
static

Definition at line 1169 of file GrDirectContext.cpp.

1170 {
1173 options,
1175
1176 direct->fGpu = GrMockGpu::Make(mockOptions, options, direct.get());
1177 if (!direct->init()) {
1178 return nullptr;
1179 }
1180
1181 return direct;
1182}
static sk_sp< GrContextThreadSafeProxy > Make(GrBackendApi, const GrContextOptions &)
static std::unique_ptr< GrGpu > Make(const GrMockOptions *, const GrContextOptions &, GrDirectContext *)
Definition GrMockGpu.cpp:56

◆ maxRenderTargetSize()

int GrRecordingContext::maxRenderTargetSize ( ) const

Gets the maximum supported render target size.

Definition at line 79 of file GrRecordingContext.cpp.

169{ return this->caps()->maxRenderTargetSize(); }
int maxRenderTargetSize() const
Definition GrCaps.h:223

◆ maxSurfaceSampleCountForColorType()

SK_API int GrRecordingContext::maxSurfaceSampleCountForColorType ( SkColorType  colorType) const
inline

Gets the maximum supported sample count for a color type. 1 is returned if only non-MSAA rendering is supported for the color type. 0 is returned if rendering to this color type is not supported at all.

Definition at line 96 of file GrRecordingContext.h.

96 {
98 }
SK_API int maxSurfaceSampleCountForColorType(SkColorType colorType) const

◆ maxTextureSize()

int GrRecordingContext::maxTextureSize ( ) const

Gets the maximum supported texture size.

Definition at line 74 of file GrRecordingContext.cpp.

167{ return this->caps()->maxTextureSize(); }
int maxTextureSize() const
Definition GrCaps.h:229

◆ onGetAtlasManager()

GrAtlasManager * GrDirectContext::onGetAtlasManager ( )
inlineprotected

Definition at line 916 of file GrDirectContext.h.

916{ return fAtlasManager.get(); }

◆ onGetSmallPathAtlasMgr()

skgpu::ganesh::SmallPathAtlasMgr * GrDirectContext::onGetSmallPathAtlasMgr ( )
protected

Definition at line 415 of file GrDirectContext.cpp.

415 {
416 if (!fSmallPathAtlasMgr) {
417 fSmallPathAtlasMgr = std::make_unique<skgpu::ganesh::SmallPathAtlasMgr>();
418
419 this->priv().addOnFlushCallbackObject(fSmallPathAtlasMgr.get());
420 }
421
422 if (!fSmallPathAtlasMgr->initAtlas(this->proxyProvider(), this->caps())) {
423 return nullptr;
424 }
425
426 return fSmallPathAtlasMgr.get();
427}

◆ oomed()

bool GrDirectContext::oomed ( )

Checks if the underlying 3D API reported an out-of-memory error. If this returns true it is reset and will return false until another out-of-memory error is reported by the 3D API. If the context is abandoned then this will report false.

Currently this is implemented for:

OpenGL [ES] - Note that client calls to glGetError() may swallow GL_OUT_OF_MEMORY errors and therefore hide the error from Skia. Also, it is not advised to use this in combination with enabling GrContextOptions::fSkipGLErrorChecks. That option may prevent the context from ever checking the GL context for OOM.

Vulkan - Reports true if VK_ERROR_OUT_OF_HOST_MEMORY or VK_ERROR_OUT_OF_DEVICE_MEMORY has occurred.

Definition at line 191 of file GrDirectContext.cpp.

191{ return fGpu ? fGpu->checkAndResetOOMed() : false; }

◆ performDeferredCleanup()

void GrDirectContext::performDeferredCleanup ( std::chrono::milliseconds  msNotUsed,
GrPurgeResourceOptions  opts = GrPurgeResourceOptions::kAllResources 
)

Purge GPU resources that haven't been used in the past 'msNotUsed' milliseconds or are otherwise marked for deletion, regardless of whether the context is under budget.

Parameters
msNotUsedOnly unlocked resources not used in these last milliseconds will be cleaned up.
optsSpecify which resources should be cleaned up. If kScratchResourcesOnly then, all unlocked scratch resources older than 'msNotUsed' will be purged but the unlocked resources with persistent data will remain. If kAllResources

Definition at line 362 of file GrDirectContext.cpp.

363 {
364 TRACE_EVENT0("skia.gpu", TRACE_FUNC);
365
367
368 if (this->abandoned()) {
369 return;
370 }
371
373 fMappedBufferManager->process();
374 auto purgeTime = skgpu::StdSteadyClock::now() - msNotUsed;
375
376 fResourceCache->purgeAsNeeded();
377 fResourceCache->purgeResourcesNotUsedSince(purgeTime, opts);
378
379 // The textBlob Cache doesn't actually hold any GPU resource but this is a convenient
380 // place to purge stale blobs
382}
void purgeStaleBlobs() SK_EXCLUDES(fSpinLock)

◆ precompileShader()

bool GrDirectContext::precompileShader ( const SkData key,
const SkData data 
)

Definition at line 1126 of file GrDirectContext.cpp.

1126 {
1127 return fGpu->precompileShader(key, data);
1128}

◆ priv() [1/2]

GrDirectContextPriv GrDirectContext::priv ( )
inline

Definition at line 186 of file GrDirectContextPriv.h.

186{ return GrDirectContextPriv(this); }
friend class GrDirectContextPriv

◆ priv() [2/2]

const GrDirectContextPriv GrDirectContext::priv ( ) const
inline

Definition at line 189 of file GrDirectContextPriv.h.

189 {
190 return GrDirectContextPriv(const_cast<GrDirectContext*>(this));
191}

◆ purgeResourcesNotUsedInMs()

void GrDirectContext::purgeResourcesNotUsedInMs ( std::chrono::milliseconds  msNotUsed)
inline

Definition at line 243 of file GrDirectContext.h.

243 {
244 this->performDeferredCleanup(msNotUsed);
245 }
void performDeferredCleanup(std::chrono::milliseconds msNotUsed, GrPurgeResourceOptions opts=GrPurgeResourceOptions::kAllResources)

◆ purgeUnlockedResources() [1/2]

void GrDirectContext::purgeUnlockedResources ( GrPurgeResourceOptions  opts)

This entry point is intended for instances where an app has been backgrounded or suspended. If 'scratchResourcesOnly' is true all unlocked scratch resources will be purged but the unlocked resources with persistent data will remain. If 'scratchResourcesOnly' is false then all unlocked resources will be purged. In either case, after the unlocked resources are purged a separate pass will be made to ensure that resource usage is under budget (i.e., even if 'scratchResourcesOnly' is true some resources with persistent data may be purged to be under budget).

Parameters
optsIf kScratchResourcesOnly only unlocked scratch resources will be purged prior enforcing the budget requirements.

Definition at line 345 of file GrDirectContext.cpp.

345 {
347
348 if (this->abandoned()) {
349 return;
350 }
351
352 fResourceCache->purgeUnlockedResources(opts);
353 fResourceCache->purgeAsNeeded();
354
355 // The textBlob Cache doesn't actually hold any GPU resource but this is a convenient
356 // place to purge stale blobs
358
359 fGpu->releaseUnlockedBackendObjects();
360}

◆ purgeUnlockedResources() [2/2]

void GrDirectContext::purgeUnlockedResources ( size_t  bytesToPurge,
bool  preferScratchResources 
)

Purge unlocked resources from the cache until the the provided byte count has been reached or we have purged all unlocked resources. The default policy is to purge in LRU order, but can be overridden to prefer purging scratch resources (in LRU order) prior to purging other resource types.

Parameters
maxBytesToPurgethe desired number of bytes to be purged.
preferScratchResourcesIf true scratch resources will be purged prior to other resource types.

Definition at line 384 of file GrDirectContext.cpp.

384 {
386
387 if (this->abandoned()) {
388 return;
389 }
390
391 fResourceCache->purgeUnlockedResources(bytesToPurge, preferScratchResources);
392}

◆ releaseResourcesAndAbandonContext()

void GrDirectContext::releaseResourcesAndAbandonContext ( )

This is similar to abandonContext() however the underlying 3D context is not yet lost and the context will cleanup all allocated resources before returning. After returning it will assume that the underlying context may no longer be valid.

The typical use case for this function is that the client is going to destroy the 3D context but can't guarantee that context will be destroyed first (perhaps because it may be ref'ed elsewhere by either the client or Skia objects).

For Vulkan, even if the device becomes lost, the VkQueue, VkDevice, or VkInstance used to create the context must be alive before calling releaseResourcesAndAbandonContext.

Definition at line 193 of file GrDirectContext.cpp.

193 {
195 return;
196 }
197
199
200 // We need to make sure all work is finished on the gpu before we start releasing resources.
201 this->syncAllOutstandingGpuWork(/*shouldExecuteWhileAbandoned=*/true);
202
203 fResourceProvider->abandon();
204
205 // Release all resources in the backend 3D API.
206 fResourceCache->releaseAll();
207
208 // Must be after GrResourceCache::releaseAll().
209 fMappedBufferManager.reset();
210
211 fGpu->disconnect(GrGpu::DisconnectType::kCleanup);
212#if !defined(SK_ENABLE_OPTIMIZE_SIZE)
213 if (fSmallPathAtlasMgr) {
214 fSmallPathAtlasMgr->reset();
215 }
216#endif
217 fAtlasManager->freeAll();
218}

◆ resetContext()

void GrDirectContext::resetContext ( uint32_t  state = kAll_GrBackendState)

The context normally assumes that no outsider is setting state within the underlying 3D API's context/device/whatever. This call informs the context that the state was modified and it should resend. Shouldn't be called frequently for good performance. The flag bits, state, is dependent on which backend is used by the context, either GL or D3D (possible in future).

Definition at line 129 of file GrDirectContext.cpp.

129 {
131 fGpu->markContextDirty(state);
132}
AtkStateType state

◆ resetGLTextureBindings()

void GrDirectContext::resetGLTextureBindings ( )

If the backend is GrBackendApi::kOpenGL, then all texture unit/target combinations for which the context has modified the bound texture will have texture id 0 bound. This does not flush the context. Calling resetContext() does not change the set that will be bound to texture id 0 on the next call to resetGLTextureBindings(). After this is called all unit/target combinations are considered to have unmodified bindings until the context subsequently modifies them (meaning if this is called twice in a row with no intervening context usage then the second call is a no-op.)

Definition at line 122 of file GrDirectContext.cpp.

122 {
123 if (this->abandoned() || this->backend() != GrBackendApi::kOpenGL) {
124 return;
125 }
126 fGpu->resetTextureBindings();
127}

◆ setBackendRenderTargetState()

bool GrDirectContext::setBackendRenderTargetState ( const GrBackendRenderTarget backendRenderTarget,
const skgpu::MutableTextureState state,
skgpu::MutableTextureState previousState = nullptr,
GrGpuFinishedProc  finishedProc = nullptr,
GrGpuFinishedContext  finishedContext = nullptr 
)

Definition at line 1098 of file GrDirectContext.cpp.

1102 {
1103 auto callback = skgpu::RefCntedCallback::Make(finishedProc, finishedContext);
1104
1105 if (this->abandoned()) {
1106 return false;
1107 }
1108
1109 return fGpu->setBackendRenderTargetState(backendRenderTarget, state, previousState,
1110 std::move(callback));
1111}
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback

◆ setBackendTextureState()

bool GrDirectContext::setBackendTextureState ( const GrBackendTexture backendTexture,
const skgpu::MutableTextureState state,
skgpu::MutableTextureState previousState = nullptr,
GrGpuFinishedProc  finishedProc = nullptr,
GrGpuFinishedContext  finishedContext = nullptr 
)

Updates the state of the GrBackendTexture/RenderTarget to have the passed in skgpu::MutableTextureState. All objects that wrap the backend surface (i.e. SkSurfaces and SkImages) will also be aware of this state change. This call does not submit the state change to the gpu, but requires the client to call submit to send it to the GPU. The work for this call is ordered linearly with all other calls that require GrContext::submit to be called (e.g updateBackendTexture and flush). If finishedProc is not null then it will be called with finishedContext after the state transition is known to have occurred on the GPU.

See skgpu::MutableTextureState to see what state can be set via this call.

If the backend API is Vulkan, the caller can set the skgpu::MutableTextureState's VkImageLayout to VK_IMAGE_LAYOUT_UNDEFINED or queueFamilyIndex to VK_QUEUE_FAMILY_IGNORED to tell Skia to not change those respective states.

If previousState is not null and this returns true, then Skia will have filled in previousState to have the values of the state before this call.

Definition at line 1083 of file GrDirectContext.cpp.

1087 {
1088 auto callback = skgpu::RefCntedCallback::Make(finishedProc, finishedContext);
1089
1090 if (this->abandoned()) {
1091 return false;
1092 }
1093
1094 return fGpu->setBackendTextureState(backendTexture, state, previousState, std::move(callback));
1095}

◆ setResourceCacheLimit()

void GrDirectContext::setResourceCacheLimit ( size_t  maxResourceBytes)

Specify the GPU resource cache limit. If the cache currently exceeds this limit, it will be purged (LRU) to keep the cache within the limit.

Parameters
maxResourceBytesThe maximum number of bytes of video memory that can be held in the cache.

Definition at line 340 of file GrDirectContext.cpp.

340 {
342 fResourceCache->setLimit(maxResourceBytes);
343}

◆ setResourceCacheLimits()

void GrDirectContext::setResourceCacheLimits ( int  maxResources,
size_t  maxResourceBytes 
)

DEPRECATED Specify the GPU resource cache limits. If the current cache exceeds the maxResourceBytes limit, it will be purged (LRU) to keep the cache within the limit.

Parameters
maxResourcesUnused.
maxResourceBytesThe maximum number of bytes of video memory that can be held in the cache.

Definition at line 335 of file GrDirectContext.cpp.

335 {
337 this->setResourceCacheLimit(maxResourceBytes);
338}

◆ storeVkPipelineCacheData()

void GrDirectContext::storeVkPipelineCacheData ( )

Definition at line 546 of file GrDirectContext.cpp.

546 {
547 if (fGpu) {
548 fGpu->storeVkPipelineCacheData();
549 }
550}

◆ submit()

bool GrDirectContext::submit ( GrSyncCpu  sync = GrSyncCpu::kNo)

Submit outstanding work to the gpu from all previously un-submitted flushes. The return value of the submit will indicate whether or not the submission to the GPU was successful.

If the call returns true, all previously passed in semaphores in flush calls will have been submitted to the GPU and they can safely be waited on. The caller should wait on those semaphores or perform some other global synchronization before deleting the semaphores.

If it returns false, then those same semaphores will not have been submitted and we will not try to submit them again. The caller is free to delete the semaphores at any time.

If sync flag is GrSyncCpu::kYes, this function will return once the gpu has finished with all submitted work.

Definition at line 448 of file GrDirectContext.cpp.

448 {
450 if (this->abandoned()) {
451 return false;
452 }
453
454 if (!fGpu) {
455 return false;
456 }
457
458 return fGpu->submitToGpu(sync);
459}

◆ supportsDistanceFieldText()

bool GrDirectContext::supportsDistanceFieldText ( ) const

Definition at line 554 of file GrDirectContext.cpp.

554 {
555 return this->caps()->shaderCaps()->supportsDistanceFieldText();
556}
const GrShaderCaps * shaderCaps() const
Definition GrCaps.h:63
bool supportsDistanceFieldText() const
Definition SkSLUtil.h:80

◆ supportsProtectedContent()

bool GrRecordingContext::supportsProtectedContent ( ) const

Does this context support protected content?

Definition at line 89 of file GrRecordingContext.cpp.

178 {
179 return this->caps()->supportsProtectedContent();
180}
bool supportsProtectedContent() const
Definition GrCaps.h:422

◆ threadSafeProxy()

sk_sp< GrContextThreadSafeProxy > GrDirectContext::threadSafeProxy ( )

Definition at line 118 of file GrDirectContext.cpp.

118 {
120}
sk_sp< GrContextThreadSafeProxy > threadSafeProxy()

◆ updateBackendTexture() [1/5]

bool GrDirectContext::updateBackendTexture ( const GrBackendTexture backendTexture,
const SkColor4f color,
GrGpuFinishedProc  finishedProc,
GrGpuFinishedContext  finishedContext 
)

If possible, updates a backend texture to be filled to a particular color. The client should check the return value to see if the update was successful. The client can pass in a finishedProc to be notified when the data has been uploaded by the gpu and the texture can be deleted. The client is required to call submit to send the upload work to the gpu. The finishedProc will always get called even if we failed to update the GrBackendTexture. For the Vulkan backend after a successful update the layout of the created VkImage will be: VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL

Definition at line 836 of file GrDirectContext.cpp.

839 {
840 auto finishedCallback = skgpu::RefCntedCallback::Make(finishedProc, finishedContext);
841
842 if (this->abandoned()) {
843 return false;
844 }
845
846 return fGpu->clearBackendTexture(backendTexture, std::move(finishedCallback), color.array());
847}

◆ updateBackendTexture() [2/5]

bool GrDirectContext::updateBackendTexture ( const GrBackendTexture backendTexture,
const SkPixmap  srcData[],
int  numLevels,
GrSurfaceOrigin  textureOrigin = kTopLeft_GrSurfaceOrigin,
GrGpuFinishedProc  finishedProc = nullptr,
GrGpuFinishedContext  finishedContext = nullptr 
)

If possible, updates a backend texture filled with the provided pixmap data. The client should check the return value to see if the update was successful. The client can pass in a finishedProc to be notified when the data has been uploaded by the gpu and the texture can be deleted. The client is required to call submit to send the upload work to the gpu. The finishedProc will always get called even if we failed to create the GrBackendTexture. The backend texture must be compatible with the provided pixmap(s). Compatible, in this case, means that the backend format is compatible with the base pixmap's colortype. The src data can be deleted when this call returns. If the backend texture is mip mapped, the data for all the mipmap levels must be provided. In the mipmapped case all the colortypes of the provided pixmaps must be the same. Additionally, all the miplevels must be sized correctly (please see SkMipmap::ComputeLevelSize and ComputeLevelCount). The GrSurfaceOrigin controls whether the pixmap data is vertically flipped in the texture. Note: the pixmap's alphatypes and colorspaces are ignored. For the Vulkan backend after a successful update the layout of the created VkImage will be: VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL

Definition at line 875 of file GrDirectContext.cpp.

880 {
881 auto finishedCallback = skgpu::RefCntedCallback::Make(finishedProc, finishedContext);
882
883 if (this->abandoned()) {
884 return false;
885 }
886
887 if (!srcData || numLevels <= 0) {
888 return false;
889 }
890
891 // If the texture has MIP levels then we require that the full set is overwritten.
892 int numExpectedLevels = 1;
893 if (backendTexture.hasMipmaps()) {
894 numExpectedLevels = SkMipmap::ComputeLevelCount(backendTexture.width(),
895 backendTexture.height()) + 1;
896 }
897 if (numLevels != numExpectedLevels) {
898 return false;
899 }
900 return update_texture_with_pixmaps(this,
901 srcData,
902 numLevels,
903 backendTexture,
904 textureOrigin,
905 std::move(finishedCallback));
906}
bool hasMipmaps() const
static int ComputeLevelCount(int baseWidth, int baseHeight)
Definition SkMipmap.cpp:134

◆ updateBackendTexture() [3/5]

bool GrDirectContext::updateBackendTexture ( const GrBackendTexture backendTexture,
SkColorType  skColorType,
const SkColor4f color,
GrGpuFinishedProc  finishedProc,
GrGpuFinishedContext  finishedContext 
)

If possible, updates a backend texture to be filled to a particular color. The data in GrBackendTexture and passed in color is interpreted with respect to the passed in SkColorType. The client should check the return value to see if the update was successful. The client can pass in a finishedProc to be notified when the data has been uploaded by the gpu and the texture can be deleted. The client is required to call submit to send the upload work to the gpu. The finishedProc will always get called even if we failed to update the GrBackendTexture. For the Vulkan backend after a successful update the layout of the created VkImage will be: VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL

Definition at line 849 of file GrDirectContext.cpp.

853 {
854 auto finishedCallback = skgpu::RefCntedCallback::Make(finishedProc, finishedContext);
855
856 if (this->abandoned()) {
857 return false;
858 }
859
860 GrBackendFormat format = backendTexture.getBackendFormat();
861 GrColorType grColorType = SkColorTypeToGrColorType(skColorType);
862
863 if (!this->caps()->areColorTypeAndFormatCompatible(grColorType, format)) {
864 return false;
865 }
866
867 skgpu::Swizzle swizzle = this->caps()->getWriteSwizzle(format, grColorType);
868 SkColor4f swizzledColor = swizzle.applyTo(color);
869
870 return fGpu->clearBackendTexture(backendTexture,
871 std::move(finishedCallback),
872 swizzledColor.array());
873}
GrBackendFormat getBackendFormat() const

◆ updateBackendTexture() [4/5]

bool GrDirectContext::updateBackendTexture ( const GrBackendTexture texture,
const SkPixmap srcData,
GrSurfaceOrigin  textureOrigin = kTopLeft_GrSurfaceOrigin,
GrGpuFinishedProc  finishedProc = nullptr,
GrGpuFinishedContext  finishedContext = nullptr 
)
inline

Convenience version of updateBackendTexture that takes just a base level pixmap.

Definition at line 710 of file GrDirectContext.h.

714 {
715 return this->updateBackendTexture(texture,
716 &srcData,
717 1,
718 textureOrigin,
719 finishedProc,
720 finishedContext);
721 }
bool updateBackendTexture(const GrBackendTexture &, const SkColor4f &color, GrGpuFinishedProc finishedProc, GrGpuFinishedContext finishedContext)

◆ updateBackendTexture() [5/5]

bool GrDirectContext::updateBackendTexture ( const GrBackendTexture texture,
const SkPixmap  srcData[],
int  numLevels,
GrGpuFinishedProc  finishedProc,
GrGpuFinishedContext  finishedContext 
)

Definition at line 823 of file GrDirectContext.cpp.

827 {
828 return this->updateBackendTexture(texture,
829 srcData,
830 numLevels,
832 finishedProc,
833 finishedContext);
834}

◆ updateCompressedBackendTexture() [1/2]

bool GrDirectContext::updateCompressedBackendTexture ( const GrBackendTexture backendTexture,
const SkColor4f color,
GrGpuFinishedProc  finishedProc,
GrGpuFinishedContext  finishedContext 
)

If possible, updates a backend texture filled with the provided color. If the texture is mipmapped, all levels of the mip chain will be updated to have the supplied color. The client should check the return value to see if the update was successful. The client can pass in a finishedProc to be notified when the data has been uploaded by the gpu and the texture can be deleted. The client is required to call submit to send the upload work to the gpu. The finishedProc will always get called even if we failed to create the GrBackendTexture. For the Vulkan backend after a successful update the layout of the created VkImage will be: VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL

Definition at line 1029 of file GrDirectContext.cpp.

1032 {
1033 auto finishedCallback = skgpu::RefCntedCallback::Make(finishedProc, finishedContext);
1034
1035 if (this->abandoned()) {
1036 return false;
1037 }
1038
1039 SkTextureCompressionType compression =
1041 if (compression == SkTextureCompressionType::kNone) {
1042 return {};
1043 }
1044 size_t size = SkCompressedDataSize(compression,
1045 backendTexture.dimensions(),
1046 nullptr,
1047 backendTexture.hasMipmaps());
1048 SkAutoMalloc storage(size);
1049 skgpu::FillInCompressedData(compression,
1050 backendTexture.dimensions(),
1051 backendTexture.mipmapped(),
1052 static_cast<char*>(storage.get()),
1053 color);
1054 return fGpu->updateCompressedBackendTexture(backendTexture,
1055 std::move(finishedCallback),
1056 storage.get(),
1057 size);
1058}
SkISize dimensions() const
skgpu::Mipmapped mipmapped() const

◆ updateCompressedBackendTexture() [2/2]

bool GrDirectContext::updateCompressedBackendTexture ( const GrBackendTexture backendTexture,
const void *  data,
size_t  dataSize,
GrGpuFinishedProc  finishedProc,
GrGpuFinishedContext  finishedContext 
)

If possible, updates a backend texture filled with the provided raw data. The client should check the return value to see if the update was successful. The client can pass in a finishedProc to be notified when the data has been uploaded by the gpu and the texture can be deleted. The client is required to call submit to send the upload work to the gpu. The finishedProc will always get called even if we failed to create the GrBackendTexture. If a mipmapped texture is passed in, the data for all the mipmap levels must be provided. Additionally, all the miplevels must be sized correctly (please see SkMipMap::ComputeLevelSize and ComputeLevelCount). For the Vulkan backend after a successful update the layout of the created VkImage will be: VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL

Definition at line 1060 of file GrDirectContext.cpp.

1064 {
1065 auto finishedCallback = skgpu::RefCntedCallback::Make(finishedProc, finishedContext);
1066
1067 if (this->abandoned()) {
1068 return false;
1069 }
1070
1071 if (!compressedData) {
1072 return false;
1073 }
1074
1075 return fGpu->updateCompressedBackendTexture(backendTexture,
1076 std::move(finishedCallback),
1077 compressedData,
1078 dataSize);
1079}

◆ wait()

bool GrDirectContext::wait ( int  numSemaphores,
const GrBackendSemaphore waitSemaphores,
bool  deleteSemaphoresAfterWait = true 
)

Inserts a list of GPU semaphores that the current GPU-backed API must wait on before executing any more commands on the GPU. We only guarantee blocking transfer and fragment shader work, but may block earlier stages as well depending on the backend.If this call returns false, then the GPU back-end will not wait on any passed in semaphores, and the client will still own the semaphores, regardless of the value of deleteSemaphoresAfterWait.

If deleteSemaphoresAfterWait is false then Skia will not delete the semaphores. In this case it is the client's responsibility to not destroy or attempt to reuse the semaphores until it knows that Skia has finished waiting on them. This can be done by using finishedProcs on flush calls.

This is not supported on the GL backend.

Definition at line 395 of file GrDirectContext.cpp.

396 {
397 if (!fGpu || !fGpu->caps()->backendSemaphoreSupport()) {
398 return false;
399 }
400 GrWrapOwnership ownership =
401 deleteSemaphoresAfterWait ? kAdopt_GrWrapOwnership : kBorrow_GrWrapOwnership;
402 for (int i = 0; i < numSemaphores; ++i) {
403 std::unique_ptr<GrSemaphore> sema = fResourceProvider->wrapBackendSemaphore(
404 waitSemaphores[i], GrSemaphoreWrapType::kWillWait, ownership);
405 // If we failed to wrap the semaphore it means the client didn't give us a valid semaphore
406 // to begin with. Therefore, it is fine to not wait on it.
407 if (sema) {
408 fGpu->waitSemaphore(sema.get());
409 }
410 }
411 return true;
412}
GrWrapOwnership
Definition GrTypesPriv.h:76
@ kAdopt_GrWrapOwnership
Definition GrTypesPriv.h:81
@ kBorrow_GrWrapOwnership
Definition GrTypesPriv.h:78

Friends And Related Symbol Documentation

◆ GrDirectContextPriv

friend class GrDirectContextPriv
friend

Definition at line 989 of file GrDirectContext.h.


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