Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Friends | List of all members
SkSurface_Base Class Referenceabstract

#include <SkSurface_Base.h>

Inheritance diagram for SkSurface_Base:
SkSurface SkRefCnt SkRefCntBase SkNullSurface SkSurface_Ganesh SkSurface_Raster skgpu::graphite::Surface

Public Types

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
 

Public Member Functions

 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
 
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
 

Friends

class SkCanvas
 
class SkSurface
 

Additional Inherited Members

- 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 38 of file SkSurface_Base.h.

Member Enumeration Documentation

◆ Type

enum class SkSurface_Base::Type
strong
Enumerator
kNull 
kGanesh 
kGraphite 
kRaster 

Definition at line 53 of file SkSurface_Base.h.

53 {
54 kNull, // intentionally associating 0 with a null canvas
55 kGanesh,
57 kRaster,
58 };

Constructor & Destructor Documentation

◆ SkSurface_Base() [1/2]

SkSurface_Base::SkSurface_Base ( int  width,
int  height,
const SkSurfaceProps props 
)

Definition at line 32 of file SkSurface_Base.cpp.

friend class SkSurface
int width() const
Definition SkSurface.h:178
const SkSurfaceProps & props() const
Definition SkSurface.h:604
int height() const
Definition SkSurface.h:184

◆ SkSurface_Base() [2/2]

SkSurface_Base::SkSurface_Base ( const SkImageInfo info,
const SkSurfaceProps props 
)

Definition at line 35 of file SkSurface_Base.cpp.

36 : SkSurface(info, props) {}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213

◆ ~SkSurface_Base()

SkSurface_Base::~SkSurface_Base ( )
override

Definition at line 38 of file SkSurface_Base.cpp.

38 {
39 // in case the canvas outsurvives us, we null the callback
40 if (fCachedCanvas) {
41 fCachedCanvas->setSurfaceBase(nullptr);
42 }
43}

Member Function Documentation

◆ getCachedCanvas()

SkCanvas * SkSurface_Base::getCachedCanvas ( )
inline

Definition at line 192 of file SkSurface_Base.h.

192 {
193 if (nullptr == fCachedCanvas) {
194 fCachedCanvas = std::unique_ptr<SkCanvas>(this->onNewCanvas());
195 if (fCachedCanvas) {
196 fCachedCanvas->setSurfaceBase(this);
197 }
198 }
199 return fCachedCanvas.get();
200}
virtual SkCanvas * onNewCanvas()=0

◆ hasCachedImage()

bool SkSurface_Base::hasCachedImage ( ) const
inline

Definition at line 172 of file SkSurface_Base.h.

172{ return fCachedImage != nullptr; }

◆ isGaneshBacked()

bool SkSurface_Base::isGaneshBacked ( ) const
inline

Definition at line 68 of file SkSurface_Base.h.

68{ return this->type() == Type::kGanesh; }
virtual Type type() const

◆ isGraphiteBacked()

bool SkSurface_Base::isGraphiteBacked ( ) const
inline

Definition at line 70 of file SkSurface_Base.h.

70{ return this->type() == Type::kGraphite; }

◆ isRasterBacked()

bool SkSurface_Base::isRasterBacked ( ) const
inline

Definition at line 66 of file SkSurface_Base.h.

66{ return this->type() == Type::kRaster; }

◆ newGenerationID()

uint32_t SkSurface_Base::newGenerationID ( )

Definition at line 127 of file SkSurface_Base.cpp.

127 {
128 SkASSERT(!fCachedCanvas || fCachedCanvas->getSurfaceBase() == this);
129 static std::atomic<uint32_t> nextID{1};
130 return nextID.fetch_add(1, std::memory_order_relaxed);
131}
#define SkASSERT(cond)
Definition SkAssert.h:116

◆ onAsyncRescaleAndReadPixels()

void SkSurface_Base::onAsyncRescaleAndReadPixels ( const SkImageInfo info,
const SkIRect  srcRect,
SkSurface::RescaleGamma  rescaleGamma,
RescaleMode  rescaleMode,
SkSurface::ReadPixelsCallback  callback,
SkSurface::ReadPixelsContext  context 
)
virtual

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

Reimplemented in skgpu::graphite::Surface, and SkSurface_Ganesh.

Definition at line 57 of file SkSurface_Base.cpp.

62 {
64 SkPixmap peek;
65 SkIRect srcRect;
66 if (this->peekPixels(&peek)) {
67 src.installPixels(peek);
68 srcRect = origSrcRect;
69 } else {
70 src.setInfo(this->imageInfo().makeDimensions(origSrcRect.size()));
71 src.allocPixels();
72 if (!this->readPixels(src, origSrcRect.x(), origSrcRect.y())) {
73 callback(context, nullptr);
74 return;
75 }
76 srcRect = SkIRect::MakeSize(src.dimensions());
77 }
78 return SkRescaleAndReadPixels(src, info, srcRect, rescaleGamma, rescaleMode, callback,
79 context);
80}
void SkRescaleAndReadPixels(SkBitmap bmp, const SkImageInfo &resultInfo, const SkIRect &srcRect, SkImage::RescaleGamma rescaleGamma, SkImage::RescaleMode rescaleMode, SkImage::ReadPixelsCallback callback, SkImage::ReadPixelsContext context)
virtual SkImageInfo imageInfo() const
Definition SkSurface.h:188
bool peekPixels(SkPixmap *pixmap)
bool readPixels(const SkPixmap &dst, int srcX, int srcY)
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
static constexpr SkIRect MakeSize(const SkISize &size)
Definition SkRect.h:66

◆ onAsyncRescaleAndReadPixelsYUV420()

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

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

Reimplemented in SkSurface_Ganesh, and skgpu::graphite::Surface.

Definition at line 82 of file SkSurface_Base.cpp.

85 {
86 // TODO: Call non-YUV asyncRescaleAndReadPixels and then make our callback convert to YUV and
87 // call client's callback.
88 callback(context, nullptr);
89}

◆ onCapabilities()

sk_sp< const SkCapabilities > SkSurface_Base::onCapabilities ( )
virtual

Reimplemented in SkSurface_Ganesh, skgpu::graphite::Surface, SkNullSurface, and SkSurface_Raster.

Definition at line 133 of file SkSurface_Base.cpp.

133 {
135}
static sk_sp< const SkCapabilities > RasterBackend()

◆ onCharacterize()

virtual bool SkSurface_Base::onCharacterize ( GrSurfaceCharacterization ) const
inlinevirtual

Reimplemented in SkSurface_Ganesh.

Definition at line 162 of file SkSurface_Base.h.

162{ return false; }

◆ onCopyOnWrite()

virtual bool SkSurface_Base::onCopyOnWrite ( ContentChangeMode  )
pure virtual

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.

Implemented in SkSurface_Ganesh, skgpu::graphite::Surface, SkNullSurface, and SkSurface_Raster.

◆ onDiscard()

virtual void SkSurface_Base::onDiscard ( )
inlinevirtual

Called as a performance hint when the Surface is allowed to make it's contents undefined.

Reimplemented in SkSurface_Ganesh.

Definition at line 135 of file SkSurface_Base.h.

135{}

◆ onDraw()

void SkSurface_Base::onDraw ( SkCanvas canvas,
SkScalar  x,
SkScalar  y,
const SkSamplingOptions sampling,
const SkPaint paint 
)
virtual

Default implementation:

image = this->newImageSnapshot(); if (image) { image->draw(canvas, ...); image->unref(); }

Reimplemented in SkNullSurface, SkSurface_Raster, and SkSurface_Ganesh.

Definition at line 49 of file SkSurface_Base.cpp.

50 {
51 auto image = this->makeImageSnapshot();
52 if (image) {
53 canvas->drawImage(image.get(), x, y, sampling, paint);
54 }
55}
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
Definition SkCanvas.h:1528
sk_sp< SkImage > makeImageSnapshot()
Definition SkSurface.cpp:90
T * get() const
Definition SkRefCnt.h:303
const Paint & paint
sk_sp< SkImage > image
Definition examples.cpp:29
double y
double x

◆ onGetRecorder()

skgpu::graphite::Recorder * SkSurface_Base::onGetRecorder ( ) const
virtual

Reimplemented in skgpu::graphite::Surface.

Definition at line 47 of file SkSurface_Base.cpp.

47{ return nullptr; }

◆ onGetRecordingContext()

GrRecordingContext * SkSurface_Base::onGetRecordingContext ( ) const
virtual

Reimplemented in SkSurface_Ganesh.

Definition at line 45 of file SkSurface_Base.cpp.

45{ return nullptr; }

◆ onIsCompatible()

virtual bool SkSurface_Base::onIsCompatible ( const GrSurfaceCharacterization ) const
inlinevirtual

Reimplemented in SkSurface_Ganesh.

Definition at line 163 of file SkSurface_Base.h.

163{ return false; }

◆ onNewCanvas()

virtual SkCanvas * SkSurface_Base::onNewCanvas ( )
pure virtual

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.

Implemented in SkSurface_Ganesh, skgpu::graphite::Surface, SkNullSurface, and SkSurface_Raster.

◆ onNewImageSnapshot()

virtual sk_sp< SkImage > SkSurface_Base::onNewImageSnapshot ( const SkIRect subset = nullptr)
inlinevirtual

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 in SkSurface_Ganesh, skgpu::graphite::Surface, SkSurface_Raster, and SkNullSurface.

Definition at line 94 of file SkSurface_Base.h.

94{ return nullptr; }

◆ onNewSurface()

virtual sk_sp< SkSurface > SkSurface_Base::onNewSurface ( const SkImageInfo )
pure virtual

◆ onRestoreBackingMutability()

virtual void SkSurface_Base::onRestoreBackingMutability ( )
inlinevirtual

Signal the surface to remind its backing store that it's mutable again. Called only when we didn't copy-on-write; we assume the copies start mutable.

Reimplemented in SkSurface_Raster.

Definition at line 150 of file SkSurface_Base.h.

150{}

◆ onWait()

virtual bool SkSurface_Base::onWait ( int  numSemaphores,
const GrBackendSemaphore waitSemaphores,
bool  deleteSemaphoresAfterWait 
)
inlinevirtual

Caused the current backend 3D API to wait on the passed in semaphores before executing new commands on the gpu. Any previously submitting commands will not be blocked by these semaphores.

Reimplemented in SkSurface_Ganesh.

Definition at line 157 of file SkSurface_Base.h.

158 {
159 return false;
160 }

◆ onWritePixels()

virtual void SkSurface_Base::onWritePixels ( const SkPixmap ,
int  x,
int  y 
)
pure virtual

◆ refCachedImage()

sk_sp< SkImage > SkSurface_Base::refCachedImage ( )
inline

Definition at line 202 of file SkSurface_Base.h.

202 {
203 if (fCachedImage) {
204 return fCachedImage;
205 }
206
207 fCachedImage = this->onNewImageSnapshot();
208
209 SkASSERT(!fCachedCanvas || fCachedCanvas->getSurfaceBase() == this);
210 return fCachedImage;
211}
virtual sk_sp< SkImage > onNewImageSnapshot(const SkIRect *subset=nullptr)

◆ replaceBackendTexture()

bool SkSurface_Base::replaceBackendTexture ( const GrBackendTexture backendTexture,
GrSurfaceOrigin  origin,
ContentChangeMode  mode,
TextureReleaseProc  ,
ReleaseContext   
)
inlineoverridevirtual

If the surface was made via MakeFromBackendTexture then it's backing texture may be substituted with a different texture. The contents of the previous backing texture are copied into the new texture. SkCanvas state is preserved. The original sample count is used. The GrBackendFormat and dimensions of replacement texture must match that of the original.

Upon success textureReleaseProc is called when it is safe to delete the texture in the backend API (accounting only for use of the texture by this surface). If SkSurface creation fails textureReleaseProc is called before this function returns.

Parameters
backendTexturethe new backing texture for the surface
modeRetain or discard current Content
TextureReleaseProcfunction called when texture can be released
ReleaseContextstate passed to textureReleaseProc

Implements SkSurface.

Reimplemented in SkSurface_Ganesh.

Definition at line 45 of file SkSurface_Base.h.

49 {
50 return false;
51 }

◆ type()

virtual Type SkSurface_Base::type ( ) const
inlinevirtual

Reimplemented in SkSurface_Ganesh, skgpu::graphite::Surface, SkNullSurface, and SkSurface_Raster.

Definition at line 63 of file SkSurface_Base.h.

63{ return Type::kNull; }

Friends And Related Symbol Documentation

◆ SkCanvas

friend class SkCanvas
friend

Definition at line 188 of file SkSurface_Base.h.

◆ SkSurface

friend class SkSurface
friend

Definition at line 189 of file SkSurface_Base.h.


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