Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
DrawContext.h
Go to the documentation of this file.
1/*
2 * Copyright 2021 Google LLC
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef skgpu_graphite_DrawContext_DEFINED
9#define skgpu_graphite_DrawContext_DEFINED
10
15
22
23#include <vector>
24
25class SkPixmap;
26
27namespace skgpu::graphite {
28
29class Geometry;
30class Recorder;
31class Transform;
32
33class Caps;
34class ComputePathAtlas;
35class DrawTask;
36class PathAtlas;
37class Task;
38class TextureProxy;
39
40/**
41 * DrawContext records draw commands into a specific Surface, via a general task graph
42 * representing GPU work and their inter-dependencies.
43 */
44class DrawContext final : public SkRefCnt {
45public:
46 static sk_sp<DrawContext> Make(const Caps* caps,
48 SkISize deviceSize,
49 const SkColorInfo&,
50 const SkSurfaceProps&);
51
52 ~DrawContext() override;
53
54 const SkImageInfo& imageInfo() const { return fImageInfo; }
55 const SkColorInfo& colorInfo() const { return fImageInfo.colorInfo(); }
56 TextureProxy* target() { return fTarget.get(); }
57 const TextureProxy* target() const { return fTarget.get(); }
58 sk_sp<TextureProxy> refTarget() const { return fTarget; }
59
60 // May be null if the target is not texturable.
61 const TextureProxyView& readSurfaceView() const { return fReadView; }
62
63 const SkSurfaceProps& surfaceProps() const { return fSurfaceProps; }
64
65 int pendingRenderSteps() const { return fPendingDraws->renderStepCount(); }
66
67 void clear(const SkColor4f& clearColor);
68 void discard();
69
70 void recordDraw(const Renderer* renderer,
71 const Transform& localToDevice,
72 const Geometry& geometry,
73 const Clip& clip,
74 DrawOrder ordering,
75 const PaintParams* paint,
76 const StrokeStyle* stroke);
77
78 bool recordUpload(Recorder* recorder,
79 sk_sp<TextureProxy> targetProxy,
80 const SkColorInfo& srcColorInfo,
81 const SkColorInfo& dstColorInfo,
82 const std::vector<MipLevel>& levels,
83 const SkIRect& dstRect,
84 std::unique_ptr<ConditionalUploadContext>);
85
86 // Returns the transient path atlas that uses compute to accumulate coverage masks for atlas
87 // draws recorded to this SDC. The atlas gets created lazily upon request. Returns nullptr
88 // if compute path generation is not supported.
90
91 // Moves all accumulated pending recorded operations (draws and uploads), and any other
92 // dependent tasks into the DrawTask currently being built.
93 void flush(Recorder*);
94
95 // Flushes (if needed) and completes the current DrawTask, returning it to the caller.
96 // Subsequent recorded operations will be added to a new DrawTask.
98
99private:
101
102 sk_sp<TextureProxy> fTarget;
103 TextureProxyView fReadView;
104 SkImageInfo fImageInfo;
105 const SkSurfaceProps fSurfaceProps;
106
107 // The in-progress DrawTask that will be snapped and returned when some external requirement
108 // must depend on the contents of this DrawContext's target. As higher-level Skia operations
109 // are recorded, it can be necessary to flush pending draws and uploads into the task list.
110 // This provides a place to reset scratch textures or buffers as their previous state will have
111 // been consumed by the flushed tasks rendering to this DrawContext's target.
112 sk_sp<DrawTask> fCurrentDrawTask;
113
114 // Stores the most immediately recorded draws and uploads into the DrawContext's target. These
115 // are collected outside of the DrawTask so that encoder switches can be minimized when
116 // flushing.
117 std::unique_ptr<DrawList> fPendingDraws;
118 std::unique_ptr<UploadList> fPendingUploads;
119 // Load and store information for the current pending draws.
120 LoadOp fPendingLoadOp = LoadOp::kLoad;
121 StoreOp fPendingStoreOp = StoreOp::kStore;
122 std::array<float, 4> fPendingClearColor = { 0, 0, 0, 0 };
123
124 // Accumulates atlas coverage masks generated by compute dispatches that are required by one or
125 // more entries in `fPendingDraws`. When pending draws are snapped into a new DrawPass, a
126 // compute dispatch group gets recorded which schedules the accumulated masks to get drawn into
127 // an atlas texture. The accumulated masks are then cleared which frees up the atlas for
128 // future draws.
129 //
130 // TODO: Currently every PathAtlas contains a single texture. If multiple snapped draw
131 // passes resulted in multiple ComputePathAtlas dispatch groups, the later dispatches would
132 // overwrite the atlas texture since all compute tasks are scheduled before render tasks. This
133 // is currently not an issue since there is only one DrawPass per flush but we may want to
134 // either support one atlas texture per DrawPass or record the dispatches once per
135 // RenderPassTask rather than DrawPass.
136 std::unique_ptr<ComputePathAtlas> fComputePathAtlas;
137};
138
139} // namespace skgpu::graphite
140
141#endif // skgpu_graphite_DrawContext_DEFINED
static SkPath clip(const SkPath &path, const SkHalfPlane &plane)
Definition SkPath.cpp:3824
const SkSurfaceProps & surfaceProps() const
Definition DrawContext.h:63
const SkImageInfo & imageInfo() const
Definition DrawContext.h:54
void recordDraw(const Renderer *renderer, const Transform &localToDevice, const Geometry &geometry, const Clip &clip, DrawOrder ordering, const PaintParams *paint, const StrokeStyle *stroke)
const SkColorInfo & colorInfo() const
Definition DrawContext.h:55
const TextureProxy * target() const
Definition DrawContext.h:57
static sk_sp< DrawContext > Make(const Caps *caps, sk_sp< TextureProxy > target, SkISize deviceSize, const SkColorInfo &, const SkSurfaceProps &)
sk_sp< TextureProxy > refTarget() const
Definition DrawContext.h:58
PathAtlas * getComputePathAtlas(Recorder *)
void clear(const SkColor4f &clearColor)
sk_sp< Task > snapDrawTask(Recorder *)
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 >)
const TextureProxyView & readSurfaceView() const
Definition DrawContext.h:61
const Paint & paint
skgpu::graphite::Transform Transform
const SkColorInfo & colorInfo() const
Definition DM.cpp:1161