Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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"
22#include "include/gpu/GrTypes.h"
24#include "src/core/SkDevice.h"
30
31#include <cstddef>
32#include <memory>
33#include <utility>
34
36class GrClip;
39class GrSurfaceProxy;
40class SkBitmap;
41class SkBlender;
42class SkColorSpace;
43class SkDrawable;
44class SkLatticeIter;
45class SkMatrix;
46class SkMesh;
47class SkPaint;
48class SkPath;
49class SkPixmap;
50class SkRRect;
51class SkRegion;
52class SkSpecialImage;
53class SkSurfaceProps;
55class SkVertices;
56enum SkAlphaType : int;
57enum SkColorType : int;
58enum class GrAA : bool;
59enum class GrColorType;
60enum class SkBackingFit;
61enum class SkBlendMode;
62enum class SkTileMode;
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,
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 SkRect& oval, SkScalar startAngle, SkScalar sweepAngle,
189 bool useCenter, const SkPaint& paint) override;
190 void drawPath(const SkPath& path, const SkPaint& paint, bool pathIsMutable) override;
191
192 void drawVertices(const SkVertices*, sk_sp<SkBlender>, const SkPaint&, bool) override;
193 void drawMesh(const SkMesh&, sk_sp<SkBlender>, const SkPaint&) override;
194#if !defined(SK_ENABLE_OPTIMIZE_SIZE)
195 void drawShadow(const SkPath&, const SkDrawShadowRec&) override;
196#endif
197 void drawAtlas(const SkRSXform[], const SkRect[], const SkColor[], int count, sk_sp<SkBlender>,
198 const SkPaint&) override;
199
200 void drawImageRect(const SkImage*, const SkRect* src, const SkRect& dst,
201 const SkSamplingOptions&, const SkPaint&,
203 bool shouldDrawAsTiledImageRect() const override { return true; }
205 const SkImage*,
206 const SkRect* src,
207 const SkRect& dst,
208 const SkSamplingOptions&,
209 const SkPaint&,
211 void drawImageLattice(const SkImage*, const SkCanvas::Lattice&,
212 const SkRect& dst, SkFilterMode, const SkPaint&) override;
213
214 void drawDrawable(SkCanvas*, SkDrawable*, const SkMatrix*) override;
215
216 void drawDevice(SkDevice*, const SkSamplingOptions&, const SkPaint&) override;
218 const SkPaint&, SkCanvas::SrcRectConstraint) override;
219
220 void drawEdgeAAQuad(const SkRect& rect, const SkPoint clip[4], SkCanvas::QuadAAFlags aaFlags,
221 const SkColor4f& color, SkBlendMode mode) override;
222 void drawEdgeAAImageSet(const SkCanvas::ImageSetEntry[], int count, const SkPoint dstClips[],
223 const SkMatrix preViewMatrices[], const SkSamplingOptions&,
224 const SkPaint&, SkCanvas::SrcRectConstraint) override;
225
226 // Assumes the src and dst rects have already been optimized to fit the proxy.
227 // Only implemented by the gpu devices.
228 // This method is the lowest level draw used for tiled bitmap draws. It doesn't attempt to
229 // modify its parameters (e.g., adjust src & dst) but just draws the image however it can. It
230 // could, almost, be replaced with a drawEdgeAAImageSet call for the tiled bitmap draw use
231 // case but the extra tilemode requirement and the intermediate parameter processing (e.g.,
232 // trying to alter the SrcRectConstraint) currently block that.
233 void drawEdgeAAImage(const SkImage*,
234 const SkRect& src,
235 const SkRect& dst,
236 const SkPoint dstClip[4],
238 const SkMatrix& localToDevice,
239 const SkSamplingOptions&,
240 const SkPaint&,
242 const SkMatrix& srcToDst,
243 SkTileMode);
244
246 const SkPaint& paint) override;
247
248 void drawSlug(SkCanvas*, const sktext::gpu::Slug* slug, const SkPaint& paint) override;
249
252 sk_sp<SkSpecialImage> snapSpecial(const SkIRect& subset, bool forceCopy = false) override;
253 sk_sp<SkSpecialImage> snapSpecialScaled(const SkIRect& subset, const SkISize& dstDims) override;
254
255 sk_sp<SkDevice> createDevice(const CreateInfo&, const SkPaint*) override;
256
258
259 Device* asGaneshDevice() override { return this; }
260
261 SkIRect devClipBounds() const override { return fClip.getConservativeBounds(); }
262
263 void pushClipStack() override { fClip.save(); }
264 void popClipStack() override { fClip.restore(); }
265
266 void clipRect(const SkRect& rect, SkClipOp op, bool aa) override {
268 fClip.clipRect(this->localToDevice(), rect, GrAA(aa), op);
269 }
270 void clipRRect(const SkRRect& rrect, SkClipOp op, bool aa) override {
272 fClip.clipRRect(this->localToDevice(), rrect, GrAA(aa), op);
273 }
274 void clipPath(const SkPath& path, SkClipOp op, bool aa) override;
275
276 void replaceClip(const SkIRect& rect) override {
277 // Transform from "global/canvas" coordinates to relative to this device
278 SkRect deviceRect = SkMatrixPriv::MapRect(this->globalToDevice(), SkRect::Make(rect));
279 fClip.replaceClip(deviceRect.round());
280 }
281 void clipRegion(const SkRegion& globalRgn, SkClipOp op) override;
282
283 bool isClipAntiAliased() const override;
284
285 bool isClipEmpty() const override {
286 return fClip.clipState() == ClipStack::ClipState::kEmpty;
287 }
288
289 bool isClipRect() const override {
292 }
293
294 bool isClipWideOpen() const override {
296 }
297
298 void android_utils_clipAsRgn(SkRegion*) const override;
299 bool android_utils_clipWithStencil() override;
300
301private:
302 enum class DeviceFlags {
303 kNone = 0,
304 kNeedClear = 1 << 0, //!< Surface requires an initial clear
305 kIsOpaque = 1 << 1, //!< Hint from client that rendering to this device will be
306 // opaque even if the config supports alpha.
307 };
309
310 static SkImageInfo MakeInfo(SurfaceContext*, DeviceFlags);
311 static bool CheckAlphaTypeAndGetFlags(SkAlphaType, InitContents, DeviceFlags*);
312
314
315 const sktext::gpu::SDFTControl fSDFTControl;
316
317 std::unique_ptr<SurfaceDrawContext> fSurfaceDrawContext;
318
319 ClipStack fClip;
320
321 static sk_sp<Device> Make(std::unique_ptr<SurfaceDrawContext>,
324
325 Device(std::unique_ptr<SurfaceDrawContext>, DeviceFlags);
326
327 void onDrawGlyphRunList(SkCanvas*, const sktext::GlyphRunList&, const SkPaint& paint) override;
328
329 bool onReadPixels(const SkPixmap&, int, int) override;
330 bool onWritePixels(const SkPixmap&, int, int) override;
331 bool onAccessPixels(SkPixmap*) override;
332
334 SkColorType colorType) const override;
335
336 void onClipShader(sk_sp<SkShader> shader) override {
337 fClip.clipShader(std::move(shader));
338 }
339
340 const GrClip* clip() const { return &fClip; }
341
342 // If not null, dstClip must be contained inside dst and will also respect the edge AA flags.
343 // If 'preViewMatrix' is not null, final CTM will be this->ctm() * preViewMatrix.
344 void drawImageQuadDirect(const SkImage*,
345 const SkRect& src,
346 const SkRect& dst,
347 const SkPoint dstClip[4],
349 const SkMatrix* preViewMatrix,
350 const SkSamplingOptions&,
351 const SkPaint&,
353
354 // FIXME(michaelludwig) - Should be removed in favor of using drawImageQuad with edge flags to
355 // for every element in the SkLatticeIter.
356 void drawViewLattice(GrSurfaceProxyView,
357 const GrColorInfo& colorInfo,
358 std::unique_ptr<SkLatticeIter>,
359 const SkRect& dst,
361 const SkPaint&);
362
363 friend class ::SkSurface_Ganesh; // for access to surfaceProps
364 friend class skgpu::TiledTextureUtils; // for access to clip()
365};
366
367GR_MAKE_BITFIELD_CLASS_OPS(Device::DeviceFlags)
368
369} // namespace skgpu::ganesh
370
371#endif // skgpu_v1_Device_DEFINED
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
int count
GrAA
GrColorType
#define GR_MAKE_BITFIELD_CLASS_OPS(X)
Definition GrTypes.h:42
GrSurfaceOrigin
Definition GrTypes.h:147
#define GR_DECL_BITFIELD_CLASS_OPS_FRIENDS(X)
Definition GrTypes.h:77
SkColor4f color
SkAlphaType
Definition SkAlphaType.h:26
#define SkASSERT(cond)
Definition SkAssert.h:116
SkBackingFit
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
Type::kYUV Type::kRGBA() int(0.7 *637)
SrcRectConstraint
Definition SkCanvas.h:1541
const SkM44 & globalToDevice() const
Definition SkDevice.h:191
sk_sp< SkSpecialImage > snapSpecial()
Definition SkDevice.cpp:321
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
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
void replaceClip(const SkIRect &rect)
void clipRRect(const SkRRect &rrect, SkClipOp op, bool aa) override
Definition Device.h:270
void drawArc(const SkRect &oval, SkScalar startAngle, SkScalar sweepAngle, bool useCenter, const SkPaint &paint) override
Definition Device.cpp:775
void drawShadow(const SkPath &, const SkDrawShadowRec &) override
Definition Device.cpp:1179
void drawOval(const SkRect &oval, const SkPaint &paint) override
Definition Device.cpp:750
void android_utils_clipAsRgn(SkRegion *) const override
Definition Device.cpp:411
void drawDRRect(const SkRRect &outer, const SkRRect &inner, const SkPaint &paint) override
Definition Device.cpp:672
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:443
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:567
void clipRect(const SkRect &rect, SkClipOp op, bool aa) override
Definition Device.h:266
bool isClipEmpty() const override
Definition Device.h:285
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:597
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:294
sk_sp< sktext::gpu::Slug > convertGlyphRunListToSlug(const sktext::GlyphRunList &glyphRunList, const SkPaint &paint) override
Definition Device.cpp:1495
void popClipStack() override
Definition Device.h:264
void onClipShader(sk_sp< SkShader > shader) override
Definition Device.h:336
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:431
bool shouldDrawAsTiledImageRect() const override
Definition Device.h:203
void drawPoints(SkCanvas::PointMode mode, size_t count, const SkPoint[], const SkPaint &paint) override
Definition Device.cpp:460
bool onWritePixels(const SkPixmap &, int, int) override
Definition Device.cpp:341
bool onReadPixels(const SkPixmap &, int, int) override
Definition Device.cpp:329
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:368
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
sk_sp< skif::Backend > createImageFilteringBackend(const SkSurfaceProps &surfaceProps, SkColorType colorType) const override
Definition Device.cpp:835
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
bool onAccessPixels(SkPixmap *) override
Definition Device.cpp:353
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:394
SkIRect devClipBounds() const override
Definition Device.h:261
void drawRRect(const SkRRect &r, const SkPaint &paint) override
Definition Device.cpp:633
SurfaceDrawContext * surfaceDrawContext()
Definition Device.cpp:358
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:383
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:212
void replaceClip(const SkIRect &rect) override
Definition Device.h:276
void onDrawGlyphRunList(SkCanvas *, const sktext::GlyphRunList &, const SkPaint &paint) override
Definition Device.cpp:1235
Device * asGaneshDevice() override
Definition Device.h:259
bool isClipRect() const override
Definition Device.h:289
GrRecordingContext * recordingContext() const override
Definition Device.h:101
void drawRegion(const SkRegion &r, const SkPaint &paint) override
Definition Device.cpp:725
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:263
sk_sp< SkSpecialImage > makeSpecial(const SkBitmap &) override
Definition Device.cpp:841
const Paint & paint
float SkScalar
Definition extension.cpp:12
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
Budgeted
Definition GpuTypes.h:35
Mipmapped
Definition GpuTypes.h:53
Protected
Definition GpuTypes.h:61
static SkRect Make(const SkISize &size)
Definition SkRect.h:669
void round(SkIRect *dst) const
Definition SkRect.h:1228