Flutter Engine
The Flutter Engine
Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Private Member Functions | List of all members
skgpu::ganesh::SurfaceFillContext Class Reference

#include <SurfaceFillContext.h>

Inheritance diagram for skgpu::ganesh::SurfaceFillContext:
skgpu::ganesh::SurfaceContext skgpu::ganesh::SurfaceDrawContext

Public Member Functions

 SurfaceFillContext (GrRecordingContext *rContext, GrSurfaceProxyView readView, GrSurfaceProxyView writeView, const GrColorInfo &colorInfo)
 
SurfaceFillContextasFillContext () override
 
OpsTaskgetOpsTask ()
 
void discard ()
 
void resolveMSAA ()
 
template<SkAlphaType AlphaType>
void clear (const SkIRect &rect, const SkRGBA4f< AlphaType > &color)
 
template<SkAlphaType AlphaType>
void clear (const SkRGBA4f< AlphaType > &color)
 
template<SkAlphaType AlphaType>
void clearAtLeast (const SkIRect &scissor, const SkRGBA4f< AlphaType > &color)
 
void fillRectWithFP (const SkIRect &dstRect, std::unique_ptr< GrFragmentProcessor >)
 
void fillRectWithFP (const SkIRect &dstRect, const SkMatrix &localMatrix, std::unique_ptr< GrFragmentProcessor >)
 
void fillRectToRectWithFP (const SkRect &srcRect, const SkIRect &dstRect, std::unique_ptr< GrFragmentProcessor > fp)
 
void fillRectToRectWithFP (const SkIRect &srcRect, const SkIRect &dstRect, std::unique_ptr< GrFragmentProcessor > fp)
 
void fillWithFP (std::unique_ptr< GrFragmentProcessor > fp)
 
bool blitTexture (GrSurfaceProxyView, const SkIRect &srcRect, const SkIPoint &dstPoint)
 
sk_sp< GrRenderTaskrefRenderTask ()
 
int numSamples () const
 
bool wrapsVkSecondaryCB () const
 
SkArenaAllocarenaAlloc ()
 
sktext::gpu::SubRunAllocatorsubRunAlloc ()
 
const GrSurfaceProxyViewwriteSurfaceView () const
 
- Public Member Functions inherited from skgpu::ganesh::SurfaceContext
 SurfaceContext (GrRecordingContext *, GrSurfaceProxyView readView, const GrColorInfo &)
 
virtual ~SurfaceContext ()=default
 
GrRecordingContextrecordingContext () const
 
const GrColorInfocolorInfo () const
 
GrImageInfo imageInfo () const
 
GrSurfaceOrigin origin () const
 
skgpu::Swizzle readSwizzle () const
 
GrSurfaceProxyView readSurfaceView ()
 
SkISize dimensions () const
 
int width () const
 
int height () const
 
skgpu::Mipmapped mipmapped () const
 
const GrCapscaps () const
 
bool readPixels (GrDirectContext *dContext, GrPixmap dst, SkIPoint srcPt)
 
void asyncRescaleAndReadPixels (GrDirectContext *, const SkImageInfo &info, const SkIRect &srcRect, RescaleGamma rescaleGamma, RescaleMode, ReadPixelsCallback callback, ReadPixelsContext callbackContext)
 
void asyncRescaleAndReadPixelsYUV420 (GrDirectContext *, SkYUVColorSpace yuvColorSpace, bool readAlpha, sk_sp< SkColorSpace > dstColorSpace, const SkIRect &srcRect, SkISize dstSize, RescaleGamma rescaleGamma, RescaleMode, ReadPixelsCallback callback, ReadPixelsContext context)
 
bool writePixels (GrDirectContext *dContext, GrCPixmap src, SkIPoint dstPt)
 
bool writePixels (GrDirectContext *dContext, const GrCPixmap src[], int numLevels)
 
GrSurfaceProxyasSurfaceProxy ()
 
const GrSurfaceProxyasSurfaceProxy () const
 
sk_sp< GrSurfaceProxyasSurfaceProxyRef ()
 
GrTextureProxyasTextureProxy ()
 
const GrTextureProxyasTextureProxy () const
 
sk_sp< GrTextureProxyasTextureProxyRef ()
 
GrRenderTargetProxyasRenderTargetProxy ()
 
const GrRenderTargetProxyasRenderTargetProxy () const
 
sk_sp< GrRenderTargetProxyasRenderTargetProxyRef ()
 
virtual SurfaceFillContextasFillContext ()
 
std::unique_ptr< SurfaceFillContextrescale (const GrImageInfo &info, GrSurfaceOrigin, SkIRect srcRect, SkImage::RescaleGamma, SkImage::RescaleMode)
 
bool rescaleInto (SurfaceFillContext *dst, SkIRect dstRect, SkIRect srcRect, SkImage::RescaleGamma, SkImage::RescaleMode)
 

Protected Member Functions

OpsTaskreplaceOpsTask ()
 
void addOp (GrOp::Owner)
 
template<SkAlphaType AlphaType>
std::array< float, 4 > adjustColorAlphaType (SkRGBA4f< AlphaType > color) const
 
- Protected Member Functions inherited from skgpu::ganesh::SurfaceContext
GrDrawingManagerdrawingManager ()
 
const GrDrawingManagerdrawingManager () const
 
PixelTransferResult transferPixels (GrColorType colorType, const SkIRect &rect)
 
void asyncReadPixels (GrDirectContext *, const SkIRect &srcRect, SkColorType, ReadPixelsCallback, ReadPixelsContext)
 

Static Protected Member Functions

static void ClearToGrPaint (std::array< float, 4 > color, GrPaint *paint)
 
template<SkAlphaType AlphaType>
static std::array< float, 4 > ConvertColor (SkRGBA4f< AlphaType > color)
 
template<>
std::array< float, 4 > ConvertColor (SkPMColor4f color)
 
template<>
std::array< float, 4 > ConvertColor (SkColor4f color)
 

Protected Attributes

GrSurfaceProxyView fWriteView
 
- Protected Attributes inherited from skgpu::ganesh::SurfaceContext
SkDEBUGCODE(void validate() const ;) SkDEBUGCODE(skgpu GrRecordingContextfContext
 
GrSurfaceProxyView fReadView
 

Private Member Functions

virtual void willReplaceOpsTask (OpsTask *prevTask, OpsTask *nextTask)
 
virtual OpsTask::CanDiscardPreviousOps canDiscardPreviousOpsOnFullClear () const
 

Additional Inherited Members

- Public Types inherited from skgpu::ganesh::SurfaceContext
using ReadPixelsCallback = SkImage::ReadPixelsCallback
 
using ReadPixelsContext = SkImage::ReadPixelsContext
 
using RescaleGamma = SkImage::RescaleGamma
 
using RescaleMode = SkImage::RescaleMode
 

Detailed Description

Definition at line 17 of file SurfaceFillContext.h.

Constructor & Destructor Documentation

◆ SurfaceFillContext()

skgpu::ganesh::SurfaceFillContext::SurfaceFillContext ( GrRecordingContext rContext,
GrSurfaceProxyView  readView,
GrSurfaceProxyView  writeView,
const GrColorInfo colorInfo 
)

Definition at line 37 of file SurfaceFillContext.cpp.

41 : SurfaceContext(rContext, std::move(readView), colorInfo)
42 , fWriteView(std::move(writeView)) {
44 SkASSERT(this->origin() == fWriteView.origin());
45
46 fOpsTask = sk_ref_sp(rContext->priv().drawingManager()->getLastOpsTask(this->asSurfaceProxy()));
47
48 SkDEBUGCODE(this->validate();)
49}
#define SkASSERT(cond)
Definition: SkAssert.h:116
sk_sp< T > sk_ref_sp(T *obj)
Definition: SkRefCnt.h:381
skgpu::ganesh::OpsTask * getLastOpsTask(const GrSurfaceProxy *) const
GrDrawingManager * drawingManager()
GrRecordingContextPriv priv()
GrSurfaceOrigin origin() const
GrSurfaceProxy * proxy() const
GrSurfaceProxy * asSurfaceProxy()
const GrColorInfo & colorInfo() const
SurfaceContext(GrRecordingContext *, GrSurfaceProxyView readView, const GrColorInfo &)
GrSurfaceOrigin origin() const

Member Function Documentation

◆ addOp()

void skgpu::ganesh::SurfaceFillContext::addOp ( GrOp::Owner  op)
protected

Definition at line 156 of file SurfaceFillContext.cpp.

156 {
157 GrDrawingManager* drawingMgr = this->drawingManager();
158 this->getOpsTask()->addOp(drawingMgr,
159 std::move(op),
160 GrTextureResolveManager(drawingMgr),
161 *this->caps());
162}
void addOp(GrDrawingManager *, GrOp::Owner, GrTextureResolveManager, const GrCaps &)
Definition: OpsTask.cpp:417
GrDrawingManager * drawingManager()
const GrCaps * caps() const

◆ adjustColorAlphaType()

template<SkAlphaType AlphaType>
std::array< float, 4 > skgpu::ganesh::SurfaceFillContext::adjustColorAlphaType ( SkRGBA4f< AlphaType >  color) const
protected

Definition at line 176 of file SurfaceFillContext.h.

176 {
177 if (AlphaType == kUnknown_SkAlphaType ||
178 this->colorInfo().alphaType() == kUnknown_SkAlphaType) {
179 return color.array();
180 }
181 return (AlphaType == this->colorInfo().alphaType()) ? color.array() : ConvertColor(color);
182}
@ kUnknown_SkAlphaType
uninitialized
Definition: SkAlphaType.h:27
static std::array< float, 4 > ConvertColor(SkRGBA4f< AlphaType > color)
DlColor color

◆ arenaAlloc()

SkArenaAlloc * skgpu::ganesh::SurfaceFillContext::arenaAlloc ( )
inline

Definition at line 111 of file SurfaceFillContext.h.

111{ return this->arenas()->arenaAlloc(); }
SkArenaAlloc * arenaAlloc()

◆ asFillContext()

SurfaceFillContext * skgpu::ganesh::SurfaceFillContext::asFillContext ( )
inlineoverridevirtual

Reimplemented from skgpu::ganesh::SurfaceContext.

Definition at line 24 of file SurfaceFillContext.h.

24{ return this; }

◆ blitTexture()

bool skgpu::ganesh::SurfaceFillContext::blitTexture ( GrSurfaceProxyView  view,
const SkIRect srcRect,
const SkIPoint dstPoint 
)

Draws the src texture with no matrix. The dstRect is the dstPoint with the width and height of the srcRect. The srcRect and dstRect are clipped to the bounds of the src and dst surfaces respectively.

Definition at line 110 of file SurfaceFillContext.cpp.

112 {
113 SkASSERT(view.asTextureProxy());
114
115 SkIPoint clippedDstPoint = dstPoint;
116 SkIRect clippedSrcRect = srcRect;
118 &clippedDstPoint,
119 view.dimensions(),
120 &clippedSrcRect)) {
121 return false;
122 }
123
124 SkIRect clippedDstRect = SkIRect::MakePtSize(clippedDstPoint, clippedSrcRect.size());
125
126 auto fp = GrTextureEffect::Make(std::move(view), kUnknown_SkAlphaType);
127 this->fillRectToRectWithFP(SkRect::Make(clippedSrcRect), clippedDstRect, std::move(fp));
128 return true;
129}
static bool GrClipSrcRectAndDstPoint(const SkISize &dstSize, SkIPoint *dstPoint, const SkISize &srcSize, SkIRect *srcRect)
Definition: GrRect.h:48
GrTextureProxy * asTextureProxy() const
SkISize dimensions() const
static std::unique_ptr< GrFragmentProcessor > Make(GrSurfaceProxyView, SkAlphaType, const SkMatrix &=SkMatrix::I(), GrSamplerState::Filter=GrSamplerState::Filter::kNearest, GrSamplerState::MipmapMode mipmapMode=GrSamplerState::MipmapMode::kNone)
void fillRectToRectWithFP(const SkRect &srcRect, const SkIRect &dstRect, std::unique_ptr< GrFragmentProcessor > fp)
const uint32_t fp
Definition: SkRect.h:32
constexpr SkISize size() const
Definition: SkRect.h:172
static constexpr SkIRect MakePtSize(SkIPoint pt, SkISize size)
Definition: SkRect.h:78
static SkRect Make(const SkISize &size)
Definition: SkRect.h:669

◆ canDiscardPreviousOpsOnFullClear()

virtual OpsTask::CanDiscardPreviousOps skgpu::ganesh::SurfaceFillContext::canDiscardPreviousOpsOnFullClear ( ) const
inlineprivatevirtual

Override to be called to participate in the decision to discard all previous ops if a fullscreen clear occurs.

Definition at line 146 of file SurfaceFillContext.h.

◆ clear() [1/2]

template<SkAlphaType AlphaType>
void skgpu::ganesh::SurfaceFillContext::clear ( const SkIRect rect,
const SkRGBA4f< AlphaType > &  color 
)
inline

Clear the rect of the render target to the given color.

Parameters
rectthe rect to clear to
colorthe color to clear to.

Definition at line 46 of file SurfaceFillContext.h.

46 {
47 this->internalClear(&rect, this->adjustColorAlphaType(color));
48 }
std::array< float, 4 > adjustColorAlphaType(SkRGBA4f< AlphaType > color) const
sk_sp< SkBlender > blender SkRect rect
Definition: SkRecords.h:350

◆ clear() [2/2]

template<SkAlphaType AlphaType>
void skgpu::ganesh::SurfaceFillContext::clear ( const SkRGBA4f< AlphaType > &  color)
inline

Clears the entire render target to the color.

Definition at line 51 of file SurfaceFillContext.h.

51 {
52 this->internalClear(nullptr, this->adjustColorAlphaType(color));
53 }

◆ clearAtLeast()

template<SkAlphaType AlphaType>
void skgpu::ganesh::SurfaceFillContext::clearAtLeast ( const SkIRect scissor,
const SkRGBA4f< AlphaType > &  color 
)
inline

Clear at minimum the pixels within 'scissor', but is allowed to clear the full render target if that is the more performant option.

Definition at line 60 of file SurfaceFillContext.h.

60 {
61 this->internalClear(&scissor,
62 this->adjustColorAlphaType(color),
63 /* upgrade to full */ true);
64 }

◆ ClearToGrPaint()

void skgpu::ganesh::SurfaceFillContext::ClearToGrPaint ( std::array< float, 4 >  color,
GrPaint paint 
)
staticprotected

Creates a constant color paint for a clear, using src-over if possible to improve batching.

Definition at line 143 of file SurfaceFillContext.cpp.

143 {
144 paint->setColor4f({color[0], color[1], color[2], color[3]});
145 if (color[3] == 1.f) {
146 // Can just rely on the src-over blend mode to do the right thing.
147 // This may improve batching.
148 paint->setPorterDuffXPFactory(SkBlendMode::kSrcOver);
149 } else {
150 // A clear overwrites the prior color, so even if it's transparent, it behaves as if it
151 // were src blended
152 paint->setPorterDuffXPFactory(SkBlendMode::kSrc);
153 }
154}
@ kSrcOver
r = s + (1-sa)*d
const Paint & paint
Definition: color_source.cc:38

◆ ConvertColor() [1/3]

template<>
std::array< float, 4 > skgpu::ganesh::SurfaceFillContext::ConvertColor ( SkColor4f  color)
inlinestaticprotected

Definition at line 1 of file SurfaceFillContext.h.

171 {
172 return color.premul().array();
173}

◆ ConvertColor() [2/3]

template<>
std::array< float, 4 > skgpu::ganesh::SurfaceFillContext::ConvertColor ( SkPMColor4f  color)
inlinestaticprotected

Definition at line 1 of file SurfaceFillContext.h.

165 {
166 return color.unpremul().array();
167}

◆ ConvertColor() [3/3]

template<SkAlphaType AlphaType>
static std::array< float, 4 > skgpu::ganesh::SurfaceFillContext::ConvertColor ( SkRGBA4f< AlphaType >  color)
staticprotected

◆ discard()

void skgpu::ganesh::SurfaceFillContext::discard ( )

Provides a performance hint that the render target's contents are allowed to become undefined.

Definition at line 62 of file SurfaceFillContext.cpp.

62 {
65 SkDEBUGCODE(this->validate();)
66 GR_CREATE_TRACE_MARKER_CONTEXT("SurfaceFillContext", "discard", fContext);
67
68 AutoCheckFlush acf(this->drawingManager());
69
70 this->getOpsTask()->discard();
71}
#define GR_CREATE_TRACE_MARKER_CONTEXT(classname, op, context)
Definition: GrTracing.h:18
#define RETURN_IF_ABANDONED
#define ASSERT_SINGLE_OWNER
SkDEBUGCODE(void validate() const ;) SkDEBUGCODE(skgpu GrRecordingContext * fContext

◆ fillRectToRectWithFP() [1/2]

void skgpu::ganesh::SurfaceFillContext::fillRectToRectWithFP ( const SkIRect srcRect,
const SkIRect dstRect,
std::unique_ptr< GrFragmentProcessor fp 
)
inline

Fills 'dstRect' with 'fp' using a local matrix that maps 'srcRect' to 'dstRect'

Definition at line 86 of file SurfaceFillContext.h.

88 {
89 this->fillRectToRectWithFP(SkRect::Make(srcRect), dstRect, std::move(fp));
90 }

◆ fillRectToRectWithFP() [2/2]

void skgpu::ganesh::SurfaceFillContext::fillRectToRectWithFP ( const SkRect srcRect,
const SkIRect dstRect,
std::unique_ptr< GrFragmentProcessor fp 
)
inline

Fills 'dstRect' with 'fp' using a local matrix that maps 'srcRect' to 'dstRect'

Definition at line 78 of file SurfaceFillContext.h.

80 {
81 SkMatrix lm = SkMatrix::RectToRect(SkRect::Make(dstRect), srcRect);
82 this->fillRectWithFP(dstRect, lm, std::move(fp));
83 }
static SkMatrix RectToRect(const SkRect &src, const SkRect &dst, ScaleToFit mode=kFill_ScaleToFit)
Definition: SkMatrix.h:157
void fillRectWithFP(const SkIRect &dstRect, std::unique_ptr< GrFragmentProcessor >)

◆ fillRectWithFP() [1/2]

void skgpu::ganesh::SurfaceFillContext::fillRectWithFP ( const SkIRect dstRect,
const SkMatrix localMatrix,
std::unique_ptr< GrFragmentProcessor fp 
)

A convenience version of fillRectWithFP that applies a coordinate transformation via GrMatrixEffect.

Definition at line 103 of file SurfaceFillContext.cpp.

105 {
106 fp = GrMatrixEffect::Make(localMatrix, std::move(fp));
107 this->fillRectWithFP(dstRect, std::move(fp));
108}
static std::unique_ptr< GrFragmentProcessor > Make(const SkMatrix &matrix, std::unique_ptr< GrFragmentProcessor > child)

◆ fillRectWithFP() [2/2]

void skgpu::ganesh::SurfaceFillContext::fillRectWithFP ( const SkIRect dstRect,
std::unique_ptr< GrFragmentProcessor fp 
)

Fills 'dstRect' with 'fp'

Definition at line 86 of file SurfaceFillContext.cpp.

87 {
90 SkDEBUGCODE(this->validate();)
91 GR_CREATE_TRACE_MARKER_CONTEXT("SurfaceFillContext", "fillRectWithFP", fContext);
92
93 AutoCheckFlush acf(this->drawingManager());
94
96 paint.setColorFragmentProcessor(std::move(fp));
97 paint.setPorterDuffXPFactory(SkBlendMode::kSrc);
98 auto op = FillRectOp::MakeNonAARect(fContext, std::move(paint), SkMatrix::I(),
99 SkRect::Make(dstRect));
100 this->addDrawOp(std::move(op));
101}
static const SkMatrix & I()
Definition: SkMatrix.cpp:1544
static GrOp::Owner MakeNonAARect(GrRecordingContext *, GrPaint &&, const SkMatrix &view, const SkRect &, const GrUserStencilSettings *=nullptr)
Definition: FillRectOp.cpp:480

◆ fillWithFP()

void skgpu::ganesh::SurfaceFillContext::fillWithFP ( std::unique_ptr< GrFragmentProcessor fp)
inline

Fills the entire render target with the passed FP.

Definition at line 93 of file SurfaceFillContext.h.

93 {
95 }
SkISize dimensions() const
static constexpr SkIRect MakeSize(const SkISize &size)
Definition: SkRect.h:66

◆ getOpsTask()

OpsTask * skgpu::ganesh::SurfaceFillContext::getOpsTask ( )

Definition at line 51 of file SurfaceFillContext.cpp.

51 {
53 SkDEBUGCODE(this->validate();)
54
55 if (!fOpsTask || fOpsTask->isClosed()) {
56 this->replaceOpsTask();
57 }
58 SkASSERT(!fOpsTask->isClosed());
59 return fOpsTask.get();
60}

◆ numSamples()

int skgpu::ganesh::SurfaceFillContext::numSamples ( ) const
inline

Definition at line 108 of file SurfaceFillContext.h.

108{ return this->asRenderTargetProxy()->numSamples(); }
GrRenderTargetProxy * asRenderTargetProxy()

◆ refRenderTask()

sk_sp< GrRenderTask > skgpu::ganesh::SurfaceFillContext::refRenderTask ( )

Definition at line 131 of file SurfaceFillContext.cpp.

131 {
132 return sk_ref_sp(this->getOpsTask());
133}

◆ replaceOpsTask()

OpsTask * skgpu::ganesh::SurfaceFillContext::replaceOpsTask ( )
protected

Definition at line 135 of file SurfaceFillContext.cpp.

135 {
136 sk_sp<OpsTask> newOpsTask = this->drawingManager()->newOpsTask(this->writeSurfaceView(),
137 this->arenas());
138 this->willReplaceOpsTask(fOpsTask.get(), newOpsTask.get());
139 fOpsTask = std::move(newOpsTask);
140 return fOpsTask.get();
141}
sk_sp< skgpu::ganesh::OpsTask > newOpsTask(GrSurfaceProxyView, sk_sp< GrArenas > arenas)
T * get() const
Definition: SkRefCnt.h:303
const GrSurfaceProxyView & writeSurfaceView() const
virtual void willReplaceOpsTask(OpsTask *prevTask, OpsTask *nextTask)

◆ resolveMSAA()

void skgpu::ganesh::SurfaceFillContext::resolveMSAA ( )

Definition at line 73 of file SurfaceFillContext.cpp.

73 {
76 SkDEBUGCODE(this->validate();)
77 GR_CREATE_TRACE_MARKER_CONTEXT("SurfaceFillContext", "resolveMSAA", fContext);
78
79 AutoCheckFlush acf(this->drawingManager());
80
83 *this->caps());
84}
void newTextureResolveRenderTask(sk_sp< GrSurfaceProxy > proxy, GrSurfaceProxy::ResolveFlags, const GrCaps &)
sk_sp< GrSurfaceProxy > asSurfaceProxyRef()

◆ subRunAlloc()

sktext::gpu::SubRunAllocator * skgpu::ganesh::SurfaceFillContext::subRunAlloc ( )
inline

Definition at line 112 of file SurfaceFillContext.h.

112{ return this->arenas()->subRunAlloc(); }
sktext::gpu::SubRunAllocator * subRunAlloc()

◆ willReplaceOpsTask()

virtual void skgpu::ganesh::SurfaceFillContext::willReplaceOpsTask ( OpsTask prevTask,
OpsTask nextTask 
)
inlineprivatevirtual

Override to be notified in subclass before the current ops task is replaced.

Definition at line 140 of file SurfaceFillContext.h.

140{}

◆ wrapsVkSecondaryCB()

bool skgpu::ganesh::SurfaceFillContext::wrapsVkSecondaryCB ( ) const
inline

Definition at line 109 of file SurfaceFillContext.h.

109{ return this->asRenderTargetProxy()->wrapsVkSecondaryCB(); }
bool wrapsVkSecondaryCB() const

◆ writeSurfaceView()

const GrSurfaceProxyView & skgpu::ganesh::SurfaceFillContext::writeSurfaceView ( ) const
inline

Definition at line 114 of file SurfaceFillContext.h.

114{ return fWriteView; }

Member Data Documentation

◆ fWriteView

GrSurfaceProxyView skgpu::ganesh::SurfaceFillContext::fWriteView
protected

Definition at line 132 of file SurfaceFillContext.h.


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