Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Attributes | Protected Member Functions | List of all members
SkSurface Class Referenceabstract

#include <SkSurface.h>

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

Public Types

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

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 Attributes

static constexpr BackendHandleAccess kFlushRead_BackendHandleAccess
 
static constexpr BackendHandleAccess kFlushWrite_BackendHandleAccess
 
static constexpr BackendHandleAccess kDiscardWrite_BackendHandleAccess
 

Protected Member Functions

 SkSurface (int width, int height, const SkSurfaceProps *surfaceProps)
 
 SkSurface (const SkImageInfo &imageInfo, const SkSurfaceProps *surfaceProps)
 
void dirtyGenerationID ()
 

Detailed Description

SkSurface is responsible for managing the pixels that a canvas draws into. The pixels can be allocated either in CPU memory (a raster surface) or on the GPU (a GrRenderTarget surface). SkSurface takes care of allocating a SkCanvas that will draw into the surface. Call surface->getCanvas() to use that canvas (but don't delete it, it is owned by the surface). SkSurface always has non-zero dimensions. If there is a request for a new surface, and either of the requested dimensions are zero, then nullptr will be returned.

Clients should not subclass SkSurface as there is a lot of internal machinery that is not publicly accessible.

Definition at line 161 of file SkSurface.h.

Member Typedef Documentation

◆ AsyncReadResult

Definition at line 461 of file SkSurface.h.

◆ ReadPixelsCallback

using SkSurface::ReadPixelsCallback = void(ReadPixelsContext, std::unique_ptr<const AsyncReadResult>)

Client-provided callback to asyncRescaleAndReadPixels() or asyncRescaleAndReadPixelsYUV420() that is called when read result is ready or on failure.

Definition at line 469 of file SkSurface.h.

◆ ReadPixelsContext

Client-provided context that is passed to client-provided ReadPixelsContext.

Definition at line 464 of file SkSurface.h.

◆ ReleaseContext

Caller data passed to TextureReleaseProc; may be nullptr.

Definition at line 249 of file SkSurface.h.

◆ RescaleGamma

Controls the gamma that rescaling occurs in for asyncRescaleAndReadPixels() and asyncRescaleAndReadPixelsYUV420().

Definition at line 474 of file SkSurface.h.

◆ RescaleMode

Definition at line 475 of file SkSurface.h.

◆ TextureReleaseProc

User function called when supplied texture may be deleted.

Definition at line 251 of file SkSurface.h.

Member Enumeration Documentation

◆ BackendHandleAccess

enum class SkSurface::BackendHandleAccess
strong
Enumerator
kFlushRead 

back-end object is readable

kFlushWrite 

back-end object is writable

kDiscardWrite 

back-end object must be overwritten

kFlushRead_BackendHandleAccess 
kFlushWrite_BackendHandleAccess 
kDiscardWrite_BackendHandleAccess 

Definition at line 229 of file SkSurface.h.

229 {
230 kFlushRead, //!< back-end object is readable
231 kFlushWrite, //!< back-end object is writable
232 kDiscardWrite, //!< back-end object must be overwritten
233
234 // Legacy names, remove when clients are migrated
238 };
static constexpr BackendHandleAccess kDiscardWrite_BackendHandleAccess
Definition SkSurface.h:245
static constexpr BackendHandleAccess kFlushRead_BackendHandleAccess
Definition SkSurface.h:241
static constexpr BackendHandleAccess kFlushWrite_BackendHandleAccess
Definition SkSurface.h:243
@ kFlushRead
back-end object is readable
@ kFlushWrite
back-end object is writable
@ kDiscardWrite
back-end object must be overwritten

◆ ContentChangeMode

Enumerator
kDiscard_ContentChangeMode 

discards surface on change

kRetain_ContentChangeMode 

preserves surface on change

Definition at line 203 of file SkSurface.h.

203 {
204 kDiscard_ContentChangeMode, //!< discards surface on change
205 kRetain_ContentChangeMode, //!< preserves surface on change
206 };
@ kDiscard_ContentChangeMode
discards surface on change
Definition SkSurface.h:204
@ kRetain_ContentChangeMode
preserves surface on change
Definition SkSurface.h:205

Constructor & Destructor Documentation

◆ SkSurface() [1/2]

SkSurface::SkSurface ( int  width,
int  height,
const SkSurfaceProps surfaceProps 
)
protected

Definition at line 55 of file SkSurface.cpp.

56 : fProps(SkSurfacePropsCopyOrDefault(props)), fWidth(width), fHeight(height)
57{
58 SkASSERT(fWidth > 0);
59 SkASSERT(fHeight > 0);
60 fGenerationID = 0;
61}
#define SkASSERT(cond)
Definition SkAssert.h:116
static SkSurfaceProps SkSurfacePropsCopyOrDefault(const SkSurfaceProps *props)
int width() const
Definition SkSurface.h:178
const SkSurfaceProps & props() const
Definition SkSurface.h:604
int height() const
Definition SkSurface.h:184

◆ SkSurface() [2/2]

SkSurface::SkSurface ( const SkImageInfo imageInfo,
const SkSurfaceProps surfaceProps 
)
protected

Definition at line 63 of file SkSurface.cpp.

64 : fProps(SkSurfacePropsCopyOrDefault(props)), fWidth(info.width()), fHeight(info.height())
65{
66 SkASSERT(fWidth > 0);
67 SkASSERT(fHeight > 0);
68 fGenerationID = 0;
69}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213

Member Function Documentation

◆ asyncRescaleAndReadPixels()

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

Makes surface pixel data available to caller, possibly asynchronously. It can also rescale the surface pixels.

Currently asynchronous reads are only supported on the GPU backend and only when the underlying 3D API supports transfer buffers and CPU/GPU synchronization primitives. In all other cases this operates synchronously.

Data is read from the source sub-rectangle, is optionally converted to a linear gamma, is rescaled to the size indicated by 'info', is then converted to the color space, color type, and alpha type of 'info'. A 'srcRect' that is not contained by the bounds of the surface causes failure.

When the pixel data is ready the caller's ReadPixelsCallback is called with a AsyncReadResult containing pixel data in the requested color type, alpha type, and color space. The AsyncReadResult will have count() == 1. Upon failure the callback is called with nullptr for AsyncReadResult. For a GPU surface this flushes work but a submit must occur to guarantee a finite time before the callback is called.

The data is valid for the lifetime of AsyncReadResult with the exception that if the SkSurface is GPU-backed the data is immediately invalidated if the context is abandoned or destroyed.

Parameters
infoinfo of the requested pixels
srcRectsubrectangle of surface to read
rescaleGammacontrols whether rescaling is done in the surface's gamma or whether the source data is transformed to a linear gamma before rescaling.
rescaleModecontrols the technique of the rescaling
callbackfunction to call with result of the read
contextpassed to callback

Definition at line 139 of file SkSurface.cpp.

144 {
145 if (!SkIRect::MakeWH(this->width(), this->height()).contains(srcRect) ||
147 callback(context, nullptr);
148 return;
149 }
151 info, srcRect, rescaleGamma, rescaleMode, callback, context);
152}
static bool SkImageInfoIsValid(const SkImageInfo &info)
static bool contains(const SkRect &r, SkPoint p)
static SkSurface_Base * asSB(SkSurface *surface)
virtual void onAsyncRescaleAndReadPixels(const SkImageInfo &, const SkIRect srcRect, RescaleGamma, RescaleMode, ReadPixelsCallback, ReadPixelsContext)
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
static constexpr SkIRect MakeWH(int32_t w, int32_t h)
Definition SkRect.h:56

◆ asyncRescaleAndReadPixelsYUV420()

void SkSurface::asyncRescaleAndReadPixelsYUV420 ( SkYUVColorSpace  yuvColorSpace,
sk_sp< SkColorSpace dstColorSpace,
const SkIRect srcRect,
const SkISize dstSize,
RescaleGamma  rescaleGamma,
RescaleMode  rescaleMode,
ReadPixelsCallback  callback,
ReadPixelsContext  context 
)

Similar to asyncRescaleAndReadPixels but performs an additional conversion to YUV. The RGB->YUV conversion is controlled by 'yuvColorSpace'. The YUV data is returned as three planes ordered y, u, v. The u and v planes are half the width and height of the resized rectangle. The y, u, and v values are single bytes. Currently this fails if 'dstSize' width and height are not even. A 'srcRect' that is not contained by the bounds of the surface causes failure.

When the pixel data is ready the caller's ReadPixelsCallback is called with a AsyncReadResult containing the planar data. The AsyncReadResult will have count() == 3. Upon failure the callback is called with nullptr for AsyncReadResult. For a GPU surface this flushes work but a submit must occur to guarantee a finite time before the callback is called.

The data is valid for the lifetime of AsyncReadResult with the exception that if the SkSurface is GPU-backed the data is immediately invalidated if the context is abandoned or destroyed.

Parameters
yuvColorSpaceThe transformation from RGB to YUV. Applied to the resized image after it is converted to dstColorSpace.
dstColorSpaceThe color space to convert the resized image to, after rescaling.
srcRectThe portion of the surface to rescale and convert to YUV planes.
dstSizeThe size to rescale srcRect to
rescaleGammacontrols whether rescaling is done in the surface's gamma or whether the source data is transformed to a linear gamma before rescaling.
rescaleModecontrols the sampling technique of the rescaling
callbackfunction to call with the planar read result
contextpassed to callback

Definition at line 154 of file SkSurface.cpp.

161 {
162 if (!SkIRect::MakeWH(this->width(), this->height()).contains(srcRect) || dstSize.isZero() ||
163 (dstSize.width() & 0b1) || (dstSize.height() & 0b1)) {
164 callback(context, nullptr);
165 return;
166 }
167 asSB(this)->onAsyncRescaleAndReadPixelsYUV420(yuvColorSpace,
168 /*readAlpha=*/false,
169 std::move(dstColorSpace),
170 srcRect,
171 dstSize,
172 rescaleGamma,
173 rescaleMode,
174 callback,
175 context);
176}
virtual void onAsyncRescaleAndReadPixelsYUV420(SkYUVColorSpace, bool readAlpha, sk_sp< SkColorSpace > dstColorSpace, SkIRect srcRect, SkISize dstSize, RescaleGamma, RescaleMode, ReadPixelsCallback, ReadPixelsContext)
constexpr int32_t width() const
Definition SkSize.h:36
constexpr int32_t height() const
Definition SkSize.h:37
bool isZero() const
Definition SkSize.h:28

◆ asyncRescaleAndReadPixelsYUVA420()

void SkSurface::asyncRescaleAndReadPixelsYUVA420 ( SkYUVColorSpace  yuvColorSpace,
sk_sp< SkColorSpace dstColorSpace,
const SkIRect srcRect,
const SkISize dstSize,
RescaleGamma  rescaleGamma,
RescaleMode  rescaleMode,
ReadPixelsCallback  callback,
ReadPixelsContext  context 
)

Identical to asyncRescaleAndReadPixelsYUV420 but a fourth plane is returned in the AsyncReadResult passed to 'callback'. The fourth plane contains the alpha chanel at the same full resolution as the Y plane.

Definition at line 178 of file SkSurface.cpp.

185 {
186 if (!SkIRect::MakeWH(this->width(), this->height()).contains(srcRect) || dstSize.isZero() ||
187 (dstSize.width() & 0b1) || (dstSize.height() & 0b1)) {
188 callback(context, nullptr);
189 return;
190 }
191 asSB(this)->onAsyncRescaleAndReadPixelsYUV420(yuvColorSpace,
192 /*readAlpha=*/true,
193 std::move(dstColorSpace),
194 srcRect,
195 dstSize,
196 rescaleGamma,
197 rescaleMode,
198 callback,
199 context);
200}

◆ capabilities()

sk_sp< const SkCapabilities > SkSurface::capabilities ( )

Returns SkCapabilities that describes the capabilities of the SkSurface's device.

Returns
SkCapabilities of SkSurface's device.

Definition at line 86 of file SkSurface.cpp.

86 {
87 return asSB(this)->onCapabilities();
88}
virtual sk_sp< const SkCapabilities > onCapabilities()

◆ characterize()

bool SkSurface::characterize ( GrSurfaceCharacterization characterization) const

Initializes GrSurfaceCharacterization that can be used to perform GPU back-end processing in a separate thread. Typically this is used to divide drawing into multiple tiles. GrDeferredDisplayListRecorder records the drawing commands for each tile.

Return true if SkSurface supports characterization. raster surface returns false.

Parameters
characterizationproperties for parallel drawing
Returns
true if supported

example: https://fiddle.skia.org/c/@Surface_characterize

Definition at line 239 of file SkSurface.cpp.

239 {
240 return asConstSB(this)->onCharacterize(characterization);
241}
static const SkSurface_Base * asConstSB(const SkSurface *surface)
virtual bool onCharacterize(GrSurfaceCharacterization *) const

◆ dirtyGenerationID()

void SkSurface::dirtyGenerationID ( )
inlineprotected

Definition at line 646 of file SkSurface.h.

646 {
647 fGenerationID = 0;
648 }

◆ draw() [1/2]

void SkSurface::draw ( SkCanvas canvas,
SkScalar  x,
SkScalar  y,
const SkPaint paint = nullptr 
)
inline

Definition at line 349 of file SkSurface.h.

349 {
350 this->draw(canvas, x, y, SkSamplingOptions(), paint);
351 }
void draw(SkCanvas *canvas, SkScalar x, SkScalar y, const SkSamplingOptions &sampling, const SkPaint *paint)
const Paint & paint
double y
double x

◆ draw() [2/2]

void SkSurface::draw ( SkCanvas canvas,
SkScalar  x,
SkScalar  y,
const SkSamplingOptions sampling,
const SkPaint paint 
)

Draws SkSurface contents to canvas, with its top-left corner at (x, y).

If SkPaint paint is not nullptr, apply SkColorFilter, alpha, SkImageFilter, and SkBlendMode.

Parameters
canvasSkCanvas drawn into
xhorizontal offset in SkCanvas
yvertical offset in SkCanvas
samplingwhat technique to use when sampling the surface pixels
paintSkPaint containing SkBlendMode, SkColorFilter, SkImageFilter, and so on; or nullptr

example: https://fiddle.skia.org/c/@Surface_draw

Definition at line 116 of file SkSurface.cpp.

117 {
118 asSB(this)->onDraw(canvas, x, y, sampling, paint);
119}
virtual void onDraw(SkCanvas *, SkScalar x, SkScalar y, const SkSamplingOptions &, const SkPaint *)

◆ generationID()

uint32_t SkSurface::generationID ( )

Returns unique value identifying the content of SkSurface. Returned value changes each time the content changes. Content is changed by drawing, or by calling notifyContentWillChange().

Returns
unique content identifier

example: https://fiddle.skia.org/c/@Surface_notifyContentWillChange

Definition at line 71 of file SkSurface.cpp.

71 {
72 if (0 == fGenerationID) {
73 fGenerationID = asSB(this)->newGenerationID();
74 }
75 return fGenerationID;
76}
uint32_t newGenerationID()

◆ getCanvas()

SkCanvas * SkSurface::getCanvas ( )

Returns SkCanvas that draws into SkSurface. Subsequent calls return the same SkCanvas. SkCanvas returned is managed and owned by SkSurface, and is deleted when SkSurface is deleted.

Returns
drawing SkCanvas for SkSurface

example: https://fiddle.skia.org/c/@Surface_getCanvas

Definition at line 82 of file SkSurface.cpp.

82 {
83 return asSB(this)->getCachedCanvas();
84}
SkCanvas * getCachedCanvas()

◆ height()

int SkSurface::height ( ) const
inline

Returns pixel row count; may be zero or greater.

Returns
number of pixel rows

Definition at line 184 of file SkSurface.h.

184{ return fHeight; }

◆ imageInfo()

virtual SkImageInfo SkSurface::imageInfo ( ) const
inlinevirtual

Returns an ImageInfo describing the surface.

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

Definition at line 188 of file SkSurface.h.

188{ return SkImageInfo::MakeUnknown(fWidth, fHeight); }
static SkImageInfo MakeUnknown()

◆ isCompatible()

bool SkSurface::isCompatible ( const GrSurfaceCharacterization characterization) const

Is this surface compatible with the provided characterization?

This method can be used to determine if an existing SkSurface is a viable destination for an GrDeferredDisplayList.

Parameters
characterizationThe characterization for which a compatibility check is desired
Returns
true if this surface is compatible with the characterization; false otherwise

Definition at line 243 of file SkSurface.cpp.

243 {
244 return asConstSB(this)->onIsCompatible(characterization);
245}
virtual bool onIsCompatible(const GrSurfaceCharacterization &) const

◆ makeImageSnapshot() [1/2]

sk_sp< SkImage > SkSurface::makeImageSnapshot ( )

Returns SkImage capturing SkSurface contents. Subsequent drawing to SkSurface contents are not captured. SkImage allocation is accounted for if SkSurface was created with skgpu::Budgeted::kYes.

Returns
SkImage initialized with SkSurface contents

example: https://fiddle.skia.org/c/@Surface_makeImageSnapshot

Definition at line 90 of file SkSurface.cpp.

90 {
91 return asSB(this)->refCachedImage();
92}
sk_sp< SkImage > refCachedImage()

◆ makeImageSnapshot() [2/2]

sk_sp< SkImage > SkSurface::makeImageSnapshot ( const SkIRect bounds)

Like the no-parameter version, this returns an image of the current surface contents. This variant takes a rectangle specifying the subset of the surface that is of interest. These bounds will be sanitized before being used.

  • If bounds extends beyond the surface, it will be trimmed to just the intersection of it and the surface.
  • If bounds does not intersect the surface, then this returns nullptr.
  • If bounds == the surface, then this is the same as calling the no-parameter variant.

example: https://fiddle.skia.org/c/@Surface_makeImageSnapshot_2

Definition at line 94 of file SkSurface.cpp.

94 {
95 const SkIRect surfBounds = { 0, 0, fWidth, fHeight };
96 SkIRect bounds = srcBounds;
97 if (!bounds.intersect(surfBounds)) {
98 return nullptr;
99 }
100 SkASSERT(!bounds.isEmpty());
101 if (bounds == surfBounds) {
102 return this->makeImageSnapshot();
103 } else {
104 return asSB(this)->onNewImageSnapshot(&bounds);
105 }
106}
virtual sk_sp< SkImage > onNewImageSnapshot(const SkIRect *subset=nullptr)
sk_sp< SkImage > makeImageSnapshot()
Definition SkSurface.cpp:90
Optional< SkRect > bounds
Definition SkRecords.h:189

◆ makeSurface() [1/2]

sk_sp< SkSurface > SkSurface::makeSurface ( const SkImageInfo imageInfo)

Returns a compatible SkSurface, or nullptr. Returned SkSurface contains the same raster, GPU, or null properties as the original. Returned SkSurface does not share the same pixels.

Returns nullptr if imageInfo width or height are zero, or if imageInfo is incompatible with SkSurface.

Parameters
imageInfowidth, height, SkColorType, SkAlphaType, SkColorSpace, of SkSurface; width and height must be greater than zero
Returns
compatible SkSurface or nullptr

example: https://fiddle.skia.org/c/@Surface_makeSurface

Definition at line 108 of file SkSurface.cpp.

108 {
109 return asSB(this)->onNewSurface(info);
110}
virtual sk_sp< SkSurface > onNewSurface(const SkImageInfo &)=0

◆ makeSurface() [2/2]

sk_sp< SkSurface > SkSurface::makeSurface ( int  width,
int  height 
)

Calls makeSurface(ImageInfo) with the same ImageInfo as this surface, but with the specified width and height.

Definition at line 112 of file SkSurface.cpp.

112 {
113 return this->makeSurface(this->imageInfo().makeWH(width, height));
114}
sk_sp< SkSurface > makeSurface(const SkImageInfo &imageInfo)
virtual SkImageInfo imageInfo() const
Definition SkSurface.h:188

◆ notifyContentWillChange()

void SkSurface::notifyContentWillChange ( ContentChangeMode  mode)

Notifies that SkSurface contents will be changed by code outside of Skia. Subsequent calls to generationID() return a different value.

TODO: Can kRetain_ContentChangeMode be deprecated?

example: https://fiddle.skia.org/c/@Surface_notifyContentWillChange

Definition at line 78 of file SkSurface.cpp.

78 {
79 sk_ignore_unused_variable(asSB(this)->aboutToDraw(mode));
80}
void sk_ignore_unused_variable(const T &)
Definition SkTemplates.h:37

◆ peekPixels()

bool SkSurface::peekPixels ( SkPixmap pixmap)

Copies SkSurface pixel address, row bytes, and SkImageInfo to SkPixmap, if address is available, and returns true. If pixel address is not available, return false and leave SkPixmap unchanged.

pixmap contents become invalid on any future change to SkSurface.

Parameters
pixmapstorage for pixel state if pixels are readable; otherwise, ignored
Returns
true if SkSurface has direct access to pixels

example: https://fiddle.skia.org/c/@Surface_peekPixels

Definition at line 121 of file SkSurface.cpp.

121 {
122 return this->getCanvas()->peekPixels(pmap);
123}
bool peekPixels(SkPixmap *pixmap)
SkCanvas * getCanvas()
Definition SkSurface.cpp:82

◆ props()

const SkSurfaceProps & SkSurface::props ( ) const
inline

Returns SkSurfaceProps for surface.

Returns
LCD striping orientation and setting for device independent fonts

Definition at line 604 of file SkSurface.h.

604{ return fProps; }

◆ readPixels() [1/3]

bool SkSurface::readPixels ( const SkBitmap dst,
int  srcX,
int  srcY 
)

Copies SkRect of pixels from SkSurface into bitmap.

Source SkRect corners are (srcX, srcY) and SkSurface (width(), height()). Destination SkRect corners are (0, 0) and (bitmap.width(), bitmap.height()). Copies each readable pixel intersecting both rectangles, without scaling, converting to bitmap.colorType() and bitmap.alphaType() if required.

Pixels are readable when SkSurface is raster, or backed by a GPU.

The destination pixel storage must be allocated by the caller.

Pixel values are converted only if SkColorType and SkAlphaType do not match. Only pixels within both source and destination rectangles are copied. dst contents outside SkRect intersection are unchanged.

Pass negative values for srcX or srcY to offset pixels across or down destination.

Does not copy, and returns false if:

  • Source and destination rectangles do not intersect.
  • SkSurface pixels could not be converted to dst.colorType() or dst.alphaType().
  • dst pixels could not be allocated.
  • dst.rowBytes() is too small to contain one row of pixels.
Parameters
dststorage for pixels copied from SkSurface
srcXoffset into readable pixels on x-axis; may be negative
srcYoffset into readable pixels on y-axis; may be negative
Returns
true if pixels were copied

example: https://fiddle.skia.org/c/@Surface_readPixels_3

Definition at line 134 of file SkSurface.cpp.

134 {
135 SkPixmap pm;
136 return bitmap.peekPixels(&pm) && this->readPixels(pm, srcX, srcY);
137}
bool readPixels(const SkPixmap &dst, int srcX, int srcY)

◆ readPixels() [2/3]

bool SkSurface::readPixels ( const SkImageInfo dstInfo,
void *  dstPixels,
size_t  dstRowBytes,
int  srcX,
int  srcY 
)

Copies SkRect of pixels from SkCanvas into dstPixels.

Source SkRect corners are (srcX, srcY) and SkSurface (width(), height()). Destination SkRect corners are (0, 0) and (dstInfo.width(), dstInfo.height()). Copies each readable pixel intersecting both rectangles, without scaling, converting to dstInfo.colorType() and dstInfo.alphaType() if required.

Pixels are readable when SkSurface is raster, or backed by a GPU.

The destination pixel storage must be allocated by the caller.

Pixel values are converted only if SkColorType and SkAlphaType do not match. Only pixels within both source and destination rectangles are copied. dstPixels contents outside SkRect intersection are unchanged.

Pass negative values for srcX or srcY to offset pixels across or down destination.

Does not copy, and returns false if:

  • Source and destination rectangles do not intersect.
  • SkSurface pixels could not be converted to dstInfo.colorType() or dstInfo.alphaType().
  • dstRowBytes is too small to contain one row of pixels.
Parameters
dstInfowidth, height, SkColorType, and SkAlphaType of dstPixels
dstPixelsstorage for pixels; dstInfo.height() times dstRowBytes, or larger
dstRowBytessize of one destination row; dstInfo.width() times pixel size, or larger
srcXoffset into readable pixels on x-axis; may be negative
srcYoffset into readable pixels on y-axis; may be negative
Returns
true if pixels were copied

Definition at line 129 of file SkSurface.cpp.

130 {
131 return this->readPixels({dstInfo, dstPixels, dstRowBytes}, srcX, srcY);
132}

◆ readPixels() [3/3]

bool SkSurface::readPixels ( const SkPixmap dst,
int  srcX,
int  srcY 
)

Copies SkRect of pixels to dst.

Source SkRect corners are (srcX, srcY) and SkSurface (width(), height()). Destination SkRect corners are (0, 0) and (dst.width(), dst.height()). Copies each readable pixel intersecting both rectangles, without scaling, converting to dst.colorType() and dst.alphaType() if required.

Pixels are readable when SkSurface is raster, or backed by a GPU.

The destination pixel storage must be allocated by the caller.

Pixel values are converted only if SkColorType and SkAlphaType do not match. Only pixels within both source and destination rectangles are copied. dst contents outside SkRect intersection are unchanged.

Pass negative values for srcX or srcY to offset pixels across or down destination.

Does not copy, and returns false if:

  • Source and destination rectangles do not intersect.
  • SkPixmap pixels could not be allocated.
  • dst.rowBytes() is too small to contain one row of pixels.
Parameters
dststorage for pixels copied from SkSurface
srcXoffset into readable pixels on x-axis; may be negative
srcYoffset into readable pixels on y-axis; may be negative
Returns
true if pixels were copied

example: https://fiddle.skia.org/c/@Surface_readPixels

Definition at line 125 of file SkSurface.cpp.

125 {
126 return this->getCanvas()->readPixels(pm, srcX, srcY);
127}
bool readPixels(const SkImageInfo &dstInfo, void *dstPixels, size_t dstRowBytes, int srcX, int srcY)
Definition SkCanvas.cpp:386

◆ recorder()

skgpu::graphite::Recorder * SkSurface::recorder ( ) const

Returns the recorder being used by the SkSurface.

Returns
the recorder, if available; nullptr otherwise

Definition at line 232 of file SkSurface.cpp.

232{ return asConstSB(this)->onGetRecorder(); }
virtual skgpu::graphite::Recorder * onGetRecorder() const

◆ recordingContext()

GrRecordingContext * SkSurface::recordingContext ( ) const

Returns the recording context being used by the SkSurface.

Returns
the recording context, if available; nullptr otherwise

Definition at line 228 of file SkSurface.cpp.

228 {
229 return asConstSB(this)->onGetRecordingContext();
230}
virtual GrRecordingContext * onGetRecordingContext() const

◆ replaceBackendTexture()

virtual bool SkSurface::replaceBackendTexture ( const GrBackendTexture backendTexture,
GrSurfaceOrigin  origin,
ContentChangeMode  mode = kRetain_ContentChangeMode,
TextureReleaseProc  = nullptr,
ReleaseContext  = nullptr 
)
pure virtual

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

Implemented in SkSurface_Ganesh, and SkSurface_Base.

◆ wait()

bool SkSurface::wait ( int  numSemaphores,
const GrBackendSemaphore waitSemaphores,
bool  deleteSemaphoresAfterWait = true 
)

Inserts a list of GPU semaphores that the current GPU-backed API must wait on before executing any more commands on the GPU for this surface. We only guarantee blocking transfer and fragment shader work, but may block earlier stages as well depending on the backend. If this call returns false, then the GPU back-end will not wait on any passed in semaphores, and the client will still own the semaphores, regardless of the value of deleteSemaphoresAfterWait.

If deleteSemaphoresAfterWait is false then Skia will not delete the semaphores. In this case it is the client's responsibility to not destroy or attempt to reuse the semaphores until it knows that Skia has finished waiting on them. This can be done by using finishedProcs on flush calls.

Parameters
numSemaphoressize of waitSemaphores array
waitSemaphoresarray of semaphore containers @paramm deleteSemaphoresAfterWait who owns and should delete the semaphores
Returns
true if GPU is waiting on semaphores

Definition at line 234 of file SkSurface.cpp.

235 {
236 return asSB(this)->onWait(numSemaphores, waitSemaphores, deleteSemaphoresAfterWait);
237}
virtual bool onWait(int numSemaphores, const GrBackendSemaphore *waitSemaphores, bool deleteSemaphoresAfterWait)

◆ width()

int SkSurface::width ( ) const
inline

Returns pixel count in each row; may be zero or greater.

Returns
number of pixel columns

Definition at line 178 of file SkSurface.h.

178{ return fWidth; }

◆ writePixels() [1/2]

void SkSurface::writePixels ( const SkBitmap src,
int  dstX,
int  dstY 
)

Copies SkRect of pixels from the src SkBitmap to the SkSurface.

Source SkRect corners are (0, 0) and (src.width(), src.height()). Destination SkRect corners are (dstX, dstY) and (dstX + Surface width(), dstY + Surface height()).

Copies each readable pixel intersecting both rectangles, without scaling, converting to SkSurface colorType() and SkSurface alphaType() if required.

Parameters
srcstorage for pixels to copy to SkSurface
dstXx-axis position relative to SkSurface to begin copy; may be negative
dstYy-axis position relative to SkSurface to begin copy; may be negative

example: https://fiddle.skia.org/c/@Surface_writePixels_2

Definition at line 221 of file SkSurface.cpp.

221 {
222 SkPixmap pm;
223 if (src.peekPixels(&pm)) {
224 this->writePixels(pm, x, y);
225 }
226}
void writePixels(const SkPixmap &src, int dstX, int dstY)

◆ writePixels() [2/2]

void SkSurface::writePixels ( const SkPixmap src,
int  dstX,
int  dstY 
)

Copies SkRect of pixels from the src SkPixmap to the SkSurface.

Source SkRect corners are (0, 0) and (src.width(), src.height()). Destination SkRect corners are (dstX, dstY) and (dstX + Surface width(), dstY + Surface height()).

Copies each readable pixel intersecting both rectangles, without scaling, converting to SkSurface colorType() and SkSurface alphaType() if required.

Parameters
srcstorage for pixels to copy to SkSurface
dstXx-axis position relative to SkSurface to begin copy; may be negative
dstYy-axis position relative to SkSurface to begin copy; may be negative

example: https://fiddle.skia.org/c/@Surface_writePixels

Definition at line 202 of file SkSurface.cpp.

202 {
203 if (pmap.addr() == nullptr || pmap.width() <= 0 || pmap.height() <= 0) {
204 return;
205 }
206
207 const SkIRect srcR = SkIRect::MakeXYWH(x, y, pmap.width(), pmap.height());
208 const SkIRect dstR = SkIRect::MakeWH(this->width(), this->height());
209 if (SkIRect::Intersects(srcR, dstR)) {
211 if (srcR.contains(dstR)) {
213 }
214 if (!asSB(this)->aboutToDraw(mode)) {
215 return;
216 }
217 asSB(this)->onWritePixels(pmap, x, y);
218 }
219}
virtual void onWritePixels(const SkPixmap &, int x, int y)=0
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
static bool Intersects(const SkIRect &a, const SkIRect &b)
Definition SkRect.h:535
static constexpr SkIRect MakeXYWH(int32_t x, int32_t y, int32_t w, int32_t h)
Definition SkRect.h:104
bool contains(int32_t x, int32_t y) const
Definition SkRect.h:463

Member Data Documentation

◆ kDiscardWrite_BackendHandleAccess

constexpr BackendHandleAccess SkSurface::kDiscardWrite_BackendHandleAccess
staticconstexpr
Initial value:

Definition at line 245 of file SkSurface.h.

◆ kFlushRead_BackendHandleAccess

constexpr BackendHandleAccess SkSurface::kFlushRead_BackendHandleAccess
staticconstexpr
Initial value:

Definition at line 241 of file SkSurface.h.

◆ kFlushWrite_BackendHandleAccess

constexpr BackendHandleAccess SkSurface::kFlushWrite_BackendHandleAccess
staticconstexpr
Initial value:

Definition at line 243 of file SkSurface.h.


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