Flutter Engine
The Flutter Engine
Public Member Functions | Static Public Member Functions | Friends | List of all members
skgpu::graphite::Surface Class Referencefinal

#include <Surface_Graphite.h>

Inheritance diagram for skgpu::graphite::Surface:
SkSurface_Base SkSurface SkRefCnt SkRefCntBase

Public Member Functions

 Surface (sk_sp< Device >)
 
 ~Surface () override
 
SkImageInfo imageInfo () const override
 
SkSurface_Base::Type type () const override
 
RecorderonGetRecorder () const override
 
SkCanvasonNewCanvas () override
 
sk_sp< SkSurfaceonNewSurface (const SkImageInfo &) override
 
sk_sp< SkImageonNewImageSnapshot (const SkIRect *subset) override
 
void onWritePixels (const SkPixmap &, int x, int y) override
 
void onAsyncRescaleAndReadPixels (const SkImageInfo &info, SkIRect srcRect, RescaleGamma rescaleGamma, RescaleMode rescaleMode, ReadPixelsCallback callback, ReadPixelsContext context) override
 
void onAsyncRescaleAndReadPixelsYUV420 (SkYUVColorSpace yuvColorSpace, bool readAlpha, sk_sp< SkColorSpace > dstColorSpace, SkIRect srcRect, SkISize dstSize, RescaleGamma rescaleGamma, RescaleMode, ReadPixelsCallback callback, ReadPixelsContext context) override
 
bool onCopyOnWrite (ContentChangeMode) override
 
sk_sp< const SkCapabilitiesonCapabilities () override
 
TextureProxyView readSurfaceView () const
 
sk_sp< ImageasImage () const
 
sk_sp< ImagemakeImageCopy (const SkIRect *subset, Mipmapped) const
 
TextureProxybackingTextureProxy () const
 
- Public Member Functions inherited from SkSurface_Base
 SkSurface_Base (int width, int height, const SkSurfaceProps *)
 
 SkSurface_Base (const SkImageInfo &, const SkSurfaceProps *)
 
 ~SkSurface_Base () override
 
bool replaceBackendTexture (const GrBackendTexture &, GrSurfaceOrigin, ContentChangeMode, TextureReleaseProc, ReleaseContext) override
 
virtual Type type () const
 
bool isRasterBacked () const
 
bool isGaneshBacked () const
 
bool isGraphiteBacked () const
 
virtual GrRecordingContextonGetRecordingContext () const
 
virtual skgpu::graphite::RecorderonGetRecorder () const
 
virtual SkCanvasonNewCanvas ()=0
 
virtual sk_sp< SkSurfaceonNewSurface (const SkImageInfo &)=0
 
virtual sk_sp< SkImageonNewImageSnapshot (const SkIRect *subset=nullptr)
 
virtual void onWritePixels (const SkPixmap &, int x, int y)=0
 
virtual void onAsyncRescaleAndReadPixels (const SkImageInfo &, const SkIRect srcRect, RescaleGamma, RescaleMode, ReadPixelsCallback, ReadPixelsContext)
 
virtual void onAsyncRescaleAndReadPixelsYUV420 (SkYUVColorSpace, bool readAlpha, sk_sp< SkColorSpace > dstColorSpace, SkIRect srcRect, SkISize dstSize, RescaleGamma, RescaleMode, ReadPixelsCallback, ReadPixelsContext)
 
virtual void onDraw (SkCanvas *, SkScalar x, SkScalar y, const SkSamplingOptions &, const SkPaint *)
 
virtual void onDiscard ()
 
virtual bool onCopyOnWrite (ContentChangeMode)=0
 
virtual void onRestoreBackingMutability ()
 
virtual bool onWait (int numSemaphores, const GrBackendSemaphore *waitSemaphores, bool deleteSemaphoresAfterWait)
 
virtual bool onCharacterize (GrSurfaceCharacterization *) const
 
virtual bool onIsCompatible (const GrSurfaceCharacterization &) const
 
virtual sk_sp< const SkCapabilitiesonCapabilities ()
 
SkCanvasgetCachedCanvas ()
 
sk_sp< SkImagerefCachedImage ()
 
bool hasCachedImage () const
 
uint32_t newGenerationID ()
 
- Public Member Functions inherited from SkSurface
bool isCompatible (const GrSurfaceCharacterization &characterization) const
 
int width () const
 
int height () const
 
virtual SkImageInfo imageInfo () const
 
uint32_t generationID ()
 
void notifyContentWillChange (ContentChangeMode mode)
 
GrRecordingContextrecordingContext () const
 
skgpu::graphite::Recorderrecorder () const
 
virtual bool replaceBackendTexture (const GrBackendTexture &backendTexture, GrSurfaceOrigin origin, ContentChangeMode mode=kRetain_ContentChangeMode, TextureReleaseProc=nullptr, ReleaseContext=nullptr)=0
 
SkCanvasgetCanvas ()
 
sk_sp< const SkCapabilitiescapabilities ()
 
sk_sp< SkSurfacemakeSurface (const SkImageInfo &imageInfo)
 
sk_sp< SkSurfacemakeSurface (int width, int height)
 
sk_sp< SkImagemakeImageSnapshot ()
 
sk_sp< SkImagemakeImageSnapshot (const SkIRect &bounds)
 
void draw (SkCanvas *canvas, SkScalar x, SkScalar y, const SkSamplingOptions &sampling, const SkPaint *paint)
 
void draw (SkCanvas *canvas, SkScalar x, SkScalar y, const SkPaint *paint=nullptr)
 
bool peekPixels (SkPixmap *pixmap)
 
bool readPixels (const SkPixmap &dst, int srcX, int srcY)
 
bool readPixels (const SkImageInfo &dstInfo, void *dstPixels, size_t dstRowBytes, int srcX, int srcY)
 
bool readPixels (const SkBitmap &dst, int srcX, int srcY)
 
void asyncRescaleAndReadPixels (const SkImageInfo &info, const SkIRect &srcRect, RescaleGamma rescaleGamma, RescaleMode rescaleMode, ReadPixelsCallback callback, ReadPixelsContext context)
 
void asyncRescaleAndReadPixelsYUV420 (SkYUVColorSpace yuvColorSpace, sk_sp< SkColorSpace > dstColorSpace, const SkIRect &srcRect, const SkISize &dstSize, RescaleGamma rescaleGamma, RescaleMode rescaleMode, ReadPixelsCallback callback, ReadPixelsContext context)
 
void asyncRescaleAndReadPixelsYUVA420 (SkYUVColorSpace yuvColorSpace, sk_sp< SkColorSpace > dstColorSpace, const SkIRect &srcRect, const SkISize &dstSize, RescaleGamma rescaleGamma, RescaleMode rescaleMode, ReadPixelsCallback callback, ReadPixelsContext context)
 
void writePixels (const SkPixmap &src, int dstX, int dstY)
 
void writePixels (const SkBitmap &src, int dstX, int dstY)
 
const SkSurfacePropsprops () const
 
bool wait (int numSemaphores, const GrBackendSemaphore *waitSemaphores, bool deleteSemaphoresAfterWait=true)
 
bool characterize (GrSurfaceCharacterization *characterization) const
 
- 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< SurfaceMake (Recorder *recorder, const SkImageInfo &info, std::string_view label, Budgeted budgeted, Mipmapped mipmapped=Mipmapped::kNo, SkBackingFit backingFit=SkBackingFit::kExact, const SkSurfaceProps *props=nullptr)
 
static sk_sp< SurfaceMakeScratch (Recorder *recorder, const SkImageInfo &info, std::string_view label, Budgeted budgeted=Budgeted::kYes, Mipmapped mipmapped=Mipmapped::kNo, SkBackingFit backingFit=SkBackingFit::kApprox)
 

Friends

void Flush (SkSurface *)
 

Additional Inherited Members

- Public Types inherited from SkSurface_Base
enum class  Type { kNull , kGanesh , kGraphite , kRaster }
 
- Public Types inherited from SkSurface
enum  ContentChangeMode { kDiscard_ContentChangeMode , kRetain_ContentChangeMode }
 
enum class  BackendHandleAccess {
  kFlushRead , kFlushWrite , kDiscardWrite , kFlushRead_BackendHandleAccess = kFlushRead ,
  kFlushWrite_BackendHandleAccess = kFlushWrite , kDiscardWrite_BackendHandleAccess = kDiscardWrite
}
 
using ReleaseContext = void *
 
using TextureReleaseProc = void(*)(ReleaseContext)
 
using AsyncReadResult = SkImage::AsyncReadResult
 
using ReadPixelsContext = void *
 
using ReadPixelsCallback = void(ReadPixelsContext, std::unique_ptr< const AsyncReadResult >)
 
using RescaleGamma = SkImage::RescaleGamma
 
using RescaleMode = SkImage::RescaleMode
 
- Static Public Attributes inherited from SkSurface
static constexpr BackendHandleAccess kFlushRead_BackendHandleAccess
 
static constexpr BackendHandleAccess kFlushWrite_BackendHandleAccess
 
static constexpr BackendHandleAccess kDiscardWrite_BackendHandleAccess
 
- Protected Member Functions inherited from SkSurface
 SkSurface (int width, int height, const SkSurfaceProps *surfaceProps)
 
 SkSurface (const SkImageInfo &imageInfo, const SkSurfaceProps *surfaceProps)
 
void dirtyGenerationID ()
 

Detailed Description

Definition at line 26 of file Surface_Graphite.h.

Constructor & Destructor Documentation

◆ Surface()

Surface::Surface ( sk_sp< Device device)

Definition at line 28 of file Surface_Graphite.cpp.

29 : SkSurface_Base(device->width(), device->height(), &device->surfaceProps())
30 , fDevice(std::move(device))
31 , fImageView(Image::WrapDevice(fDevice)) {}
SkSurface_Base(int width, int height, const SkSurfaceProps *)
static sk_sp< Image > WrapDevice(sk_sp< Device > device)
VkDevice device
Definition: main.cc:53

◆ ~Surface()

Surface::~Surface ( )
override

Definition at line 33 of file Surface_Graphite.cpp.

33 {
34 // Mark the device immutable when the Surface is destroyed to flush any pending work to the
35 // recorder and to flag the device so that any linked image views can detach from the Device
36 // when they are next drawn.
37 fDevice->setImmutable();
38}

Member Function Documentation

◆ asImage()

sk_sp< Image > Surface::asImage ( ) const

Definition at line 60 of file Surface_Graphite.cpp.

60 {
61 if (this->hasCachedImage()) {
62 SKGPU_LOG_W("Intermingling makeImageSnapshot and asImage calls may produce "
63 "unexpected results. Please use either the old _or_ new API.");
64 }
65 return fImageView;
66}
#define SKGPU_LOG_W(fmt,...)
Definition: Log.h:40
bool hasCachedImage() const

◆ backingTextureProxy()

TextureProxy * Surface::backingTextureProxy ( ) const

Definition at line 112 of file Surface_Graphite.cpp.

112{ return fDevice->target(); }

◆ imageInfo()

SkImageInfo Surface::imageInfo ( ) const
overridevirtual

Returns an ImageInfo describing the surface.

Reimplemented from SkSurface.

Definition at line 40 of file Surface_Graphite.cpp.

40 {
41 return fDevice->imageInfo();
42}

◆ Make()

static sk_sp< Surface > skgpu::graphite::Surface::Make ( Recorder recorder,
const SkImageInfo info,
std::string_view  label,
Budgeted  budgeted,
Mipmapped  mipmapped = Mipmapped::kNo,
SkBackingFit  backingFit = SkBackingFit::kExact,
const SkSurfaceProps props = nullptr 
)
inlinestatic

Definition at line 29 of file Surface_Graphite.h.

35 {
36 return Make(recorder, info, std::move(label), budgeted, mipmapped, backingFit, props,
37 LoadOp::kClear, /*registerWithRecorder=*/true);
38 }
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
const SkSurfaceProps & props() const
Definition: SkSurface.h:604
skgpu::graphite::Recorder * recorder() const
Definition: SkSurface.cpp:232
static sk_sp< Surface > Make(Recorder *recorder, const SkImageInfo &info, std::string_view label, Budgeted budgeted, Mipmapped mipmapped=Mipmapped::kNo, SkBackingFit backingFit=SkBackingFit::kExact, const SkSurfaceProps *props=nullptr)

◆ makeImageCopy()

sk_sp< Image > Surface::makeImageCopy ( const SkIRect subset,
Mipmapped  mipmapped 
) const

Definition at line 68 of file Surface_Graphite.cpp.

68 {
69 if (this->hasCachedImage()) {
70 SKGPU_LOG_W("Intermingling makeImageSnapshot and asImage calls may produce "
71 "unexpected results. Please use either the old _or_ new API.");
72 }
73
74 SkIRect srcRect = subset ? *subset : SkIRect::MakeSize(this->imageInfo().dimensions());
75 // NOTE: Must copy through fDevice and not fImageView if the surface's texture is not sampleable
76 return fDevice->makeImageCopy(srcRect, Budgeted::kNo, mipmapped, SkBackingFit::kExact);
77}
SkImageInfo imageInfo() const override
Definition: SkRect.h:32
static constexpr SkIRect MakeSize(const SkISize &size)
Definition: SkRect.h:66

◆ MakeScratch()

static sk_sp< Surface > skgpu::graphite::Surface::MakeScratch ( Recorder recorder,
const SkImageInfo info,
std::string_view  label,
Budgeted  budgeted = Budgeted::kYes,
Mipmapped  mipmapped = Mipmapped::kNo,
SkBackingFit  backingFit = SkBackingFit::kApprox 
)
inlinestatic

Definition at line 43 of file Surface_Graphite.h.

48 {
49 return Make(recorder, info, std::move(label), budgeted, mipmapped, backingFit,
50 /*props=*/nullptr, LoadOp::kDiscard, /*registerWithRecorder=*/false);
51 }

◆ onAsyncRescaleAndReadPixels()

void Surface::onAsyncRescaleAndReadPixels ( const SkImageInfo info,
SkIRect  srcRect,
RescaleGamma  rescaleGamma,
RescaleMode  rescaleMode,
ReadPixelsCallback  callback,
ReadPixelsContext  context 
)
overridevirtual

Default implementation does a rescale/read and then calls the callback.

Reimplemented from SkSurface_Base.

Definition at line 85 of file Surface_Graphite.cpp.

90 {
91 // Not supported for Graphite. Use Context::asyncRescaleAndReadPixels instead.
92 callback(context, nullptr);
93}
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback

◆ onAsyncRescaleAndReadPixelsYUV420()

void Surface::onAsyncRescaleAndReadPixelsYUV420 ( SkYUVColorSpace  yuvColorSpace,
bool  readAlpha,
sk_sp< SkColorSpace dstColorSpace,
SkIRect  srcRect,
SkISize  dstSize,
RescaleGamma  rescaleGamma,
RescaleMode  ,
ReadPixelsCallback  callback,
ReadPixelsContext  context 
)
overridevirtual

Default implementation does a rescale/read/yuv conversion and then calls the callback.

Reimplemented from SkSurface_Base.

Definition at line 95 of file Surface_Graphite.cpp.

103 {
104 // Not supported for Graphite. Use Context::asyncRescaleAndReadPixelsYUV420 instead.
105 callback(context, nullptr);
106}

◆ onCapabilities()

sk_sp< const SkCapabilities > Surface::onCapabilities ( )
overridevirtual

Reimplemented from SkSurface_Base.

Definition at line 108 of file Surface_Graphite.cpp.

108 {
109 return fDevice->recorder()->priv().caps()->capabilities();
110}

◆ onCopyOnWrite()

bool Surface::onCopyOnWrite ( ContentChangeMode  )
overridevirtual

If the surface is about to change, we call this so that our subclass can optionally fork their backend (copy-on-write) in case it was being shared with the cachedImage.

Returns false if the backing cannot be un-shared.

Implements SkSurface_Base.

Definition at line 83 of file Surface_Graphite.cpp.

83{ return true; }

◆ onGetRecorder()

Recorder * Surface::onGetRecorder ( ) const
overridevirtual

Reimplemented from SkSurface_Base.

Definition at line 44 of file Surface_Graphite.cpp.

44{ return fDevice->recorder(); }

◆ onNewCanvas()

SkCanvas * Surface::onNewCanvas ( )
overridevirtual

Allocate a canvas that will draw into this surface. We will cache this canvas, to return the same object to the caller multiple times. We take ownership, and will call unref() on the canvas when we go out of scope.

Implements SkSurface_Base.

Definition at line 50 of file Surface_Graphite.cpp.

50{ return new SkCanvas(fDevice); }
friend class SkCanvas

◆ onNewImageSnapshot()

sk_sp< SkImage > Surface::onNewImageSnapshot ( const SkIRect subset)
overridevirtual

Allocate an SkImage that represents the current contents of the surface. This needs to be able to outlive the surface itself (if need be), and must faithfully represent the current contents, even if the surface is changed after this called (e.g. it is drawn to via its canvas).

If a subset is specified, the the impl must make a copy, rather than try to wait on copy-on-write.

Reimplemented from SkSurface_Base.

Definition at line 56 of file Surface_Graphite.cpp.

56 {
57 return this->makeImageCopy(subset, fDevice->target()->mipmapped());
58}
sk_sp< Image > makeImageCopy(const SkIRect *subset, Mipmapped) const

◆ onNewSurface()

sk_sp< SkSurface > Surface::onNewSurface ( const SkImageInfo ii)
overridevirtual

Implements SkSurface_Base.

Definition at line 52 of file Surface_Graphite.cpp.

52 {
53 return fDevice->makeSurface(ii, this->props());
54}

◆ onWritePixels()

void Surface::onWritePixels ( const SkPixmap pixmap,
int  x,
int  y 
)
overridevirtual

Implements SkSurface_Base.

Definition at line 79 of file Surface_Graphite.cpp.

79 {
80 fDevice->writePixels(pixmap, x, y);
81}
double y
double x

◆ readSurfaceView()

TextureProxyView Surface::readSurfaceView ( ) const

Definition at line 46 of file Surface_Graphite.cpp.

46 {
47 return fDevice->readSurfaceView();
48}

◆ type()

SkSurface_Base::Type skgpu::graphite::Surface::type ( ) const
inlineoverridevirtual

Reimplemented from SkSurface_Base.

Definition at line 60 of file Surface_Graphite.h.

Friends And Related Function Documentation

◆ Flush

void Flush ( SkSurface )
friend

Definition at line 25 of file GpuTools.h.

25 {
26#if defined(SK_GANESH)
28#endif
29#if defined(SK_GRAPHITE)
31#endif
32}
VkSurfaceKHR surface
Definition: main.cc:49
SK_API GrSemaphoresSubmitted Flush(sk_sp< SkSurface >)
void Flush(sk_sp< SkSurface > surface)

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