Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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"
25#include "include/core/SkSize.h"
32
33#include <cstddef>
34#include <cstdint>
35#include <utility>
36
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) {
254 sh = as_SB(sh)->makeInvertAlpha();
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;
336 virtual void drawPoints(SkCanvas::PointMode mode, size_t count,
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 SkRect& oval, SkScalar startAngle,
346 SkScalar sweepAngle, bool useCenter, const SkPaint& paint);
347 virtual void drawRRect(const SkRRect& rr,
348 const SkPaint& paint) = 0;
349
350 // Default impl calls drawPath()
351 virtual void drawDRRect(const SkRRect& outer,
352 const SkRRect& inner, const SkPaint&);
353
354 /**
355 * If pathIsMutable, then the implementation is allowed to cast path to a
356 * non-const pointer and modify it in place (as an optimization). Canvas
357 * may do this to implement helpers such as drawOval, by placing a temp
358 * path on the stack to hold the representation of the oval.
359 */
360 virtual void drawPath(const SkPath& path,
361 const SkPaint& paint,
362 bool pathIsMutable = false) = 0;
363
364 virtual void drawImageRect(const SkImage*, const SkRect* src, const SkRect& dst,
365 const SkSamplingOptions&, const SkPaint&,
367 // Return true if canvas calls to drawImage or drawImageRect should try to
368 // be drawn in a tiled way.
369 virtual bool shouldDrawAsTiledImageRect() const { return false; }
371 const SkImage*,
372 const SkRect* src,
373 const SkRect& dst,
374 const SkSamplingOptions&,
375 const SkPaint&,
376 SkCanvas::SrcRectConstraint) { return false; }
377
378 virtual void drawImageLattice(const SkImage*, const SkCanvas::Lattice&,
379 const SkRect& dst, SkFilterMode, const SkPaint&);
380
381 /**
382 * If skipColorXform is true, then the implementation should assume that the provided
383 * vertex colors are already in the destination color space.
384 */
385 virtual void drawVertices(const SkVertices*,
387 const SkPaint&,
388 bool skipColorXform = false) = 0;
389 virtual void drawMesh(const SkMesh& mesh, sk_sp<SkBlender>, const SkPaint&) = 0;
390 virtual void drawShadow(const SkPath&, const SkDrawShadowRec&);
391
392 // default implementation calls drawVertices
393 virtual void drawPatch(const SkPoint cubics[12], const SkColor colors[4],
394 const SkPoint texCoords[4], sk_sp<SkBlender>, const SkPaint& paint);
395
396 // default implementation calls drawVertices
397 virtual void drawAtlas(const SkRSXform[], const SkRect[], const SkColor[], int count,
398 sk_sp<SkBlender>, const SkPaint&);
399
400 virtual void drawAnnotation(const SkRect&, const char[], SkData*) {}
401
402 // Default impl always calls drawRect() with a solid-color paint, setting it to anti-aliased
403 // only when all edge flags are set. If there's a clip region, it draws that using drawPath,
404 // or uses clipPath().
405 virtual void drawEdgeAAQuad(const SkRect& rect, const SkPoint clip[4],
406 SkCanvas::QuadAAFlags aaFlags, const SkColor4f& color,
407 SkBlendMode mode);
408 // Default impl uses drawImageRect per entry, being anti-aliased only when an entry's edge flags
409 // are all set. If there's a clip region, it will be applied using clipPath().
410 virtual void drawEdgeAAImageSet(const SkCanvas::ImageSetEntry[], int count,
411 const SkPoint dstClips[], const SkMatrix preViewMatrices[],
412 const SkSamplingOptions&, const SkPaint&,
414
415 virtual void drawDrawable(SkCanvas*, SkDrawable*, const SkMatrix*);
416
417 // -- "Special" drawing and image routines
418
419 // Snap the 'subset' contents from this device, possibly as a read-only view. If 'forceCopy'
420 // is true then the returned image's pixels must not be affected by subsequent draws into the
421 // device. When 'forceCopy' is false, the image can be a view into the device's pixels
422 // (avoiding a copy for performance, at the expense of safety). Default returns null.
423 virtual sk_sp<SkSpecialImage> snapSpecial(const SkIRect& subset, bool forceCopy = false);
424 // Can return null if unable to perform scaling as part of the copy, even if snapSpecial() w/o
425 // scaling would succeed.
426 virtual sk_sp<SkSpecialImage> snapSpecialScaled(const SkIRect& subset, const SkISize& dstDims);
427 // Get a view of the entire device's current contents as an image.
429
430 /**
431 * The SkDevice passed will be an SkDevice which was returned by a call to
432 * onCreateDevice on this device with kNeverTile_TileExpectation.
433 *
434 * The default implementation calls snapSpecial() and drawSpecial() with the relative transform
435 * from the input device to this device. The provided SkPaint cannot have a mask filter or
436 * image filter, and any shader is ignored.
437 */
438 virtual void drawDevice(SkDevice*, const SkSamplingOptions&, const SkPaint&);
439
440 /**
441 * Draw the special image's subset to this device, subject to the given matrix transform instead
442 * of the device's current local to device matrix.
443 *
444 * If 'constraint' is kFast, the rendered geometry of the image still reflects the extent of
445 * the SkSpecialImage's subset, but it's assumed that the pixel data beyond the subset is valid
446 * (e.g. SkSpecialImage::makeSubset() was called to crop a larger image).
447 */
448 virtual void drawSpecial(SkSpecialImage*, const SkMatrix& localToDevice,
449 const SkSamplingOptions&, const SkPaint&,
450 SkCanvas::SrcRectConstraint constraint =
452
453 /**
454 * Draw the special image's subset to this device, treating its alpha channel as coverage for
455 * the draw and ignoring any RGB channels that might be present. This will be drawn using the
456 * provided matrix transform instead of the device's current local to device matrix.
457 *
458 * Coverage values beyond the image's subset are treated as 0 (i.e. kDecal tiling). Color values
459 * before coverage are determined as normal by the SkPaint, ignoring style, path effects,
460 * mask filters and image filters. The local coords of any SkShader on the paint should be
461 * relative to the SkDevice's current matrix (i.e. 'maskToDevice' determines how the coverage
462 * mask aligns with device-space, but otherwise shading proceeds like other draws).
463 */
464 virtual void drawCoverageMask(const SkSpecialImage*, const SkMatrix& maskToDevice,
465 const SkSamplingOptions&, const SkPaint&);
466
467 /**
468 * Draw rrect with an optimized path for analytic blurs, if provided by the device.
469 */
470 virtual bool drawBlurredRRect(const SkRRect&, const SkPaint&, float deviceSigma) {
471 return false;
472 }
473
474 /**
475 * Evaluate 'filter' and draw the final output into this device using 'paint'. The 'mapping'
476 * defines the parameter-to-layer space transform used to evaluate the image filter on 'src',
477 * and the layer-to-device space transform that is used to draw the result into this device.
478 * Since 'mapping' fully specifies the transform, this draw function ignores the current
479 * local-to-device matrix (i.e. just like drawSpecial and drawDevice).
480 *
481 * The final paint must not have an image filter or mask filter set on it; a shader is ignored.
482 * The provided color type will be used for any intermediate surfaces that need to be created as
483 * part of filter evaluation. It does not have to be src's color type or this Device's type.
484 */
485 void drawFilteredImage(const skif::Mapping& mapping, SkSpecialImage* src, SkColorType ct,
486 const SkImageFilter*, const SkSamplingOptions&, const SkPaint&);
487
488protected:
489 // DEPRECATED: Can be deleted once SkCanvas::onDrawImage() uses skif::FilterResult so don't
490 // bother re-arranging.
493
494 // Configure the device's coordinate spaces, specifying both how its device image maps back to
495 // the global space (via 'deviceToGlobal') and the initial CTM of the device (via
496 // 'localToDevice', i.e. what geometry drawn into this device will be transformed with).
497 //
498 // (bufferOriginX, bufferOriginY) defines where the (0,0) pixel the device's backing buffer
499 // is anchored in the device space. The final device-to-global matrix stored by the SkDevice
500 // will include a pre-translation by T(deviceOriginX, deviceOriginY), and the final
501 // local-to-device matrix will have a post-translation of T(-deviceOriginX, -deviceOriginY).
503 const SkM44& globalToDevice,
504 const SkM44& localToDevice,
505 int bufferOriginX,
506 int bufferOriginY);
507 // Convenience to configure the device to be axis-aligned with the root canvas, but with a
508 // unique origin.
509 void setOrigin(const SkM44& globalCTM, int x, int y) {
510 this->setDeviceCoordinateSystem(SkM44(), SkM44(), globalCTM, x, y);
511 }
512
513 // Returns whether or not localToDevice() has changed since the last call to this function.
515 bool wasDirty = fLocalToDeviceDirty;
516 fLocalToDeviceDirty = false;
517 return wasDirty;
518 }
519
520private:
521 friend class SkCanvas; // for setOrigin/setDeviceCoordinateSystem
523
524 // Defaults to a CPU image filtering backend.
526 SkColorType colorType) const;
527
528 // Implementations can assume that the device from (x,y) to (w,h) will fit within dst.
529 virtual bool onReadPixels(const SkPixmap&, int x, int y) { return false; }
530
531 // Implementations can assume that the src image placed at 'x,y' will fit within the device.
532 virtual bool onWritePixels(const SkPixmap&, int x, int y) { return false; }
533
534 virtual bool onAccessPixels(SkPixmap*) { return false; }
535
536 virtual bool onPeekPixels(SkPixmap*) { return false; }
537
538 virtual void onClipShader(sk_sp<SkShader>) = 0;
539
540 // Only called with glyphRunLists that do not contain RSXForm.
543 const SkPaint& paint) = 0;
544
545 void simplifyGlyphRunRSXFormAndRedraw(SkCanvas*,
547 const SkPaint& paint);
548
549 const SkImageInfo fInfo;
550 const SkSurfaceProps fSurfaceProps;
551 SkM44 fLocalToDevice;
552 // fDeviceToGlobal and fGlobalToDevice are inverses of each other; there are never that many
553 // SkDevices, so pay the memory cost to avoid recalculating the inverse.
554 SkM44 fDeviceToGlobal;
555 SkM44 fGlobalToDevice;
556
557 // fLocalToDevice but as a 3x3.
558 SkMatrix fLocalToDevice33;
559
560 // fLocalToDevice is the device CTM, not the global CTM.
561 // It maps from local space to the device's coordinate space.
562 // fDeviceToGlobal * fLocalToDevice will match the canvas' CTM.
563 //
564 // setGlobalCTM and setLocalToDevice are intentionally not virtual for performance reasons.
565 // However, track a dirty bit for subclasses that want to defer local-to-device dependent
566 // calculations until needed for a clip or draw.
567 bool fLocalToDeviceDirty = true;
568};
569
571public:
572 SkNoPixelsDevice(const SkIRect& bounds, const SkSurfaceProps& props);
573 SkNoPixelsDevice(const SkIRect& bounds, const SkSurfaceProps& props,
574 sk_sp<SkColorSpace> colorSpace);
575
576 // Returns false if the device could not be reset; this should only be called on a root device.
578
579 // SkNoPixelsDevice tracks the clip conservatively in order to respond to some queries as
580 // accurately as possible while emphasizing performance
581 void pushClipStack() override;
582 void popClipStack() override;
583 void clipRect(const SkRect& rect, SkClipOp op, bool aa) override;
584 void clipRRect(const SkRRect& rrect, SkClipOp op, bool aa) override;
585 void clipPath(const SkPath& path, SkClipOp op, bool aa) override;
586 void clipRegion(const SkRegion& globalRgn, SkClipOp op) override;
587 void replaceClip(const SkIRect& rect) override;
588 bool isClipAntiAliased() const override { return this->clip().fIsAA; }
589 bool isClipEmpty() const override { return this->devClipBounds().isEmpty(); }
590 bool isClipRect() const override { return this->clip().fIsRect && !this->isClipEmpty(); }
591 bool isClipWideOpen() const override {
592 return this->clip().fIsRect &&
593 this->devClipBounds() == this->bounds();
594 }
595 void android_utils_clipAsRgn(SkRegion* rgn) const override {
596 rgn->setRect(this->devClipBounds());
597 }
598 SkIRect devClipBounds() const override { return this->clip().fClipBounds; }
599
600protected:
601
602 void drawPaint(const SkPaint& paint) override {}
603 void drawPoints(SkCanvas::PointMode, size_t, const SkPoint[], const SkPaint&) override {}
604 void drawImageRect(const SkImage*, const SkRect*, const SkRect&,
605 const SkSamplingOptions&, const SkPaint&,
606 SkCanvas::SrcRectConstraint) override {}
607 void drawRect(const SkRect&, const SkPaint&) override {}
608 void drawOval(const SkRect&, const SkPaint&) override {}
609 void drawRRect(const SkRRect&, const SkPaint&) override {}
610 void drawPath(const SkPath&, const SkPaint&, bool) override {}
611 void drawDevice(SkDevice*, const SkSamplingOptions&, const SkPaint&) override {}
612 void drawVertices(const SkVertices*, sk_sp<SkBlender>, const SkPaint&, bool) override {}
613 void drawMesh(const SkMesh&, sk_sp<SkBlender>, const SkPaint&) override {}
614
615 void drawSlug(SkCanvas*, const sktext::gpu::Slug*, const SkPaint&) override {}
616 void onDrawGlyphRunList(SkCanvas*, const sktext::GlyphRunList&, const SkPaint&) override {}
617
618 bool isNoPixelsDevice() const override { return true; }
619
620private:
621 struct ClipState {
622 SkIRect fClipBounds;
623 int fDeferredSaveCount;
624 bool fIsAA;
625 bool fIsRect;
626
627 ClipState(const SkIRect& bounds, bool isAA, bool isRect)
628 : fClipBounds(bounds)
629 , fDeferredSaveCount(0)
630 , fIsAA(isAA)
631 , fIsRect(isRect) {}
632
633 void op(SkClipOp op, const SkM44& transform, const SkRect& bounds,
634 bool isAA, bool fillsBounds);
635 };
636
637 void onClipShader(sk_sp<SkShader> shader) override;
638
639 const ClipState& clip() const { return fClipStack.back(); }
640 ClipState& writableClip();
641
643};
644
646public:
648 : fDevice(device)
649 , fPrevLocalToDevice(device->localToDevice())
650 {
651 fDevice->setLocalToDevice(SkM44(localToDevice));
652 }
654 fDevice->setLocalToDevice(fPrevLocalToDevice);
655 }
656
657private:
658 SkDevice* fDevice;
659 const SkM44 fPrevLocalToDevice;
660};
661
662#endif
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
int count
SkColor4f color
#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:3824
SkFilterMode
SkScalerContextFlags
SkShaderBase * as_SB(SkShader *shader)
SkPixelGeometry
Type::kYUV Type::kRGBA() int(0.7 *637)
SkAutoDeviceTransformRestore(SkDevice *device, const SkMatrix &localToDevice)
Definition SkDevice.h:647
SrcRectConstraint
Definition SkCanvas.h:1541
@ kStrict_SrcRectConstraint
sample only inside bounds; slower
Definition SkCanvas.h:1542
void drawFilteredImage(const skif::Mapping &mapping, SkSpecialImage *src, SkColorType ct, const SkImageFilter *, const SkSamplingOptions &, const SkPaint &)
Definition SkDevice.cpp:352
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:237
SkScalerContextFlags scalerContextFlags() const
Definition SkDevice.cpp:503
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:112
int height() const
Definition SkDevice.h:120
SkIPoint getOrigin() const
Definition SkDevice.cpp:90
virtual void drawAtlas(const SkRSXform[], const SkRect[], const SkColor[], int count, sk_sp< SkBlender >, const SkPaint &)
Definition SkDevice.cpp:204
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:529
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:534
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:307
virtual skgpu::ganesh::Device * asGaneshDevice()
Definition SkDevice.h:287
virtual bool drawBlurredRRect(const SkRRect &, const SkPaint &, float deviceSigma)
Definition SkDevice.h:470
virtual sk_sp< skif::Backend > createImageFilteringBackend(const SkSurfaceProps &surfaceProps, SkColorType colorType) const
Definition SkDevice.cpp:325
void drawGlyphRunList(SkCanvas *, const sktext::GlyphRunList &glyphRunList, const SkPaint &paint)
Definition SkDevice.cpp:431
virtual void drawEdgeAAImageSet(const SkCanvas::ImageSetEntry[], int count, const SkPoint dstClips[], const SkMatrix preViewMatrices[], const SkSamplingOptions &, const SkPaint &, SkCanvas::SrcRectConstraint)
Definition SkDevice.cpp:254
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:142
virtual skgpu::graphite::Device * asGraphiteDevice()
Definition SkDevice.h:288
virtual void * getRasterHandle() const
Definition SkDevice.h:282
sk_sp< SkSpecialImage > snapSpecial()
Definition SkDevice.cpp:321
virtual bool onWritePixels(const SkPixmap &, int x, int y)
Definition SkDevice.h:532
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:317
virtual void pushClipStack()=0
bool accessPixels(SkPixmap *pmap)
Definition SkDevice.cpp:388
const SkMatrix & localToDevice() const
Definition SkDevice.h:179
virtual void drawSlug(SkCanvas *, const sktext::gpu::Slug *slug, const SkPaint &paint)
Definition SkDevice.cpp:493
void setOrigin(const SkM44 &globalCTM, int x, int y)
Definition SkDevice.h:509
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:305
bool isPixelAlignedToGlobal() const
Definition SkDevice.cpp:81
virtual void drawDevice(SkDevice *, const SkSamplingOptions &, const SkPaint &)
Definition SkDevice.cpp:330
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:536
virtual bool android_utils_clipWithStencil()
Definition SkDevice.h:267
virtual sk_sp< SkSpecialImage > makeSpecial(const SkBitmap &)
Definition SkDevice.cpp:314
const SkM44 & deviceToGlobal() const
Definition SkDevice.h:186
virtual void drawDrawable(SkCanvas *, SkDrawable *, const SkMatrix *)
Definition SkDevice.cpp:299
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:51
void setGlobalCTM(const SkM44 &ctm)
Definition SkDevice.cpp:72
virtual sk_sp< sktext::gpu::Slug > convertGlyphRunListToSlug(const sktext::GlyphRunList &glyphRunList, const SkPaint &paint)
Definition SkDevice.cpp:488
bool peekPixels(SkPixmap *)
Definition SkDevice.cpp:396
virtual sk_sp< SkSurface > makeSurface(const SkImageInfo &, const SkSurfaceProps &)
Definition SkDevice.cpp:499
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:153
bool checkLocalToDeviceDirty()
Definition SkDevice.h:514
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:370
virtual void drawAnnotation(const SkRect &, const char[], SkData *)
Definition SkDevice.h:400
void getGlobalBounds(SkIRect *bounds) const
Definition SkDevice.h:225
virtual void drawPath(const SkPath &path, const SkPaint &paint, bool pathIsMutable=false)=0
virtual void drawArc(const SkRect &oval, SkScalar startAngle, SkScalar sweepAngle, bool useCenter, const SkPaint &paint)
Definition SkDevice.cpp:133
virtual void onClipShader(sk_sp< SkShader >)=0
SkMatrix getRelativeTransform(const SkDevice &) const
Definition SkDevice.cpp:102
virtual bool shouldDrawAsTiledImageRect() const
Definition SkDevice.h:369
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:164
Definition SkM44.h:150
SkMatrix asM33() const
Definition SkM44.h:409
static SkRect MapRect(const SkM44 &m, const SkRect &r)
Definition SkM44.cpp:216
void android_utils_clipAsRgn(SkRegion *rgn) const override
Definition SkDevice.h:595
void drawRRect(const SkRRect &, const SkPaint &) override
Definition SkDevice.h:609
void clipRegion(const SkRegion &globalRgn, SkClipOp op) override
Definition SkDevice.cpp:600
void clipRect(const SkRect &rect, SkClipOp op, bool aa) override
Definition SkDevice.cpp:581
bool isClipWideOpen() const override
Definition SkDevice.h:591
bool resetForNextPicture(const SkIRect &bounds)
Definition SkDevice.cpp:531
void drawPath(const SkPath &, const SkPaint &, bool) override
Definition SkDevice.h:610
SkIRect devClipBounds() const override
Definition SkDevice.h:598
void drawOval(const SkRect &, const SkPaint &) override
Definition SkDevice.h:608
void onClipShader(sk_sp< SkShader > shader) override
Definition SkDevice.cpp:605
void drawVertices(const SkVertices *, sk_sp< SkBlender >, const SkPaint &, bool) override
Definition SkDevice.h:612
void popClipStack() override
Definition SkDevice.cpp:556
bool isNoPixelsDevice() const override
Definition SkDevice.h:618
bool isClipAntiAliased() const override
Definition SkDevice.h:588
void replaceClip(const SkIRect &rect) override
Definition SkDevice.cpp:609
void drawImageRect(const SkImage *, const SkRect *, const SkRect &, const SkSamplingOptions &, const SkPaint &, SkCanvas::SrcRectConstraint) override
Definition SkDevice.h:604
void clipPath(const SkPath &path, SkClipOp op, bool aa) override
Definition SkDevice.cpp:591
void drawDevice(SkDevice *, const SkSamplingOptions &, const SkPaint &) override
Definition SkDevice.h:611
void drawPaint(const SkPaint &paint) override
Definition SkDevice.h:602
bool isClipEmpty() const override
Definition SkDevice.h:589
void onDrawGlyphRunList(SkCanvas *, const sktext::GlyphRunList &, const SkPaint &) override
Definition SkDevice.h:616
void pushClipStack() override
Definition SkDevice.cpp:551
void drawSlug(SkCanvas *, const sktext::gpu::Slug *, const SkPaint &) override
Definition SkDevice.h:615
void drawMesh(const SkMesh &, sk_sp< SkBlender >, const SkPaint &) override
Definition SkDevice.h:613
bool isClipRect() const override
Definition SkDevice.h:590
void drawPoints(SkCanvas::PointMode, size_t, const SkPoint[], const SkPaint &) override
Definition SkDevice.h:603
void clipRRect(const SkRRect &rrect, SkClipOp op, bool aa) override
Definition SkDevice.cpp:586
void drawRect(const SkRect &, const SkPaint &) override
Definition SkDevice.h:607
bool setRect(const SkIRect &rect)
Definition SkRegion.cpp:192
sk_sp< SkShader > makeInvertAlpha() const
sk_sp< SkShader > makeWithCTM(const SkMatrix &) const
const Paint & paint
VkDevice device
Definition main.cc:53
float SkScalar
Definition extension.cpp:12
double y
double x
static SkColor4f transform(SkColor4f c, SkColorSpace *src, SkColorSpace *dst)
Definition p3.cpp:47
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
static constexpr SkIRect MakeWH(int32_t w, int32_t h)
Definition SkRect.h:56
bool isEmpty() const
Definition SkRect.h:202
bool isOpaque() const
SkISize dimensions() const
int width() const
int height() const
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