Flutter Engine
The Flutter Engine
SkDevice.h
Go to the documentation of this file.
1/*
2 * Copyright 2010 The Android Open Source Project
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 SkDevice_DEFINED
9#define SkDevice_DEFINED
10
11#include "include/core/SkBlender.h" // IWYU pragma: keep
16#include "include/core/SkM44.h"
19#include "include/core/SkRect.h"
24#include "include/core/SkSize.h"
31
32#include <cstddef>
33#include <cstdint>
34#include <utility>
35
36struct SkArc;
37class SkBitmap;
38class SkColorSpace;
39class SkMesh;
40struct SkDrawShadowRec;
41class SkImageFilter;
43class SkSpecialImage;
45class SkData;
46class SkDrawable;
47class SkImage;
48class SkPaint;
49class SkPath;
50class SkPixmap;
51class SkRRect;
52class SkSurface;
53class SkVertices;
54enum SkColorType : int;
55enum class SkBlendMode;
56enum class SkScalerContextFlags : uint32_t;
57struct SkRSXform;
58
59namespace sktext {
60class GlyphRunList;
61}
62
63namespace skif {
64class Backend;
65class Mapping;
66}
67namespace skgpu::ganesh {
68class Device;
69}
70namespace skgpu::graphite {
71class Device;
72class Recorder;
73}
74namespace sktext::gpu {
75class SDFTControl;
76class Slug;
77}
78
82 // This is a pointer so this can be compiled without SK_GPU_SUPPORT.
84};
85
86/**
87 * SkDevice is the internal API and implementation that SkCanvas will use to perform rendering and
88 * implement the saveLayer abstraction. A device wraps some pixel allocation (for non-document based
89 * devices) or wraps some other container that stores rendering operations. The drawing operations
90 * perform equivalently to their corresponding functions in SkCanvas except that the canvas is
91 * responsible for all SkImageFilters. An image filter is applied by automatically creating a layer,
92 * drawing the filter-less paint into the layer, and then evaluating the filter on the layer's
93 * image.
94 *
95 * Each layer in an SkCanvas stack is represented by an SkDevice instance that was created by the
96 * parent SkDevice (up to the canvas's base device). In most cases these devices will be pixel
97 * aligned with one another but may differ in size based on the known extent of the active clip. In
98 * complex image filtering scenarios, they may not be axis aligned, although the effective pixel
99 * size should remain approximately equal across all devices in a canvas.
100 *
101 * While SkCanvas manages a single stack of layers and canvas transforms, SkDevice does not have a
102 * stack of transforms. Instead, it has a single active transform that is modified as needed by
103 * SkCanvas. However, SkDevices are the means by which SkCanvas manages the clip stack because each
104 * layer's clip stack starts anew (although the layer's results are then clipped by its parent's
105 * stack when it is restored).
106 */
107class SkDevice : public SkRefCnt {
108public:
109 SkDevice(const SkImageInfo&, const SkSurfaceProps&);
110
111 // -- Surface properties and metadata
112
113 /**
114 * Return ImageInfo for this device. If the canvas is not backed by pixels
115 * (cpu or gpu), then the info's ColorType will be kUnknown_SkColorType.
116 */
117 const SkImageInfo& imageInfo() const { return fInfo; }
118
119 int width() const { return this->imageInfo().width(); }
120 int height() const { return this->imageInfo().height(); }
121
122 bool isOpaque() const { return this->imageInfo().isOpaque(); }
123
124 // NOTE: Image dimensions as a rect, *not* the current restricted clip bounds.
125 SkIRect bounds() const { return SkIRect::MakeWH(this->width(), this->height()); }
126 SkISize size() const { return this->imageInfo().dimensions(); }
127
128 /**
129 * Return SurfaceProps for this device.
130 */
132 return fSurfaceProps;
133 }
134
136
138 return {fSurfaceProps, this->scalerContextFlags(), nullptr};
139 }
140
141 // -- Direct pixel manipulation
142
143 /**
144 * Write the pixels in 'src' into this Device at the specified x,y offset. The caller is
145 * responsible for "pre-clipping" the src.
146 */
147 bool writePixels(const SkPixmap& src, int x, int y) { return this->onWritePixels(src, x, y); }
148
149 /**
150 * Read pixels from this Device at the specified x,y offset into dst. The caller is
151 * responsible for "pre-clipping" the dst
152 */
153 bool readPixels(const SkPixmap& dst, int x, int y) { return this->onReadPixels(dst, x, y); }
154
155 /**
156 * Try to get write-access to the pixels behind the device. If successful, this returns true
157 * and fills-out the pixmap parameter. On success it also bumps the genID of the underlying
158 * bitmap.
159 *
160 * On failure, returns false and ignores the pixmap parameter.
161 */
162 bool accessPixels(SkPixmap* pmap);
163
164 /**
165 * Try to get read-only-access to the pixels behind the device. If successful, this returns
166 * true and fills-out the pixmap parameter.
167 *
168 * On failure, returns false and ignores the pixmap parameter.
169 */
170 bool peekPixels(SkPixmap*);
171
172
173 // -- Device's transform (both current transform affecting draws, and its fixed global mapping)
174
175 /**
176 * Returns the transformation that maps from the local space to the device's coordinate space.
177 */
178 const SkM44& localToDevice44() const { return fLocalToDevice; }
179 const SkMatrix& localToDevice() const { return fLocalToDevice33; }
180
181 /**
182 * Return the device's coordinate space transform: this maps from the device's coordinate space
183 * into the global canvas' space (or root device space). This includes the translation
184 * necessary to account for the device's origin.
185 */
186 const SkM44& deviceToGlobal() const { return fDeviceToGlobal; }
187 /**
188 * Return the inverse of getDeviceToGlobal(), mapping from the global canvas' space (or root
189 * device space) into this device's coordinate space.
190 */
191 const SkM44& globalToDevice() const { return fGlobalToDevice; }
192 /**
193 * DEPRECATED: This asserts that 'getDeviceToGlobal' is a translation matrix with integer
194 * components. In the future some SkDevices will have more complex device-to-global transforms,
195 * so getDeviceToGlobal() or getRelativeTransform() should be used instead.
196 */
197 SkIPoint getOrigin() const;
198 /**
199 * Returns true when this device's pixel grid is axis aligned with the global coordinate space,
200 * and any relative translation between the two spaces is in integer pixel units.
201 */
202 bool isPixelAlignedToGlobal() const;
203 /**
204 * Get the transformation from this device's coordinate system to the provided device space.
205 * This transform can be used to draw this device into the provided device, such that once
206 * that device is drawn to the root device, the net effect will be that this device's contents
207 * have been transformed by the global CTM.
208 */
210
212 fLocalToDevice = localToDevice;
213 fLocalToDevice33 = fLocalToDevice.asM33();
214 fLocalToDeviceDirty = true;
215 }
216 void setGlobalCTM(const SkM44& ctm);
217
218 // -- Device's clip bounds and stack manipulation
219
220 /**
221 * Return the bounds of the device in the coordinate space of the root canvas. The root device
222 * will have its top-left at 0,0, but other devices such as those associated with saveLayer may
223 * have a non-zero origin.
224 */
227 *bounds = SkMatrixPriv::MapRect(fDeviceToGlobal, SkRect::Make(this->bounds())).roundOut();
228 }
229
232 this->getGlobalBounds(&bounds);
233 return bounds;
234 }
235
236 /**
237 * Returns the bounding box of the current clip, in this device's coordinate space. No pixels
238 * outside of these bounds will be touched by draws unless the clip is further modified (at
239 * which point this will return the updated bounds).
240 */
241 virtual SkIRect devClipBounds() const = 0;
242
243 virtual void pushClipStack() = 0;
244 virtual void popClipStack() = 0;
245
246 virtual void clipRect(const SkRect& rect, SkClipOp op, bool aa) = 0;
247 virtual void clipRRect(const SkRRect& rrect, SkClipOp op, bool aa) = 0;
248 virtual void clipPath(const SkPath& path, SkClipOp op, bool aa) = 0;
249 virtual void clipRegion(const SkRegion& region, SkClipOp op) = 0;
250
252 sh = as_SB(sh)->makeWithCTM(this->localToDevice());
253 if (op == SkClipOp::kDifference) {
255 }
256 this->onClipShader(std::move(sh));
257 }
258
259 virtual void replaceClip(const SkIRect& rect) = 0;
260
261 virtual bool isClipAntiAliased() const = 0;
262 virtual bool isClipEmpty() const = 0;
263 virtual bool isClipRect() const = 0;
264 virtual bool isClipWideOpen() const = 0;
265
266 virtual void android_utils_clipAsRgn(SkRegion*) const = 0;
267 virtual bool android_utils_clipWithStencil() { return false; }
268
269 // -- Device reflection
270
271 // TEMPORARY: Whether or not SkCanvas should use an layer and image filters to simulate
272 // mask filters and then draw the filtered mask using drawCoverageMask. Unlike regular
273 // layers, the color type passed to SkDevice::createDevice() will always be an alpha-only
274 // color type. Eventually this will be the only way that mask filters are handled (barring
275 // dedicated fast-paths for blurs on [r]rects and text).
276 virtual bool useDrawCoverageMaskForMaskFilters() const { return false; }
277
278 // SkCanvas uses NoPixelsDevice when onCreateDevice fails; but then it needs to be able to
279 // inspect a layer's device to know if calling drawDevice() later is allowed.
280 virtual bool isNoPixelsDevice() const { return false; }
281
282 virtual void* getRasterHandle() const { return nullptr; }
283
284 virtual GrRecordingContext* recordingContext() const { return nullptr; }
285 virtual skgpu::graphite::Recorder* recorder() const { return nullptr; }
286
287 virtual skgpu::ganesh::Device* asGaneshDevice() { return nullptr; }
288 virtual skgpu::graphite::Device* asGraphiteDevice() { return nullptr; }
289
290 // Marking an SkDevice immutable declares the intent that rendering to the device is
291 // complete, allowing it to be sampled as an image without requiring a copy. Drawing
292 // operations may not function and may assert if invoked after setImmutable() is called.
293 virtual void setImmutable() {}
294
296
297 struct CreateInfo {
299 SkPixelGeometry geo,
300 SkRasterHandleAllocator* allocator)
301 : fInfo(info)
302 , fPixelGeometry(geo)
303 , fAllocator(allocator)
304 {}
305
309 };
310
311 /**
312 * Create a new device based on CreateInfo. If the paint is not null, then it represents a
313 * preview of how the new device will be composed with its creator device (this).
314 *
315 * The subclass may be handed this device in drawDevice(), so it must always return a device
316 * that it knows how to draw, and that it knows how to identify if it is not of the same
317 * subclass (since drawDevice is passed a SkDevice*). If the subclass cannot fulfill that
318 * contract (e.g. PDF cannot support some settings on the paint) it should return NULL, and the
319 * caller may then decide to explicitly create a bitmapdevice, knowing that later it could not
320 * call drawDevice with it (but it could call drawSprite or drawBitmap).
321 */
322 virtual sk_sp<SkDevice> createDevice(const CreateInfo&, const SkPaint*) { return nullptr; }
323
324 // -- Drawing routines (called after saveLayers and imagefilter operations are applied)
325
326 // Ensure that non-RSXForm runs are passed to onDrawGlyphRunList.
328 const sktext::GlyphRunList& glyphRunList,
329 const SkPaint& paint);
330 // Slug handling routines.
332 const sktext::GlyphRunList& glyphRunList, const SkPaint& paint);
333 virtual void drawSlug(SkCanvas*, const sktext::gpu::Slug* slug, const SkPaint& paint);
334
335 virtual void drawPaint(const SkPaint& paint) = 0;
337 const SkPoint[], const SkPaint& paint) = 0;
338 virtual void drawRect(const SkRect& r,
339 const SkPaint& paint) = 0;
340 virtual void drawRegion(const SkRegion& r,
341 const SkPaint& paint);
342 virtual void drawOval(const SkRect& oval,
343 const SkPaint& paint) = 0;
344 /** By the time this is called we know that abs(sweepAngle) is in the range [0, 360). */
345 virtual void drawArc(const SkArc& arc, const SkPaint& paint);
346 virtual void drawRRect(const SkRRect& rr,
347 const SkPaint& paint) = 0;
348
349 // Default impl calls drawPath()
350 virtual void drawDRRect(const SkRRect& outer,
351 const SkRRect& inner, const SkPaint&);
352
353 /**
354 * If pathIsMutable, then the implementation is allowed to cast path to a
355 * non-const pointer and modify it in place (as an optimization). Canvas
356 * may do this to implement helpers such as drawOval, by placing a temp
357 * path on the stack to hold the representation of the oval.
358 */
359 virtual void drawPath(const SkPath& path,
360 const SkPaint& paint,
361 bool pathIsMutable = false) = 0;
362
363 virtual void drawImageRect(const SkImage*, const SkRect* src, const SkRect& dst,
364 const SkSamplingOptions&, const SkPaint&,
366 // Return true if canvas calls to drawImage or drawImageRect should try to
367 // be drawn in a tiled way.
368 virtual bool shouldDrawAsTiledImageRect() const { return false; }
370 const SkImage*,
371 const SkRect* src,
372 const SkRect& dst,
373 const SkSamplingOptions&,
374 const SkPaint&,
375 SkCanvas::SrcRectConstraint) { return false; }
376
377 virtual void drawImageLattice(const SkImage*, const SkCanvas::Lattice&,
378 const SkRect& dst, SkFilterMode, const SkPaint&);
379
380 /**
381 * If skipColorXform is true, then the implementation should assume that the provided
382 * vertex colors are already in the destination color space.
383 */
384 virtual void drawVertices(const SkVertices*,
386 const SkPaint&,
387 bool skipColorXform = false) = 0;
388 virtual void drawMesh(const SkMesh& mesh, sk_sp<SkBlender>, const SkPaint&) = 0;
389 virtual void drawShadow(const SkPath&, const SkDrawShadowRec&);
390
391 // default implementation calls drawVertices
392 virtual void drawPatch(const SkPoint cubics[12], const SkColor colors[4],
393 const SkPoint texCoords[4], sk_sp<SkBlender>, const SkPaint& paint);
394
395 // default implementation calls drawVertices
396 virtual void drawAtlas(const SkRSXform[], const SkRect[], const SkColor[], int count,
397 sk_sp<SkBlender>, const SkPaint&);
398
399 virtual void drawAnnotation(const SkRect&, const char[], SkData*) {}
400
401 // Default impl always calls drawRect() with a solid-color paint, setting it to anti-aliased
402 // only when all edge flags are set. If there's a clip region, it draws that using drawPath,
403 // or uses clipPath().
404 virtual void drawEdgeAAQuad(const SkRect& rect, const SkPoint clip[4],
405 SkCanvas::QuadAAFlags aaFlags, const SkColor4f& color,
407 // Default impl uses drawImageRect per entry, being anti-aliased only when an entry's edge flags
408 // are all set. If there's a clip region, it will be applied using clipPath().
409 virtual void drawEdgeAAImageSet(const SkCanvas::ImageSetEntry[], int count,
410 const SkPoint dstClips[], const SkMatrix preViewMatrices[],
411 const SkSamplingOptions&, const SkPaint&,
413
414 virtual void drawDrawable(SkCanvas*, SkDrawable*, const SkMatrix*);
415
416 // -- "Special" drawing and image routines
417
418 // Snap the 'subset' contents from this device, possibly as a read-only view. If 'forceCopy'
419 // is true then the returned image's pixels must not be affected by subsequent draws into the
420 // device. When 'forceCopy' is false, the image can be a view into the device's pixels
421 // (avoiding a copy for performance, at the expense of safety). Default returns null.
422 virtual sk_sp<SkSpecialImage> snapSpecial(const SkIRect& subset, bool forceCopy = false);
423 // Can return null if unable to perform scaling as part of the copy, even if snapSpecial() w/o
424 // scaling would succeed.
425 virtual sk_sp<SkSpecialImage> snapSpecialScaled(const SkIRect& subset, const SkISize& dstDims);
426 // Get a view of the entire device's current contents as an image.
428
429 /**
430 * The SkDevice passed will be an SkDevice which was returned by a call to
431 * onCreateDevice on this device with kNeverTile_TileExpectation.
432 *
433 * The default implementation calls snapSpecial() and drawSpecial() with the relative transform
434 * from the input device to this device. The provided SkPaint cannot have a mask filter or
435 * image filter, and any shader is ignored.
436 */
437 virtual void drawDevice(SkDevice*, const SkSamplingOptions&, const SkPaint&);
438
439 /**
440 * Draw the special image's subset to this device, subject to the given matrix transform instead
441 * of the device's current local to device matrix.
442 *
443 * If 'constraint' is kFast, the rendered geometry of the image still reflects the extent of
444 * the SkSpecialImage's subset, but it's assumed that the pixel data beyond the subset is valid
445 * (e.g. SkSpecialImage::makeSubset() was called to crop a larger image).
446 */
447 virtual void drawSpecial(SkSpecialImage*, const SkMatrix& localToDevice,
448 const SkSamplingOptions&, const SkPaint&,
449 SkCanvas::SrcRectConstraint constraint =
451
452 /**
453 * Draw the special image's subset to this device, treating its alpha channel as coverage for
454 * the draw and ignoring any RGB channels that might be present. This will be drawn using the
455 * provided matrix transform instead of the device's current local to device matrix.
456 *
457 * Coverage values beyond the image's subset are treated as 0 (i.e. kDecal tiling). Color values
458 * before coverage are determined as normal by the SkPaint, ignoring style, path effects,
459 * mask filters and image filters. The local coords of any SkShader on the paint should be
460 * relative to the SkDevice's current matrix (i.e. 'maskToDevice' determines how the coverage
461 * mask aligns with device-space, but otherwise shading proceeds like other draws).
462 */
463 virtual void drawCoverageMask(const SkSpecialImage*, const SkMatrix& maskToDevice,
464 const SkSamplingOptions&, const SkPaint&);
465
466 /**
467 * Draw rrect with an optimized path for analytic blurs, if provided by the device.
468 */
469 virtual bool drawBlurredRRect(const SkRRect&, const SkPaint&, float deviceSigma) {
470 return false;
471 }
472
473 /**
474 * Evaluate 'filter' and draw the final output into this device using 'paint'. The 'mapping'
475 * defines the parameter-to-layer space transform used to evaluate the image filter on 'src',
476 * and the layer-to-device space transform that is used to draw the result into this device.
477 * Since 'mapping' fully specifies the transform, this draw function ignores the current
478 * local-to-device matrix (i.e. just like drawSpecial and drawDevice).
479 *
480 * The final paint must not have an image filter or mask filter set on it; a shader is ignored.
481 * The provided color type will be used for any intermediate surfaces that need to be created as
482 * part of filter evaluation. It does not have to be src's color type or this Device's type.
483 */
485 const SkImageFilter*, const SkSamplingOptions&, const SkPaint&);
486
487protected:
488 // DEPRECATED: Can be deleted once SkCanvas::onDrawImage() uses skif::FilterResult so don't
489 // bother re-arranging.
492
493 // Configure the device's coordinate spaces, specifying both how its device image maps back to
494 // the global space (via 'deviceToGlobal') and the initial CTM of the device (via
495 // 'localToDevice', i.e. what geometry drawn into this device will be transformed with).
496 //
497 // (bufferOriginX, bufferOriginY) defines where the (0,0) pixel the device's backing buffer
498 // is anchored in the device space. The final device-to-global matrix stored by the SkDevice
499 // will include a pre-translation by T(deviceOriginX, deviceOriginY), and the final
500 // local-to-device matrix will have a post-translation of T(-deviceOriginX, -deviceOriginY).
502 const SkM44& globalToDevice,
503 const SkM44& localToDevice,
504 int bufferOriginX,
505 int bufferOriginY);
506 // Convenience to configure the device to be axis-aligned with the root canvas, but with a
507 // unique origin.
508 void setOrigin(const SkM44& globalCTM, int x, int y) {
509 this->setDeviceCoordinateSystem(SkM44(), SkM44(), globalCTM, x, y);
510 }
511
512 // Returns whether or not localToDevice() has changed since the last call to this function.
514 bool wasDirty = fLocalToDeviceDirty;
515 fLocalToDeviceDirty = false;
516 return wasDirty;
517 }
518
519private:
520 friend class SkCanvas; // for setOrigin/setDeviceCoordinateSystem
522
523 // Defaults to a CPU image filtering backend.
525 SkColorType colorType) const;
526
527 // Implementations can assume that the device from (x,y) to (w,h) will fit within dst.
528 virtual bool onReadPixels(const SkPixmap&, int x, int y) { return false; }
529
530 // Implementations can assume that the src image placed at 'x,y' will fit within the device.
531 virtual bool onWritePixels(const SkPixmap&, int x, int y) { return false; }
532
533 virtual bool onAccessPixels(SkPixmap*) { return false; }
534
535 virtual bool onPeekPixels(SkPixmap*) { return false; }
536
537 virtual void onClipShader(sk_sp<SkShader>) = 0;
538
539 // Only called with glyphRunLists that do not contain RSXForm.
542 const SkPaint& paint) = 0;
543
544 void simplifyGlyphRunRSXFormAndRedraw(SkCanvas*,
546 const SkPaint& paint);
547
548 const SkImageInfo fInfo;
549 const SkSurfaceProps fSurfaceProps;
550 SkM44 fLocalToDevice;
551 // fDeviceToGlobal and fGlobalToDevice are inverses of each other; there are never that many
552 // SkDevices, so pay the memory cost to avoid recalculating the inverse.
553 SkM44 fDeviceToGlobal;
554 SkM44 fGlobalToDevice;
555
556 // fLocalToDevice but as a 3x3.
557 SkMatrix fLocalToDevice33;
558
559 // fLocalToDevice is the device CTM, not the global CTM.
560 // It maps from local space to the device's coordinate space.
561 // fDeviceToGlobal * fLocalToDevice will match the canvas' CTM.
562 //
563 // setGlobalCTM and setLocalToDevice are intentionally not virtual for performance reasons.
564 // However, track a dirty bit for subclasses that want to defer local-to-device dependent
565 // calculations until needed for a clip or draw.
566 bool fLocalToDeviceDirty = true;
567};
568
570public:
571 SkNoPixelsDevice(const SkIRect& bounds, const SkSurfaceProps& props);
572 SkNoPixelsDevice(const SkIRect& bounds, const SkSurfaceProps& props,
573 sk_sp<SkColorSpace> colorSpace);
574
575 // Returns false if the device could not be reset; this should only be called on a root device.
577
578 // SkNoPixelsDevice tracks the clip conservatively in order to respond to some queries as
579 // accurately as possible while emphasizing performance
580 void pushClipStack() override;
581 void popClipStack() override;
582 void clipRect(const SkRect& rect, SkClipOp op, bool aa) override;
583 void clipRRect(const SkRRect& rrect, SkClipOp op, bool aa) override;
584 void clipPath(const SkPath& path, SkClipOp op, bool aa) override;
585 void clipRegion(const SkRegion& globalRgn, SkClipOp op) override;
586 void replaceClip(const SkIRect& rect) override;
587 bool isClipAntiAliased() const override { return this->clip().fIsAA; }
588 bool isClipEmpty() const override { return this->devClipBounds().isEmpty(); }
589 bool isClipRect() const override { return this->clip().fIsRect && !this->isClipEmpty(); }
590 bool isClipWideOpen() const override {
591 return this->clip().fIsRect &&
592 this->devClipBounds() == this->bounds();
593 }
594 void android_utils_clipAsRgn(SkRegion* rgn) const override {
595 rgn->setRect(this->devClipBounds());
596 }
597 SkIRect devClipBounds() const override { return this->clip().fClipBounds; }
598
599protected:
600
601 void drawPaint(const SkPaint& paint) override {}
602 void drawPoints(SkCanvas::PointMode, size_t, const SkPoint[], const SkPaint&) override {}
603 void drawImageRect(const SkImage*, const SkRect*, const SkRect&,
604 const SkSamplingOptions&, const SkPaint&,
605 SkCanvas::SrcRectConstraint) override {}
606 void drawRect(const SkRect&, const SkPaint&) override {}
607 void drawOval(const SkRect&, const SkPaint&) override {}
608 void drawRRect(const SkRRect&, const SkPaint&) override {}
609 void drawPath(const SkPath&, const SkPaint&, bool) override {}
610 void drawDevice(SkDevice*, const SkSamplingOptions&, const SkPaint&) override {}
611 void drawVertices(const SkVertices*, sk_sp<SkBlender>, const SkPaint&, bool) override {}
612 void drawMesh(const SkMesh&, sk_sp<SkBlender>, const SkPaint&) override {}
613
614 void drawSlug(SkCanvas*, const sktext::gpu::Slug*, const SkPaint&) override {}
615 void onDrawGlyphRunList(SkCanvas*, const sktext::GlyphRunList&, const SkPaint&) override {}
616
617 bool isNoPixelsDevice() const override { return true; }
618
619private:
620 struct ClipState {
621 SkIRect fClipBounds;
622 int fDeferredSaveCount;
623 bool fIsAA;
624 bool fIsRect;
625
626 ClipState(const SkIRect& bounds, bool isAA, bool isRect)
627 : fClipBounds(bounds)
628 , fDeferredSaveCount(0)
629 , fIsAA(isAA)
630 , fIsRect(isRect) {}
631
632 void op(SkClipOp op, const SkM44& transform, const SkRect& bounds,
633 bool isAA, bool fillsBounds);
634 };
635
636 void onClipShader(sk_sp<SkShader> shader) override;
637
638 const ClipState& clip() const { return fClipStack.back(); }
639 ClipState& writableClip();
640
642};
643
645public:
647 : fDevice(device)
648 , fPrevLocalToDevice(device->localToDevice())
649 {
650 fDevice->setLocalToDevice(SkM44(localToDevice));
651 }
653 fDevice->setLocalToDevice(fPrevLocalToDevice);
654 }
655
656private:
657 SkDevice* fDevice;
658 const SkM44 fPrevLocalToDevice;
659};
660
661#endif
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
int count
Definition: FontMgrTest.cpp:50
#define SkASSERT(cond)
Definition: SkAssert.h:116
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)
static SkPath clip(const SkPath &path, const SkHalfPlane &plane)
Definition: SkPath.cpp:3892
SkFilterMode
SkScalerContextFlags
SkShaderBase * as_SB(SkShader *shader)
Definition: SkShaderBase.h:412
SkPixelGeometry
SkAutoDeviceTransformRestore(SkDevice *device, const SkMatrix &localToDevice)
Definition: SkDevice.h:646
SrcRectConstraint
Definition: SkCanvas.h:1541
@ kStrict_SrcRectConstraint
sample only inside bounds; slower
Definition: SkCanvas.h:1542
Definition: SkData.h:25
void drawFilteredImage(const skif::Mapping &mapping, SkSpecialImage *src, SkColorType ct, const SkImageFilter *, const SkSamplingOptions &, const SkPaint &)
Definition: SkDevice.cpp:347
const SkImageInfo & imageInfo() const
Definition: SkDevice.h:117
bool writePixels(const SkPixmap &src, int x, int y)
Definition: SkDevice.h:147
virtual sk_sp< SkDevice > createDevice(const CreateInfo &, const SkPaint *)
Definition: SkDevice.h:322
virtual void drawVertices(const SkVertices *, sk_sp< SkBlender >, const SkPaint &, bool skipColorXform=false)=0
virtual void drawRRect(const SkRRect &rr, const SkPaint &paint)=0
virtual void drawEdgeAAQuad(const SkRect &rect, const SkPoint clip[4], SkCanvas::QuadAAFlags aaFlags, const SkColor4f &color, SkBlendMode mode)
Definition: SkDevice.cpp:236
SkScalerContextFlags scalerContextFlags() const
Definition: SkDevice.cpp:498
virtual void drawPoints(SkCanvas::PointMode mode, size_t count, const SkPoint[], const SkPaint &paint)=0
virtual void drawRegion(const SkRegion &r, const SkPaint &paint)
Definition: SkDevice.cpp:113
int height() const
Definition: SkDevice.h:120
SkIPoint getOrigin() const
Definition: SkDevice.cpp:91
SkDevice(const SkImageInfo &, const SkSurfaceProps &)
Definition: SkDevice.cpp:45
virtual void drawAtlas(const SkRSXform[], const SkRect[], const SkColor[], int count, sk_sp< SkBlender >, const SkPaint &)
Definition: SkDevice.cpp:203
virtual void clipPath(const SkPath &path, SkClipOp op, bool aa)=0
SkISize size() const
Definition: SkDevice.h:126
virtual bool onReadPixels(const SkPixmap &, int x, int y)
Definition: SkDevice.h:528
bool readPixels(const SkPixmap &dst, int x, int y)
Definition: SkDevice.h:153
void setLocalToDevice(const SkM44 &localToDevice)
Definition: SkDevice.h:211
virtual SkStrikeDeviceInfo strikeDeviceInfo() const
Definition: SkDevice.h:137
bool isOpaque() const
Definition: SkDevice.h:122
virtual bool isClipEmpty() const =0
void clipShader(sk_sp< SkShader > sh, SkClipOp op)
Definition: SkDevice.h:251
virtual bool onAccessPixels(SkPixmap *)
Definition: SkDevice.h:533
virtual void drawShadow(const SkPath &, const SkDrawShadowRec &)
virtual bool isClipRect() const =0
virtual void clipRegion(const SkRegion &region, SkClipOp op)=0
virtual void drawCoverageMask(const SkSpecialImage *, const SkMatrix &maskToDevice, const SkSamplingOptions &, const SkPaint &)
Definition: SkDevice.cpp:306
virtual skgpu::ganesh::Device * asGaneshDevice()
Definition: SkDevice.h:287
virtual bool drawBlurredRRect(const SkRRect &, const SkPaint &, float deviceSigma)
Definition: SkDevice.h:469
virtual sk_sp< skif::Backend > createImageFilteringBackend(const SkSurfaceProps &surfaceProps, SkColorType colorType) const
Definition: SkDevice.cpp:324
void drawGlyphRunList(SkCanvas *, const sktext::GlyphRunList &glyphRunList, const SkPaint &paint)
Definition: SkDevice.cpp:426
virtual void drawEdgeAAImageSet(const SkCanvas::ImageSetEntry[], int count, const SkPoint dstClips[], const SkMatrix preViewMatrices[], const SkSamplingOptions &, const SkPaint &, SkCanvas::SrcRectConstraint)
Definition: SkDevice.cpp:253
virtual bool isClipWideOpen() const =0
const SkM44 & globalToDevice() const
Definition: SkDevice.h:191
virtual void drawDRRect(const SkRRect &outer, const SkRRect &inner, const SkPaint &)
Definition: SkDevice.cpp:141
virtual skgpu::graphite::Device * asGraphiteDevice()
Definition: SkDevice.h:288
virtual void * getRasterHandle() const
Definition: SkDevice.h:282
sk_sp< SkSpecialImage > snapSpecial()
Definition: SkDevice.cpp:320
virtual bool onWritePixels(const SkPixmap &, int x, int y)
Definition: SkDevice.h:531
virtual void setImmutable()
Definition: SkDevice.h:293
virtual void popClipStack()=0
virtual sk_sp< SkSpecialImage > snapSpecialScaled(const SkIRect &subset, const SkISize &dstDims)
Definition: SkDevice.cpp:316
virtual void pushClipStack()=0
bool accessPixels(SkPixmap *pmap)
Definition: SkDevice.cpp:383
const SkMatrix & localToDevice() const
Definition: SkDevice.h:179
virtual void drawSlug(SkCanvas *, const sktext::gpu::Slug *slug, const SkPaint &paint)
Definition: SkDevice.cpp:488
void setOrigin(const SkM44 &globalCTM, int x, int y)
Definition: SkDevice.h:508
virtual GrRecordingContext * recordingContext() const
Definition: SkDevice.h:284
virtual void android_utils_clipAsRgn(SkRegion *) const =0
virtual void drawSpecial(SkSpecialImage *, const SkMatrix &localToDevice, const SkSamplingOptions &, const SkPaint &, SkCanvas::SrcRectConstraint constraint=SkCanvas::kStrict_SrcRectConstraint)
Definition: SkDevice.cpp:304
bool isPixelAlignedToGlobal() const
Definition: SkDevice.cpp:82
virtual void drawDevice(SkDevice *, const SkSamplingOptions &, const SkPaint &)
Definition: SkDevice.cpp:329
virtual void clipRRect(const SkRRect &rrect, SkClipOp op, bool aa)=0
virtual SkIRect devClipBounds() const =0
const SkSurfaceProps & surfaceProps() const
Definition: SkDevice.h:131
virtual void clipRect(const SkRect &rect, SkClipOp op, bool aa)=0
virtual bool onPeekPixels(SkPixmap *)
Definition: SkDevice.h:535
virtual bool android_utils_clipWithStencil()
Definition: SkDevice.h:267
virtual sk_sp< SkSpecialImage > makeSpecial(const SkBitmap &)
Definition: SkDevice.cpp:313
const SkM44 & deviceToGlobal() const
Definition: SkDevice.h:186
virtual void drawDrawable(SkCanvas *, SkDrawable *, const SkMatrix *)
Definition: SkDevice.cpp:298
virtual void onDrawGlyphRunList(SkCanvas *, const sktext::GlyphRunList &, const SkPaint &paint)=0
virtual skgpu::graphite::Recorder * recorder() const
Definition: SkDevice.h:285
void setDeviceCoordinateSystem(const SkM44 &deviceToGlobal, const SkM44 &globalToDevice, const SkM44 &localToDevice, int bufferOriginX, int bufferOriginY)
Definition: SkDevice.cpp:52
void setGlobalCTM(const SkM44 &ctm)
Definition: SkDevice.cpp:73
virtual sk_sp< sktext::gpu::Slug > convertGlyphRunListToSlug(const sktext::GlyphRunList &glyphRunList, const SkPaint &paint)
Definition: SkDevice.cpp:483
bool peekPixels(SkPixmap *)
Definition: SkDevice.cpp:391
virtual sk_sp< SkSurface > makeSurface(const SkImageInfo &, const SkSurfaceProps &)
Definition: SkDevice.cpp:494
virtual void drawPaint(const SkPaint &paint)=0
virtual void drawMesh(const SkMesh &mesh, sk_sp< SkBlender >, const SkPaint &)=0
virtual bool isClipAntiAliased() const =0
virtual bool useDrawCoverageMaskForMaskFilters() const
Definition: SkDevice.h:276
int width() const
Definition: SkDevice.h:119
virtual void drawPatch(const SkPoint cubics[12], const SkColor colors[4], const SkPoint texCoords[4], sk_sp< SkBlender >, const SkPaint &paint)
Definition: SkDevice.cpp:152
bool checkLocalToDeviceDirty()
Definition: SkDevice.h:513
virtual void drawRect(const SkRect &r, const SkPaint &paint)=0
virtual void drawImageRect(const SkImage *, const SkRect *src, const SkRect &dst, const SkSamplingOptions &, const SkPaint &, SkCanvas::SrcRectConstraint)=0
const SkM44 & localToDevice44() const
Definition: SkDevice.h:178
SkIRect bounds() const
Definition: SkDevice.h:125
virtual bool drawAsTiledImageRect(SkCanvas *, const SkImage *, const SkRect *src, const SkRect &dst, const SkSamplingOptions &, const SkPaint &, SkCanvas::SrcRectConstraint)
Definition: SkDevice.h:369
virtual void drawArc(const SkArc &arc, const SkPaint &paint)
Definition: SkDevice.cpp:134
virtual void drawAnnotation(const SkRect &, const char[], SkData *)
Definition: SkDevice.h:399
void getGlobalBounds(SkIRect *bounds) const
Definition: SkDevice.h:225
virtual void drawPath(const SkPath &path, const SkPaint &paint, bool pathIsMutable=false)=0
virtual void onClipShader(sk_sp< SkShader >)=0
SkMatrix getRelativeTransform(const SkDevice &) const
Definition: SkDevice.cpp:103
virtual bool shouldDrawAsTiledImageRect() const
Definition: SkDevice.h:368
virtual void drawOval(const SkRect &oval, const SkPaint &paint)=0
SkIRect getGlobalBounds() const
Definition: SkDevice.h:230
virtual bool isNoPixelsDevice() const
Definition: SkDevice.h:280
virtual void replaceClip(const SkIRect &rect)=0
virtual void drawImageLattice(const SkImage *, const SkCanvas::Lattice &, const SkRect &dst, SkFilterMode, const SkPaint &)
Definition: SkDevice.cpp:163
Definition: SkM44.h:150
SkMatrix asM33() const
Definition: SkM44.h:409
static SkRect MapRect(const SkM44 &m, const SkRect &r)
Definition: SkM44.cpp:216
Definition: SkMesh.h:263
void android_utils_clipAsRgn(SkRegion *rgn) const override
Definition: SkDevice.h:594
void drawRRect(const SkRRect &, const SkPaint &) override
Definition: SkDevice.h:608
void clipRegion(const SkRegion &globalRgn, SkClipOp op) override
Definition: SkDevice.cpp:595
void clipRect(const SkRect &rect, SkClipOp op, bool aa) override
Definition: SkDevice.cpp:576
bool isClipWideOpen() const override
Definition: SkDevice.h:590
bool resetForNextPicture(const SkIRect &bounds)
Definition: SkDevice.cpp:526
void drawPath(const SkPath &, const SkPaint &, bool) override
Definition: SkDevice.h:609
SkIRect devClipBounds() const override
Definition: SkDevice.h:597
void drawOval(const SkRect &, const SkPaint &) override
Definition: SkDevice.h:607
void drawVertices(const SkVertices *, sk_sp< SkBlender >, const SkPaint &, bool) override
Definition: SkDevice.h:611
void popClipStack() override
Definition: SkDevice.cpp:551
bool isNoPixelsDevice() const override
Definition: SkDevice.h:617
bool isClipAntiAliased() const override
Definition: SkDevice.h:587
void replaceClip(const SkIRect &rect) override
Definition: SkDevice.cpp:604
void drawImageRect(const SkImage *, const SkRect *, const SkRect &, const SkSamplingOptions &, const SkPaint &, SkCanvas::SrcRectConstraint) override
Definition: SkDevice.h:603
void clipPath(const SkPath &path, SkClipOp op, bool aa) override
Definition: SkDevice.cpp:586
void drawDevice(SkDevice *, const SkSamplingOptions &, const SkPaint &) override
Definition: SkDevice.h:610
void drawPaint(const SkPaint &paint) override
Definition: SkDevice.h:601
bool isClipEmpty() const override
Definition: SkDevice.h:588
void onDrawGlyphRunList(SkCanvas *, const sktext::GlyphRunList &, const SkPaint &) override
Definition: SkDevice.h:615
void pushClipStack() override
Definition: SkDevice.cpp:546
void drawSlug(SkCanvas *, const sktext::gpu::Slug *, const SkPaint &) override
Definition: SkDevice.h:614
void drawMesh(const SkMesh &, sk_sp< SkBlender >, const SkPaint &) override
Definition: SkDevice.h:612
bool isClipRect() const override
Definition: SkDevice.h:589
void drawPoints(SkCanvas::PointMode, size_t, const SkPoint[], const SkPaint &) override
Definition: SkDevice.h:602
SkNoPixelsDevice(const SkIRect &bounds, const SkSurfaceProps &props)
Definition: SkDevice.cpp:512
void clipRRect(const SkRRect &rrect, SkClipOp op, bool aa) override
Definition: SkDevice.cpp:581
void drawRect(const SkRect &, const SkPaint &) override
Definition: SkDevice.h:606
Definition: SkPath.h:59
bool setRect(const SkIRect &rect)
Definition: SkRegion.cpp:192
sk_sp< SkShader > makeInvertAlpha() const
sk_sp< SkShader > makeWithCTM(const SkMatrix &) const
const Paint & paint
Definition: color_source.cc:38
DlColor color
VkDevice device
Definition: main.cc:53
double y
double x
PODArray< SkPoint > dstClips
Definition: SkRecords.h:364
ClipOpAndAA opAA SkRegion region
Definition: SkRecords.h:238
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
SkMesh mesh
Definition: SkRecords.h:345
PODArray< SkColor > colors
Definition: SkRecords.h:276
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
sh
Definition: run_sh.py:10
Definition: SkDevice.h:63
static SkColor4f transform(SkColor4f c, SkColorSpace *src, SkColorSpace *dst)
Definition: p3.cpp:47
Definition: SkArc.h:15
const SkPixelGeometry fPixelGeometry
Definition: SkDevice.h:307
SkRasterHandleAllocator * fAllocator
Definition: SkDevice.h:308
const SkImageInfo fInfo
Definition: SkDevice.h:306
CreateInfo(const SkImageInfo &info, SkPixelGeometry geo, SkRasterHandleAllocator *allocator)
Definition: SkDevice.h:298
Definition: SkRect.h:32
static constexpr SkIRect MakeWH(int32_t w, int32_t h)
Definition: SkRect.h:56
bool isEmpty() const
Definition: SkRect.h:202
Definition: SkSize.h:16
bool isOpaque() const
Definition: SkImageInfo.h:415
SkISize dimensions() const
Definition: SkImageInfo.h:421
int width() const
Definition: SkImageInfo.h:365
int height() const
Definition: SkImageInfo.h:371
static SkRect Make(const SkISize &size)
Definition: SkRect.h:669
void roundOut(SkIRect *dst) const
Definition: SkRect.h:1241
const SkSurfaceProps fSurfaceProps
Definition: SkDevice.h:80
const SkScalerContextFlags fScalerContextFlags
Definition: SkDevice.h:81
const sktext::gpu::SDFTControl *const fSDFTControl
Definition: SkDevice.h:83