Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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 97 of file Context.cpp.

97 {
98#if defined(GRAPHITE_TEST_UTILS)
100 for (auto& recorder : fTrackedRecorders) {
101 recorder->priv().setContext(nullptr);
102 }
103#endif
104}
#define ASSERT_SINGLE_OWNER
Definition Device.cpp:120

◆ Context() [3/3]

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

Definition at line 78 of file Context.cpp.

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

169 {
170 if (!image || !as_IB(image)->isGraphiteBacked()) {
171 callback(callbackContext, nullptr);
172 return;
173 }
174 // TODO(b/238756380): YUVA read not supported right now
175 if (as_IB(image)->isYUVA()) {
176 callback(callbackContext, nullptr);
177 return;
178 }
179
181 callback(callbackContext, nullptr);
182 return;
183 }
184
185 if (srcRect.size() == dstImageInfo.bounds().size()) {
186 // No need for rescale
187 auto graphiteImage = reinterpret_cast<const skgpu::graphite::Image*>(image);
188 const TextureProxyView& proxyView = graphiteImage->textureProxyView();
189 return this->asyncReadPixels(proxyView.proxy(),
190 image->imageInfo(),
191 dstImageInfo.colorInfo(),
192 srcRect,
193 callback,
194 callbackContext);
195 }
196
197 // Make a recorder to record drawing commands into
198 std::unique_ptr<Recorder> recorder = this->makeRecorder();
199
200 sk_sp<SkImage> scaledImage = RescaleImage(recorder.get(),
201 image,
202 srcRect,
203 dstImageInfo,
204 rescaleGamma,
205 rescaleMode);
206 if (!scaledImage) {
207 callback(callbackContext, nullptr);
208 return;
209 }
210
211 // Add draw commands to queue before starting the transfer
212 std::unique_ptr<Recording> recording = recorder->snap();
213 if (!recording) {
214 callback(callbackContext, nullptr);
215 return;
216 }
217 InsertRecordingInfo recordingInfo;
218 recordingInfo.fRecording = recording.get();
219 if (!this->insertRecording(recordingInfo)) {
220 callback(callbackContext, nullptr);
221 return;
222 }
223
224 SkASSERT(scaledImage->imageInfo() == dstImageInfo);
225
226 auto scaledGraphiteImage = reinterpret_cast<const skgpu::graphite::Image*>(scaledImage.get());
227 const TextureProxyView& scaledProxyView = scaledGraphiteImage->textureProxyView();
228
229 this->asyncReadPixels(scaledProxyView.proxy(),
230 dstImageInfo,
231 dstImageInfo.colorInfo(),
232 dstImageInfo.bounds(),
233 callback,
234 callbackContext);
235}
#define SkASSERT(cond)
Definition SkAssert.h:116
static SkImage_Base * as_IB(SkImage *image)
const SkImageInfo & imageInfo() const
Definition SkImage.h:279
T * get() const
Definition SkRefCnt.h:303
std::unique_ptr< Recorder > makeRecorder(const RecorderOptions &={})
Definition Context.cpp:130
bool insertRecording(const InsertRecordingInfo &)
Definition Context.cpp:142
const TextureProxyView & textureProxyView() const
sk_sp< SkImage > image
Definition examples.cpp:29
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
sk_sp< SkImage > RescaleImage(Recorder *recorder, const SkImage *srcImage, SkIRect srcIRect, const SkImageInfo &dstInfo, SkImage::RescaleGamma rescaleGamma, SkImage::RescaleMode rescaleMode)
constexpr SkISize size() const
Definition SkRect.h:172
static constexpr SkIRect MakeSize(const SkISize &size)
Definition SkRect.h:66
bool contains(int32_t x, int32_t y) const
Definition SkRect.h:463
const SkColorInfo & colorInfo() const
SkIRect bounds() const
SkISize dimensions() const

◆ 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 237 of file Context.cpp.

243 {
244 if (!static_cast<const SkSurface_Base*>(surface)->isGraphiteBacked()) {
245 callback(callbackContext, nullptr);
246 return;
247 }
248
250 this->asyncRescaleAndReadPixels(surfaceImage.get(),
251 dstImageInfo,
252 srcRect,
253 rescaleGamma,
254 rescaleMode,
255 callback,
256 callbackContext);
257}
sk_sp< T > sk_ref_sp(T *obj)
Definition SkRefCnt.h:381
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:163
VkSurfaceKHR surface
Definition main.cc:49
SK_API sk_sp< SkImage > AsImage(sk_sp< const SkSurface >)

◆ 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 340 of file Context.cpp.

348 {
349 this->asyncRescaleAndReadPixelsYUV420Impl(image,
350 yuvColorSpace,
351 /*readAlpha=*/false,
352 dstColorSpace,
353 srcRect,
354 dstSize,
355 rescaleGamma,
356 rescaleMode,
357 callback,
358 callbackContext);
359}

◆ 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 361 of file Context.cpp.

369 {
370 if (!static_cast<const SkSurface_Base*>(surface)->isGraphiteBacked()) {
371 callback(callbackContext, nullptr);
372 return;
373 }
374
376 this->asyncRescaleAndReadPixelsYUV420(surfaceImage.get(),
377 yuvColorSpace,
378 dstColorSpace,
379 srcRect,
380 dstSize,
381 rescaleGamma,
382 rescaleMode,
383 callback,
384 callbackContext);
385}
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:340

◆ 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 387 of file Context.cpp.

395 {
396 this->asyncRescaleAndReadPixelsYUV420Impl(image,
397 yuvColorSpace,
398 /*readAlpha=*/true,
399 dstColorSpace,
400 srcRect,
401 dstSize,
402 rescaleGamma,
403 rescaleMode,
404 callback,
405 callbackContext);
406}

◆ 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 408 of file Context.cpp.

416 {
417 if (!static_cast<const SkSurface_Base*>(surface)->isGraphiteBacked()) {
418 callback(callbackContext, nullptr);
419 return;
420 }
421
423 this->asyncRescaleAndReadPixelsYUVA420(surfaceImage.get(),
424 yuvColorSpace,
425 dstColorSpace,
426 srcRect,
427 dstSize,
428 rescaleGamma,
429 rescaleMode,
430 callback,
431 callbackContext);
432}
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:387

◆ backend()

BackendApi Context::backend ( ) const

Definition at line 128 of file Context.cpp.

128{ return fSharedContext->backend(); }

◆ checkAsyncWorkCompletion()

void Context::checkAsyncWorkCompletion ( )

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

Definition at line 786 of file Context.cpp.

786 {
787 this->checkForFinishedWork(SyncToCpu::kNo);
788}

◆ 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 816 of file Context.cpp.

816 {
818 return fResourceProvider->getResourceCacheCurrentBudgetedBytes();
819}

◆ 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 790 of file Context.cpp.

790 {
792
793 if (!texture.isValid() || texture.backend() != this->backend()) {
794 return;
795 }
796 fResourceProvider->deleteBackendTexture(texture);
797}
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 826 of file Context.cpp.

826 {
828 fResourceProvider->dumpMemoryStatistics(traceMemoryDump);
829 // TODO: What is the graphite equivalent for the text blob cache and how do we print out its
830 // used bytes here (see Ganesh implementation).
831}

◆ 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 799 of file Context.cpp.

799 {
801
803
804 fResourceProvider->freeGpuResources();
805}

◆ hasUnfinishedGpuWork()

bool Context::hasUnfinishedGpuWork ( ) const

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

Definition at line 161 of file Context.cpp.

161{ return fQueueManager->hasUnfinishedGpuWork(); }

◆ insertRecording()

bool Context::insertRecording ( const InsertRecordingInfo info)

Definition at line 142 of file Context.cpp.

142 {
144
145 return fQueueManager->addRecording(info, this);
146}
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 833 of file Context.cpp.

833 {
834 return fSharedContext->isDeviceLost();
835}

◆ makeRecorder()

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

Definition at line 130 of file Context.cpp.

130 {
132
133 auto recorder = std::unique_ptr<Recorder>(new Recorder(fSharedContext, options));
134#if defined(GRAPHITE_TEST_UTILS)
135 if (fStoreContextRefInRecorder) {
136 recorder->priv().setContext(this);
137 }
138#endif
139 return recorder;
140}

◆ maxBudgetedBytes()

size_t Context::maxBudgetedBytes ( ) const

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

Definition at line 821 of file Context.cpp.

821 {
823 return fResourceProvider->getResourceCacheLimit();
824}

◆ maxTextureSize()

int Context::maxTextureSize ( ) const

Returns the maximum texture dimension supported by the underlying backend.

Definition at line 837 of file Context.cpp.

837 {
838 return fSharedContext->caps()->maxTextureSize();
839}

◆ 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 807 of file Context.cpp.

807 {
809
811
812 auto purgeTime = skgpu::StdSteadyClock::now() - msNotUsed;
813 fResourceProvider->purgeResourcesNotUsedSince(purgeTime);
814}

◆ 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 148 of file Context.cpp.

148 {
150
151 if (syncToCpu == SyncToCpu::kYes && !fSharedContext->caps()->allowCpuSync()) {
152 SKGPU_LOG_E("SyncToCpu::kYes not supported with ContextOptions::fNeverYieldToWebGPU. "
153 "The parameter is ignored and no synchronization will occur.");
154 syncToCpu = SyncToCpu::kNo;
155 }
156 bool success = fQueueManager->submitToGpu();
157 this->checkForFinishedWork(syncToCpu);
158 return success;
159}
#define SKGPU_LOG_E(fmt,...)
Definition Log.h:38

◆ supportsProtectedContent()

bool Context::supportsProtectedContent ( ) const

Definition at line 841 of file Context.cpp.

841 {
842 return fSharedContext->isProtected() == Protected::kYes;
843}

Friends And Related Symbol 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: