Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | List of all members
skgpu::graphite::DrawContext Class Referencefinal

#include <DrawContext.h>

Inheritance diagram for skgpu::graphite::DrawContext:
SkRefCnt SkRefCntBase

Public Member Functions

 ~DrawContext () override
 
const SkImageInfoimageInfo () const
 
const SkColorInfocolorInfo () const
 
TextureProxytarget ()
 
const TextureProxytarget () const
 
sk_sp< TextureProxyrefTarget () const
 
const TextureProxyViewreadSurfaceView () const
 
const SkSurfacePropssurfaceProps () const
 
int pendingRenderSteps () const
 
void clear (const SkColor4f &clearColor)
 
void discard ()
 
void recordDraw (const Renderer *renderer, const Transform &localToDevice, const Geometry &geometry, const Clip &clip, DrawOrder ordering, const PaintParams *paint, const StrokeStyle *stroke)
 
bool recordUpload (Recorder *recorder, sk_sp< TextureProxy > targetProxy, const SkColorInfo &srcColorInfo, const SkColorInfo &dstColorInfo, const std::vector< MipLevel > &levels, const SkIRect &dstRect, std::unique_ptr< ConditionalUploadContext >)
 
PathAtlasgetComputePathAtlas (Recorder *)
 
void flush (Recorder *)
 
sk_sp< TasksnapDrawTask (Recorder *)
 
- 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< DrawContextMake (const Caps *caps, sk_sp< TextureProxy > target, SkISize deviceSize, const SkColorInfo &, const SkSurfaceProps &)
 

Detailed Description

DrawContext records draw commands into a specific Surface, via a general task graph representing GPU work and their inter-dependencies.

Definition at line 44 of file DrawContext.h.

Constructor & Destructor Documentation

◆ ~DrawContext()

skgpu::graphite::DrawContext::~DrawContext ( )
overridedefault

Member Function Documentation

◆ clear()

void skgpu::graphite::DrawContext::clear ( const SkColor4f clearColor)

Definition at line 112 of file DrawContext.cpp.

112 {
113 this->discard();
114
115 fPendingLoadOp = LoadOp::kClear;
116 SkPMColor4f pmColor = clearColor.premul();
117 fPendingClearColor = pmColor.array();
118}
std::array< float, 4 > array() const
Definition SkColor.h:317

◆ colorInfo()

const SkColorInfo & skgpu::graphite::DrawContext::colorInfo ( ) const
inline

Definition at line 55 of file DrawContext.h.

55{ return fImageInfo.colorInfo(); }
const SkColorInfo & colorInfo() const

◆ discard()

void skgpu::graphite::DrawContext::discard ( )

Definition at line 120 of file DrawContext.cpp.

120 {
121 // Non-loading operations on a fully lazy target can corrupt data beyond the DrawContext's
122 // region so should be avoided.
123 SkASSERT(!fTarget->isFullyLazy());
124
125 // A fullscreen clear or discard will overwrite anything that came before, so clear the DrawList
126 // NOTE: Eventually the current DrawTask should be reset, once there are no longer implicit
127 // dependencies on atlas tasks between DrawContexts. When that's resolved, the only tasks in the
128 // current DrawTask are those that directly impact the target, which becomes irrelevant with the
129 // clear op overwriting it. For now, preserve the previous tasks that might include atlas
130 // uploads that are not explicitly shared between DrawContexts.
131 if (fPendingDraws->renderStepCount() > 0) {
132 fPendingDraws = std::make_unique<DrawList>();
133 }
134 if (fComputePathAtlas) {
135 fComputePathAtlas->reset();
136 }
137
138 if (discard_op_should_use_clear(fImageInfo.colorType())) {
139 // In theory the clear color shouldn't matter since a discardable state should be fully
140 // overwritten by later draws, but if a previous call to clear() had injected bad data,
141 // the discard should not inherit it.
142 fPendingClearColor = {0.f, 0.f, 0.f, 0.f};
143 fPendingLoadOp = LoadOp::kClear;
144 } else {
145 fPendingLoadOp = LoadOp::kDiscard;
146 }
147}
#define SkASSERT(cond)
Definition SkAssert.h:116
SkColorType colorType() const

◆ flush()

void skgpu::graphite::DrawContext::flush ( Recorder recorder)

Definition at line 186 of file DrawContext.cpp.

186 {
187 if (fPendingUploads->size() > 0) {
189 "# uploads", fPendingUploads->size());
190 fCurrentDrawTask->addTask(UploadTask::Make(fPendingUploads.get()));
191 // The UploadTask steals the collected upload instances, automatically resetting this list
192 SkASSERT(fPendingUploads->size() == 0);
193 }
194
195 // Generate compute dispatches that render into the atlas texture used by pending draws.
196 // TODO: Once compute atlas caching is implemented, DrawContext might not hold onto to this
197 // at which point a recordDispatch() could be added and it stores a pending dispatches list that
198 // much like how uploads are handled. In that case, Device would be responsible for triggering
199 // the recording of dispatches, but that may happen naturally in AtlasProvider::recordUploads().
200 if (fComputePathAtlas) {
201 auto dispatchGroup = fComputePathAtlas->recordDispatches(recorder);
202 fComputePathAtlas->reset();
203
204 if (dispatchGroup) {
205 // For now this check is valid as all coverage mask draws involve dispatches
206 SkASSERT(fPendingDraws->hasCoverageMaskDraws());
207
209 "# dispatches", dispatchGroup->dispatches().size());
211 dispatches.emplace_back(std::move(dispatchGroup));
212 fCurrentDrawTask->addTask(ComputeTask::Make(std::move(dispatches)));
213 } // else no pending compute work needed to be recorded
214 } // else platform doesn't support compute or atlas was never initialized.
215
216 if (fPendingDraws->renderStepCount() == 0 && fPendingLoadOp != LoadOp::kClear) {
217 // Nothing will be rasterized to the target that warrants a RenderPassTask, but we preserve
218 // any added uploads or compute tasks since those could also affect the target w/o
219 // rasterizing anything directly.
220 return;
221 }
222
223 // Convert the pending draws and load/store ops into a DrawPass that will be executed after
224 // the collected uploads and compute dispatches.
225 // TODO: At this point, there's only ever one DrawPass in a RenderPassTask to a target. When
226 // subpasses are implemented, they will either be collected alongside fPendingDraws or added
227 // to the RenderPassTask separately.
228 std::unique_ptr<DrawPass> pass = DrawPass::Make(recorder,
229 std::move(fPendingDraws),
230 fTarget,
231 this->imageInfo(),
232 std::make_pair(fPendingLoadOp, fPendingStoreOp),
233 fPendingClearColor);
234 fPendingDraws = std::make_unique<DrawList>();
235 // Now that there is content drawn to the target, that content must be loaded on any subsequent
236 // render pass.
237 fPendingLoadOp = LoadOp::kLoad;
238 fPendingStoreOp = StoreOp::kStore;
239
240 if (pass) {
241 SkASSERT(fTarget.get() == pass->target());
242
243 const Caps* caps = recorder->priv().caps();
244 auto [loadOp, storeOp] = pass->ops();
245 auto writeSwizzle = caps->getWriteSwizzle(this->colorInfo().colorType(),
246 fTarget->textureInfo());
247
248 RenderPassDesc desc = RenderPassDesc::Make(caps, fTarget->textureInfo(), loadOp, storeOp,
249 pass->depthStencilFlags(),
250 pass->clearColor(),
251 pass->requiresMSAA(),
252 writeSwizzle);
253
255 passes.emplace_back(std::move(pass));
256 fCurrentDrawTask->addTask(RenderPassTask::Make(std::move(passes), desc, fTarget));
257 }
258 // else pass creation failed, DrawPass will have logged why. Don't discard the previously
259 // accumulated tasks, however, since they may represent operations on an atlas that other
260 // DrawContexts now implicitly depend on.
261}
static SkColorType colorType(AImageDecoder *decoder, const AImageDecoderHeaderInfo *headerInfo)
#define TRACE_EVENT_SCOPE_THREAD
#define TRACE_FUNC
skgpu::Swizzle getWriteSwizzle(SkColorType, const TextureInfo &) const
Definition Caps.cpp:141
skia_private::STArray< 1, std::unique_ptr< DispatchGroup > > DispatchGroupList
Definition ComputeTask.h:28
static sk_sp< ComputeTask > Make(DispatchGroupList dispatchGroups)
const SkImageInfo & imageInfo() const
Definition DrawContext.h:54
const SkColorInfo & colorInfo() const
Definition DrawContext.h:55
static std::unique_ptr< DrawPass > Make(Recorder *, std::unique_ptr< DrawList >, sk_sp< TextureProxy > target, const SkImageInfo &targetInfo, std::pair< LoadOp, StoreOp >, std::array< float, 4 > clearColor)
Definition DrawPass.cpp:452
const Caps * caps() const
static sk_sp< RenderPassTask > Make(DrawPassList, const RenderPassDesc &, sk_sp< TextureProxy > target)
skia_private::STArray< 1, std::unique_ptr< DrawPass > > DrawPassList
static sk_sp< UploadTask > Make(UploadList *)
T & emplace_back(Args &&... args)
Definition SkTArray.h:243
static RenderPassDesc Make(const Caps *caps, const TextureInfo &targetInfo, LoadOp loadOp, StoreOp storeOp, SkEnumBitMask< DepthStencilFlags > depthStencilFlags, const std::array< float, 4 > &clearColor, bool requiresMSAA, Swizzle writeSwizzle)
#define TRACE_EVENT_INSTANT1(category_group, name, arg1_name, arg1_val)

◆ getComputePathAtlas()

PathAtlas * skgpu::graphite::DrawContext::getComputePathAtlas ( Recorder recorder)

Definition at line 179 of file DrawContext.cpp.

179 {
180 if (!fComputePathAtlas) {
181 fComputePathAtlas = recorder->priv().atlasProvider()->createComputePathAtlas(recorder);
182 }
183 return fComputePathAtlas.get();
184}
std::unique_ptr< ComputePathAtlas > createComputePathAtlas(Recorder *recorder) const
AtlasProvider * atlasProvider()

◆ imageInfo()

const SkImageInfo & skgpu::graphite::DrawContext::imageInfo ( ) const
inline

Definition at line 54 of file DrawContext.h.

54{ return fImageInfo; }

◆ Make()

sk_sp< DrawContext > skgpu::graphite::DrawContext::Make ( const Caps caps,
sk_sp< TextureProxy target,
SkISize  deviceSize,
const SkColorInfo colorInfo,
const SkSurfaceProps props 
)
static

Definition at line 64 of file DrawContext.cpp.

68 {
69 if (!target) {
70 return nullptr;
71 }
72 // We don't render to unknown or unpremul alphatypes
75 return nullptr;
76 }
77 if (!caps->isRenderable(target->textureInfo())) {
78 return nullptr;
79 }
80
81 // Accept an approximate-fit texture, but make sure it's at least as large as the device's
82 // logical size.
83 // TODO: validate that the color type and alpha type are compatible with the target's info
84 SkASSERT(target->isFullyLazy() || (target->dimensions().width() >= deviceSize.width() &&
85 target->dimensions().height() >= deviceSize.height()));
87 return sk_sp<DrawContext>(new DrawContext(caps, std::move(target), imageInfo, props));
88}
kUnpremul_SkAlphaType
@ kUnknown_SkAlphaType
uninitialized
Definition SkAlphaType.h:27
SkAlphaType alphaType() const
const TextureInfo & textureInfo() const
constexpr int32_t width() const
Definition SkSize.h:36
constexpr int32_t height() const
Definition SkSize.h:37
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)

◆ pendingRenderSteps()

int skgpu::graphite::DrawContext::pendingRenderSteps ( ) const
inline

Definition at line 65 of file DrawContext.h.

65{ return fPendingDraws->renderStepCount(); }

◆ readSurfaceView()

const TextureProxyView & skgpu::graphite::DrawContext::readSurfaceView ( ) const
inline

Definition at line 61 of file DrawContext.h.

61{ return fReadView; }

◆ recordDraw()

void skgpu::graphite::DrawContext::recordDraw ( const Renderer renderer,
const Transform localToDevice,
const Geometry geometry,
const Clip clip,
DrawOrder  ordering,
const PaintParams paint,
const StrokeStyle stroke 
)

Definition at line 149 of file DrawContext.cpp.

155 {
156 SkASSERT(SkIRect::MakeSize(this->imageInfo().dimensions()).contains(clip.scissor()));
157 fPendingDraws->recordDraw(renderer, localToDevice, geometry, clip, ordering, paint, stroke);
158}
static bool contains(const SkRect &r, SkPoint p)
static SkPath clip(const SkPath &path, const SkHalfPlane &plane)
Definition SkPath.cpp:3824
const Paint & paint
static constexpr SkIRect MakeSize(const SkISize &size)
Definition SkRect.h:66

◆ recordUpload()

bool skgpu::graphite::DrawContext::recordUpload ( Recorder recorder,
sk_sp< TextureProxy targetProxy,
const SkColorInfo srcColorInfo,
const SkColorInfo dstColorInfo,
const std::vector< MipLevel > &  levels,
const SkIRect dstRect,
std::unique_ptr< ConditionalUploadContext condContext 
)

Definition at line 160 of file DrawContext.cpp.

166 {
167 // Our caller should have clipped to the bounds of the surface already.
168 SkASSERT(targetProxy->isFullyLazy() ||
169 SkIRect::MakeSize(targetProxy->dimensions()).contains(dstRect));
170 return fPendingUploads->recordUpload(recorder,
171 std::move(targetProxy),
172 srcColorInfo,
173 dstColorInfo,
174 levels,
175 dstRect,
176 std::move(condContext));
177}
bool contains(int32_t x, int32_t y) const
Definition SkRect.h:463

◆ refTarget()

sk_sp< TextureProxy > skgpu::graphite::DrawContext::refTarget ( ) const
inline

Definition at line 58 of file DrawContext.h.

58{ return fTarget; }

◆ snapDrawTask()

sk_sp< Task > skgpu::graphite::DrawContext::snapDrawTask ( Recorder recorder)

Definition at line 263 of file DrawContext.cpp.

263 {
264 // If flush() was explicitly called earlier and no new work was recorded, this call to flush()
265 // is a no-op and shouldn't hurt performance.
266 this->flush(recorder);
267
268 if (!fCurrentDrawTask->hasTasks()) {
269 return nullptr;
270 }
271
272 sk_sp<Task> snappedTask = std::move(fCurrentDrawTask);
273 fCurrentDrawTask = sk_make_sp<DrawTask>(fTarget);
274 return snappedTask;
275}

◆ surfaceProps()

const SkSurfaceProps & skgpu::graphite::DrawContext::surfaceProps ( ) const
inline

Definition at line 63 of file DrawContext.h.

63{ return fSurfaceProps; }

◆ target() [1/2]

TextureProxy * skgpu::graphite::DrawContext::target ( )
inline

Definition at line 56 of file DrawContext.h.

56{ return fTarget.get(); }

◆ target() [2/2]

const TextureProxy * skgpu::graphite::DrawContext::target ( ) const
inline

Definition at line 57 of file DrawContext.h.

57{ return fTarget.get(); }

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