Flutter Engine
The Flutter Engine
Public Member Functions | Protected Member Functions | Private Member Functions | List of all members
GrDeferredProxyUploader Class Reference

#include <GrDeferredProxyUploader.h>

Inheritance diagram for GrDeferredProxyUploader:
SkNoncopyable GrTDeferredProxyUploader< T >

Public Member Functions

 GrDeferredProxyUploader ()
 
virtual ~GrDeferredProxyUploader ()
 
void scheduleUpload (GrOpFlushState *flushState, GrTextureProxy *proxy)
 
void signalAndFreeData ()
 
SkAutoPixmapStoragegetPixels ()
 
- Public Member Functions inherited from SkNoncopyable
 SkNoncopyable ()=default
 
 SkNoncopyable (SkNoncopyable &&)=default
 
SkNoncopyableoperator= (SkNoncopyable &&)=default
 

Protected Member Functions

void wait ()
 

Private Member Functions

virtual void freeData ()
 

Detailed Description

GrDeferredProxyUploader assists with threaded generation of textures. Currently used by both software clip masks, and the software path renderer. The calling code typically needs to store some additional data (T) for use on the worker thread. GrTDeferredProxyUploader allows storing such data. The common flow is:

1) A GrTDeferredProxyUploader is created, with some payload (eg an SkPath to draw). The uploader is owned by the proxy that it's going to populate. 2) A task is created with a pointer to the uploader. A worker thread executes that task, using the payload data to allocate and fill in the fPixels pixmap. 3) The worker thread calls signalAndFreeData(), which notifies the main thread that the pixmap is ready, and then deletes the payload data (which is no longer needed). 4) In parallel to 2-3, on the main thread... Some op is created that refers to the proxy. When that op is added to an op list, the op list retains a pointer to the "deferred" proxies. 5) At flush time, the op list ensures that the deferred proxies are instantiated, then calls scheduleUpload on those proxies, which calls scheduleUpload on the uploader (below). 6) scheduleUpload defers the upload even further, by adding an ASAPUpload to the flush. 7) When the ASAP upload happens, we wait to make sure that the pixels are marked ready (from step #3 on the worker thread). Then we perform the actual upload to the texture. Finally, we call resetDeferredUploader, which deletes the uploader object, causing fPixels to be freed.

Definition at line 40 of file GrDeferredProxyUploader.h.

Constructor & Destructor Documentation

◆ GrDeferredProxyUploader()

GrDeferredProxyUploader::GrDeferredProxyUploader ( )
inline

Definition at line 42 of file GrDeferredProxyUploader.h.

42: fScheduledUpload(false), fWaited(false) {}

◆ ~GrDeferredProxyUploader()

virtual GrDeferredProxyUploader::~GrDeferredProxyUploader ( )
inlinevirtual

Definition at line 44 of file GrDeferredProxyUploader.h.

44 {
45 // In normal usage (i.e., through GrTDeferredProxyUploader) this will be redundant
46 this->wait();
47 }

Member Function Documentation

◆ freeData()

virtual void GrDeferredProxyUploader::freeData ( )
inlineprivatevirtual

Definition at line 90 of file GrDeferredProxyUploader.h.

90{}

◆ getPixels()

SkAutoPixmapStorage * GrDeferredProxyUploader::getPixels ( )
inline

Definition at line 79 of file GrDeferredProxyUploader.h.

79{ return &fPixels; }

◆ scheduleUpload()

void GrDeferredProxyUploader::scheduleUpload ( GrOpFlushState flushState,
GrTextureProxy proxy 
)
inline

Definition at line 49 of file GrDeferredProxyUploader.h.

49 {
50 if (fScheduledUpload) {
51 // Multiple references to the owning proxy may have caused us to already execute
52 return;
53 }
54
55 auto uploadMask = [this, proxy](GrDeferredTextureUploadWritePixelsFn& writePixelsFn) {
56 this->wait();
57 GrColorType pixelColorType = SkColorTypeToGrColorType(this->fPixels.info().colorType());
58 // If the worker thread was unable to allocate pixels, this check will fail, and we'll
59 // end up drawing with an uninitialized mask texture, but at least we won't crash.
60 if (this->fPixels.addr()) {
61 writePixelsFn(proxy,
63 pixelColorType,
64 this->fPixels.addr(),
65 this->fPixels.rowBytes());
66 }
67 // Upload has finished, so tell the proxy to release this GrDeferredProxyUploader
69 };
70 flushState->addASAPUpload(std::move(uploadMask));
71 fScheduledUpload = true;
72 }
std::function< bool(GrTextureProxy *, SkIRect, GrColorType srcColorType, const void *, size_t rowBytes)> GrDeferredTextureUploadWritePixelsFn
GrColorType
Definition: GrTypesPriv.h:540
static constexpr GrColorType SkColorTypeToGrColorType(SkColorType ct)
Definition: GrTypesPriv.h:629
skgpu::AtlasToken addASAPUpload(GrDeferredTextureUploadFn &&) final
GrTextureProxyPriv texPriv()
const SkImageInfo & info() const
Definition: SkPixmap.h:135
const void * addr() const
Definition: SkPixmap.h:153
SkISize dimensions() const
Definition: SkPixmap.h:171
static constexpr SkIRect MakeSize(const SkISize &size)
Definition: SkRect.h:66
SkColorType colorType() const
Definition: SkImageInfo.h:373

◆ signalAndFreeData()

void GrDeferredProxyUploader::signalAndFreeData ( )
inline

Definition at line 74 of file GrDeferredProxyUploader.h.

74 {
75 this->freeData();
76 fPixelsReady.signal();
77 }
void signal(int n=1)
Definition: SkSemaphore.h:56

◆ wait()

void GrDeferredProxyUploader::wait ( )
inlineprotected

Definition at line 82 of file GrDeferredProxyUploader.h.

82 {
83 if (!fWaited) {
84 fPixelsReady.wait();
85 fWaited = true;
86 }
87 }
void wait()
Definition: SkSemaphore.h:74

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