Flutter Engine
The Flutter Engine
Device.h
Go to the documentation of this file.
1/*
2 * Copyright 2010 Google Inc.
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_v1_Device_DEFINED
9#define skgpu_v1_Device_DEFINED
10
16#include "include/core/SkRect.h"
21#include "include/gpu/GrTypes.h"
23#include "src/core/SkDevice.h"
29
30#include <cstddef>
31#include <memory>
32#include <utility>
33
35class GrClip;
38class GrSurfaceProxy;
39class SkBitmap;
40class SkBlender;
41class SkColorSpace;
42class SkDrawable;
43class SkLatticeIter;
44class SkMatrix;
45class SkMesh;
46class SkPaint;
47class SkPath;
48class SkPixmap;
49class SkRRect;
50class SkRegion;
51class SkSpecialImage;
52class SkSurfaceProps;
54class SkVertices;
55enum SkAlphaType : int;
56enum SkColorType : int;
57enum class GrAA : bool;
58enum class GrColorType;
59enum class SkBackingFit;
60enum class SkBlendMode;
61enum class SkTileMode;
62struct SkArc;
63struct SkDrawShadowRec;
64struct SkISize;
65struct SkPoint;
66struct SkRSXform;
67namespace skgpu {
68enum class Budgeted : bool;
69enum class Mipmapped : bool;
70class TiledTextureUtils;
71}
72namespace skif {
73class Backend;
74}
75namespace sktext {
76class GlyphRunList;
77namespace gpu {
78 class Slug;
79}}
80
81
82namespace skgpu::ganesh {
83
84class SurfaceContext;
85class SurfaceFillContext;
87
88/**
89 * Subclass of SkDevice, which directs all drawing to the GrGpu owned by the canvas.
90 */
91class Device final : public SkDevice {
92public:
93 enum class InitContents {
94 kClear,
95 kUninit
96 };
97
100
101 GrRecordingContext* recordingContext() const override { return fContext.get(); }
102
103 bool wait(int numSemaphores,
104 const GrBackendSemaphore* waitSemaphores,
105 bool deleteSemaphoresAfterWait);
106
107 void discard();
108 void resolveMSAA();
109
115 const SkSurfaceProps&);
117
122
124 const SkIRect& srcRect,
125 RescaleGamma rescaleGamma,
126 RescaleMode rescaleMode,
128 ReadPixelsContext context);
129
131 bool readAlpha,
132 sk_sp<SkColorSpace> dstColorSpace,
133 const SkIRect& srcRect,
134 SkISize dstSize,
135 RescaleGamma rescaleGamma,
138 ReadPixelsContext context);
139
140 /**
141 * This factory uses the color space, origin, surface properties, and initialization
142 * method along with the provided proxy to create the gpu device.
143 */
149 const SkSurfaceProps&,
151
152 /**
153 * This factory uses the budgeted, imageInfo, fit, sampleCount, mipmapped, and isProtected
154 * parameters to create a proxy to back the gpu device. The color space (from the image info),
155 * origin, surface properties, and initialization method are then used (with the created proxy)
156 * to create the device.
157 */
160 const SkImageInfo&,
162 int sampleCount,
166 const SkSurfaceProps&,
168
169 ~Device() override;
170
174
175 SkStrikeDeviceInfo strikeDeviceInfo() const override;
176
177 // set all pixels to 0
178 void clearAll();
179
180 void drawPaint(const SkPaint& paint) override;
181 void drawPoints(SkCanvas::PointMode mode, size_t count, const SkPoint[],
182 const SkPaint& paint) override;
183 void drawRect(const SkRect& r, const SkPaint& paint) override;
184 void drawRRect(const SkRRect& r, const SkPaint& paint) override;
185 void drawDRRect(const SkRRect& outer, const SkRRect& inner, const SkPaint& paint) override;
186 void drawRegion(const SkRegion& r, const SkPaint& paint) override;
187 void drawOval(const SkRect& oval, const SkPaint& paint) override;
188 void drawArc(const SkArc& arc, const SkPaint& paint) override;
189 void drawPath(const SkPath& path, const SkPaint& paint, bool pathIsMutable) override;
190
191 void drawVertices(const SkVertices*, sk_sp<SkBlender>, const SkPaint&, bool) override;
192 void drawMesh(const SkMesh&, sk_sp<SkBlender>, const SkPaint&) override;
193#if !defined(SK_ENABLE_OPTIMIZE_SIZE)
194 void drawShadow(const SkPath&, const SkDrawShadowRec&) override;
195#endif
196 void drawAtlas(const SkRSXform[], const SkRect[], const SkColor[], int count, sk_sp<SkBlender>,
197 const SkPaint&) override;
198
199 void drawImageRect(const SkImage*, const SkRect* src, const SkRect& dst,
200 const SkSamplingOptions&, const SkPaint&,
202 bool shouldDrawAsTiledImageRect() const override { return true; }
204 const SkImage*,
205 const SkRect* src,
206 const SkRect& dst,
207 const SkSamplingOptions&,
208 const SkPaint&,
210 void drawImageLattice(const SkImage*, const SkCanvas::Lattice&,
211 const SkRect& dst, SkFilterMode, const SkPaint&) override;
212
213 void drawDrawable(SkCanvas*, SkDrawable*, const SkMatrix*) override;
214
215 void drawDevice(SkDevice*, const SkSamplingOptions&, const SkPaint&) override;
217 const SkPaint&, SkCanvas::SrcRectConstraint) override;
218
219 void drawEdgeAAQuad(const SkRect& rect, const SkPoint clip[4], SkCanvas::QuadAAFlags aaFlags,
220 const SkColor4f& color, SkBlendMode mode) override;
223 const SkPaint&, SkCanvas::SrcRectConstraint) override;
224
225 // Assumes the src and dst rects have already been optimized to fit the proxy.
226 // Only implemented by the gpu devices.
227 // This method is the lowest level draw used for tiled bitmap draws. It doesn't attempt to
228 // modify its parameters (e.g., adjust src & dst) but just draws the image however it can. It
229 // could, almost, be replaced with a drawEdgeAAImageSet call for the tiled bitmap draw use
230 // case but the extra tilemode requirement and the intermediate parameter processing (e.g.,
231 // trying to alter the SrcRectConstraint) currently block that.
232 void drawEdgeAAImage(const SkImage*,
233 const SkRect& src,
234 const SkRect& dst,
235 const SkPoint dstClip[4],
237 const SkMatrix& localToDevice,
238 const SkSamplingOptions&,
239 const SkPaint&,
241 const SkMatrix& srcToDst,
242 SkTileMode);
243
245 const SkPaint& paint) override;
246
247 void drawSlug(SkCanvas*, const sktext::gpu::Slug* slug, const SkPaint& paint) override;
248
251 sk_sp<SkSpecialImage> snapSpecial(const SkIRect& subset, bool forceCopy = false) override;
252 sk_sp<SkSpecialImage> snapSpecialScaled(const SkIRect& subset, const SkISize& dstDims) override;
253
254 sk_sp<SkDevice> createDevice(const CreateInfo&, const SkPaint*) override;
255
257
258 Device* asGaneshDevice() override { return this; }
259
260 SkIRect devClipBounds() const override { return fClip.getConservativeBounds(); }
261
262 void pushClipStack() override { fClip.save(); }
263 void popClipStack() override { fClip.restore(); }
264
265 void clipRect(const SkRect& rect, SkClipOp op, bool aa) override {
267 fClip.clipRect(this->localToDevice(), rect, GrAA(aa), op);
268 }
269 void clipRRect(const SkRRect& rrect, SkClipOp op, bool aa) override {
271 fClip.clipRRect(this->localToDevice(), rrect, GrAA(aa), op);
272 }
273 void clipPath(const SkPath& path, SkClipOp op, bool aa) override;
274
275 void replaceClip(const SkIRect& rect) override {
276 // Transform from "global/canvas" coordinates to relative to this device
277 SkRect deviceRect = SkMatrixPriv::MapRect(this->globalToDevice(), SkRect::Make(rect));
278 fClip.replaceClip(deviceRect.round());
279 }
280 void clipRegion(const SkRegion& globalRgn, SkClipOp op) override;
281
282 bool isClipAntiAliased() const override;
283
284 bool isClipEmpty() const override {
285 return fClip.clipState() == ClipStack::ClipState::kEmpty;
286 }
287
288 bool isClipRect() const override {
291 }
292
293 bool isClipWideOpen() const override {
295 }
296
297 void android_utils_clipAsRgn(SkRegion*) const override;
298 bool android_utils_clipWithStencil() override;
299
300private:
301 enum class DeviceFlags {
302 kNone = 0,
303 kNeedClear = 1 << 0, //!< Surface requires an initial clear
304 kIsOpaque = 1 << 1, //!< Hint from client that rendering to this device will be
305 // opaque even if the config supports alpha.
306 };
307 GR_DECL_BITFIELD_CLASS_OPS_FRIENDS(DeviceFlags);
308
309 static SkImageInfo MakeInfo(SurfaceContext*, DeviceFlags);
310 static bool CheckAlphaTypeAndGetFlags(SkAlphaType, InitContents, DeviceFlags*);
311
313
314 const sktext::gpu::SDFTControl fSDFTControl;
315
316 std::unique_ptr<SurfaceDrawContext> fSurfaceDrawContext;
317
318 ClipStack fClip;
319
320 static sk_sp<Device> Make(std::unique_ptr<SurfaceDrawContext>,
323
324 Device(std::unique_ptr<SurfaceDrawContext>, DeviceFlags);
325
326 void onDrawGlyphRunList(SkCanvas*, const sktext::GlyphRunList&, const SkPaint& paint) override;
327
328 bool onReadPixels(const SkPixmap&, int, int) override;
329 bool onWritePixels(const SkPixmap&, int, int) override;
330 bool onAccessPixels(SkPixmap*) override;
331
332 sk_sp<skif::Backend> createImageFilteringBackend(const SkSurfaceProps& surfaceProps,
333 SkColorType colorType) const override;
334
335 void onClipShader(sk_sp<SkShader> shader) override {
336 fClip.clipShader(std::move(shader));
337 }
338
339 const GrClip* clip() const { return &fClip; }
340
341 // If not null, dstClip must be contained inside dst and will also respect the edge AA flags.
342 // If 'preViewMatrix' is not null, final CTM will be this->ctm() * preViewMatrix.
343 void drawImageQuadDirect(const SkImage*,
344 const SkRect& src,
345 const SkRect& dst,
346 const SkPoint dstClip[4],
348 const SkMatrix* preViewMatrix,
349 const SkSamplingOptions&,
350 const SkPaint&,
352
353 // FIXME(michaelludwig) - Should be removed in favor of using drawImageQuad with edge flags to
354 // for every element in the SkLatticeIter.
355 void drawViewLattice(GrSurfaceProxyView,
356 const GrColorInfo& colorInfo,
357 std::unique_ptr<SkLatticeIter>,
358 const SkRect& dst,
360 const SkPaint&);
361
362 friend class ::SkSurface_Ganesh; // for access to surfaceProps
363 friend class skgpu::TiledTextureUtils; // for access to clip()
364};
365
366GR_MAKE_BITFIELD_CLASS_OPS(Device::DeviceFlags)
367
368} // namespace skgpu::ganesh
369
370#endif // skgpu_v1_Device_DEFINED
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
int count
Definition: FontMgrTest.cpp:50
GrAA
Definition: GrTypesPriv.h:173
GrColorType
Definition: GrTypesPriv.h:540
#define GR_MAKE_BITFIELD_CLASS_OPS(X)
Definition: GrTypes.h:42
GrSurfaceOrigin
Definition: GrTypes.h:147
SkAlphaType
Definition: SkAlphaType.h:26
#define SkASSERT(cond)
Definition: SkAssert.h:116
SkBackingFit
Definition: SkBackingFit.h:16
SkBlendMode
Definition: SkBlendMode.h:38
SkClipOp
Definition: SkClipOp.h:13
SkColorType
Definition: SkColorType.h:19
uint32_t SkColor
Definition: SkColor.h:37
static SkColorType colorType(AImageDecoder *decoder, const AImageDecoderHeaderInfo *headerInfo)
SkYUVColorSpace
Definition: SkImageInfo.h:68
SkFilterMode
SkTileMode
Definition: SkTileMode.h:13
Definition: GrClip.h:29
SrcRectConstraint
Definition: SkCanvas.h:1541
const SkM44 & globalToDevice() const
Definition: SkDevice.h:191
sk_sp< SkSpecialImage > snapSpecial()
Definition: SkDevice.cpp:320
const SkMatrix & localToDevice() const
Definition: SkDevice.h:179
const SkSurfaceProps & surfaceProps() const
Definition: SkDevice.h:131
void * ReadPixelsContext
Definition: SkImage.h:578
RescaleMode
Definition: SkImage.h:587
RescaleGamma
Definition: SkImage.h:585
void(ReadPixelsContext, std::unique_ptr< const AsyncReadResult >) ReadPixelsCallback
Definition: SkImage.h:583
static SkRect MapRect(const SkM44 &m, const SkRect &r)
Definition: SkM44.cpp:216
Definition: SkMesh.h:263
Definition: SkPath.h:59
ContentChangeMode
Definition: SkSurface.h:203
T * get() const
Definition: SkRefCnt.h:303
void clipRRect(const SkMatrix &ctm, const SkRRect &rrect, GrAA aa, SkClipOp op)
Definition: ClipStack.h:77
void clipRect(const SkMatrix &ctm, const SkRect &rect, GrAA aa, SkClipOp op)
Definition: ClipStack.h:74
ClipState clipState() const
Definition: ClipStack.h:62
SkIRect getConservativeBounds() const override
Definition: ClipStack.cpp:1195
void replaceClip(const SkIRect &rect)
Definition: ClipStack.cpp:1542
void clipRRect(const SkRRect &rrect, SkClipOp op, bool aa) override
Definition: Device.h:269
void drawShadow(const SkPath &, const SkDrawShadowRec &) override
Definition: Device.cpp:1179
void drawOval(const SkRect &oval, const SkPaint &paint) override
Definition: Device.cpp:751
void android_utils_clipAsRgn(SkRegion *) const override
Definition: Device.cpp:412
void drawDRRect(const SkRRect &outer, const SkRRect &inner, const SkPaint &paint) override
Definition: Device.cpp:673
void drawPath(const SkPath &path, const SkPaint &paint, bool pathIsMutable) override
Definition: Device.cpp:803
SkImage::ReadPixelsContext ReadPixelsContext
Definition: Device.h:121
void drawPaint(const SkPaint &paint) override
Definition: Device.cpp:444
SkStrikeDeviceInfo strikeDeviceInfo() const override
Definition: Device.cpp:1491
GrSurfaceProxyView readSurfaceView()
Definition: Device.cpp:1283
void drawRect(const SkRect &r, const SkPaint &paint) override
Definition: Device.cpp:568
void clipRect(const SkRect &rect, SkClipOp op, bool aa) override
Definition: Device.h:265
bool isClipEmpty() const override
Definition: Device.h:284
void drawVertices(const SkVertices *, sk_sp< SkBlender >, const SkPaint &, bool) override
Definition: Device.cpp:1110
void drawEdgeAAQuad(const SkRect &rect, const SkPoint clip[4], SkCanvas::QuadAAFlags aaFlags, const SkColor4f &color, SkBlendMode mode) override
Definition: Device.cpp:598
bool android_utils_clipWithStencil() override
Definition: Device.cpp:1465
void drawDrawable(SkCanvas *, SkDrawable *, const SkMatrix *) override
Definition: Device.cpp:1261
bool isClipWideOpen() const override
Definition: Device.h:293
sk_sp< sktext::gpu::Slug > convertGlyphRunListToSlug(const sktext::GlyphRunList &glyphRunList, const SkPaint &paint) override
Definition: Device.cpp:1495
void popClipStack() override
Definition: Device.h:263
bool drawAsTiledImageRect(SkCanvas *, const SkImage *, const SkRect *src, const SkRect &dst, const SkSamplingOptions &, const SkPaint &, SkCanvas::SrcRectConstraint) override
Definition: Device.cpp:1000
bool isClipAntiAliased() const override
Definition: Device.cpp:432
bool shouldDrawAsTiledImageRect() const override
Definition: Device.h:202
void drawPoints(SkCanvas::PointMode mode, size_t count, const SkPoint[], const SkPaint &paint) override
Definition: Device.cpp:461
sk_sp< SkSpecialImage > snapSpecialScaled(const SkIRect &subset, const SkISize &dstDims) override
Definition: Device.cpp:935
sk_sp< SkSurface > makeSurface(const SkImageInfo &, const SkSurfaceProps &) override
Definition: Device.cpp:1448
GrRenderTargetProxy * targetProxy()
Definition: Device.cpp:1287
bool wait(int numSemaphores, const GrBackendSemaphore *waitSemaphores, bool deleteSemaphoresAfterWait)
Definition: Device.cpp:1291
void drawAtlas(const SkRSXform[], const SkRect[], const SkColor[], int count, sk_sp< SkBlender >, const SkPaint &) override
Definition: Device.cpp:1198
SurfaceFillContext * surfaceFillContext()
Definition: Device.cpp:369
void drawEdgeAAImageSet(const SkCanvas::ImageSetEntry[], int count, const SkPoint dstClips[], const SkMatrix preViewMatrices[], const SkSamplingOptions &, const SkPaint &, SkCanvas::SrcRectConstraint) override
void drawMesh(const SkMesh &, sk_sp< SkBlender >, const SkPaint &) override
Definition: Device.cpp:1145
void asyncRescaleAndReadPixelsYUV420(SkYUVColorSpace yuvColorSpace, bool readAlpha, sk_sp< SkColorSpace > dstColorSpace, const SkIRect &srcRect, SkISize dstSize, RescaleGamma rescaleGamma, RescaleMode, ReadPixelsCallback callback, ReadPixelsContext context)
Definition: Device.cpp:1389
void asyncRescaleAndReadPixels(const SkImageInfo &info, const SkIRect &srcRect, RescaleGamma rescaleGamma, RescaleMode rescaleMode, ReadPixelsCallback callback, ReadPixelsContext context)
Definition: Device.cpp:1373
SkImage::ReadPixelsCallback ReadPixelsCallback
Definition: Device.h:120
void drawImageRect(const SkImage *, const SkRect *src, const SkRect &dst, const SkSamplingOptions &, const SkPaint &, SkCanvas::SrcRectConstraint) override
Definition: Device.cpp:976
void drawDevice(SkDevice *, const SkSamplingOptions &, const SkPaint &) override
Definition: Device.cpp:967
void clipRegion(const SkRegion &globalRgn, SkClipOp op) override
Definition: Device.cpp:395
SkIRect devClipBounds() const override
Definition: Device.h:260
void drawRRect(const SkRRect &r, const SkPaint &paint) override
Definition: Device.cpp:634
SurfaceDrawContext * surfaceDrawContext()
Definition: Device.cpp:359
bool replaceBackingProxy(SkSurface::ContentChangeMode, sk_sp< GrRenderTargetProxy >, GrColorType, sk_sp< SkColorSpace >, GrSurfaceOrigin, const SkSurfaceProps &)
Definition: Device.cpp:1308
void drawSpecial(SkSpecialImage *, const SkMatrix &localToDevice, const SkSamplingOptions &, const SkPaint &, SkCanvas::SrcRectConstraint) override
void clipPath(const SkPath &path, SkClipOp op, bool aa) override
Definition: Device.cpp:384
void drawEdgeAAImage(const SkImage *, const SkRect &src, const SkRect &dst, const SkPoint dstClip[4], SkCanvas::QuadAAFlags, const SkMatrix &localToDevice, const SkSamplingOptions &, const SkPaint &, SkCanvas::SrcRectConstraint, const SkMatrix &srcToDst, SkTileMode)
static sk_sp< Device > Make(GrRecordingContext *, GrColorType, sk_sp< GrSurfaceProxy >, sk_sp< SkColorSpace >, GrSurfaceOrigin, const SkSurfaceProps &, InitContents)
Definition: Device.cpp:213
void drawArc(const SkArc &arc, const SkPaint &paint) override
Definition: Device.cpp:776
void replaceClip(const SkIRect &rect) override
Definition: Device.h:275
Device * asGaneshDevice() override
Definition: Device.h:258
bool isClipRect() const override
Definition: Device.h:288
GrRecordingContext * recordingContext() const override
Definition: Device.h:101
void drawRegion(const SkRegion &r, const SkPaint &paint) override
Definition: Device.cpp:726
void drawSlug(SkCanvas *, const sktext::gpu::Slug *slug, const SkPaint &paint) override
Definition: Device.cpp:1504
sk_sp< SkDevice > createDevice(const CreateInfo &, const SkPaint *) override
Definition: Device.cpp:1418
void drawImageLattice(const SkImage *, const SkCanvas::Lattice &, const SkRect &dst, SkFilterMode, const SkPaint &) override
Definition: Device.cpp:1094
void pushClipStack() override
Definition: Device.h:262
sk_sp< SkSpecialImage > makeSpecial(const SkBitmap &) override
Definition: Device.cpp:841
const Paint & paint
Definition: color_source.cc:38
DlColor color
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
PODArray< SkPoint > dstClips
Definition: SkRecords.h:364
SkRRect rrect
Definition: SkRecords.h:232
SkRect oval
Definition: SkRecords.h:249
sk_sp< SkBlender > blender SkRect rect
Definition: SkRecords.h:350
PODArray< SkMatrix > preViewMatrices
Definition: SkRecords.h:365
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive mode
Definition: switches.h:228
dst
Definition: cp.py:12
Definition: GpuTools.h:21
Budgeted
Definition: GpuTypes.h:35
Mipmapped
Definition: GpuTypes.h:53
Protected
Definition: GpuTypes.h:61
Definition: SkDevice.h:63
Definition: SkArc.h:15
Definition: SkRect.h:32
Definition: SkSize.h:16
static SkRect Make(const SkISize &size)
Definition: SkRect.h:669
void round(SkIRect *dst) const
Definition: SkRect.h:1228