Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
skif::FilterResult::AutoSurface Class Reference

Public Member Functions

 AutoSurface (const Context &ctx, const LayerSpace< SkIRect > &dstBounds, PixelBoundary boundary, bool renderInParameterSpace, const SkSurfaceProps *props=nullptr)
 
 operator bool () const
 
SkCanvascanvas ()
 
SkDevicedevice ()
 
SkCanvasoperator-> ()
 
FilterResult snap ()
 

Detailed Description

Definition at line 525 of file SkImageFilterTypes.cpp.

Constructor & Destructor Documentation

◆ AutoSurface()

skif::FilterResult::AutoSurface::AutoSurface ( const Context ctx,
const LayerSpace< SkIRect > &  dstBounds,
PixelBoundary  boundary,
bool  renderInParameterSpace,
const SkSurfaceProps props = nullptr 
)
inline

Definition at line 527 of file SkImageFilterTypes.cpp.

532 : fDstBounds(dstBounds)
533 , fBoundary(boundary) {
534 // We don't intersect by ctx.desiredOutput() and only use the Context to make the surface.
535 // It is assumed the caller has already accounted for the desired output, or it's a
536 // situation where the desired output shouldn't apply (e.g. this surface will be transformed
537 // to align with the actual desired output via FilterResult metadata).
538 sk_sp<SkDevice> device = nullptr;
539 if (!dstBounds.isEmpty()) {
540 fDstBounds.outset(LayerSpace<SkISize>({this->padding(), this->padding()}));
541 device = ctx.backend()->makeDevice(SkISize(fDstBounds.size()),
542 ctx.refColorSpace(),
543 props);
544 }
545
546 if (!device) {
547 return;
548 }
549
550 // Wrap the device in a canvas and use that to configure its origin and clip. This ensures
551 // the device and the canvas are in sync regardless of how the AutoSurface user intends
552 // to render.
553 ctx.markNewSurface();
554 fCanvas.emplace(std::move(device));
555 fCanvas->translate(-fDstBounds.left(), -fDstBounds.top());
556 fCanvas->clear(SkColors::kTransparent);
557 if (fBoundary == PixelBoundary::kTransparent) {
558 // Clip to the original un-padded dst bounds, ensuring that the border pixels remain
559 // fully transparent.
560 fCanvas->clipIRect(SkIRect(dstBounds));
561 } else {
562 // Otherwise clip to the possibly padded fDstBounds, if the backend made an approx-fit
563 // surface. If the bounds were padded for PixelBoundary::kInitialized, this will allow
564 // the border pixels to be rendered naturally.
565 fCanvas->clipIRect(SkIRect(fDstBounds));
566 }
567
568 if (renderInParameterSpace) {
569 fCanvas->concat(SkMatrix(ctx.mapping().layerMatrix()));
570 }
571 }
void outset(const LayerSpace< SkISize > &delta)
LayerSpace< SkISize > size() const
constexpr SkColor4f kTransparent
Definition: SkColor.h:434
Definition: SkRect.h:32
Definition: SkSize.h:16

Member Function Documentation

◆ canvas()

SkCanvas * skif::FilterResult::AutoSurface::canvas ( )
inline

Definition at line 575 of file SkImageFilterTypes.cpp.

575{ SkASSERT(fCanvas.has_value()); return &*fCanvas; }
#define SkASSERT(cond)
Definition: SkAssert.h:116

◆ device()

SkDevice * skif::FilterResult::AutoSurface::device ( )
inline

Definition at line 576 of file SkImageFilterTypes.cpp.

576{ return SkCanvasPriv::TopDevice(this->canvas()); }
static SkDevice * TopDevice(const SkCanvas *canvas)
Definition: SkCanvasPriv.h:65

◆ operator bool()

skif::FilterResult::AutoSurface::operator bool ( ) const
inlineexplicit

Definition at line 573 of file SkImageFilterTypes.cpp.

573{ return fCanvas.has_value(); }

◆ operator->()

SkCanvas * skif::FilterResult::AutoSurface::operator-> ( )
inline

Definition at line 577 of file SkImageFilterTypes.cpp.

577{ return this->canvas(); }

◆ snap()

FilterResult skif::FilterResult::AutoSurface::snap ( )
inline

Definition at line 579 of file SkImageFilterTypes.cpp.

579 {
580 if (fCanvas.has_value()) {
581 // Finish everything and mark the device as immutable so that snapSpecial() can avoid
582 // copying data.
583 fCanvas->restoreToCount(0);
584 this->device()->setImmutable();
585
586 // Snap a subset of the device with the padded dst bounds
587 SkIRect subset = SkIRect::MakeWH(fDstBounds.width(), fDstBounds.height());
589 fCanvas.reset(); // Only use the AutoSurface once
590
591 if (image && fBoundary != PixelBoundary::kUnknown) {
592 // Inset subset relative to 'image' reported size
593 const int padding = this->padding();
594 subset = SkIRect::MakeSize(image->dimensions()).makeInset(padding, padding);
595 LayerSpace<SkIPoint> origin{{fDstBounds.left() + padding,
596 fDstBounds.top() + padding}};
597 return {image->makeSubset(subset), origin, fBoundary};
598 } else {
599 // No adjustment to make
600 return {image, fDstBounds.topLeft(), PixelBoundary::kUnknown};
601 }
602 } else {
603 return {};
604 }
605 }
virtual void setImmutable()
Definition: SkDevice.h:293
virtual sk_sp< SkSpecialImage > snapSpecial(const SkIRect &subset, bool forceCopy=false)
Definition: SkDevice.cpp:315
sk_sp< SkSpecialImage > makeSubset(const SkIRect &subset) const
SkISize dimensions() const
const SkSpecialImage * image() const
LayerSpace< SkIPoint > topLeft() const
static constexpr SkIRect MakeSize(const SkISize &size)
Definition: SkRect.h:66
static constexpr SkIRect MakeWH(int32_t w, int32_t h)
Definition: SkRect.h:56
SkIRect makeInset(int32_t dx, int32_t dy) const
Definition: SkRect.h:332

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