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

Member Function Documentation

◆ device()

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

Definition at line 579 of file SkImageFilterTypes.cpp.

579{ SkASSERT(fCanvas.has_value()); return SkCanvasPriv::TopDevice(&*fCanvas); }
#define SkASSERT(cond)
Definition SkAssert.h:116
static SkDevice * TopDevice(const SkCanvas *canvas)

◆ operator bool()

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

Definition at line 577 of file SkImageFilterTypes.cpp.

577{ return fCanvas.has_value(); }

◆ operator->()

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

Definition at line 580 of file SkImageFilterTypes.cpp.

580{ SkASSERT(fCanvas.has_value()); return &*fCanvas; }

◆ snap()

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

Definition at line 582 of file SkImageFilterTypes.cpp.

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