Skia
2D Graphics Library
SkSurface Class Reference

#include <SkSurface.h>

Inheritance diagram for SkSurface:

Public Types

enum  ContentChangeMode { kDiscard_ContentChangeMode, kRetain_ContentChangeMode }
 
enum  BackendHandleAccess { kFlushRead_BackendHandleAccess, kFlushWrite_BackendHandleAccess, kDiscardWrite_BackendHandleAccess }
 
enum  BackendSurfaceAccess { BackendSurfaceAccess::kNoAccess, BackendSurfaceAccess::kPresent }
 
typedef void * ReleaseContext
 Caller data passed to RenderTarget/TextureReleaseProc; may be nullptr. More...
 
typedef void(* RenderTargetReleaseProc) (ReleaseContext releaseContext)
 User function called when supplied render target may be deleted. More...
 
typedef void(* TextureReleaseProc) (ReleaseContext releaseContext)
 User function called when supplied texture may be deleted. More...
 
using AsyncReadResult = SkImage::AsyncReadResult
 
using ReadPixelsContext = void *
 Client-provided context that is passed to client-provided ReadPixelsContext. More...
 
using 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. More...
 
using RescaleGamma = SkImage::RescaleGamma
 Controls the gamma that rescaling occurs in for asyncRescaleAndReadPixels() and asyncRescaleAndReadPixelsYUV420(). More...
 

Public Member Functions

bool isCompatible (const SkSurfaceCharacterization &characterization) const
 Is this surface compatible with the provided characterization? More...
 
int width () const
 Returns pixel count in each row; may be zero or greater. More...
 
int height () const
 Returns pixel row count; may be zero or greater. More...
 
SkImageInfo imageInfo ()
 Returns an ImageInfo describing the surface. More...
 
uint32_t generationID ()
 Returns unique value identifying the content of SkSurface. More...
 
void notifyContentWillChange (ContentChangeMode mode)
 Notifies that SkSurface contents will be changed by code outside of Skia. More...
 
GrRecordingContextrecordingContext ()
 Returns the recording context being used by the SkSurface. More...
 
GrBackendTexture getBackendTexture (BackendHandleAccess backendHandleAccess)
 Retrieves the back-end texture. More...
 
GrBackendRenderTarget getBackendRenderTarget (BackendHandleAccess backendHandleAccess)
 Retrieves the back-end render target. More...
 
bool replaceBackendTexture (const GrBackendTexture &backendTexture, GrSurfaceOrigin origin, ContentChangeMode mode=kRetain_ContentChangeMode, TextureReleaseProc textureReleaseProc=nullptr, ReleaseContext releaseContext=nullptr)
 If the surface was made via MakeFromBackendTexture then it's backing texture may be substituted with a different texture. More...
 
SkCanvasgetCanvas ()
 Returns SkCanvas that draws into SkSurface. More...
 
sk_sp< SkSurfacemakeSurface (const SkImageInfo &imageInfo)
 Returns a compatible SkSurface, or nullptr. More...
 
sk_sp< SkSurfacemakeSurface (int width, int height)
 Calls makeSurface(ImageInfo) with the same ImageInfo as this surface, but with the specified width and height. More...
 
sk_sp< SkImagemakeImageSnapshot ()
 Returns SkImage capturing SkSurface contents. More...
 
sk_sp< SkImagemakeImageSnapshot (const SkIRect &bounds)
 Like the no-parameter version, this returns an image of the current surface contents. More...
 
void draw (SkCanvas *canvas, SkScalar x, SkScalar y, const SkPaint *paint)
 Draws SkSurface contents to canvas, with its top-left corner at (x, y). More...
 
bool peekPixels (SkPixmap *pixmap)
 Copies SkSurface pixel address, row bytes, and SkImageInfo to SkPixmap, if address is available, and returns true. More...
 
bool readPixels (const SkPixmap &dst, int srcX, int srcY)
 Copies SkRect of pixels to dst. More...
 
bool readPixels (const SkImageInfo &dstInfo, void *dstPixels, size_t dstRowBytes, int srcX, int srcY)
 Copies SkRect of pixels from SkCanvas into dstPixels. More...
 
bool readPixels (const SkBitmap &dst, int srcX, int srcY)
 Copies SkRect of pixels from SkSurface into bitmap. More...
 
void asyncRescaleAndReadPixels (const SkImageInfo &info, const SkIRect &srcRect, RescaleGamma rescaleGamma, SkFilterQuality rescaleQuality, ReadPixelsCallback callback, ReadPixelsContext context)
 Makes surface pixel data available to caller, possibly asynchronously. More...
 
void asyncRescaleAndReadPixelsYUV420 (SkYUVColorSpace yuvColorSpace, sk_sp< SkColorSpace > dstColorSpace, const SkIRect &srcRect, const SkISize &dstSize, RescaleGamma rescaleGamma, SkFilterQuality rescaleQuality, ReadPixelsCallback callback, ReadPixelsContext context)
 Similar to asyncRescaleAndReadPixels but performs an additional conversion to YUV. More...
 
void writePixels (const SkPixmap &src, int dstX, int dstY)
 Copies SkRect of pixels from the src SkPixmap to the SkSurface. More...
 
void writePixels (const SkBitmap &src, int dstX, int dstY)
 Copies SkRect of pixels from the src SkBitmap to the SkSurface. More...
 
const SkSurfacePropsprops () const
 Returns SkSurfaceProps for surface. More...
 
void flushAndSubmit (bool syncCpu=false)
 Call to ensure all reads/writes of the surface have been issued to the underlying 3D API. More...
 
GrSemaphoresSubmitted flush (BackendSurfaceAccess access, const GrFlushInfo &info)
 Issues pending SkSurface commands to the GPU-backed API objects and resolves any SkSurface MSAA. More...
 
GrSemaphoresSubmitted flush (const GrFlushInfo &info, const GrBackendSurfaceMutableState *newState=nullptr)
 Issues pending SkSurface commands to the GPU-backed API objects and resolves any SkSurface MSAA. More...
 
void flush ()
 
bool 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. More...
 
bool characterize (SkSurfaceCharacterization *characterization) const
 Initializes SkSurfaceCharacterization that can be used to perform GPU back-end processing in a separate thread. More...
 
bool draw (sk_sp< const SkDeferredDisplayList > deferredDisplayList, int xOffset=0, int yOffset=0)
 Draws the deferred display list created via a SkDeferredDisplayListRecorder. More...
 
bool unique () const
 May return true if the caller is the only owner. More...
 
void ref () const
 Increment the reference count. More...
 
void unref () const
 Decrement the reference count. More...
 

Static Public Member Functions

static sk_sp< SkSurfaceMakeRasterDirect (const SkImageInfo &imageInfo, void *pixels, size_t rowBytes, const SkSurfaceProps *surfaceProps=nullptr)
 Allocates raster SkSurface. More...
 
static sk_sp< SkSurfaceMakeRasterDirect (const SkPixmap &pm, const SkSurfaceProps *props=nullptr)
 
static sk_sp< SkSurfaceMakeRasterDirectReleaseProc (const SkImageInfo &imageInfo, void *pixels, size_t rowBytes, void(*releaseProc)(void *pixels, void *context), void *context, const SkSurfaceProps *surfaceProps=nullptr)
 Allocates raster SkSurface. More...
 
static sk_sp< SkSurfaceMakeRaster (const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
 Allocates raster SkSurface. More...
 
static sk_sp< SkSurfaceMakeRaster (const SkImageInfo &imageInfo, const SkSurfaceProps *props=nullptr)
 Allocates raster SkSurface. More...
 
static sk_sp< SkSurfaceMakeRasterN32Premul (int width, int height, const SkSurfaceProps *surfaceProps=nullptr)
 Allocates raster SkSurface. More...
 
static sk_sp< SkSurfaceMakeFromBackendTexture (GrRecordingContext *context, const GrBackendTexture &backendTexture, GrSurfaceOrigin origin, int sampleCnt, SkColorType colorType, sk_sp< SkColorSpace > colorSpace, const SkSurfaceProps *surfaceProps, TextureReleaseProc textureReleaseProc=nullptr, ReleaseContext releaseContext=nullptr)
 Wraps a GPU-backed texture into SkSurface. More...
 
static sk_sp< SkSurfaceMakeFromBackendRenderTarget (GrRecordingContext *context, const GrBackendRenderTarget &backendRenderTarget, GrSurfaceOrigin origin, SkColorType colorType, sk_sp< SkColorSpace > colorSpace, const SkSurfaceProps *surfaceProps, RenderTargetReleaseProc releaseProc=nullptr, ReleaseContext releaseContext=nullptr)
 Wraps a GPU-backed buffer into SkSurface. More...
 
static sk_sp< SkSurfaceMakeRenderTarget (GrRecordingContext *context, SkBudgeted budgeted, const SkImageInfo &imageInfo, int sampleCount, GrSurfaceOrigin surfaceOrigin, const SkSurfaceProps *surfaceProps, bool shouldCreateWithMips=false)
 Returns SkSurface on GPU indicated by context. More...
 
static sk_sp< SkSurfaceMakeRenderTarget (GrRecordingContext *context, SkBudgeted budgeted, const SkImageInfo &imageInfo, int sampleCount, const SkSurfaceProps *surfaceProps)
 Returns SkSurface on GPU indicated by context. More...
 
static sk_sp< SkSurfaceMakeRenderTarget (GrRecordingContext *context, SkBudgeted budgeted, const SkImageInfo &imageInfo)
 Returns SkSurface on GPU indicated by context. More...
 
static sk_sp< SkSurfaceMakeRenderTarget (GrRecordingContext *context, const SkSurfaceCharacterization &characterization, SkBudgeted budgeted)
 Returns SkSurface on GPU indicated by context that is compatible with the provided characterization. More...
 
static sk_sp< SkSurfaceMakeNull (int width, int height)
 Returns SkSurface without backing pixels. More...
 

Static Public Attributes

static const BackendHandleAccess kFlushRead_TextureHandleAccess
 Deprecated. More...
 
static const BackendHandleAccess kFlushWrite_TextureHandleAccess
 Deprecated. More...
 
static const BackendHandleAccess kDiscardWrite_TextureHandleAccess
 Deprecated. More...
 

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.

Member Typedef Documentation

◆ AsyncReadResult

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

◆ ReadPixelsContext

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

◆ ReleaseContext

Caller data passed to RenderTarget/TextureReleaseProc; may be nullptr.

◆ RenderTargetReleaseProc

typedef void(* SkSurface::RenderTargetReleaseProc) (ReleaseContext releaseContext)

User function called when supplied render target may be deleted.

◆ RescaleGamma

◆ TextureReleaseProc

typedef void(* SkSurface::TextureReleaseProc) (ReleaseContext releaseContext)

User function called when supplied texture may be deleted.

Member Enumeration Documentation

◆ BackendHandleAccess

Enumerator
kFlushRead_BackendHandleAccess 

back-end object is readable

kFlushWrite_BackendHandleAccess 

back-end object is writable

kDiscardWrite_BackendHandleAccess 

back-end object must be overwritten

◆ BackendSurfaceAccess

Enumerator
kNoAccess 

back-end object will not be used by client

kPresent 

back-end surface will be used for presenting to screen

◆ ContentChangeMode

Enumerator
kDiscard_ContentChangeMode 

discards surface on change

kRetain_ContentChangeMode 

preserves surface on change

Constructor & Destructor Documentation

◆ SkSurface() [1/2]

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

◆ SkSurface() [2/2]

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

Member Function Documentation

◆ asyncRescaleAndReadPixels()

void SkSurface::asyncRescaleAndReadPixels ( const SkImageInfo info,
const SkIRect srcRect,
RescaleGamma  rescaleGamma,
SkFilterQuality  rescaleQuality,
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.
rescaleQualitycontrols the quality (and cost) of the rescaling
callbackfunction to call with result of the read
contextpassed to callback

◆ asyncRescaleAndReadPixelsYUV420()

void SkSurface::asyncRescaleAndReadPixelsYUV420 ( SkYUVColorSpace  yuvColorSpace,
sk_sp< SkColorSpace dstColorSpace,
const SkIRect srcRect,
const SkISize dstSize,
RescaleGamma  rescaleGamma,
SkFilterQuality  rescaleQuality,
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.
rescaleQualitycontrols the quality (and cost) of the rescaling
callbackfunction to call with the planar read result
contextpassed to callback

◆ characterize()

bool SkSurface::characterize ( SkSurfaceCharacterization characterization) const

Initializes SkSurfaceCharacterization that can be used to perform GPU back-end processing in a separate thread.

Typically this is used to divide drawing into multiple tiles. SkDeferredDisplayListRecorder 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

◆ dirtyGenerationID()

void SkSurface::dirtyGenerationID ( )
inlineprotected

◆ draw() [1/2]

bool SkSurface::draw ( sk_sp< const SkDeferredDisplayList deferredDisplayList,
int  xOffset = 0,
int  yOffset = 0 
)

Draws the deferred display list created via a SkDeferredDisplayListRecorder.

If the deferred display list is not compatible with this SkSurface, the draw is skipped and false is return.

The xOffset and yOffset parameters are experimental and, if not both zero, will cause the draw to be ignored. When implemented, if xOffset or yOffset are non-zero, the DDL will be drawn offset by that amount into the surface.

Parameters
deferredDisplayListdrawing commands
xOffsetx-offset at which to draw the DDL
yOffsety-offset at which to draw the DDL
Returns
false if deferredDisplayList is not compatible

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

◆ draw() [2/2]

void SkSurface::draw ( SkCanvas canvas,
SkScalar  x,
SkScalar  y,
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
paintSkPaint containing SkBlendMode, SkColorFilter, SkImageFilter, and so on; or nullptr

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

◆ flush() [1/3]

void SkSurface::flush ( )
inline

◆ flush() [2/3]

GrSemaphoresSubmitted SkSurface::flush ( BackendSurfaceAccess  access,
const GrFlushInfo info 
)

Issues pending SkSurface commands to the GPU-backed API objects and resolves any SkSurface MSAA.

A call to GrDirectContext::submit is always required to ensure work is actually sent to the gpu. Some specific API details: GL: Commands are actually sent to the driver, but glFlush is never called. Thus some sync objects from the flush will not be valid until a submission occurs.

Vulkan/Metal/D3D/Dawn: Commands are recorded to the backend APIs corresponding command buffer or encoder objects. However, these objects are not sent to the gpu until a submission occurs.

The work that is submitted to the GPU will be dependent on the BackendSurfaceAccess that is passed in.

If BackendSurfaceAccess::kNoAccess is passed in all commands will be issued to the GPU.

If BackendSurfaceAccess::kPresent is passed in and the backend API is not Vulkan, it is treated the same as kNoAccess. If the backend API is Vulkan, the VkImage that backs the SkSurface will be transferred back to its original queue. If the SkSurface was created by wrapping a VkImage, the queue will be set to the queue which was originally passed in on the GrVkImageInfo. Additionally, if the original queue was not external or foreign the layout of the VkImage will be set to VK_IMAGE_LAYOUT_PRESENT_SRC_KHR.

The GrFlushInfo describes additional options to flush. Please see documentation at GrFlushInfo for more info.

If the return is GrSemaphoresSubmitted::kYes, only initialized GrBackendSemaphores will be submitted to the gpu during the next submit call (it is possible Skia failed to create a subset of the semaphores). The client should not wait on these semaphores until after submit has been called, but must keep them alive until then. If a submit flag was passed in with the flush these valid semaphores can we waited on immediately. If this call returns GrSemaphoresSubmitted::kNo, the GPU backend will not submit any semaphores to be signaled on the GPU. Thus the client should not have the GPU wait on any of the semaphores passed in with the GrFlushInfo. Regardless of whether semaphores were submitted to the GPU or not, the client is still responsible for deleting any initialized semaphores. Regardleess of semaphore submission the context will still be flushed. It should be emphasized that a return value of GrSemaphoresSubmitted::kNo does not mean the flush did not happen. It simply means there were no semaphores submitted to the GPU. A caller should only take this as a failure if they passed in semaphores to be submitted.

Pending surface commands are flushed regardless of the return result.

Parameters
accesstype of access the call will do on the backend object after flush
infoflush options

◆ flush() [3/3]

GrSemaphoresSubmitted SkSurface::flush ( const GrFlushInfo info,
const GrBackendSurfaceMutableState newState = nullptr 
)

Issues pending SkSurface commands to the GPU-backed API objects and resolves any SkSurface MSAA.

A call to GrDirectContext::submit is always required to ensure work is actually sent to the gpu. Some specific API details: GL: Commands are actually sent to the driver, but glFlush is never called. Thus some sync objects from the flush will not be valid until a submission occurs.

Vulkan/Metal/D3D/Dawn: Commands are recorded to the backend APIs corresponding command buffer or encoder objects. However, these objects are not sent to the gpu until a submission occurs.

The GrFlushInfo describes additional options to flush. Please see documentation at GrFlushInfo for more info.

If a GrBackendSurfaceMutableState is passed in, at the end of the flush we will transition the surface to be in the state requested by the GrBackendSurfaceMutableState. If the surface (or SkImage or GrBackendSurface wrapping the same backend object) is used again after this flush the state may be changed and no longer match what is requested here. This is often used if the surface will be used for presenting or external use and the client wants backend object to be prepped for that use. A finishedProc or semaphore on the GrFlushInfo will also include the work for any requested state change.

If the backend API is Vulkan, the caller can set the GrBackendSurfaceMutableState's VkImageLayout to VK_IMAGE_LAYOUT_UNDEFINED or queueFamilyIndex to VK_QUEUE_FAMILY_IGNORED to tell Skia to not change those respective states.

If the return is GrSemaphoresSubmitted::kYes, only initialized GrBackendSemaphores will be submitted to the gpu during the next submit call (it is possible Skia failed to create a subset of the semaphores). The client should not wait on these semaphores until after submit has been called, but must keep them alive until then. If a submit flag was passed in with the flush these valid semaphores can we waited on immediately. If this call returns GrSemaphoresSubmitted::kNo, the GPU backend will not submit any semaphores to be signaled on the GPU. Thus the client should not have the GPU wait on any of the semaphores passed in with the GrFlushInfo. Regardless of whether semaphores were submitted to the GPU or not, the client is still responsible for deleting any initialized semaphores. Regardleess of semaphore submission the context will still be flushed. It should be emphasized that a return value of GrSemaphoresSubmitted::kNo does not mean the flush did not happen. It simply means there were no semaphores submitted to the GPU. A caller should only take this as a failure if they passed in semaphores to be submitted.

Pending surface commands are flushed regardless of the return result.

Parameters
infoflush options
accessoptional state change request after flush

◆ flushAndSubmit()

void SkSurface::flushAndSubmit ( bool  syncCpu = false)

Call to ensure all reads/writes of the surface have been issued to the underlying 3D API.

Skia will correctly order its own draws and pixel operations. This must to be used to ensure correct ordering when the surface backing store is accessed outside Skia (e.g. direct use of the 3D API or a windowing system). GrDirectContext has additional flush and submit methods that apply to all surfaces and images created from a GrDirectContext. This is equivalent to calling SkSurface::flush with a default GrFlushInfo followed by GrDirectContext::submit(syncCpu).

◆ 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

◆ getBackendRenderTarget()

GrBackendRenderTarget SkSurface::getBackendRenderTarget ( BackendHandleAccess  backendHandleAccess)

Retrieves the back-end render target.

If SkSurface has no back-end render target, an invalid object is returned. Call GrBackendRenderTarget::isValid to determine if the result is valid.

The returned GrBackendRenderTarget should be discarded if the SkSurface is drawn to or deleted.

Returns
GPU render target reference; invalid on failure

◆ getBackendTexture()

GrBackendTexture SkSurface::getBackendTexture ( BackendHandleAccess  backendHandleAccess)

Retrieves the back-end texture.

If SkSurface has no back-end texture, an invalid object is returned. Call GrBackendTexture::isValid to determine if the result is valid.

The returned GrBackendTexture should be discarded if the SkSurface is drawn to or deleted.

Returns
GPU texture reference; invalid on failure

◆ 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

◆ height()

int SkSurface::height ( ) const
inline

Returns pixel row count; may be zero or greater.

Returns
number of pixel rows

◆ imageInfo()

SkImageInfo SkSurface::imageInfo ( )

Returns an ImageInfo describing the surface.

◆ isCompatible()

bool SkSurface::isCompatible ( const SkSurfaceCharacterization 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 SkDeferredDisplayList.

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

◆ MakeFromBackendRenderTarget()

static sk_sp<SkSurface> SkSurface::MakeFromBackendRenderTarget ( GrRecordingContext context,
const GrBackendRenderTarget backendRenderTarget,
GrSurfaceOrigin  origin,
SkColorType  colorType,
sk_sp< SkColorSpace colorSpace,
const SkSurfaceProps surfaceProps,
RenderTargetReleaseProc  releaseProc = nullptr,
ReleaseContext  releaseContext = nullptr 
)
static

Wraps a GPU-backed buffer into SkSurface.

Caller must ensure backendRenderTarget is valid for the lifetime of returned SkSurface.

SkSurface is returned if all parameters are valid. backendRenderTarget is valid if its pixel configuration agrees with colorSpace and context; for instance, if backendRenderTarget has an sRGB configuration, then context must support sRGB, and colorSpace must be present. Further, backendRenderTarget width and height must not exceed context capabilities, and the context must be able to support back-end render targets.

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

If SK_SUPPORT_GPU is defined as zero, has no effect and returns nullptr.

Parameters
contextGPU context
backendRenderTargetGPU intermediate memory buffer
colorSpacerange of colors
surfacePropsLCD striping orientation and setting for device independent fonts; may be nullptr
releaseProcfunction called when backendRenderTarget can be released
releaseContextstate passed to releaseProc
Returns
SkSurface if all parameters are valid; otherwise, nullptr

◆ MakeFromBackendTexture()

static sk_sp<SkSurface> SkSurface::MakeFromBackendTexture ( GrRecordingContext context,
const GrBackendTexture backendTexture,
GrSurfaceOrigin  origin,
int  sampleCnt,
SkColorType  colorType,
sk_sp< SkColorSpace colorSpace,
const SkSurfaceProps surfaceProps,
TextureReleaseProc  textureReleaseProc = nullptr,
ReleaseContext  releaseContext = nullptr 
)
static

Wraps a GPU-backed texture into SkSurface.

Caller must ensure the texture is valid for the lifetime of returned SkSurface. If sampleCnt greater than zero, creates an intermediate MSAA SkSurface which is used for drawing backendTexture.

SkSurface is returned if all parameters are valid. backendTexture is valid if its pixel configuration agrees with colorSpace and context; for instance, if backendTexture has an sRGB configuration, then context must support sRGB, and colorSpace must be present. Further, backendTexture width and height must not exceed context capabilities, and the context must be able to support back-end textures.

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.

If SK_SUPPORT_GPU is defined as zero, has no effect and returns nullptr.

Parameters
contextGPU context
backendTexturetexture residing on GPU
sampleCntsamples per pixel, or 0 to disable full scene anti-aliasing
colorSpacerange of colors; may be nullptr
surfacePropsLCD striping orientation and setting for device independent fonts; may be nullptr
textureReleaseProcfunction called when texture can be released
releaseContextstate passed to textureReleaseProc
Returns
SkSurface if all parameters are valid; otherwise, nullptr

◆ 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 SkBudgeted::kYes.

Returns
SkImage initialized with SkSurface contents

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

◆ 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

◆ MakeNull()

static sk_sp<SkSurface> SkSurface::MakeNull ( int  width,
int  height 
)
static

Returns SkSurface without backing pixels.

Drawing to SkCanvas returned from SkSurface has no effect. Calling makeImageSnapshot() on returned SkSurface returns nullptr.

Parameters
widthone or greater
heightone or greater
Returns
SkSurface if width and height are positive; otherwise, nullptr

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

◆ MakeRaster() [1/2]

static sk_sp<SkSurface> SkSurface::MakeRaster ( const SkImageInfo imageInfo,
const SkSurfaceProps props = nullptr 
)
inlinestatic

Allocates raster SkSurface.

SkCanvas returned by SkSurface draws directly into pixels. Allocates and zeroes pixel memory. Pixel memory size is imageInfo.height() times imageInfo.minRowBytes(). Pixel memory is deleted when SkSurface is deleted.

SkSurface is returned if all parameters are valid. Valid parameters include: info dimensions are greater than zero; info contains SkColorType and SkAlphaType supported by raster surface.

Parameters
imageInfowidth, height, SkColorType, SkAlphaType, SkColorSpace, of raster surface; width and height must be greater than zero
propsLCD striping orientation and setting for device independent fonts; may be nullptr
Returns
SkSurface if all parameters are valid; otherwise, nullptr

◆ MakeRaster() [2/2]

static sk_sp<SkSurface> SkSurface::MakeRaster ( const SkImageInfo imageInfo,
size_t  rowBytes,
const SkSurfaceProps surfaceProps 
)
static

Allocates raster SkSurface.

SkCanvas returned by SkSurface draws directly into pixels. Allocates and zeroes pixel memory. Pixel memory size is imageInfo.height() times rowBytes, or times imageInfo.minRowBytes() if rowBytes is zero. Pixel memory is deleted when SkSurface is deleted.

SkSurface is returned if all parameters are valid. Valid parameters include: info dimensions are greater than zero; info contains SkColorType and SkAlphaType supported by raster surface; rowBytes is large enough to contain info width pixels of SkColorType, or is zero.

If rowBytes is zero, a suitable value will be chosen internally.

Parameters
imageInfowidth, height, SkColorType, SkAlphaType, SkColorSpace, of raster surface; width and height must be greater than zero
rowBytesinterval from one SkSurface row to the next; may be zero
surfacePropsLCD striping orientation and setting for device independent fonts; may be nullptr
Returns
SkSurface if all parameters are valid; otherwise, nullptr

◆ MakeRasterDirect() [1/2]

static sk_sp<SkSurface> SkSurface::MakeRasterDirect ( const SkImageInfo imageInfo,
void *  pixels,
size_t  rowBytes,
const SkSurfaceProps surfaceProps = nullptr 
)
static

Allocates raster SkSurface.

SkCanvas returned by SkSurface draws directly into pixels.

SkSurface is returned if all parameters are valid. Valid parameters include: info dimensions are greater than zero; info contains SkColorType and SkAlphaType supported by raster surface; pixels is not nullptr; rowBytes is large enough to contain info width pixels of SkColorType.

Pixel buffer size should be info height times computed rowBytes. Pixels are not initialized. To access pixels after drawing, peekPixels() or readPixels().

Parameters
imageInfowidth, height, SkColorType, SkAlphaType, SkColorSpace, of raster surface; width and height must be greater than zero
pixelspointer to destination pixels buffer
rowBytesinterval from one SkSurface row to the next
surfacePropsLCD striping orientation and setting for device independent fonts; may be nullptr
Returns
SkSurface if all parameters are valid; otherwise, nullptr

◆ MakeRasterDirect() [2/2]

static sk_sp<SkSurface> SkSurface::MakeRasterDirect ( const SkPixmap pm,
const SkSurfaceProps props = nullptr 
)
inlinestatic

◆ MakeRasterDirectReleaseProc()

static sk_sp<SkSurface> SkSurface::MakeRasterDirectReleaseProc ( const SkImageInfo imageInfo,
void *  pixels,
size_t  rowBytes,
void(*)(void *pixels, void *context)  releaseProc,
void *  context,
const SkSurfaceProps surfaceProps = nullptr 
)
static

Allocates raster SkSurface.

SkCanvas returned by SkSurface draws directly into pixels. releaseProc is called with pixels and context when SkSurface is deleted.

SkSurface is returned if all parameters are valid. Valid parameters include: info dimensions are greater than zero; info contains SkColorType and SkAlphaType supported by raster surface; pixels is not nullptr; rowBytes is large enough to contain info width pixels of SkColorType.

Pixel buffer size should be info height times computed rowBytes. Pixels are not initialized. To access pixels after drawing, call flush() or peekPixels().

Parameters
imageInfowidth, height, SkColorType, SkAlphaType, SkColorSpace, of raster surface; width and height must be greater than zero
pixelspointer to destination pixels buffer
rowBytesinterval from one SkSurface row to the next
releaseProccalled when SkSurface is deleted; may be nullptr
contextpassed to releaseProc; may be nullptr
surfacePropsLCD striping orientation and setting for device independent fonts; may be nullptr
Returns
SkSurface if all parameters are valid; otherwise, nullptr

◆ MakeRasterN32Premul()

static sk_sp<SkSurface> SkSurface::MakeRasterN32Premul ( int  width,
int  height,
const SkSurfaceProps surfaceProps = nullptr 
)
static

Allocates raster SkSurface.

SkCanvas returned by SkSurface draws directly into pixels. Allocates and zeroes pixel memory. Pixel memory size is height times width times four. Pixel memory is deleted when SkSurface is deleted.

Internally, sets SkImageInfo to width, height, native color type, and kPremul_SkAlphaType.

SkSurface is returned if width and height are greater than zero.

Use to create SkSurface that matches SkPMColor, the native pixel arrangement on the platform. SkSurface drawn to output device skips converting its pixel format.

Parameters
widthpixel column count; must be greater than zero
heightpixel row count; must be greater than zero
surfacePropsLCD striping orientation and setting for device independent fonts; may be nullptr
Returns
SkSurface if all parameters are valid; otherwise, nullptr

◆ MakeRenderTarget() [1/4]

static sk_sp<SkSurface> SkSurface::MakeRenderTarget ( GrRecordingContext context,
const SkSurfaceCharacterization characterization,
SkBudgeted  budgeted 
)
static

Returns SkSurface on GPU indicated by context that is compatible with the provided characterization.

budgeted selects whether allocation for pixels is tracked by context.

Parameters
contextGPU context
characterizationdescription of the desired SkSurface
Returns
SkSurface if all parameters are valid; otherwise, nullptr

◆ MakeRenderTarget() [2/4]

static sk_sp<SkSurface> SkSurface::MakeRenderTarget ( GrRecordingContext context,
SkBudgeted  budgeted,
const SkImageInfo imageInfo 
)
inlinestatic

Returns SkSurface on GPU indicated by context.

Allocates memory for pixels, based on the width, height, and SkColorType in SkImageInfo. budgeted selects whether allocation for pixels is tracked by context. imageInfo describes the pixel format in SkColorType, and transparency in SkAlphaType, and color matching in SkColorSpace.

SkSurface bottom-left corner is pinned to the origin.

Parameters
contextGPU context
imageInfowidth, height, SkColorType, SkAlphaType, SkColorSpace, of raster surface; width, or height, or both, may be zero
Returns
SkSurface if all parameters are valid; otherwise, nullptr

◆ MakeRenderTarget() [3/4]

static sk_sp<SkSurface> SkSurface::MakeRenderTarget ( GrRecordingContext context,
SkBudgeted  budgeted,
const SkImageInfo imageInfo,
int  sampleCount,
const SkSurfaceProps surfaceProps 
)
inlinestatic

Returns SkSurface on GPU indicated by context.

Allocates memory for pixels, based on the width, height, and SkColorType in SkImageInfo. budgeted selects whether allocation for pixels is tracked by context. imageInfo describes the pixel format in SkColorType, and transparency in SkAlphaType, and color matching in SkColorSpace.

sampleCount requests the number of samples per pixel. Pass zero to disable multi-sample anti-aliasing. The request is rounded up to the next supported count, or rounded down if it is larger than the maximum supported count.

SkSurface bottom-left corner is pinned to the origin.

Parameters
contextGPU context
imageInfowidth, height, SkColorType, SkAlphaType, SkColorSpace, of raster surface; width, or height, or both, may be zero
sampleCountsamples per pixel, or 0 to disable multi-sample anti-aliasing
surfacePropsLCD striping orientation and setting for device independent fonts; may be nullptr
Returns
SkSurface if all parameters are valid; otherwise, nullptr

◆ MakeRenderTarget() [4/4]

static sk_sp<SkSurface> SkSurface::MakeRenderTarget ( GrRecordingContext context,
SkBudgeted  budgeted,
const SkImageInfo imageInfo,
int  sampleCount,
GrSurfaceOrigin  surfaceOrigin,
const SkSurfaceProps surfaceProps,
bool  shouldCreateWithMips = false 
)
static

Returns SkSurface on GPU indicated by context.

Allocates memory for pixels, based on the width, height, and SkColorType in SkImageInfo. budgeted selects whether allocation for pixels is tracked by context. imageInfo describes the pixel format in SkColorType, and transparency in SkAlphaType, and color matching in SkColorSpace.

sampleCount requests the number of samples per pixel. Pass zero to disable multi-sample anti-aliasing. The request is rounded up to the next supported count, or rounded down if it is larger than the maximum supported count.

surfaceOrigin pins either the top-left or the bottom-left corner to the origin.

shouldCreateWithMips hints that SkImage returned by makeImageSnapshot() is mip map.

If SK_SUPPORT_GPU is defined as zero, has no effect and returns nullptr.

Parameters
contextGPU context
imageInfowidth, height, SkColorType, SkAlphaType, SkColorSpace; width, or height, or both, may be zero
sampleCountsamples per pixel, or 0 to disable full scene anti-aliasing
surfacePropsLCD striping orientation and setting for device independent fonts; may be nullptr
shouldCreateWithMipshint that SkSurface will host mip map images
Returns
SkSurface if all parameters are valid; otherwise, nullptr

◆ 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

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

◆ 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

◆ 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

◆ props()

const SkSurfaceProps& SkSurface::props ( ) const
inline

Returns SkSurfaceProps for surface.

Returns
LCD striping orientation and setting for device independent fonts

◆ 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

◆ 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

◆ 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

◆ recordingContext()

GrRecordingContext* SkSurface::recordingContext ( )

Returns the recording context being used by the SkSurface.

Returns
the recording context, if available; nullptr otherwise

◆ ref()

void SkRefCntBase::ref ( ) const
inlineinherited

Increment the reference count.

Must be balanced by a call to unref().

◆ replaceBackendTexture()

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

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

◆ unique()

bool SkRefCntBase::unique ( ) const
inlineinherited

May return true if the caller is the only owner.

Ensures that all previous owner's actions are complete.

◆ unref()

void SkRefCntBase::unref ( ) const
inlineinherited

Decrement the reference count.

If the reference count is 1 before the decrement, then delete the object. Note that if this is the case, then the object needs to have been allocated via new, and not on the stack.

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

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

◆ width()

int SkSurface::width ( ) const
inline

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

Returns
number of pixel columns

◆ 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

◆ 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

Member Data Documentation

◆ kDiscardWrite_TextureHandleAccess

const BackendHandleAccess SkSurface::kDiscardWrite_TextureHandleAccess
static
Initial value:

Deprecated.

◆ kFlushRead_TextureHandleAccess

const BackendHandleAccess SkSurface::kFlushRead_TextureHandleAccess
static
Initial value:

Deprecated.

◆ kFlushWrite_TextureHandleAccess

const BackendHandleAccess SkSurface::kFlushWrite_TextureHandleAccess
static
Initial value:

Deprecated.


The documentation for this class was generated from the following file:
SkSurface::kFlushWrite_BackendHandleAccess
@ kFlushWrite_BackendHandleAccess
back-end object is writable
Definition: SkSurface.h:502
SkSurface::kDiscardWrite_BackendHandleAccess
@ kDiscardWrite_BackendHandleAccess
back-end object must be overwritten
Definition: SkSurface.h:503
SkSurface::kFlushRead_BackendHandleAccess
@ kFlushRead_BackendHandleAccess
back-end object is readable
Definition: SkSurface.h:501