Flutter Engine
The Flutter Engine
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Classes | Public Member Functions | Static Public Member Functions | Friends | List of all members
skgpu::graphite::Device Class Referencefinal

#include <Device.h>

Inheritance diagram for skgpu::graphite::Device:
SkDevice SkRefCnt SkRefCntBase

Classes

class  IntersectionTreeSet
 

Public Member Functions

 ~Device () override
 
DeviceasGraphiteDevice () override
 
Recorderrecorder () const override
 
void abandonRecorder ()
 
void flushPendingWorkToRecorder ()
 
const TransformlocalToDeviceTransform ()
 
void setImmutable () override
 
SkStrikeDeviceInfo strikeDeviceInfo () const override
 
TextureProxytarget ()
 
TextureProxyView readSurfaceView () const
 
sk_sp< ImagemakeImageCopy (const SkIRect &subset, Budgeted, Mipmapped, SkBackingFit)
 
bool isScratchDevice () const
 
sk_sp< TasklastDrawTask () const
 
bool useDrawCoverageMaskForMaskFilters () const override
 
void pushClipStack () override
 
void popClipStack () override
 
bool isClipWideOpen () const override
 
bool isClipEmpty () const override
 
bool isClipRect () const override
 
bool isClipAntiAliased () const override
 
SkIRect devClipBounds () const override
 
void android_utils_clipAsRgn (SkRegion *) const override
 
void clipRect (const SkRect &rect, SkClipOp, bool aa) override
 
void clipRRect (const SkRRect &rrect, SkClipOp, bool aa) override
 
void clipPath (const SkPath &path, SkClipOp, bool aa) override
 
void clipRegion (const SkRegion &globalRgn, SkClipOp) override
 
void replaceClip (const SkIRect &rect) override
 
void drawPaint (const SkPaint &paint) override
 
void drawRect (const SkRect &r, const SkPaint &paint) override
 
void drawOval (const SkRect &oval, const SkPaint &paint) override
 
void drawRRect (const SkRRect &rr, const SkPaint &paint) override
 
void drawPoints (SkCanvas::PointMode mode, size_t count, const SkPoint[], const SkPaint &paint) override
 
void drawPath (const SkPath &path, const SkPaint &paint, bool pathIsMutable=false) override
 
void drawEdgeAAQuad (const SkRect &rect, const SkPoint clip[4], SkCanvas::QuadAAFlags aaFlags, const SkColor4f &color, SkBlendMode mode) override
 
void drawEdgeAAImageSet (const SkCanvas::ImageSetEntry[], int count, const SkPoint dstClips[], const SkMatrix preViewMatrices[], const SkSamplingOptions &, const SkPaint &, SkCanvas::SrcRectConstraint) override
 
void drawImageRect (const SkImage *, const SkRect *src, const SkRect &dst, const SkSamplingOptions &, const SkPaint &, SkCanvas::SrcRectConstraint) override
 
void drawVertices (const SkVertices *, sk_sp< SkBlender >, const SkPaint &, bool) override
 
bool drawAsTiledImageRect (SkCanvas *, const SkImage *, const SkRect *src, const SkRect &dst, const SkSamplingOptions &, const SkPaint &, SkCanvas::SrcRectConstraint) override
 
void drawImageLattice (const SkImage *, const SkCanvas::Lattice &, const SkRect &dst, SkFilterMode, const SkPaint &) override
 
void drawAtlas (const SkRSXform[], const SkRect[], const SkColor[], int count, sk_sp< SkBlender >, const SkPaint &) override
 
void drawDrawable (SkCanvas *, SkDrawable *, const SkMatrix *) override
 
void drawMesh (const SkMesh &, sk_sp< SkBlender >, const SkPaint &) override
 
void drawShadow (const SkPath &, const SkDrawShadowRec &) override
 
sk_sp< SkSurfacemakeSurface (const SkImageInfo &, const SkSurfaceProps &) override
 
sk_sp< SkDevicecreateDevice (const CreateInfo &, const SkPaint *) override
 
sk_sp< SkSpecialImagesnapSpecial (const SkIRect &subset, bool forceCopy=false) override
 
void drawSpecial (SkSpecialImage *, const SkMatrix &localToDevice, const SkSamplingOptions &, const SkPaint &, SkCanvas::SrcRectConstraint) override
 
void drawCoverageMask (const SkSpecialImage *, const SkMatrix &localToDevice, const SkSamplingOptions &, const SkPaint &) override
 
bool drawBlurredRRect (const SkRRect &, const SkPaint &, float deviceSigma) override
 
- Public Member Functions inherited from SkDevice
 SkDevice (const SkImageInfo &, const SkSurfaceProps &)
 
const SkImageInfoimageInfo () const
 
int width () const
 
int height () const
 
bool isOpaque () const
 
SkIRect bounds () const
 
SkISize size () const
 
const SkSurfacePropssurfaceProps () const
 
SkScalerContextFlags scalerContextFlags () const
 
virtual SkStrikeDeviceInfo strikeDeviceInfo () const
 
bool writePixels (const SkPixmap &src, int x, int y)
 
bool readPixels (const SkPixmap &dst, int x, int y)
 
bool accessPixels (SkPixmap *pmap)
 
bool peekPixels (SkPixmap *)
 
const SkM44localToDevice44 () const
 
const SkMatrixlocalToDevice () const
 
const SkM44deviceToGlobal () const
 
const SkM44globalToDevice () const
 
SkIPoint getOrigin () const
 
bool isPixelAlignedToGlobal () const
 
SkMatrix getRelativeTransform (const SkDevice &) const
 
void setLocalToDevice (const SkM44 &localToDevice)
 
void setGlobalCTM (const SkM44 &ctm)
 
void getGlobalBounds (SkIRect *bounds) const
 
SkIRect getGlobalBounds () const
 
virtual SkIRect devClipBounds () const =0
 
virtual void pushClipStack ()=0
 
virtual void popClipStack ()=0
 
virtual void clipRect (const SkRect &rect, SkClipOp op, bool aa)=0
 
virtual void clipRRect (const SkRRect &rrect, SkClipOp op, bool aa)=0
 
virtual void clipPath (const SkPath &path, SkClipOp op, bool aa)=0
 
virtual void clipRegion (const SkRegion &region, SkClipOp op)=0
 
void clipShader (sk_sp< SkShader > sh, SkClipOp op)
 
virtual void replaceClip (const SkIRect &rect)=0
 
virtual bool isClipAntiAliased () const =0
 
virtual bool isClipEmpty () const =0
 
virtual bool isClipRect () const =0
 
virtual bool isClipWideOpen () const =0
 
virtual void android_utils_clipAsRgn (SkRegion *) const =0
 
virtual bool android_utils_clipWithStencil ()
 
virtual bool useDrawCoverageMaskForMaskFilters () const
 
virtual bool isNoPixelsDevice () const
 
virtual void * getRasterHandle () const
 
virtual GrRecordingContextrecordingContext () const
 
virtual skgpu::graphite::Recorderrecorder () const
 
virtual skgpu::ganesh::DeviceasGaneshDevice ()
 
virtual skgpu::graphite::DeviceasGraphiteDevice ()
 
virtual void setImmutable ()
 
virtual sk_sp< SkSurfacemakeSurface (const SkImageInfo &, const SkSurfaceProps &)
 
virtual sk_sp< SkDevicecreateDevice (const CreateInfo &, const SkPaint *)
 
void drawGlyphRunList (SkCanvas *, const sktext::GlyphRunList &glyphRunList, const SkPaint &paint)
 
virtual sk_sp< sktext::gpu::SlugconvertGlyphRunListToSlug (const sktext::GlyphRunList &glyphRunList, const SkPaint &paint)
 
virtual void drawSlug (SkCanvas *, const sktext::gpu::Slug *slug, const SkPaint &paint)
 
virtual void drawPaint (const SkPaint &paint)=0
 
virtual void drawPoints (SkCanvas::PointMode mode, size_t count, const SkPoint[], const SkPaint &paint)=0
 
virtual void drawRect (const SkRect &r, const SkPaint &paint)=0
 
virtual void drawRegion (const SkRegion &r, const SkPaint &paint)
 
virtual void drawOval (const SkRect &oval, const SkPaint &paint)=0
 
virtual void drawArc (const SkArc &arc, const SkPaint &paint)
 
virtual void drawRRect (const SkRRect &rr, const SkPaint &paint)=0
 
virtual void drawDRRect (const SkRRect &outer, const SkRRect &inner, const SkPaint &)
 
virtual void drawPath (const SkPath &path, const SkPaint &paint, bool pathIsMutable=false)=0
 
virtual void drawImageRect (const SkImage *, const SkRect *src, const SkRect &dst, const SkSamplingOptions &, const SkPaint &, SkCanvas::SrcRectConstraint)=0
 
virtual bool shouldDrawAsTiledImageRect () const
 
virtual bool drawAsTiledImageRect (SkCanvas *, const SkImage *, const SkRect *src, const SkRect &dst, const SkSamplingOptions &, const SkPaint &, SkCanvas::SrcRectConstraint)
 
virtual void drawImageLattice (const SkImage *, const SkCanvas::Lattice &, const SkRect &dst, SkFilterMode, const SkPaint &)
 
virtual void drawVertices (const SkVertices *, sk_sp< SkBlender >, const SkPaint &, bool skipColorXform=false)=0
 
virtual void drawMesh (const SkMesh &mesh, sk_sp< SkBlender >, const SkPaint &)=0
 
virtual void drawShadow (const SkPath &, const SkDrawShadowRec &)
 
virtual void drawPatch (const SkPoint cubics[12], const SkColor colors[4], const SkPoint texCoords[4], sk_sp< SkBlender >, const SkPaint &paint)
 
virtual void drawAtlas (const SkRSXform[], const SkRect[], const SkColor[], int count, sk_sp< SkBlender >, const SkPaint &)
 
virtual void drawAnnotation (const SkRect &, const char[], SkData *)
 
virtual void drawEdgeAAQuad (const SkRect &rect, const SkPoint clip[4], SkCanvas::QuadAAFlags aaFlags, const SkColor4f &color, SkBlendMode mode)
 
virtual void drawEdgeAAImageSet (const SkCanvas::ImageSetEntry[], int count, const SkPoint dstClips[], const SkMatrix preViewMatrices[], const SkSamplingOptions &, const SkPaint &, SkCanvas::SrcRectConstraint)
 
virtual void drawDrawable (SkCanvas *, SkDrawable *, const SkMatrix *)
 
virtual sk_sp< SkSpecialImagesnapSpecial (const SkIRect &subset, bool forceCopy=false)
 
virtual sk_sp< SkSpecialImagesnapSpecialScaled (const SkIRect &subset, const SkISize &dstDims)
 
sk_sp< SkSpecialImagesnapSpecial ()
 
virtual void drawDevice (SkDevice *, const SkSamplingOptions &, const SkPaint &)
 
virtual void drawSpecial (SkSpecialImage *, const SkMatrix &localToDevice, const SkSamplingOptions &, const SkPaint &, SkCanvas::SrcRectConstraint constraint=SkCanvas::kStrict_SrcRectConstraint)
 
virtual void drawCoverageMask (const SkSpecialImage *, const SkMatrix &maskToDevice, const SkSamplingOptions &, const SkPaint &)
 
virtual bool drawBlurredRRect (const SkRRect &, const SkPaint &, float deviceSigma)
 
void drawFilteredImage (const skif::Mapping &mapping, SkSpecialImage *src, SkColorType ct, const SkImageFilter *, const SkSamplingOptions &, const SkPaint &)
 
- Public Member Functions inherited from SkRefCntBase
 SkRefCntBase ()
 
virtual ~SkRefCntBase ()
 
bool unique () const
 
void ref () const
 
void unref () const
 

Static Public Member Functions

static sk_sp< DeviceMake (Recorder *recorder, sk_sp< TextureProxy >, SkISize deviceSize, const SkColorInfo &, const SkSurfaceProps &, LoadOp initialLoadOp, bool registerWithRecorder=true)
 
static sk_sp< DeviceMake (Recorder *, const SkImageInfo &, Budgeted, Mipmapped, SkBackingFit, const SkSurfaceProps &, LoadOp initialLoadOp, std::string_view label, bool registerWithRecorder=true)
 

Friends

class ClipStack
 

Additional Inherited Members

- Protected Member Functions inherited from SkDevice
virtual sk_sp< SkSpecialImagemakeSpecial (const SkBitmap &)
 
virtual sk_sp< SkSpecialImagemakeSpecial (const SkImage *)
 
void setDeviceCoordinateSystem (const SkM44 &deviceToGlobal, const SkM44 &globalToDevice, const SkM44 &localToDevice, int bufferOriginX, int bufferOriginY)
 
void setOrigin (const SkM44 &globalCTM, int x, int y)
 
bool checkLocalToDeviceDirty ()
 

Detailed Description

Definition at line 45 of file Device.h.

Constructor & Destructor Documentation

◆ ~Device()

skgpu::graphite::Device::~Device ( )
override

Definition at line 350 of file Device.cpp.

350 {
351 // The Device should have been marked immutable before it's destroyed, or the Recorder was the
352 // last holder of a reference to it and de-registered the device as part of its cleanup.
353 // However, if the Device was not registered with the recorder (i.e. a scratch device) we don't
354 // require that its recorder be adandoned. Scratch devices must either have been marked
355 // immutable or be destroyed before the recorder has been snapped.
356 SkASSERT(!fRecorder || fScopedRecordingID != 0);
357#if defined(SK_DEBUG)
358 if (fScopedRecordingID != 0 && fRecorder) {
359 SkASSERT(fScopedRecordingID == fRecorder->priv().nextRecordingID());
360 }
361 // else it wasn't a scratch device, or it was a scratch device that was marked immutable so its
362 // lifetime was validated when setImmutable() was called.
363#endif
364}
#define SkASSERT(cond)
Definition: SkAssert.h:116

Member Function Documentation

◆ abandonRecorder()

void skgpu::graphite::Device::abandonRecorder ( )
inline

Definition at line 75 of file Device.h.

75{ fRecorder = nullptr; }

◆ android_utils_clipAsRgn()

void skgpu::graphite::Device::android_utils_clipAsRgn ( SkRegion region) const
overridevirtual

Implements SkDevice.

Definition at line 558 of file Device.cpp.

558 {
559 SkIRect bounds = this->devClipBounds();
560 // Assume wide open and then perform intersect/difference operations reducing the region
561 region->setRect(bounds);
562 const SkRegion deviceBounds(bounds);
563 for (const ClipStack::Element& e : fClip) {
564 SkRegion tmp;
565 if (e.fShape.isRect() && e.fLocalToDevice.type() == Transform::Type::kIdentity) {
566 tmp.setRect(rect_to_pixelbounds(e.fShape.rect()));
567 } else {
568 SkPath tmpPath = e.fShape.asPath();
569 tmpPath.transform(e.fLocalToDevice);
570 tmp.setPath(tmpPath, deviceBounds);
571 }
572
573 region->op(tmp, (SkRegion::Op) e.fOp);
574 }
575}
SkIRect bounds() const
Definition: SkDevice.h:125
Definition: SkPath.h:59
void transform(const SkMatrix &matrix, SkPath *dst, SkApplyPerspectiveClip pc=SkApplyPerspectiveClip::kYes) const
Definition: SkPath.cpp:1711
bool op(const SkIRect &rect, Op op)
Definition: SkRegion.h:384
bool setRect(const SkIRect &rect)
Definition: SkRegion.cpp:192
bool setPath(const SkPath &path, const SkRegion &clip)
SkIRect devClipBounds() const override
Definition: Device.cpp:553
ClipOpAndAA opAA SkRegion region
Definition: SkRecords.h:238
Definition: SkRect.h:32

◆ asGraphiteDevice()

Device * skgpu::graphite::Device::asGraphiteDevice ( )
inlineoverridevirtual

Reimplemented from SkDevice.

Definition at line 70 of file Device.h.

70{ return this; }

◆ clipPath()

void skgpu::graphite::Device::clipPath ( const SkPath path,
SkClipOp  op,
bool  aa 
)
overridevirtual

Implements SkDevice.

Definition at line 590 of file Device.cpp.

590 {
592 // TODO: Ensure all path inspection is handled here or in SkCanvas, and that non-AA rects as
593 // paths are routed appropriately.
594 // TODO: Must also detect paths that are lines so the clip stack can be set to empty
595 fClip.clipShape(this->localToDeviceTransform(), Shape{path}, op);
596}
Shape
Definition: aaxfermodes.cpp:43
void clipShape(const Transform &localToDevice, const Shape &shape, SkClipOp op)
const Transform & localToDeviceTransform()
Definition: Device.cpp:381
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

◆ clipRect()

void skgpu::graphite::Device::clipRect ( const SkRect rect,
SkClipOp  op,
bool  aa 
)
overridevirtual

Implements SkDevice.

Definition at line 577 of file Device.cpp.

577 {
579 // TODO: Snap rect edges to pixel bounds if non-AA and axis-aligned?
580 fClip.clipShape(this->localToDeviceTransform(), Shape{rect}, op);
581}
sk_sp< SkBlender > blender SkRect rect
Definition: SkRecords.h:350

◆ clipRegion()

void skgpu::graphite::Device::clipRegion ( const SkRegion globalRgn,
SkClipOp  op 
)
overridevirtual

Implements SkDevice.

Definition at line 603 of file Device.cpp.

603 {
605
607
608 if (globalRgn.isEmpty()) {
609 fClip.clipShape(globalToDevice, Shape{}, op);
610 } else if (globalRgn.isRect()) {
611 // TODO: Region clips are non-AA so this should match non-AA onClipRect(), but we use a
612 // different transform so can't just call that instead.
613 fClip.clipShape(globalToDevice, Shape{SkRect::Make(globalRgn.getBounds())}, op);
614 } else {
615 // TODO: Can we just iterate the region and do non-AA rects for each chunk?
616 SkPath path;
617 globalRgn.getBoundaryPath(&path);
618 fClip.clipShape(globalToDevice, Shape{path}, op);
619 }
620}
const SkM44 & globalToDevice() const
Definition: SkDevice.h:191
bool getBoundaryPath(SkPath *path) const
bool isRect() const
Definition: SkRegion.h:152
const SkIRect & getBounds() const
Definition: SkRegion.h:165
bool isEmpty() const
Definition: SkRegion.h:146
skgpu::graphite::Transform Transform
static SkRect Make(const SkISize &size)
Definition: SkRect.h:669

◆ clipRRect()

void skgpu::graphite::Device::clipRRect ( const SkRRect rrect,
SkClipOp  op,
bool  aa 
)
overridevirtual

Implements SkDevice.

Definition at line 583 of file Device.cpp.

583 {
585 // TODO: Snap rrect edges to pixel bounds if non-AA and axis-aligned? Is that worth doing to
586 // seam with non-AA rects even if the curves themselves are AA'ed?
587 fClip.clipShape(this->localToDeviceTransform(), Shape{rrect}, op);
588}
SkRRect rrect
Definition: SkRecords.h:232

◆ createDevice()

sk_sp< SkDevice > skgpu::graphite::Device::createDevice ( const CreateInfo ,
const SkPaint  
)
overridevirtual

Create a new device based on CreateInfo. If the paint is not null, then it represents a preview of how the new device will be composed with its creator device (this).

The subclass may be handed this device in drawDevice(), so it must always return a device that it knows how to draw, and that it knows how to identify if it is not of the same subclass (since drawDevice is passed a SkDevice*). If the subclass cannot fulfill that contract (e.g. PDF cannot support some settings on the paint) it should return NULL, and the caller may then decide to explicitly create a bitmapdevice, knowing that later it could not call drawDevice with it (but it could call drawSprite or drawBitmap).

Reimplemented from SkDevice.

Definition at line 392 of file Device.cpp.

392 {
393 // TODO: Inspect the paint and create info to determine if there's anything that has to be
394 // modified to support inline subpasses.
395 SkSurfaceProps props =
396 this->surfaceProps().cloneWithPixelGeometry(info.fPixelGeometry);
397
398 // Skia's convention is to only clear a device if it is non-opaque.
399 LoadOp initialLoadOp = info.fInfo.isOpaque() ? LoadOp::kDiscard : LoadOp::kClear;
400
401 std::string label = this->target()->label();
402 if (label.empty()) {
403 label = "ChildDevice";
404 } else {
405 label += "_ChildDevice";
406 }
407
408 return Make(fRecorder,
409 info.fInfo,
413 props,
414 initialLoadOp,
415 label);
416}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
const SkSurfaceProps & surfaceProps() const
Definition: SkDevice.h:131
SkSurfaceProps cloneWithPixelGeometry(SkPixelGeometry newPixelGeometry) const
static sk_sp< Device > Make(Recorder *recorder, sk_sp< TextureProxy >, SkISize deviceSize, const SkColorInfo &, const SkSurfaceProps &, LoadOp initialLoadOp, bool registerWithRecorder=true)
Definition: Device.cpp:276
TextureProxy * target()
Definition: Device.cpp:1686
const char * label() const
Definition: TextureProxy.h:40

◆ devClipBounds()

SkIRect skgpu::graphite::Device::devClipBounds ( ) const
overridevirtual

Returns the bounding box of the current clip, in this device's coordinate space. No pixels outside of these bounds will be touched by draws unless the clip is further modified (at which point this will return the updated bounds).

Implements SkDevice.

Definition at line 553 of file Device.cpp.

553 {
554 return rect_to_pixelbounds(fClip.conservativeBounds());
555}

◆ drawAsTiledImageRect()

bool skgpu::graphite::Device::drawAsTiledImageRect ( SkCanvas canvas,
const SkImage image,
const SkRect src,
const SkRect dst,
const SkSamplingOptions sampling,
const SkPaint paint,
SkCanvas::SrcRectConstraint  constraint 
)
overridevirtual

Reimplemented from SkDevice.

Definition at line 691 of file Device.cpp.

697 {
698 auto recorder = canvas->recorder();
699 if (!recorder) {
700 return false;
701 }
702 SkASSERT(src);
703
704 // For Graphite this is a pretty loose heuristic. The Recorder-local cache size (relative
705 // to the large image's size) is used as a proxy for how conservative we should be when
706 // allocating tiles. Since the tiles will actually be owned by the client (via an
707 // ImageProvider) they won't actually add any memory pressure directly to Graphite.
708 size_t cacheSize = recorder->priv().getResourceCacheLimit();
709 size_t maxTextureSize = recorder->priv().caps()->maxTextureSize();
710
711#if defined(GRAPHITE_TEST_UTILS)
712 if (gOverrideMaxTextureSizeGraphite) {
713 maxTextureSize = gOverrideMaxTextureSizeGraphite;
714 }
715 gNumTilesDrawnGraphite.store(0, std::memory_order_relaxed);
716#endif
717
718 [[maybe_unused]] auto [wasTiled, numTiles] =
720 image,
721 *src,
722 dst,
724 sampling,
725 &paint,
726 constraint,
727 cacheSize,
728 maxTextureSize);
729#if defined(GRAPHITE_TEST_UTILS)
730 gNumTilesDrawnGraphite.store(numTiles, std::memory_order_relaxed);
731#endif
732 return wasTiled;
733}
virtual skgpu::graphite::Recorder * recorder() const
Definition: SkCanvas.cpp:1641
@ kAll_QuadAAFlags
Definition: SkCanvas.h:1665
static std::tuple< bool, size_t > DrawAsTiledImageRect(SkCanvas *, const SkImage *, const SkRect &srcRect, const SkRect &dstRect, SkCanvas::QuadAAFlags, const SkSamplingOptions &, const SkPaint *, SkCanvas::SrcRectConstraint, size_t cacheSize, size_t maxTextureSize)
int maxTextureSize() const
Definition: Caps.h:141
Recorder * recorder() const override
Definition: Device.h:72
size_t getResourceCacheLimit() const
Definition: Recorder.cpp:557
const Caps * caps() const
Definition: RecorderPriv.h:31
const Paint & paint
Definition: color_source.cc:38
sk_sp< const SkImage > image
Definition: SkRecords.h:269
SkSamplingOptions sampling
Definition: SkRecords.h:337
dst
Definition: cp.py:12

◆ drawAtlas()

void skgpu::graphite::Device::drawAtlas ( const  SkRSXform[],
const  SkRect[],
const  SkColor[],
int  count,
sk_sp< SkBlender ,
const SkPaint  
)
inlineoverridevirtual

Reimplemented from SkDevice.

Definition at line 179 of file Device.h.

180 {}

◆ drawBlurredRRect()

bool skgpu::graphite::Device::drawBlurredRRect ( const SkRRect ,
const SkPaint ,
float  deviceSigma 
)
overridevirtual

Draw rrect with an optimized path for analytic blurs, if provided by the device.

Reimplemented from SkDevice.

Definition at line 1717 of file Device.cpp.

1717 {
1718 SkStrokeRec style(paint);
1719 if (skgpu::BlurIsEffectivelyIdentity(deviceSigma)) {
1720 this->drawGeometry(this->localToDeviceTransform(),
1721 Geometry(rrect.isRect() ? Shape(rrect.rect()) : Shape(rrect)),
1722 paint,
1723 style);
1724 return true;
1725 }
1726
1727 std::optional<AnalyticBlurMask> analyticBlur = AnalyticBlurMask::Make(
1728 this->recorder(), this->localToDeviceTransform(), deviceSigma, rrect);
1729 if (!analyticBlur) {
1730 return false;
1731 }
1732
1733 this->drawGeometry(this->localToDeviceTransform(), Geometry(*analyticBlur), paint, style);
1734 return true;
1735}
const SkRect & rect() const
Definition: SkRRect.h:264
bool isRect() const
Definition: SkRRect.h:84
static std::optional< AnalyticBlurMask > Make(Recorder *, const Transform &localToDevice, float deviceSigma, const SkRRect &srcRRect)
constexpr bool BlurIsEffectivelyIdentity(float sigma)
Definition: BlurUtils.h:30

◆ drawCoverageMask()

void skgpu::graphite::Device::drawCoverageMask ( const SkSpecialImage ,
const SkMatrix maskToDevice,
const SkSamplingOptions ,
const SkPaint  
)
overridevirtual

Draw the special image's subset to this device, treating its alpha channel as coverage for the draw and ignoring any RGB channels that might be present. This will be drawn using the provided matrix transform instead of the device's current local to device matrix.

Coverage values beyond the image's subset are treated as 0 (i.e. kDecal tiling). Color values before coverage are determined as normal by the SkPaint, ignoring style, path effects, mask filters and image filters. The local coords of any SkShader on the paint should be relative to the SkDevice's current matrix (i.e. 'maskToDevice' determines how the coverage mask aligns with device-space, but otherwise shading proceeds like other draws).

Reimplemented from SkDevice.

Definition at line 1590 of file Device.cpp.

1593 {
1594 CoverageMaskShape::MaskInfo maskInfo{/*fTextureOrigin=*/{SkTo<uint16_t>(mask->subset().fLeft),
1595 SkTo<uint16_t>(mask->subset().fTop)},
1596 /*fMaskSize=*/{SkTo<uint16_t>(mask->width()),
1597 SkTo<uint16_t>(mask->height())}};
1598
1599 auto maskProxyView = AsView(mask->asImage());
1600 if (!maskProxyView) {
1601 SKGPU_LOG_W("Couldn't get Graphite-backed special image as texture proxy view");
1602 return;
1603 }
1604
1605 // Every other "Image" draw reaches the underlying texture via AddToKey/NotifyInUse, which
1606 // handles notifying the image and either flushing the linked surface or attaching draw tasks
1607 // from a scratch device to the current draw context. In this case, 'mask' is very likely to
1608 // be linked to a scratch device, but we must perform the same notifyInUse manually here because
1609 // the texture is consumed by the RenderStep and not part of the PaintParams.
1610 static_cast<Image_Base*>(mask->asImage().get())->notifyInUse(fRecorder, fDC.get());
1611
1612 // 'mask' logically has 0 coverage outside of its pixels, which is equivalent to kDecal tiling.
1613 // However, since we draw geometry tightly fitting 'mask', we can use the better-supported
1614 // kClamp tiling and behave effectively the same way.
1616
1617 // Ensure this is kept alive; normally textures are kept alive by the PipelineDataGatherer for
1618 // image shaders, or by the PathAtlas. This is a unique circumstance.
1619 // TODO: Find a cleaner way to ensure 'maskProxyView' is transferred to the final Recording.
1620 TextureDataBlock tdb;
1621 // NOTE: CoverageMaskRenderStep controls the final sampling options; this texture data block
1622 // serves only to keep the mask alive so the sampling passed to add() doesn't matter.
1623 tdb.add(maskProxyView.refProxy(), {SkFilterMode::kLinear, kClamp});
1624 fRecorder->priv().textureDataCache()->insert(tdb);
1625
1626 // CoverageMaskShape() wraps a Shape when it's used as a PathAtlas, but in this case the
1627 // original shape has been long lost, so just use a Rect that bounds the image.
1628 CoverageMaskShape maskShape{Shape{Rect::WH((float)mask->width(), (float)mask->height())},
1629 maskProxyView.proxy(),
1630 // Use the active local-to-device transform for this since it
1631 // determines the local coords for evaluating the skpaint, whereas
1632 // the provided 'localToDevice' just places the coverage mask.
1634 maskInfo};
1635
1636 this->drawGeometry(Transform(SkM44(localToDevice)),
1637 Geometry(maskShape),
1638 paint,
1639 DefaultFillStyle(),
1640 DrawFlags::kIgnorePathEffect);
1641}
#define SKGPU_LOG_W(fmt,...)
Definition: Log.h:40
SkTileMode
Definition: SkTileMode.h:13
const SkMatrix & localToDevice() const
Definition: SkDevice.h:179
Definition: SkM44.h:150
const T * insert(const T &dataBlock)
TextureDataCache * textureDataCache()
Definition: RecorderPriv.h:57
static AI Rect WH(float w, float h)
Definition: Rect.h:46
const SkM44 & inverse() const
TextureProxyView AsView(const SkImage *image)

◆ drawDrawable()

void skgpu::graphite::Device::drawDrawable ( SkCanvas ,
SkDrawable ,
const SkMatrix  
)
inlineoverridevirtual

Reimplemented from SkDevice.

Definition at line 182 of file Device.h.

182{}

◆ drawEdgeAAImageSet()

void skgpu::graphite::Device::drawEdgeAAImageSet ( const SkCanvas::ImageSetEntry  set[],
int  count,
const SkPoint  dstClips[],
const SkMatrix  preViewMatrices[],
const SkSamplingOptions sampling,
const SkPaint paint,
SkCanvas::SrcRectConstraint  constraint 
)
overridevirtual

Reimplemented from SkDevice.

Definition at line 828 of file Device.cpp.

831 {
832 SkASSERT(count > 0);
833
834 SkPaint paintWithShader(paint);
835 int dstClipIndex = 0;
836 for (int i = 0; i < count; ++i) {
837 // If the entry is clipped by 'dstClips', that must be provided
838 SkASSERT(!set[i].fHasClip || dstClips);
839 // Similarly, if it has an extra transform, those must be provided
840 SkASSERT(set[i].fMatrixIndex < 0 || preViewMatrices);
841
842 auto [ imageToDraw, newSampling ] =
843 skgpu::graphite::GetGraphiteBacked(this->recorder(), set[i].fImage.get(), sampling);
844 if (!imageToDraw) {
845 SKGPU_LOG_W("Device::drawImageRect: Creation of Graphite-backed image failed");
846 return;
847 }
848
849 // TODO: Produce an image shading paint key and data directly without having to reconstruct
850 // the equivalent SkPaint for each entry. Reuse the key and data between entries if possible
851 paintWithShader.setShader(paint.refShader());
852 paintWithShader.setAlphaf(paint.getAlphaf() * set[i].fAlpha);
854 imageToDraw.get(), newSampling, set[i].fSrcRect, set[i].fDstRect,
856 &paintWithShader);
857 if (dst.isEmpty()) {
858 return;
859 }
860
861 auto flags =
863 EdgeAAQuad quad = set[i].fHasClip ? EdgeAAQuad(dstClips + dstClipIndex, flags)
864 : EdgeAAQuad(dst, flags);
865
866 // TODO: Calling drawGeometry() for each entry re-evaluates the clip stack every time, which
867 // is consistent with Ganesh's behavior. It also matches the behavior if edge-AA images were
868 // submitted one at a time by SkiaRenderer (a nice client simplification). However, we
869 // should explore the performance trade off with doing one bulk evaluation for the whole set
870 if (set[i].fMatrixIndex < 0) {
871 this->drawGeometry(this->localToDeviceTransform(),
872 Geometry(quad),
873 paintWithShader,
874 DefaultFillStyle(),
875 DrawFlags::kIgnorePathEffect);
876 } else {
877 SkM44 xtraTransform(preViewMatrices[set[i].fMatrixIndex]);
878 this->drawGeometry(this->localToDeviceTransform().concat(xtraTransform),
879 Geometry(quad),
880 paintWithShader,
881 DefaultFillStyle(),
882 DrawFlags::kIgnorePathEffect);
883 }
884
885 dstClipIndex += 4 * set[i].fHasClip;
886 }
887}
int count
Definition: FontMgrTest.cpp:50
SkRect SkModifyPaintAndDstForDrawImageRect(const SkImage *image, const SkSamplingOptions &, SkRect src, SkRect dst, bool strictSrcSubset, SkPaint *paint)
@ kStrict_SrcRectConstraint
sample only inside bounds; slower
Definition: SkCanvas.h:1542
FlutterSemanticsFlag flags
PODArray< SkPoint > dstClips
Definition: SkRecords.h:364
PODArray< SkMatrix > preViewMatrices
Definition: SkRecords.h:365
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not set
Definition: switches.h:76
std::pair< sk_sp< SkImage >, SkSamplingOptions > GetGraphiteBacked(Recorder *recorder, const SkImage *imageIn, SkSamplingOptions sampling)

◆ drawEdgeAAQuad()

void skgpu::graphite::Device::drawEdgeAAQuad ( const SkRect rect,
const SkPoint  clip[4],
SkCanvas::QuadAAFlags  aaFlags,
const SkColor4f color,
SkBlendMode  mode 
)
overridevirtual

Reimplemented from SkDevice.

Definition at line 810 of file Device.cpp.

814 {
815 SkPaint solidColorPaint;
816 solidColorPaint.setColor4f(color, /*colorSpace=*/nullptr);
817 solidColorPaint.setBlendMode(mode);
818
819 auto flags = SkEnumBitMask<EdgeAAQuad::Flags>(static_cast<EdgeAAQuad::Flags>(aaFlags));
820 EdgeAAQuad quad = clip ? EdgeAAQuad(clip, flags) : EdgeAAQuad(rect, flags);
821 this->drawGeometry(this->localToDeviceTransform(),
822 Geometry(quad),
823 solidColorPaint,
824 DefaultFillStyle(),
825 DrawFlags::kIgnorePathEffect);
826}
static SkPath clip(const SkPath &path, const SkHalfPlane &plane)
Definition: SkPath.cpp:3892
void setColor4f(const SkColor4f &color, SkColorSpace *colorSpace=nullptr)
Definition: SkPaint.h:253
void setBlendMode(SkBlendMode mode)
Definition: SkPaint.cpp:151
DlColor color
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

◆ drawImageLattice()

void skgpu::graphite::Device::drawImageLattice ( const SkImage ,
const SkCanvas::Lattice ,
const SkRect dst,
SkFilterMode  ,
const SkPaint  
)
inlineoverridevirtual

Reimplemented from SkDevice.

Definition at line 177 of file Device.h.

178 {}

◆ drawImageRect()

void skgpu::graphite::Device::drawImageRect ( const SkImage image,
const SkRect src,
const SkRect dst,
const SkSamplingOptions sampling,
const SkPaint paint,
SkCanvas::SrcRectConstraint  constraint 
)
overridevirtual

Implements SkDevice.

Definition at line 889 of file Device.cpp.

891 {
894 dst,
895 /*alpha=*/1.f,
897 this->drawEdgeAAImageSet(&single, 1, nullptr, nullptr, sampling, paint, constraint);
898}
sk_sp< T > sk_ref_sp(T *obj)
Definition: SkRefCnt.h:381
SkIRect bounds() const
Definition: SkImage.h:303
void drawEdgeAAImageSet(const SkCanvas::ImageSetEntry[], int count, const SkPoint dstClips[], const SkMatrix preViewMatrices[], const SkSamplingOptions &, const SkPaint &, SkCanvas::SrcRectConstraint) override
Definition: Device.cpp:828

◆ drawMesh()

void skgpu::graphite::Device::drawMesh ( const SkMesh ,
sk_sp< SkBlender ,
const SkPaint  
)
inlineoverridevirtual

Implements SkDevice.

Definition at line 183 of file Device.h.

183{}

◆ drawOval()

void skgpu::graphite::Device::drawOval ( const SkRect oval,
const SkPaint paint 
)
overridevirtual

Implements SkDevice.

Definition at line 735 of file Device.cpp.

735 {
736 if (paint.getPathEffect()) {
737 // Dashing requires that the oval path starts on the right side and travels clockwise. This
738 // is the default for the SkPath::Oval constructor, as used by SkBitmapDevice.
739 this->drawGeometry(this->localToDeviceTransform(), Geometry(Shape(SkPath::Oval(oval))),
741 } else {
742 // TODO: This has wasted effort from the SkCanvas level since it instead converts rrects
743 // that happen to be ovals into this, only for us to go right back to rrect.
744 this->drawGeometry(this->localToDeviceTransform(), Geometry(Shape(SkRRect::MakeOval(oval))),
746 }
747}
static SkPath Oval(const SkRect &, SkPathDirection=SkPathDirection::kCW)
Definition: SkPath.cpp:3590
static SkRRect MakeOval(const SkRect &oval)
Definition: SkRRect.h:162
SkRect oval
Definition: SkRecords.h:249

◆ drawPaint()

void skgpu::graphite::Device::drawPaint ( const SkPaint paint)
overridevirtual

Implements SkDevice.

Definition at line 639 of file Device.cpp.

639 {
641 // We never want to do a fullscreen clear on a fully-lazy render target, because the device size
642 // may be smaller than the final surface we draw to, in which case we don't want to fill the
643 // entire final surface.
644 if (this->isClipWideOpen() && !fDC->target()->isFullyLazy()) {
645 if (!paint_depends_on_dst(paint)) {
646 if (std::optional<SkColor4f> color = extract_paint_color(paint, fDC->colorInfo())) {
647 // do fullscreen clear
648 fDC->clear(*color);
649 return;
650 } else {
651 // This paint does not depend on the destination and covers the entire surface, so
652 // discard everything previously recorded and proceed with the draw.
653 fDC->discard();
654 }
655 }
656 }
657
659 if (!localToDevice.valid()) {
660 // TBD: This matches legacy behavior for drawPaint() that requires local coords, although
661 // v1 handles arbitrary transforms when the paint is solid color because it just fills the
662 // device bounds directly. In the new world it might be nice to have non-invertible
663 // transforms formalized (i.e. no drawing ever, handled at SkCanvas level possibly?)
664 return;
665 }
666 Rect localCoveringBounds = localToDevice.inverseMapRect(fClip.conservativeBounds());
667 this->drawGeometry(localToDevice,
668 Geometry(Shape(localCoveringBounds)),
669 paint,
670 DefaultFillStyle(),
671 DrawFlags::kIgnorePathEffect);
672}
bool isClipWideOpen() const override
Definition: Device.h:121
#define ASSERT_SINGLE_OWNER
Definition: Device.cpp:94
TRect< Scalar > Rect
Definition: rect.h:769

◆ drawPath()

void skgpu::graphite::Device::drawPath ( const SkPath path,
const SkPaint paint,
bool  pathIsMutable = false 
)
overridevirtual

If pathIsMutable, then the implementation is allowed to cast path to a non-const pointer and modify it in place (as an optimization). Canvas may do this to implement helpers such as drawOval, by placing a temp path on the stack to hold the representation of the oval.

Implements SkDevice.

Definition at line 754 of file Device.cpp.

754 {
755 // Alternatively, we could move this analysis to SkCanvas. Also, we could consider applying the
756 // path effect, being careful about starting point and direction.
757 if (!paint.getPathEffect() && !path.isInverseFillType()) {
758 if (SkRect oval; path.isOval(&oval)) {
759 this->drawGeometry(this->localToDeviceTransform(),
760 Geometry(Shape(SkRRect::MakeOval(oval))),
761 paint,
763 return;
764 }
765 if (SkRRect rrect; path.isRRect(&rrect)) {
766 this->drawGeometry(this->localToDeviceTransform(),
767 Geometry(Shape(rrect)),
768 paint,
770 return;
771 }
772 if (SkRect rect; paint.getStyle() == SkPaint::kFill_Style && path.isRect(&rect)) {
773 this->drawGeometry(this->localToDeviceTransform(),
774 Geometry(Shape(rect)),
775 paint,
777 return;
778 }
779 }
780 this->drawGeometry(this->localToDeviceTransform(), Geometry(Shape(path)),
782}
@ kFill_Style
set to fill geometry
Definition: SkPaint.h:193

◆ drawPoints()

void skgpu::graphite::Device::drawPoints ( SkCanvas::PointMode  mode,
size_t  count,
const  SkPoint[],
const SkPaint paint 
)
overridevirtual

Implements SkDevice.

◆ drawRect()

void skgpu::graphite::Device::drawRect ( const SkRect r,
const SkPaint paint 
)
overridevirtual

Implements SkDevice.

Definition at line 674 of file Device.cpp.

674 {
675 this->drawGeometry(this->localToDeviceTransform(), Geometry(Shape(r)),
677}

◆ drawRRect()

void skgpu::graphite::Device::drawRRect ( const SkRRect rr,
const SkPaint paint 
)
overridevirtual

Implements SkDevice.

Definition at line 749 of file Device.cpp.

749 {
750 this->drawGeometry(this->localToDeviceTransform(), Geometry(Shape(rr)),
752}

◆ drawShadow()

void skgpu::graphite::Device::drawShadow ( const SkPath ,
const SkDrawShadowRec  
)
inlineoverridevirtual

Reimplemented from SkDevice.

Definition at line 184 of file Device.h.

184{}

◆ drawSpecial()

void skgpu::graphite::Device::drawSpecial ( SkSpecialImage ,
const SkMatrix localToDevice,
const SkSamplingOptions ,
const SkPaint ,
SkCanvas::SrcRectConstraint  constraint 
)
overridevirtual

Draw the special image's subset to this device, subject to the given matrix transform instead of the device's current local to device matrix.

If 'constraint' is kFast, the rendered geometry of the image still reflects the extent of the SkSpecialImage's subset, but it's assumed that the pixel data beyond the subset is valid (e.g. SkSpecialImage::makeSubset() was called to crop a larger image).

Reimplemented from SkDevice.

Definition at line 1558 of file Device.cpp.

1562 {
1563 SkASSERT(!paint.getMaskFilter() && !paint.getImageFilter());
1564
1565 sk_sp<SkImage> img = special->asImage();
1566 if (!img || !as_IB(img)->isGraphiteBacked()) {
1567 SKGPU_LOG_W("Couldn't get Graphite-backed special image as image");
1568 return;
1569 }
1570
1571 SkPaint paintWithShader(paint);
1573 img.get(),
1574 sampling,
1575 /*src=*/SkRect::Make(special->subset()),
1576 /*dst=*/SkRect::MakeIWH(special->width(), special->height()),
1577 /*strictSrcSubset=*/constraint == SkCanvas::kStrict_SrcRectConstraint,
1578 &paintWithShader);
1579 if (dst.isEmpty()) {
1580 return;
1581 }
1582
1583 this->drawGeometry(Transform(SkM44(localToDevice)),
1584 Geometry(Shape(dst)),
1585 paintWithShader,
1586 DefaultFillStyle(),
1587 DrawFlags::kIgnorePathEffect);
1588}
static SkImage_Base * as_IB(SkImage *image)
Definition: SkImage_Base.h:201
T * get() const
Definition: SkRefCnt.h:303
static SkRect MakeIWH(int w, int h)
Definition: SkRect.h:623

◆ drawVertices()

void skgpu::graphite::Device::drawVertices ( const SkVertices ,
sk_sp< SkBlender ,
const SkPaint ,
bool  skipColorXform 
)
overridevirtual

If skipColorXform is true, then the implementation should assume that the provided vertex colors are already in the destination color space.

Implements SkDevice.

Definition at line 679 of file Device.cpp.

680 {
681 // TODO - Add GPU handling of skipColorXform once Graphite has its color system more fleshed out.
682 this->drawGeometry(this->localToDeviceTransform(),
683 Geometry(sk_ref_sp(vertices)),
684 paint,
685 DefaultFillStyle(),
686 DrawFlags::kIgnorePathEffect,
687 std::move(blender),
688 skipColorXform);
689}

◆ flushPendingWorkToRecorder()

void skgpu::graphite::Device::flushPendingWorkToRecorder ( )

Definition at line 1465 of file Device.cpp.

1465 {
1466 TRACE_EVENT0("skia.gpu", TRACE_FUNC);
1467
1468 // If this is a scratch device being flushed, it should only be flushing into the expected
1469 // next recording from when the Device was first created.
1470 SkASSERT(fRecorder);
1471 SkASSERT(fScopedRecordingID == 0 || fScopedRecordingID == fRecorder->priv().nextRecordingID());
1472
1473 // TODO(b/330864257): flushPendingWorkToRecorder() can be recursively called if this Device
1474 // recorded a picture shader draw and during a flush (triggered by snap or automatically from
1475 // reaching limits), the picture shader will be rendered to a new device. If that picture drawn
1476 // to the temporary device fills up an atlas it can trigger the global
1477 // recorder->flushTrackedDevices(), which will then encounter this device that is already in
1478 // the midst of flushing. To avoid crashing we only actually flush the first time this is called
1479 // and set a bit to early-out on any recursive calls.
1480 // This is not an ideal solution since the temporary Device's flush-the-world may have reset
1481 // atlas entries that the current Device's flushed draws will reference. But at this stage it's
1482 // not possible to split the already recorded draws into a before-list and an after-list that
1483 // can reference the old and new contents of the atlas. While avoiding the crash, this may cause
1484 // incorrect accesses to a shared atlas. Once paint data is extracted at draw time, picture
1485 // shaders will be resolved outside of flushes and then this will be fixed automatically.
1486 if (fIsFlushing) {
1487 return;
1488 } else {
1489 fIsFlushing = true;
1490 }
1491
1492 this->internalFlush();
1493 sk_sp<Task> drawTask = fDC->snapDrawTask(fRecorder);
1494 if (this->isScratchDevice()) {
1495 // TODO(b/323887221): Once shared atlas resources are less brittle, scratch devices won't
1496 // flush to the recorder at all and will only store the snapped task here.
1497 fLastTask = drawTask;
1498 } else {
1499 // Non-scratch devices do not need to point back to the last snapped task since they are
1500 // always added to the root task list.
1501 // TODO: It is currently possible for scratch devices to be flushed and instantiated before
1502 // their work is finished, meaning they will produce additional tasks to be included in
1503 // a follow-up Recording: https://chat.google.com/room/AAAA2HlH94I/YU0XdFqX2Uw.
1504 // However, in this case they no longer appear scratch because the first Recording
1505 // instantiated the targets. When scratch devices are not actually registered with the
1506 // Recorder and are only included when they are drawn (e.g. restored), we should be able to
1507 // assert that `fLastTask` is null.
1508 fLastTask = nullptr;
1509 }
1510
1511 if (drawTask) {
1512 fRecorder->priv().add(std::move(drawTask));
1513
1514 // TODO(b/297344089): This always regenerates mipmaps on the draw target when it's drawn to.
1515 // This could be wasteful if we draw to a target multiple times before reading from it with
1516 // downscaling.
1517 if (fDC->target()->mipmapped() == Mipmapped::kYes) {
1518 if (!GenerateMipmaps(fRecorder, fDC->refTarget(), fDC->colorInfo())) {
1519 SKGPU_LOG_W("Device::flushPendingWorkToRecorder: Failed to generate mipmaps");
1520 }
1521 }
1522 }
1523
1524 fIsFlushing = false;
1525}
#define TRACE_FUNC
Definition: SkTraceEvent.h:30
bool isScratchDevice() const
Definition: Device.cpp:1690
void add(sk_sp< Task >)
Definition: Recorder.cpp:485
bool GenerateMipmaps(Recorder *recorder, sk_sp< TextureProxy > texture, const SkColorInfo &colorInfo)
#define TRACE_EVENT0(category_group, name)
Definition: trace_event.h:131

◆ isClipAntiAliased()

bool skgpu::graphite::Device::isClipAntiAliased ( ) const
overridevirtual

Implements SkDevice.

Definition at line 539 of file Device.cpp.

539 {
540 // All clips are AA'ed unless it's wide-open, empty, or a device-rect with integer coordinates
543 return false;
545 const ClipStack::Element rect = *fClip.begin();
546 SkASSERT(rect.fShape.isRect() && rect.fLocalToDevice.type() == Transform::Type::kIdentity);
547 return rect.fShape.rect() != rect.fShape.rect().makeRoundOut();
548 } else {
549 return true;
550 }
551}
GLenum type

◆ isClipEmpty()

bool skgpu::graphite::Device::isClipEmpty ( ) const
inlineoverridevirtual

Implements SkDevice.

Definition at line 124 of file Device.h.

124 {
125 return fClip.clipState() == ClipStack::ClipState::kEmpty;
126 }

◆ isClipRect()

bool skgpu::graphite::Device::isClipRect ( ) const
inlineoverridevirtual

Implements SkDevice.

Definition at line 127 of file Device.h.

127 {
130 }

◆ isClipWideOpen()

bool skgpu::graphite::Device::isClipWideOpen ( ) const
inlineoverridevirtual

Implements SkDevice.

Definition at line 121 of file Device.h.

121 {
123 }

◆ isScratchDevice()

bool skgpu::graphite::Device::isScratchDevice ( ) const

Definition at line 1690 of file Device.cpp.

1690 {
1691 // Scratch device status is inferred from whether or not the Device's target is instantiated.
1692 // By default devices start out un-instantiated unless they are wrapping an existing backend
1693 // texture (definitely not a scratch scenario), or Surface explicitly instantiates the target
1694 // before returning to the client (not a scratch scenario).
1695 //
1696 // Scratch device targets are instantiated during the prepareResources() phase of
1697 // Recorder::snap(). Truly scratch devices that have gone out of scope as intended will have
1698 // already been destroyed at this point. Scratch devices that become longer-lived (linked to
1699 // a client-owned object) automatically transition to non-scratch usage.
1700 return !fDC->target()->isInstantiated() && !fDC->target()->isLazy();
1701}

◆ lastDrawTask()

sk_sp< Task > skgpu::graphite::Device::lastDrawTask ( ) const

Definition at line 1460 of file Device.cpp.

1460 {
1461 SkASSERT(this->isScratchDevice());
1462 return fLastTask;
1463}

◆ localToDeviceTransform()

const Transform & skgpu::graphite::Device::localToDeviceTransform ( )

Definition at line 381 of file Device.cpp.

381 {
382 if (this->checkLocalToDeviceDirty()) {
383 fCachedLocalToDevice = Transform{this->localToDevice44()};
384 }
385 return fCachedLocalToDevice;
386}
bool checkLocalToDeviceDirty()
Definition: SkDevice.h:513
const SkM44 & localToDevice44() const
Definition: SkDevice.h:178

◆ Make() [1/2]

sk_sp< Device > skgpu::graphite::Device::Make ( Recorder recorder,
const SkImageInfo ii,
skgpu::Budgeted  budgeted,
Mipmapped  mipmapped,
SkBackingFit  backingFit,
const SkSurfaceProps props,
LoadOp  initialLoadOp,
std::string_view  label,
bool  registerWithRecorder = true 
)
static

Definition at line 244 of file Device.cpp.

252 {
253 SkASSERT(!(mipmapped == Mipmapped::kYes && backingFit == SkBackingFit::kApprox));
254 if (!recorder) {
255 return nullptr;
256 }
257
258 const Caps* caps = recorder->priv().caps();
259 SkISize backingDimensions = backingFit == SkBackingFit::kApprox ? GetApproxSize(ii.dimensions())
260 : ii.dimensions();
261 auto textureInfo = caps->getDefaultSampledTextureInfo(ii.colorType(),
262 mipmapped,
265
266 return Make(recorder,
268 backingDimensions, textureInfo, std::move(label), budgeted),
269 ii.dimensions(),
270 ii.colorInfo(),
271 props,
272 initialLoadOp,
273 registerWithRecorder);
274}
Protected isProtected() const
Definition: RecorderPriv.h:52
ResourceProvider * resourceProvider()
Definition: RecorderPriv.h:33
static sk_sp< TextureProxy > Make(const Caps *, ResourceProvider *, SkISize dimensions, const TextureInfo &, std::string_view label, skgpu::Budgeted)
SkISize GetApproxSize(SkISize size)
Definition: SkSize.h:16
const SkColorInfo & colorInfo() const
Definition: SkImageInfo.h:404
SkISize dimensions() const
Definition: SkImageInfo.h:421
SkColorType colorType() const
Definition: SkImageInfo.h:373

◆ Make() [2/2]

sk_sp< Device > skgpu::graphite::Device::Make ( Recorder recorder,
sk_sp< TextureProxy target,
SkISize  deviceSize,
const SkColorInfo colorInfo,
const SkSurfaceProps props,
LoadOp  initialLoadOp,
bool  registerWithRecorder = true 
)
static

Definition at line 276 of file Device.cpp.

282 {
283 if (!recorder) {
284 return nullptr;
285 }
286
288 std::move(target),
289 deviceSize,
290 colorInfo,
291 props);
292 if (!dc) {
293 return nullptr;
294 } else if (initialLoadOp == LoadOp::kClear) {
295 dc->clear(SkColors::kTransparent);
296 } else if (initialLoadOp == LoadOp::kDiscard) {
297 dc->discard();
298 } // else kLoad is the default initial op for a DrawContext
299
300 sk_sp<Device> device{new Device(recorder, std::move(dc))};
301 if (registerWithRecorder) {
302 // We don't register the device with the recorder until after the constructor has returned.
303 recorder->registerDevice(device);
304 } else {
305 // Since it's not registered, it should go out of scope before nextRecordingID() changes
306 // from what is saved to fScopedRecordingID.
307 SkDEBUGCODE(device->fScopedRecordingID = recorder->priv().nextRecordingID();)
308 }
309 return device;
310}
SkDEBUGCODE(SK_SPI) SkThreadID SkGetThreadID()
static sk_sp< DrawContext > Make(const Caps *caps, sk_sp< TextureProxy > target, SkISize deviceSize, const SkColorInfo &, const SkSurfaceProps &)
Definition: DrawContext.cpp:65
VkDevice device
Definition: main.cc:53
constexpr SkColor4f kTransparent
Definition: SkColor.h:434

◆ makeImageCopy()

sk_sp< Image > skgpu::graphite::Device::makeImageCopy ( const SkIRect subset,
Budgeted  budgeted,
Mipmapped  mipmapped,
SkBackingFit  backingFit 
)

Definition at line 422 of file Device.cpp.

425 {
428
429 const SkColorInfo& colorInfo = this->imageInfo().colorInfo();
430 TextureProxyView srcView = this->readSurfaceView();
431 if (!srcView) {
432 // readSurfaceView() returns an empty view when the target is not texturable. Create an
433 // equivalent view for the blitting operation.
434 Swizzle readSwizzle = fRecorder->priv().caps()->getReadSwizzle(
435 colorInfo.colorType(), this->target()->textureInfo());
436 srcView = {sk_ref_sp(this->target()), readSwizzle};
437 }
438 std::string label = this->target()->label();
439 if (label.empty()) {
440 label = "CopyDeviceTexture";
441 } else {
442 label += "_DeviceCopy";
443 }
444
445 return Image::Copy(fRecorder, srcView, colorInfo, subset, budgeted, mipmapped, backingFit,
446 label);
447}
SkColorType colorType() const
Definition: SkImageInfo.h:140
const SkImageInfo & imageInfo() const
Definition: SkDevice.h:117
skgpu::Swizzle getReadSwizzle(SkColorType, const TextureInfo &) const
Definition: Caps.cpp:129
TextureProxyView readSurfaceView() const
Definition: Device.cpp:1688
void flushPendingWorkToRecorder()
Definition: Device.cpp:1465
static sk_sp< Image > Copy(Recorder *, const TextureProxyView &srcView, const SkColorInfo &, const SkIRect &subset, Budgeted, Mipmapped, SkBackingFit, std::string_view label)

◆ makeSurface()

sk_sp< SkSurface > skgpu::graphite::Device::makeSurface ( const SkImageInfo ii,
const SkSurfaceProps props 
)
overridevirtual

Reimplemented from SkDevice.

Definition at line 418 of file Device.cpp.

418 {
419 return SkSurfaces::RenderTarget(fRecorder, ii, Mipmapped::kNo, &props);
420}
SK_API sk_sp< SkSurface > RenderTarget(GrRecordingContext *context, skgpu::Budgeted budgeted, const SkImageInfo &imageInfo, int sampleCount, GrSurfaceOrigin surfaceOrigin, const SkSurfaceProps *surfaceProps, bool shouldCreateWithMips=false, bool isProtected=false)

◆ popClipStack()

void skgpu::graphite::Device::popClipStack ( )
inlineoverridevirtual

Implements SkDevice.

Definition at line 119 of file Device.h.

◆ pushClipStack()

void skgpu::graphite::Device::pushClipStack ( )
inlineoverridevirtual

Implements SkDevice.

Definition at line 118 of file Device.h.

118{ fClip.save(); }

◆ readSurfaceView()

TextureProxyView skgpu::graphite::Device::readSurfaceView ( ) const

Definition at line 1688 of file Device.cpp.

1688{ return fDC->readSurfaceView(); }

◆ recorder()

Recorder * skgpu::graphite::Device::recorder ( ) const
inlineoverridevirtual

Reimplemented from SkDevice.

Definition at line 72 of file Device.h.

72{ return fRecorder; }

◆ replaceClip()

void skgpu::graphite::Device::replaceClip ( const SkIRect rect)
overridevirtual

Implements SkDevice.

Definition at line 622 of file Device.cpp.

622 {
623 // ReplaceClip() is currently not intended to be supported in Graphite since it's only used
624 // for emulating legacy clip ops in Android Framework, and apps/devices that require that
625 // should not use Graphite. However, if it needs to be supported, we could probably implement
626 // it by:
627 // 1. Flush all pending clip element depth draws.
628 // 2. Draw a fullscreen rect to the depth attachment using a Z value greater than what's
629 // been used so far.
630 // 3. Make sure all future "unclipped" draws use this Z value instead of 0 so they aren't
631 // sorted before the depth reset.
632 // 4. Make sure all prior elements are inactive so they can't affect subsequent draws.
633 //
634 // For now, just ignore it.
635}

◆ setImmutable()

void skgpu::graphite::Device::setImmutable ( )
overridevirtual

Reimplemented from SkDevice.

Definition at line 366 of file Device.cpp.

366 {
367 if (fRecorder) {
368 // Push any pending work to the Recorder now. setImmutable() is only called by the
369 // destructor of a client-owned Surface, or explicitly in layer/filtering workflows. In
370 // both cases this is restricted to the Recorder's thread. This is in contrast to ~Device(),
371 // which might be called from another thread if it was linked to an Image used in multiple
372 // recorders.
374 fRecorder->deregisterDevice(this);
375 // Abandoning the recorder ensures that there are no further operations that can be recorded
376 // and is relied on by Image::notifyInUse() to detect when it can unlink from a Device.
377 this->abandonRecorder();
378 }
379}
void abandonRecorder()
Definition: Device.h:75

◆ snapSpecial()

sk_sp< SkSpecialImage > skgpu::graphite::Device::snapSpecial ( const SkIRect subset,
bool  forceCopy = false 
)
overridevirtual

Reimplemented from SkDevice.

Definition at line 1651 of file Device.cpp.

1651 {
1652 // NOTE: snapSpecial() can be called even after the device has been marked immutable (null
1653 // recorder), but in those cases it should not be a copy and just returns the image view.
1654 sk_sp<Image> deviceImage;
1655 SkIRect finalSubset;
1656 if (forceCopy || !this->readSurfaceView() || this->readSurfaceView().proxy()->isFullyLazy()) {
1657 deviceImage = this->makeImageCopy(
1659 finalSubset = SkIRect::MakeSize(subset.size());
1660 } else {
1661 // TODO(b/323886870): For now snapSpecial() force adds the pending work to the recorder's
1662 // root task list. Once shared atlas management is solved and DrawTasks can be nested in a
1663 // graph then this can go away in favor of auto-flushing through the image's linked device.
1664 if (fRecorder) {
1666 }
1667 deviceImage = Image::WrapDevice(sk_ref_sp(this));
1668 finalSubset = subset;
1669 }
1670
1671 if (!deviceImage) {
1672 return nullptr;
1673 }
1674
1675 // For non-copying "snapSpecial", the semantics are returning an image view of the surface data,
1676 // and relying on higher-level draw and restore logic for the contents to make sense.
1678 fRecorder, finalSubset, std::move(deviceImage), this->surfaceProps());
1679}
sk_sp< Image > makeImageCopy(const SkIRect &subset, Budgeted, Mipmapped, SkBackingFit)
Definition: Device.cpp:422
static sk_sp< Image > WrapDevice(sk_sp< Device > device)
sk_sp< SkSpecialImage > MakeGraphite(skgpu::graphite::Recorder *recorder, const SkIRect &subset, sk_sp< SkImage > image, const SkSurfaceProps &props)
constexpr SkISize size() const
Definition: SkRect.h:172
static constexpr SkIRect MakeSize(const SkISize &size)
Definition: SkRect.h:66

◆ strikeDeviceInfo()

SkStrikeDeviceInfo skgpu::graphite::Device::strikeDeviceInfo ( ) const
overridevirtual

Reimplemented from SkDevice.

Definition at line 388 of file Device.cpp.

388 {
389 return {this->surfaceProps(), this->scalerContextFlags(), &fSDFTControl};
390}
SkScalerContextFlags scalerContextFlags() const
Definition: SkDevice.cpp:498

◆ target()

TextureProxy * skgpu::graphite::Device::target ( )

Definition at line 1686 of file Device.cpp.

1686{ return fDC->target(); }

◆ useDrawCoverageMaskForMaskFilters()

bool skgpu::graphite::Device::useDrawCoverageMaskForMaskFilters ( ) const
inlineoverridevirtual

Reimplemented from SkDevice.

Definition at line 115 of file Device.h.

115{ return true; }

Friends And Related Function Documentation

◆ ClipStack

friend class ClipStack
friend

Definition at line 328 of file Device.h.


The documentation for this class was generated from the following files: