Flutter Engine
The Flutter Engine
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 >)
 
void recordDependency (sk_sp< Task >)
 
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 113 of file DrawContext.cpp.

113 {
114 this->discard();
115
116 fPendingLoadOp = LoadOp::kClear;
117 SkPMColor4f pmColor = clearColor.premul();
118 fPendingClearColor = pmColor.array();
119}
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
Definition: SkImageInfo.h:404

◆ discard()

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

Definition at line 121 of file DrawContext.cpp.

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

◆ flush()

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

Definition at line 195 of file DrawContext.cpp.

195 {
196 if (fPendingUploads->size() > 0) {
198 "# uploads", fPendingUploads->size());
199 fCurrentDrawTask->addTask(UploadTask::Make(fPendingUploads.get()));
200 // The UploadTask steals the collected upload instances, automatically resetting this list
201 SkASSERT(fPendingUploads->size() == 0);
202 }
203
204 // Generate compute dispatches that render into the atlas texture used by pending draws.
205 // TODO: Once compute atlas caching is implemented, DrawContext might not hold onto to this
206 // at which point a recordDispatch() could be added and it stores a pending dispatches list that
207 // much like how uploads are handled. In that case, Device would be responsible for triggering
208 // the recording of dispatches, but that may happen naturally in AtlasProvider::recordUploads().
209 if (fComputePathAtlas) {
211 if (fComputePathAtlas->recordDispatches(recorder, &dispatches)) {
212 // For now this check is valid as all coverage mask draws involve dispatches
213 SkASSERT(fPendingDraws->hasCoverageMaskDraws());
214
215 fCurrentDrawTask->addTask(ComputeTask::Make(std::move(dispatches)));
216 } // else no pending compute work needed to be recorded
217
218 fComputePathAtlas->reset();
219 } // else platform doesn't support compute or atlas was never initialized.
220
221 if (fPendingDraws->renderStepCount() == 0 && fPendingLoadOp != LoadOp::kClear) {
222 // Nothing will be rasterized to the target that warrants a RenderPassTask, but we preserve
223 // any added uploads or compute tasks since those could also affect the target w/o
224 // rasterizing anything directly.
225 return;
226 }
227
228 // Convert the pending draws and load/store ops into a DrawPass that will be executed after
229 // the collected uploads and compute dispatches. If there's a dst readback copy required it
230 // inserts a CopyTextureToTexture task before the RenderPassTask.
231 // TODO: At this point, there's only ever one DrawPass in a RenderPassTask to a target. When
232 // subpasses are implemented, they will either be collected alongside fPendingDraws or added
233 // to the RenderPassTask separately.
234 sk_sp<TextureProxy> dstCopy;
235 SkIRect dstCopyPixelBounds = SkIRect::MakeEmpty();
236 if (!fPendingDraws->dstCopyBounds().isEmptyNegativeOrNaN()) {
237 TRACE_EVENT_INSTANT0("skia.gpu", "DrawPass requires dst copy", TRACE_EVENT_SCOPE_THREAD);
238
239 dstCopyPixelBounds = fPendingDraws->dstCopyBounds().makeRoundOut().asSkIRect();
240
241 // TODO: Right now this assert is ensuring that the dstCopy will be texturable since it
242 // uses the same texture info as fTarget. Ideally, if fTarget were not texturable but
243 // still readable, we would perform a fallback to a compatible texturable info. We also
244 // should decide whether or not a copy-as-draw fallback is necessary here too. All of
245 // this is handled inside Image::Copy() except we would need it to expose the task in
246 // order to link it correctly.
247 SkASSERT(recorder->priv().caps()->isTexturable(fTarget->textureInfo()));
248 dstCopy = TextureProxy::Make(recorder->priv().caps(),
249 recorder->priv().resourceProvider(),
250 dstCopyPixelBounds.size(),
251 fTarget->textureInfo(),
252 "DstCopyTexture",
254 }
255 std::unique_ptr<DrawPass> pass = DrawPass::Make(recorder,
256 std::move(fPendingDraws),
257 fTarget,
258 this->imageInfo(),
259 std::make_pair(fPendingLoadOp, fPendingStoreOp),
260 fPendingClearColor,
261 dstCopy,
262 dstCopyPixelBounds.topLeft());
263 fPendingDraws = std::make_unique<DrawList>();
264 // Now that there is content drawn to the target, that content must be loaded on any subsequent
265 // render pass.
266 fPendingLoadOp = LoadOp::kLoad;
267 fPendingStoreOp = StoreOp::kStore;
268
269 if (pass) {
270 SkASSERT(fTarget.get() == pass->target());
271
272 if (dstCopy) {
273 // Add the copy task to initialize dstCopy before the render pass task.
274 fCurrentDrawTask->addTask(CopyTextureToTextureTask::Make(
275 fTarget, dstCopyPixelBounds, dstCopy, /*dstPoint=*/{0, 0}));
276 }
277
278 const Caps* caps = recorder->priv().caps();
279 auto [loadOp, storeOp] = pass->ops();
280 auto writeSwizzle = caps->getWriteSwizzle(this->colorInfo().colorType(),
281 fTarget->textureInfo());
282
283 RenderPassDesc desc = RenderPassDesc::Make(caps, fTarget->textureInfo(), loadOp, storeOp,
284 pass->depthStencilFlags(),
285 pass->clearColor(),
286 pass->requiresMSAA(),
287 writeSwizzle);
288
290 passes.emplace_back(std::move(pass));
291 fCurrentDrawTask->addTask(RenderPassTask::Make(std::move(passes), desc, fTarget));
292 }
293 // else pass creation failed, DrawPass will have logged why. Don't discard the previously
294 // accumulated tasks, however, since they may represent operations on an atlas that other
295 // DrawContexts now implicitly depend on.
296}
static SkColorType colorType(AImageDecoder *decoder, const AImageDecoderHeaderInfo *headerInfo)
#define TRACE_EVENT_SCOPE_THREAD
#define TRACE_FUNC
Definition: SkTraceEvent.h:30
bool isTexturable(const TextureInfo &) const
Definition: Caps.cpp:66
skgpu::Swizzle getWriteSwizzle(SkColorType, const TextureInfo &) const
Definition: Caps.cpp:142
skia_private::STArray< 1, std::unique_ptr< DispatchGroup > > DispatchGroupList
Definition: ComputeTask.h:28
static sk_sp< ComputeTask > Make(DispatchGroupList dispatchGroups)
Definition: ComputeTask.cpp:17
static sk_sp< CopyTextureToTextureTask > Make(sk_sp< TextureProxy > srcProxy, SkIRect srcRect, sk_sp< TextureProxy > dstProxy, SkIPoint dstPoint, int dstLevel=0)
Definition: CopyTask.cpp:123
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, sk_sp< TextureProxy > dstCopy, SkIPoint dstCopyOffset)
Definition: DrawPass.cpp:458
const Caps * caps() const
Definition: RecorderPriv.h:31
ResourceProvider * resourceProvider()
Definition: RecorderPriv.h:33
static sk_sp< RenderPassTask > Make(DrawPassList, const RenderPassDesc &, sk_sp< TextureProxy > target)
skia_private::STArray< 1, std::unique_ptr< DrawPass > > DrawPassList
static sk_sp< TextureProxy > Make(const Caps *, ResourceProvider *, SkISize dimensions, const TextureInfo &, std::string_view label, skgpu::Budgeted)
static sk_sp< UploadTask > Make(UploadList *)
Definition: UploadTask.cpp:425
T & emplace_back(Args &&... args)
Definition: SkTArray.h:248
Definition: SkRect.h:32
constexpr SkISize size() const
Definition: SkRect.h:172
static constexpr SkIRect MakeEmpty()
Definition: SkRect.h:45
constexpr SkIPoint topLeft() const
Definition: SkRect.h:151
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_INSTANT0(category_group, name)
Definition: trace_event.h:175
#define TRACE_EVENT_INSTANT1(category_group, name, arg1_name, arg1_val)
Definition: trace_event.h:179

◆ getComputePathAtlas()

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

Definition at line 188 of file DrawContext.cpp.

188 {
189 if (!fComputePathAtlas) {
190 fComputePathAtlas = recorder->priv().atlasProvider()->createComputePathAtlas(recorder);
191 }
192 return fComputePathAtlas.get();
193}
std::unique_ptr< ComputePathAtlas > createComputePathAtlas(Recorder *recorder) const
AtlasProvider * atlasProvider()
Definition: RecorderPriv.h:61

◆ 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 65 of file DrawContext.cpp.

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

◆ recordDependency()

void skgpu::graphite::DrawContext::recordDependency ( sk_sp< Task task)

Definition at line 180 of file DrawContext.cpp.

180 {
181 SkASSERT(task);
182 // Adding `task` to the current DrawTask directly means that it will execute after any previous
183 // dependent tasks and after any previous calls to flush(), but everything else that's being
184 // collected on the DrawContext will execute after `task` once the next flush() is performed.
185 fCurrentDrawTask->addTask(std::move(task));
186}

◆ 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 150 of file DrawContext.cpp.

156 {
157 SkASSERT(SkIRect::MakeSize(this->imageInfo().dimensions()).contains(clip.scissor()));
158 fPendingDraws->recordDraw(renderer, localToDevice, geometry, clip, ordering, paint, stroke);
159}
static SkPath clip(const SkPath &path, const SkHalfPlane &plane)
Definition: SkPath.cpp:3892
const Paint & paint
Definition: color_source.cc:38
constexpr bool contains(std::string_view str, std::string_view needle)
Definition: SkStringView.h:41
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 161 of file DrawContext.cpp.

167 {
168 // Our caller should have clipped to the bounds of the surface already.
169 SkASSERT(targetProxy->isFullyLazy() ||
170 SkIRect::MakeSize(targetProxy->dimensions()).contains(dstRect));
171 return fPendingUploads->recordUpload(recorder,
172 std::move(targetProxy),
173 srcColorInfo,
174 dstColorInfo,
175 levels,
176 dstRect,
177 std::move(condContext));
178}
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 298 of file DrawContext.cpp.

298 {
299 // If flush() was explicitly called earlier and no new work was recorded, this call to flush()
300 // is a no-op and shouldn't hurt performance.
301 this->flush(recorder);
302
303 if (!fCurrentDrawTask->hasTasks()) {
304 return nullptr;
305 }
306
307 sk_sp<Task> snappedTask = std::move(fCurrentDrawTask);
308 fCurrentDrawTask = sk_make_sp<DrawTask>(fTarget);
309 return snappedTask;
310}

◆ 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: