Flutter Engine
The Flutter Engine
Classes | Public Member Functions | Protected Member Functions | Friends | List of all members
skgpu::graphite::Context Class Referencefinal

#include <Context.h>

Classes

class  ContextID
 

Public Member Functions

 Context (const Context &)=delete
 
 Context (Context &&)=delete
 
Contextoperator= (const Context &)=delete
 
Contextoperator= (Context &&)=delete
 
 ~Context ()
 
BackendApi backend () const
 
std::unique_ptr< RecordermakeRecorder (const RecorderOptions &={})
 
bool insertRecording (const InsertRecordingInfo &)
 
bool submit (SyncToCpu=SyncToCpu::kNo)
 
bool hasUnfinishedGpuWork () const
 
void asyncRescaleAndReadPixels (const SkImage *image, const SkImageInfo &dstImageInfo, const SkIRect &srcRect, SkImage::RescaleGamma rescaleGamma, SkImage::RescaleMode rescaleMode, SkImage::ReadPixelsCallback callback, SkImage::ReadPixelsContext context)
 
void asyncRescaleAndReadPixels (const SkSurface *surface, const SkImageInfo &dstImageInfo, const SkIRect &srcRect, SkImage::RescaleGamma rescaleGamma, SkImage::RescaleMode rescaleMode, SkImage::ReadPixelsCallback callback, SkImage::ReadPixelsContext context)
 
void asyncRescaleAndReadPixelsYUV420 (const SkImage *, SkYUVColorSpace yuvColorSpace, sk_sp< SkColorSpace > dstColorSpace, const SkIRect &srcRect, const SkISize &dstSize, SkImage::RescaleGamma rescaleGamma, SkImage::RescaleMode rescaleMode, SkImage::ReadPixelsCallback callback, SkImage::ReadPixelsContext context)
 
void asyncRescaleAndReadPixelsYUV420 (const SkSurface *, SkYUVColorSpace yuvColorSpace, sk_sp< SkColorSpace > dstColorSpace, const SkIRect &srcRect, const SkISize &dstSize, SkImage::RescaleGamma rescaleGamma, SkImage::RescaleMode rescaleMode, SkImage::ReadPixelsCallback callback, SkImage::ReadPixelsContext context)
 
void asyncRescaleAndReadPixelsYUVA420 (const SkImage *, SkYUVColorSpace yuvColorSpace, sk_sp< SkColorSpace > dstColorSpace, const SkIRect &srcRect, const SkISize &dstSize, SkImage::RescaleGamma rescaleGamma, SkImage::RescaleMode rescaleMode, SkImage::ReadPixelsCallback callback, SkImage::ReadPixelsContext context)
 
void asyncRescaleAndReadPixelsYUVA420 (const SkSurface *, SkYUVColorSpace yuvColorSpace, sk_sp< SkColorSpace > dstColorSpace, const SkIRect &srcRect, const SkISize &dstSize, SkImage::RescaleGamma rescaleGamma, SkImage::RescaleMode rescaleMode, SkImage::ReadPixelsCallback callback, SkImage::ReadPixelsContext context)
 
void checkAsyncWorkCompletion ()
 
void deleteBackendTexture (const BackendTexture &)
 
void freeGpuResources ()
 
void performDeferredCleanup (std::chrono::milliseconds msNotUsed)
 
size_t currentBudgetedBytes () const
 
size_t maxBudgetedBytes () const
 
void dumpMemoryStatistics (SkTraceMemoryDump *traceMemoryDump) const
 
bool isDeviceLost () const
 
int maxTextureSize () const
 
bool supportsProtectedContent () const
 
ContextPriv priv ()
 
const ContextPriv priv () const
 
ContextID contextID () const
 

Protected Member Functions

 Context (sk_sp< SharedContext >, std::unique_ptr< QueueManager >, const ContextOptions &)
 

Friends

class ContextPriv
 
class ContextCtorAccessor
 

Detailed Description

Definition at line 43 of file Context.h.

Constructor & Destructor Documentation

◆ Context() [1/3]

skgpu::graphite::Context::Context ( const Context )
delete

◆ Context() [2/3]

skgpu::graphite::Context::Context ( Context &&  )
delete

◆ ~Context()

Context::~Context ( )

Definition at line 99 of file Context.cpp.

99 {
100#if defined(GRAPHITE_TEST_UTILS)
102 for (auto& recorder : fTrackedRecorders) {
103 recorder->priv().setContext(nullptr);
104 }
105#endif
106}
#define ASSERT_SINGLE_OWNER
Definition: Context.cpp:68

◆ Context() [3/3]

Context::Context ( sk_sp< SharedContext sharedContext,
std::unique_ptr< QueueManager queueManager,
const ContextOptions options 
)
protected

Definition at line 80 of file Context.cpp.

83 : fSharedContext(std::move(sharedContext))
84 , fQueueManager(std::move(queueManager))
85 , fContextID(ContextID::Next()) {
86 // We have to create this outside the initializer list because we need to pass in the Context's
87 // SingleOwner object and it is declared last
88 fResourceProvider = fSharedContext->makeResourceProvider(&fSingleOwner,
90 options.fGpuBudgetInBytes);
91 fMappedBufferManager = std::make_unique<ClientMappedBufferManager>(this->contextID());
92#if defined(GRAPHITE_TEST_UTILS)
93 if (options.fOptionsPriv) {
94 fStoreContextRefInRecorder = options.fOptionsPriv->fStoreContextRefInRecorder;
95 }
96#endif
97}
const char * options
static constexpr uint32_t SK_InvalidGenID
Definition: SkTypes.h:192
static Context::ContextID Next()
Definition: Context.cpp:70
ContextID contextID() const
Definition: Context.h:203

Member Function Documentation

◆ asyncRescaleAndReadPixels() [1/2]

void Context::asyncRescaleAndReadPixels ( const SkImage image,
const SkImageInfo dstImageInfo,
const SkIRect srcRect,
SkImage::RescaleGamma  rescaleGamma,
SkImage::RescaleMode  rescaleMode,
SkImage::ReadPixelsCallback  callback,
SkImage::ReadPixelsContext  context 
)

Definition at line 245 of file Context.cpp.

251 {
252 this->asyncRescaleAndReadImpl(&Context::asyncReadPixels,
253 rescaleGamma, rescaleMode,
254 {image, srcRect, dstImageInfo, callback, callbackContext});
255}
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
sk_sp< const SkImage > image
Definition: SkRecords.h:269

◆ asyncRescaleAndReadPixels() [2/2]

void Context::asyncRescaleAndReadPixels ( const SkSurface surface,
const SkImageInfo dstImageInfo,
const SkIRect srcRect,
SkImage::RescaleGamma  rescaleGamma,
SkImage::RescaleMode  rescaleMode,
SkImage::ReadPixelsCallback  callback,
SkImage::ReadPixelsContext  context 
)

Definition at line 257 of file Context.cpp.

263 {
265 if (!surfaceImage) {
266 // The surface is not texturable, so the only supported readback is if there's no rescaling
267 if (surface && asConstSB(surface)->isGraphiteBacked() &&
268 srcRect.size() == dstImageInfo.dimensions()) {
269 TextureProxy* proxy = static_cast<const Surface*>(surface)->backingTextureProxy();
270 return this->asyncReadTexture(/*recorder=*/nullptr,
271 {proxy, srcRect, dstImageInfo, callback, callbackContext},
272 surface->imageInfo().colorInfo());
273 }
274 // else fall through and let asyncRescaleAndReadPixels() invoke the callback when it detects
275 // the null image.
276 }
277 this->asyncRescaleAndReadPixels(surfaceImage.get(),
278 dstImageInfo,
279 srcRect,
280 rescaleGamma,
281 rescaleMode,
282 callback,
283 callbackContext);
284}
sk_sp< T > sk_ref_sp(T *obj)
Definition: SkRefCnt.h:381
static const SkSurface_Base * asConstSB(const SkSurface *surface)
T * get() const
Definition: SkRefCnt.h:303
void asyncRescaleAndReadPixels(const SkImage *image, const SkImageInfo &dstImageInfo, const SkIRect &srcRect, SkImage::RescaleGamma rescaleGamma, SkImage::RescaleMode rescaleMode, SkImage::ReadPixelsCallback callback, SkImage::ReadPixelsContext context)
Definition: Context.cpp:245
VkSurfaceKHR surface
Definition: main.cc:49
SK_API sk_sp< SkImage > AsImage(sk_sp< const SkSurface >)
constexpr SkISize size() const
Definition: SkRect.h:172
SkISize dimensions() const
Definition: SkImageInfo.h:421

◆ asyncRescaleAndReadPixelsYUV420() [1/2]

void Context::asyncRescaleAndReadPixelsYUV420 ( const SkImage image,
SkYUVColorSpace  yuvColorSpace,
sk_sp< SkColorSpace dstColorSpace,
const SkIRect srcRect,
const SkISize dstSize,
SkImage::RescaleGamma  rescaleGamma,
SkImage::RescaleMode  rescaleMode,
SkImage::ReadPixelsCallback  callback,
SkImage::ReadPixelsContext  context 
)

Definition at line 351 of file Context.cpp.

359 {
360 // Use kOpaque alpha type to signal that we don't read back the alpha channel
361 SkImageInfo dstImageInfo = SkImageInfo::Make(dstSize,
364 std::move(dstColorSpace));
365 this->asyncRescaleAndReadImpl(&Context::asyncReadPixelsYUV420,
366 rescaleGamma, rescaleMode,
367 {image, srcRect, dstImageInfo, callback, callbackContext},
368 yuvColorSpace);
369}
@ kOpaque_SkAlphaType
pixel is opaque
Definition: SkAlphaType.h:28
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
Definition: SkColorType.h:24
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)

◆ asyncRescaleAndReadPixelsYUV420() [2/2]

void Context::asyncRescaleAndReadPixelsYUV420 ( const SkSurface surface,
SkYUVColorSpace  yuvColorSpace,
sk_sp< SkColorSpace dstColorSpace,
const SkIRect srcRect,
const SkISize dstSize,
SkImage::RescaleGamma  rescaleGamma,
SkImage::RescaleMode  rescaleMode,
SkImage::ReadPixelsCallback  callback,
SkImage::ReadPixelsContext  context 
)

Definition at line 371 of file Context.cpp.

379 {
380 // YUV[A] readback requires the surface to be texturable since the plane conversion is performed
381 // by draws. If AsImage() returns null, the image version of asyncRescaleAndReadback will
382 // automatically fail.
383 // TODO: Is it worth performing an extra copy from 'surface' into a texture in order to succeed?
385 this->asyncRescaleAndReadPixelsYUV420(surfaceImage.get(),
386 yuvColorSpace,
387 dstColorSpace,
388 srcRect,
389 dstSize,
390 rescaleGamma,
391 rescaleMode,
392 callback,
393 callbackContext);
394}
void asyncRescaleAndReadPixelsYUV420(const SkImage *, SkYUVColorSpace yuvColorSpace, sk_sp< SkColorSpace > dstColorSpace, const SkIRect &srcRect, const SkISize &dstSize, SkImage::RescaleGamma rescaleGamma, SkImage::RescaleMode rescaleMode, SkImage::ReadPixelsCallback callback, SkImage::ReadPixelsContext context)
Definition: Context.cpp:351

◆ asyncRescaleAndReadPixelsYUVA420() [1/2]

void Context::asyncRescaleAndReadPixelsYUVA420 ( const SkImage image,
SkYUVColorSpace  yuvColorSpace,
sk_sp< SkColorSpace dstColorSpace,
const SkIRect srcRect,
const SkISize dstSize,
SkImage::RescaleGamma  rescaleGamma,
SkImage::RescaleMode  rescaleMode,
SkImage::ReadPixelsCallback  callback,
SkImage::ReadPixelsContext  context 
)

Definition at line 396 of file Context.cpp.

404 {
405 SkImageInfo dstImageInfo = SkImageInfo::Make(dstSize,
408 std::move(dstColorSpace));
409 this->asyncRescaleAndReadImpl(&Context::asyncReadPixelsYUV420,
410 rescaleGamma, rescaleMode,
411 {image, srcRect, dstImageInfo, callback, callbackContext},
412 yuvColorSpace);
413}
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition: SkAlphaType.h:29

◆ asyncRescaleAndReadPixelsYUVA420() [2/2]

void Context::asyncRescaleAndReadPixelsYUVA420 ( const SkSurface surface,
SkYUVColorSpace  yuvColorSpace,
sk_sp< SkColorSpace dstColorSpace,
const SkIRect srcRect,
const SkISize dstSize,
SkImage::RescaleGamma  rescaleGamma,
SkImage::RescaleMode  rescaleMode,
SkImage::ReadPixelsCallback  callback,
SkImage::ReadPixelsContext  context 
)

Definition at line 415 of file Context.cpp.

423 {
425 this->asyncRescaleAndReadPixelsYUVA420(surfaceImage.get(),
426 yuvColorSpace,
427 dstColorSpace,
428 srcRect,
429 dstSize,
430 rescaleGamma,
431 rescaleMode,
432 callback,
433 callbackContext);
434}
void asyncRescaleAndReadPixelsYUVA420(const SkImage *, SkYUVColorSpace yuvColorSpace, sk_sp< SkColorSpace > dstColorSpace, const SkIRect &srcRect, const SkISize &dstSize, SkImage::RescaleGamma rescaleGamma, SkImage::RescaleMode rescaleMode, SkImage::ReadPixelsCallback callback, SkImage::ReadPixelsContext context)
Definition: Context.cpp:396

◆ backend()

BackendApi Context::backend ( ) const

Definition at line 130 of file Context.cpp.

130{ return fSharedContext->backend(); }

◆ checkAsyncWorkCompletion()

void Context::checkAsyncWorkCompletion ( )

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

Definition at line 746 of file Context.cpp.

746 {
747 this->checkForFinishedWork(SyncToCpu::kNo);
748}

◆ contextID()

ContextID skgpu::graphite::Context::contextID ( ) const
inline

Definition at line 203 of file Context.h.

203{ return fContextID; }

◆ currentBudgetedBytes()

size_t Context::currentBudgetedBytes ( ) const

Returns the number of bytes of the Context's gpu memory cache budget that are currently in use.

Definition at line 776 of file Context.cpp.

776 {
778 return fResourceProvider->getResourceCacheCurrentBudgetedBytes();
779}

◆ deleteBackendTexture()

void Context::deleteBackendTexture ( const BackendTexture texture)

Called to delete the passed in BackendTexture. This should only be called if the BackendTexture was created by calling Recorder::createBackendTexture on a Recorder created from this Context. If the BackendTexture is not valid or does not match the BackendApi of the Context then nothing happens.

Otherwise this will delete/release the backend object that is wrapped in the BackendTexture. The BackendTexture will be reset to an invalid state and should not be used again.

Definition at line 750 of file Context.cpp.

750 {
752
753 if (!texture.isValid() || texture.backend() != this->backend()) {
754 return;
755 }
756 fResourceProvider->deleteBackendTexture(texture);
757}
FlTexture * texture

◆ dumpMemoryStatistics()

void Context::dumpMemoryStatistics ( SkTraceMemoryDump traceMemoryDump) const

Enumerates all cached GPU resources owned by the Context and dumps their memory to traceMemoryDump.

Definition at line 786 of file Context.cpp.

786 {
788 fResourceProvider->dumpMemoryStatistics(traceMemoryDump);
789 // TODO: What is the graphite equivalent for the text blob cache and how do we print out its
790 // used bytes here (see Ganesh implementation).
791}

◆ freeGpuResources()

void Context::freeGpuResources ( )

Frees GPU resources created and held by the Context. Can be called to reduce GPU memory pressure. Any resources that are still in use (e.g. being used by work submitted to the GPU) will not be deleted by this call. If the caller wants to make sure all resources are freed, then they should first make sure to submit and wait on any outstanding work.

Definition at line 759 of file Context.cpp.

759 {
761
763
764 fResourceProvider->freeGpuResources();
765}

◆ hasUnfinishedGpuWork()

bool Context::hasUnfinishedGpuWork ( ) const

Returns true if there is work that was submitted to the GPU that has not finished.

Definition at line 175 of file Context.cpp.

175{ return fQueueManager->hasUnfinishedGpuWork(); }

◆ insertRecording()

bool Context::insertRecording ( const InsertRecordingInfo info)

Definition at line 156 of file Context.cpp.

156 {
158
159 return fQueueManager->addRecording(info, this);
160}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213

◆ isDeviceLost()

bool Context::isDeviceLost ( ) const

Returns true if the backend-specific context has gotten into an unrecoverarble, lost state (e.g. if we've gotten a VK_ERROR_DEVICE_LOST in the Vulkan backend).

Definition at line 793 of file Context.cpp.

793 {
794 return fSharedContext->isDeviceLost();
795}

◆ makeRecorder()

std::unique_ptr< Recorder > Context::makeRecorder ( const RecorderOptions options = {})

Definition at line 132 of file Context.cpp.

132 {
134
135 // This is a client-owned Recorder so pass a null context so it creates its own ResourceProvider
136 auto recorder = std::unique_ptr<Recorder>(new Recorder(fSharedContext, options, nullptr));
137#if defined(GRAPHITE_TEST_UTILS)
138 if (fStoreContextRefInRecorder) {
139 recorder->priv().setContext(this);
140 }
141#endif
142 return recorder;
143}
skgpu::graphite::Recorder Recorder

◆ maxBudgetedBytes()

size_t Context::maxBudgetedBytes ( ) const

Returns the size of Context's gpu memory cache budget in bytes.

Definition at line 781 of file Context.cpp.

781 {
783 return fResourceProvider->getResourceCacheLimit();
784}

◆ maxTextureSize()

int Context::maxTextureSize ( ) const

Returns the maximum texture dimension supported by the underlying backend.

Definition at line 797 of file Context.cpp.

797 {
798 return fSharedContext->caps()->maxTextureSize();
799}

◆ operator=() [1/2]

Context & skgpu::graphite::Context::operator= ( const Context )
delete

◆ operator=() [2/2]

Context & skgpu::graphite::Context::operator= ( Context &&  )
delete

◆ performDeferredCleanup()

void Context::performDeferredCleanup ( std::chrono::milliseconds  msNotUsed)

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

Definition at line 767 of file Context.cpp.

767 {
769
771
772 auto purgeTime = skgpu::StdSteadyClock::now() - msNotUsed;
773 fResourceProvider->purgeResourcesNotUsedSince(purgeTime);
774}

◆ priv() [1/2]

ContextPriv Context::priv ( )
inline

Definition at line 85 of file ContextPriv.h.

85{ return ContextPriv(this); }
friend class ContextPriv
Definition: Context.h:209

◆ priv() [2/2]

const ContextPriv Context::priv ( ) const
inline

Definition at line 88 of file ContextPriv.h.

88 {
89 return ContextPriv(const_cast<Context *>(this));
90}

◆ submit()

bool Context::submit ( SyncToCpu  syncToCpu = SyncToCpu::kNo)

Definition at line 162 of file Context.cpp.

162 {
164
165 if (syncToCpu == SyncToCpu::kYes && !fSharedContext->caps()->allowCpuSync()) {
166 SKGPU_LOG_E("SyncToCpu::kYes not supported with ContextOptions::fNeverYieldToWebGPU. "
167 "The parameter is ignored and no synchronization will occur.");
168 syncToCpu = SyncToCpu::kNo;
169 }
170 bool success = fQueueManager->submitToGpu();
171 this->checkForFinishedWork(syncToCpu);
172 return success;
173}
#define SKGPU_LOG_E(fmt,...)
Definition: Log.h:38

◆ supportsProtectedContent()

bool Context::supportsProtectedContent ( ) const

Definition at line 801 of file Context.cpp.

801 {
802 return fSharedContext->isProtected() == Protected::kYes;
803}

Friends And Related Function Documentation

◆ ContextCtorAccessor

friend class ContextCtorAccessor
friend

Definition at line 210 of file Context.h.

◆ ContextPriv

friend class ContextPriv
friend

Definition at line 209 of file Context.h.


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