Add self-checking code that looks to see that overview is populated and alphabetized. Eventually, this will self-check to see if methods are collected into subtopics and have reciprocal 'see also' data. Standardize phrases so that they don't start with a capital or end with a period. Self-check is a work in progress, so it is not yet run by the bookmaker bots. The self-check should run cleanly, however. To run it: ./out/skia/bookmaker -b docs -k The expected output is doc stats. Self-check errors such as missing methods in the overview would be reported here if there are any. TBR=caryclark@google.com Docs-Preview: https://skia.org/?cl=93621 Bug: skia:6898 Change-Id: I8f1f817a7b083b13138ee33d1aa090445e9304c6 Reviewed-on: https://skia-review.googlesource.com/93621 Reviewed-by: Cary Clark <caryclark@skia.org> Commit-Queue: Cary Clark <caryclark@skia.org>
92 KiB
SkSurface Reference
Surface
Class SkSurface
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.
Overview
Subtopics
topics | description |
---|---|
Constructors | functions that construct SkIPoint16 |
Member Functions | static functions and member methods |
Constructors
name | description |
---|---|
MakeFromBackendRenderTarget | creates Surface from GPU memory buffer |
MakeFromBackendTexture | creates Surface from GPU-backed texture |
MakeFromBackendTextureAsRenderTarget | creates Surface from GPU-backed texture |
MakeNull | creates Surface without backing pixels |
MakeRaster | creates Surface from SkImageInfo |
MakeRasterDirect | creates Surface from SkImageInfo and Pixel Storage |
MakeRasterDirectReleaseProc | creates Surface from SkImageInfo and Pixel Storage |
MakeRasterN32Premul | creates Surface from width, height matching output |
MakeRenderTarget | creates Surface pointing to new GPU memory buffer |
SkCanvas::makeSurface | creates Surface matching Canvas Image Info, Surface Properties |
makeSurface | creates a compatible Surface |
Member Functions
description | function |
---|---|
MakeFromBackendRenderTarget | creates Surface from GPU memory buffer |
MakeFromBackendTexture | creates Surface from GPU-backed texture |
MakeFromBackendTextureAsRenderTarget | creates Surface from GPU-backed texture |
MakeNull | creates Surface without backing pixels |
MakeRaster | creates Surface from SkImageInfo |
MakeRasterDirect | creates Surface from SkImageInfo and Pixel Storage |
MakeRasterDirectReleaseProc | creates Surface from SkImageInfo and Pixel Storage |
MakeRasterN32Premul | creates Surface from width, height matching output |
MakeRenderTarget | creates Surface pointing to new GPU memory buffer |
characterize | sets Surface Characterization for threaded pre-processing |
draw | draws Surface contents to canvas |
flush | resolve pending I/O |
flushAndSignalSemaphores | resolve pending I/O, and signal |
generationID | returns unique ID |
getCanvas | returns Canvas that draws into Surface |
getRenderTargetHandle | returns the GPU reference to render target |
getTextureHandle | returns the GPU reference to texture |
height | returns pixel row count |
makeImageSnapshot | creates Image capturing Surface contents |
makeSurface | creates a compatible Surface |
notifyContentWillChange | notifies that contents will be changed outside of Skia |
peekPixels | copies Surface parameters to Pixmap |
prepareForExternalIO | to be deprecated |
props | returns Surface Properties |
readPixels | copies Rect of pixels |
wait | rause commands until signaled |
width | returns pixel column count |
MakeRasterDirect
static sk_sp<SkSurface> MakeRasterDirect(const SkImageInfo& imageInfo, void* pixels, size_t rowBytes, const SkSurfaceProps* surfaceProps = nullptr)
Allocates raster Surface. Canvas returned by Surface draws directly into pixels.
Surface is returned if all parameters are valid. Valid parameters include: info dimensions are greater than zero; info contains Image Color Type and Image Alpha Type supported by Raster Surface; pixels is not nullptr; rowBytes is large enough to contain info width pixels of Image Color Type.
Pixel buffer size should be info height times computed rowBytes. Pixels are not initialized. To access pixels after drawing, call flush or peekPixels.
Parameters
imageInfo | width, height, Image Color Type, Image Alpha Type, Color Space, of Raster Surface; width and height must be greater than zero |
pixels | pointer to destination pixels buffer |
rowBytes | interval from one Surface row to the next |
surfaceProps | LCD striping orientation and setting for device independent fonts; may be nullptr |
Return Value
Surface if all parameters are valid; otherwise, nullptr
Example
Example Output
---
-x-
---
See Also
MakeRasterDirectReleaseProc MakeRaster MakeRasterN32Premul SkCanvas::MakeRasterDirect
MakeRasterDirectReleaseProc
static sk_sp<SkSurface> MakeRasterDirectReleaseProc(const SkImageInfo& imageInfo, void* pixels, size_t rowBytes, void (*releaseProc) (void* pixels, void* context) , void* context, const SkSurfaceProps* surfaceProps = nullptr)
Allocates raster Surface. Canvas returned by Surface draws directly into pixels. releaseProc is called with pixels and context when Surface is deleted.
Surface is returned if all parameters are valid. Valid parameters include: info dimensions are greater than zero; info contains Image Color Type and Image Alpha Type supported by Raster Surface; pixels is not nullptr; rowBytes is large enough to contain info width pixels of Image Color Type.
Pixel buffer size should be info height times computed rowBytes. Pixels are not initialized. To access pixels after drawing, call flush or peekPixels.
Parameters
imageInfo | width, height, Image Color Type, Image Alpha Type, Color Space, of Raster Surface; width and height must be greater than zero |
pixels | pointer to destination pixels buffer |
rowBytes | interval from one Surface row to the next |
releaseProc | called when Surface is deleted; may be nullptr |
context | passed to releaseProc; may be nullptr |
surfaceProps | LCD striping orientation and setting for device independent fonts; may be nullptr |
Return Value
Surface if all parameters are valid; otherwise, nullptr
Example
Example Output
---
-x-
---
expected release context
See Also
MakeRasterDirect MakeRasterN32Premul MakeRaster
MakeRaster
static sk_sp<SkSurface> MakeRaster(const SkImageInfo& imageInfo, size_t rowBytes, const SkSurfaceProps* surfaceProps)
Allocates raster Surface. Canvas returned by Surface 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 Surface is deleted.
Surface is returned if all parameters are valid. Valid parameters include: info dimensions are greater than zero; info contains Image Color Type and Image Alpha Type supported by Raster Surface; rowBytes is large enough to contain info width pixels of Image Color Type, or is zero.
If rowBytes is not zero, subsequent images returned by makeImageSnapshot have the same rowBytes.
Parameters
imageInfo | width, height, Image Color Type, Image Alpha Type, Color Space, of Raster Surface; width and height must be greater than zero |
rowBytes | interval from one Surface row to the next; may be zero |
surfaceProps | LCD striping orientation and setting for device independent fonts; may be nullptr |
Return Value
Surface if all parameters are valid; otherwise, nullptr
Example
Example Output
---
-x-
---
See Also
MakeRasterDirect MakeRasterN32Premul MakeRasterDirectReleaseProc
static sk_sp<SkSurface> MakeRaster(const SkImageInfo& imageInfo, const SkSurfaceProps* props = nullptr)
Allocates raster Surface. Canvas returned by Surface draws directly into pixels. Allocates and zeroes pixel memory. Pixel memory size is imageInfo.height times imageInfo.minRowBytes(). Pixel memory is deleted when Surface is deleted.
Surface is returned if all parameters are valid. Valid parameters include: info dimensions are greater than zero; info contains Image Color Type and Image Alpha Type supported by Raster Surface.
Parameters
imageInfo | width, height, Image Color Type, Image Alpha Type, Color Space, of Raster Surface; width and height must be greater than zero |
props | LCD striping orientation and setting for device independent fonts; may be nullptr |
Return Value
Surface if all parameters are valid; otherwise, nullptr
Example
See Also
MakeRasterDirect MakeRasterN32Premul MakeRasterDirectReleaseProc
MakeRasterN32Premul
static sk_sp<SkSurface> MakeRasterN32Premul(int width, int height, const SkSurfaceProps* surfaceProps = nullptr)
Allocates raster Surface. Canvas returned by Surface draws directly into pixels. Allocates and zeroes pixel memory. Pixel memory size is height times width times four. Pixel memory is deleted when Surface is deleted.
Internally, sets Image Info to width, height, Native Color Type, and kPremul SkAlphaType.
Surface is returned if width and height are greater than zero.
Use to create Surface that matches SkPMColor, the native pixel arrangement on the platform. Surface drawn to output device skips converting its pixel format.
Parameters
width | pixel column count; must be greater than zero |
height | pixel row count; must be greater than zero |
surfaceProps | LCD striping orientation and setting for device independent fonts; may be nullptr |
Return Value
Surface if all parameters are valid; otherwise, nullptr
Example
Example Output
---
-x-
---
See Also
MakeRasterDirect MakeRasterN32Premul MakeRasterDirectReleaseProc
MakeFromBackendTexture
static sk_sp<SkSurface> MakeFromBackendTexture(GrContext* context, const GrBackendTexture& backendTexture, GrSurfaceOrigin origin, int sampleCnt, sk_sp<SkColorSpace> colorSpace, const SkSurfaceProps* surfaceProps)
Wraps a GPU-backed texture into Surface. Caller must ensure the texture is valid for the lifetime of returned Surface. If sampleCnt greater than zero, creates an intermediate MSAA Surface which is used for drawing backendTexture.
Surface 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.
If SK_SUPPORT_GPU is defined as zero, has no effect and returns nullptr.
Parameters
context | GPU Context |
backendTexture | texture residing on GPU |
origin | one of: kBottomLeft GrSurfaceOrigin, kTopLeft GrSurfaceOrigin |
sampleCnt | samples per pixel, or 0 to disable full scene anti-aliasing |
colorSpace | range of colors |
surfaceProps | LCD striping orientation and setting for device independent fonts; may be nullptr |
Return Value
Surface if all parameters are valid; otherwise, nullptr
Example
void draw(SkCanvas* canvas) { SkPaint paint; paint.setTextSize(32); GrContext* context = canvas->getGrContext(); if (!context) { canvas->drawString("GPU only!", 20, 40, paint); return; } sk_sp gpuSurface = SkSurface::MakeFromBackendTexture(context, backEndTextureRenderTarget, kTopLeft_GrSurfaceOrigin, 0, nullptr, nullptr); auto surfaceCanvas = gpuSurface->getCanvas(); surfaceCanvas->clear(SK_ColorWHITE); surfaceCanvas->drawString("GPU rocks!", 20, 40, paint); sk_sp image(gpuSurface->makeImageSnapshot()); canvas->drawImage(image, 0, 0); }
See Also
GrBackendTexture MakeFromBackendRenderTarget MakeRenderTarget
static sk_sp<SkSurface> MakeFromBackendTexture(GrContext* context, const GrBackendTexture& backendTexture, GrSurfaceOrigin origin, int sampleCnt, SkColorType colorType, sk_sp<SkColorSpace> colorSpace, const SkSurfaceProps* surfaceProps)
Wraps a GPU-backed texture into Surface. Caller must ensure the texture is valid for the lifetime of returned Surface. If sampleCnt greater than zero, creates an intermediate MSAA Surface which is used for drawing backendTexture.
Surface 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.
If SK_SUPPORT_GPU is defined as zero, has no effect and returns nullptr.
Parameters
context | GPU Context |
backendTexture | texture residing on GPU |
origin | one of: kBottomLeft GrSurfaceOrigin, kTopLeft GrSurfaceOrigin |
sampleCnt | samples per pixel, or 0 to disable full scene anti-aliasing |
colorType | one of: kUnknown SkColorType, kAlpha 8 SkColorType, kRGB 565 SkColorType, kARGB 4444 SkColorType, kRGBA 8888 SkColorType, kBGRA 8888 SkColorType, kGray 8 SkColorType, kRGBA F16 SkColorType |
colorSpace | range of colors |
surfaceProps | LCD striping orientation and setting for device independent fonts; may be nullptr |
Return Value
Surface if all parameters are valid; otherwise, nullptr
Example
void draw(SkCanvas* canvas) { SkPaint paint; paint.setTextSize(32); GrContext* context = canvas->getGrContext(); if (!context) { canvas->drawString("GPU only!", 20, 40, paint); return; } sk_sp gpuSurface = SkSurface::MakeFromBackendTexture(context, backEndTextureRenderTarget, kTopLeft_GrSurfaceOrigin, kRGBA_8888_SkColorType, 0, nullptr, nullptr); auto surfaceCanvas = gpuSurface->getCanvas(); surfaceCanvas->clear(SK_ColorWHITE); surfaceCanvas->drawString("GPU rocks!", 20, 40, paint); sk_sp image(gpuSurface->makeImageSnapshot()); canvas->drawImage(image, 0, 0); }
See Also
GrBackendTexture MakeFromBackendRenderTarget MakeRenderTarget
MakeFromBackendRenderTarget
static sk_sp<SkSurface> MakeFromBackendRenderTarget(GrContext* context, const GrBackendRenderTarget& backendRenderTarget, GrSurfaceOrigin origin, sk_sp<SkColorSpace> colorSpace, const SkSurfaceProps* surfaceProps)
Wraps a GPU-backed buffer into Surface. Caller must ensure render target is valid for the lifetime of returned Surface.
Surface 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.
If SK_SUPPORT_GPU is defined as zero, has no effect and returns nullptr.
Parameters
context | GPU Context |
backendRenderTarget | GPU intermediate memory buffer |
origin | one of: kBottomLeft GrSurfaceOrigin, kTopLeft GrSurfaceOrigin |
colorSpace | range of colors |
surfaceProps | LCD striping orientation and setting for device independent fonts; may be nullptr |
Return Value
Surface if all parameters are valid; otherwise, nullptr
Example
void draw(SkCanvas* canvas) { SkPaint paint; paint.setTextSize(32); GrContext* context = canvas->getGrContext(); if (!context) { canvas->drawString("GPU only!", 20, 40, paint); return; } sk_sp gpuSurface = SkSurface::MakeFromBackendRenderTarget(context, backEndRenderTarget, kTopLeft_GrSurfaceOrigin, nullptr, nullptr); auto surfaceCanvas = gpuSurface->getCanvas(); surfaceCanvas->clear(SK_ColorWHITE); surfaceCanvas->drawString("GPU rocks!", 20, 40, paint); sk_sp image(gpuSurface->makeImageSnapshot()); canvas->drawImage(image, 0, 0); }
See Also
MakeFromBackendTexture MakeRenderTarget
static sk_sp<SkSurface> MakeFromBackendRenderTarget(GrContext* context, const GrBackendRenderTarget& backendRenderTarget, GrSurfaceOrigin origin, SkColorType colorType, sk_sp<SkColorSpace> colorSpace, const SkSurfaceProps* surfaceProps)
Wraps a GPU-backed buffer into Surface. Caller must ensure render target is valid for the lifetime of returned Surface.
Surface 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.
If SK_SUPPORT_GPU is defined as zero, has no effect and returns nullptr.
Parameters
context | GPU Context |
backendRenderTarget | GPU intermediate memory buffer |
origin | one of: kBottomLeft GrSurfaceOrigin, kTopLeft GrSurfaceOrigin |
colorType | one of: kUnknown SkColorType, kAlpha 8 SkColorType, kRGB 565 SkColorType, kARGB 4444 SkColorType, kRGBA 8888 SkColorType, kBGRA 8888 SkColorType, kGray 8 SkColorType, kRGBA F16 SkColorType |
colorSpace | range of colors |
surfaceProps | LCD striping orientation and setting for device independent fonts; may be nullptr |
Return Value
Surface if all parameters are valid; otherwise, nullptr
Example
void draw(SkCanvas* canvas) { SkPaint paint; paint.setTextSize(32); GrContext* context = canvas->getGrContext(); if (!context) { canvas->drawString("GPU only!", 20, 40, paint); return; } sk_sp gpuSurface = SkSurface::MakeFromBackendRenderTarget(context, backEndRenderTarget, kTopLeft_GrSurfaceOrigin, kRGBA_8888_SkColorType, nullptr, nullptr); auto surfaceCanvas = gpuSurface->getCanvas(); surfaceCanvas->clear(SK_ColorWHITE); surfaceCanvas->drawString("GPU rocks!", 20, 40, paint); sk_sp image(gpuSurface->makeImageSnapshot()); canvas->drawImage(image, 0, 0); }
See Also
MakeFromBackendTexture MakeRenderTarget
MakeFromBackendTextureAsRenderTarget
static sk_sp<SkSurface> MakeFromBackendTextureAsRenderTarget(GrContext* context, const GrBackendTexture& backendTexture, GrSurfaceOrigin origin, int sampleCnt, sk_sp<SkColorSpace> colorSpace, const SkSurfaceProps* surfaceProps)
Used to wrap a GPU-backed texture as a SkSurface. Skia will treat the texture as a rendering target only, but unlike NewFromBackendRenderTarget, Skia will manage and own the associated render target objects (but not the provided texture). Skia will not assume ownership of the texture and the client must ensure the texture is valid for the lifetime of the SkSurface.
If SK_SUPPORT_GPU is defined as zero, has no effect and returns nullptr.
Parameters
context | GPU Context |
backendTexture | texture residing on GPU |
origin | one of: kBottomLeft GrSurfaceOrigin, kTopLeft GrSurfaceOrigin |
sampleCnt | samples per pixel, or 0 to disable full scene anti-aliasing |
colorSpace | range of colors |
surfaceProps | LCD striping orientation and setting for device independent fonts; may be nullptr |
Return Value
Surface if all parameters are valid; otherwise, nullptr
Example
void draw(SkCanvas* canvas) {SkPaint paint; paint.setTextSize(32); GrContext* context = canvas->getGrContext(); if (!context) { canvas->drawString("GPU only!", 20, 40, paint); return; } sk_sp gpuSurface = SkSurface::MakeFromBackendTextureAsRenderTarget( context, backEndTextureRenderTarget, kTopLeft_GrSurfaceOrigin, 0, nullptr, nullptr); auto surfaceCanvas = gpuSurface->getCanvas(); surfaceCanvas->clear(SK_ColorWHITE); surfaceCanvas->drawString("GPU rocks!", 20, 40, paint); sk_sp image(gpuSurface->makeImageSnapshot()); canvas->drawImage(image, 0, 0); }
See Also
MakeFromBackendRenderTarget MakeRenderTarget
static sk_sp<SkSurface> MakeFromBackendTextureAsRenderTarget(GrContext* context, const GrBackendTexture& backendTexture, GrSurfaceOrigin origin, int sampleCnt, SkColorType colorType, sk_sp<SkColorSpace> colorSpace, const SkSurfaceProps* surfaceProps)
Used to wrap a GPU-backed texture as a SkSurface. Skia will treat the texture as a rendering target only, but unlike NewFromBackendRenderTarget, Skia will manage and own the associated render target objects (but not the provided texture). Skia will not assume ownership of the texture and the client must ensure the texture is valid for the lifetime of the SkSurface.
If SK_SUPPORT_GPU is defined as zero, has no effect and returns nullptr.
Parameters
context | GPU Context |
backendTexture | texture residing on GPU |
origin | one of: kBottomLeft GrSurfaceOrigin, kTopLeft GrSurfaceOrigin |
sampleCnt | samples per pixel, or 0 to disable full scene anti-aliasing |
colorType | one of: kUnknown SkColorType, kAlpha 8 SkColorType, kRGB 565 SkColorType, kARGB 4444 SkColorType, kRGBA 8888 SkColorType, kBGRA 8888 SkColorType, kGray 8 SkColorType, kRGBA F16 SkColorType |
colorSpace | range of colors |
surfaceProps | LCD striping orientation and setting for device independent fonts; may be nullptr |
Return Value
Surface if all parameters are valid; otherwise, nullptr
Example
void draw(SkCanvas* canvas) {SkPaint paint; paint.setTextSize(32); GrContext* context = canvas->getGrContext(); if (!context) { canvas->drawString("GPU only!", 20, 40, paint); return; } sk_sp gpuSurface = SkSurface::MakeFromBackendTextureAsRenderTarget( context, backEndTextureRenderTarget, kTopLeft_GrSurfaceOrigin, 0, kRGBA_8888_SkColorType, nullptr, nullptr); auto surfaceCanvas = gpuSurface->getCanvas(); surfaceCanvas->clear(SK_ColorWHITE); surfaceCanvas->drawString("GPU rocks!", 20, 40, paint); sk_sp image(gpuSurface->makeImageSnapshot()); canvas->drawImage(image, 0, 0); }
See Also
MakeFromBackendRenderTarget MakeRenderTarget
MakeRenderTarget
static sk_sp<SkSurface> MakeRenderTarget(GrContext* context, SkBudgeted budgeted, const SkImageInfo& imageInfo, int sampleCount, GrSurfaceOrigin surfaceOrigin, const SkSurfaceProps* surfaceProps, bool shouldCreateWithMips = false)
Returns offscreen Surface on GPU indicated by context. Allocates memory for pixels, based on the width, height, and Image Color Type in ImageInfo. budgeted selects whether allocation for offscreen pixels is tracked by context. imageInfo describes the pixel format in Image Color Type, and transparency in Image Alpha Type, and color matching in Color Space.
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 Image returned by makeImageSnapshot is Mip Map.
If SK_SUPPORT_GPU is defined as zero, has no effect and returns nullptr.
Parameters
context | GPU Context |
budgeted | one of: SkBudgeted::kNo, SkBudgeted::kYes |
imageInfo | width, height, Image Color Type, Image Alpha Type, Color Space; width, or height, or both, may be zero |
sampleCount | samples per pixel, or 0 to disable full scene anti-aliasing |
surfaceOrigin | one of: kBottomLeft GrSurfaceOrigin, kTopLeft GrSurfaceOrigin |
surfaceProps | LCD striping orientation and setting for device independent fonts; may be nullptr |
shouldCreateWithMips | hint that Surface will host Mip Map images |
Return Value
Surface if all parameters are valid; otherwise, nullptr
Example
See Also
MakeFromBackendRenderTarget MakeFromBackendTextureAsRenderTarget
static sk_sp<SkSurface> MakeRenderTarget(GrContext* context, SkBudgeted budgeted, const SkImageInfo& imageInfo, int sampleCount, const SkSurfaceProps* props)
Returns offscreen Surface on GPU indicated by context. Allocates memory for pixels, based on the width, height, and Image Color Type in ImageInfo. budgeted selects whether allocation for offscreen pixels is tracked by context. imageInfo describes the pixel format in Image Color Type, and transparency in Image Alpha Type, and color matching in Color Space.
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.
Surface bottom-left corner is pinned to the origin.
Parameters
context | GPU Context |
budgeted | one of: SkBudgeted::kNo, SkBudgeted::kYes |
imageInfo | width, height, Image Color Type, Image Alpha Type, Color Space, of Raster Surface; width, or height, or both, may be zero |
sampleCount | samples per pixel, or 0 to disable Multi_Sample_Anti_Aliasing |
props | LCD striping orientation and setting for device independent fonts; may be nullptr |
Return Value
Surface if all parameters are valid; otherwise, nullptr
Example
See Also
MakeFromBackendRenderTarget MakeFromBackendTextureAsRenderTarget
static sk_sp<SkSurface> MakeRenderTarget(GrContext* context, SkBudgeted budgeted, const SkImageInfo& imageInfo)
Returns offscreen Surface on GPU indicated by context. Allocates memory for pixels, based on the width, height, and Image Color Type in ImageInfo. budgeted selects whether allocation for offscreen pixels is tracked by context. imageInfo describes the pixel format in Image Color Type, and transparency in Image Alpha Type, and color matching in Color Space.
Surface bottom-left corner is pinned to the origin.
Parameters
context | GPU Context |
budgeted | one of: SkBudgeted::kNo, SkBudgeted::kYes |
imageInfo | width, height, Image Color Type, Image Alpha Type, Color Space, of Raster Surface; width, or height, or both, may be zero |
Return Value
Surface if all parameters are valid; otherwise, nullptr
Example
See Also
MakeFromBackendRenderTarget MakeFromBackendTextureAsRenderTarget
MakeNull
static sk_sp<SkSurface> MakeNull(int width, int height)
Returns Surface without backing pixels. Drawing to Canvas returned from Surface has no effect. Calling makeImageSnapshot on returned Surface returns nullptr.
Parameters
width | one or greater |
height | one or greater |
Return Value
Surface if width and height are positive; otherwise, nullptr
Example
Example Output
SkSurface::MakeNull(0, 0) == nullptr
surf->makeImageSnapshot() == nullptr
See Also
width
int width() const
Returns pixel count in each row; may be zero or greater.
Return Value
number of pixel columns
Example
Example Output
surface width=37 canvas width=37
See Also
height
int height() const
Returns pixel row count; may be zero or greater.
Return Value
number of pixel rows
Example
Example Output
surface height=1000 canvas height=1000
See Also
generationID
uint32_t generationID()
Returns unique value identifying the content of Surface. Returned value changes each time the content changes. Content is changed by drawing, or by calling notifyContentWillChange.
Return Value
unique content identifier
Example
Example Output
surface generationID: 1
surface generationID: 2
surface generationID: 3
See Also
notifyContentWillChange ContentChangeMode getCanvas
Enum SkSurface::ContentChangeMode
enum ContentChangeMode { kDiscard ContentChangeMode, kRetain ContentChangeMode, };
ContentChangeMode members are parameters to notifyContentWillChange.
Constants
SkSurface::kDiscard_ContentChangeMode | Pass to notifyContentWillChange to discard surface contents when | the surface is cleared or overwritten. |
SkSurface::kRetain_ContentChangeMode | Pass to notifyContentWillChange when to preserve surface contents. | If a snapshot has been generated, this copies the Surface contents. |
See Also
notifyContentWillChange generationID
notifyContentWillChange
void notifyContentWillChange(ContentChangeMode mode)
Notifies that Surface contents will be changed by code outside of Skia. Subsequent calls to generationID return a different value.
mode is normally passed as kRetain ContentChangeMode.
Parameters
mode | one of: kDiscard ContentChangeMode, kRetain ContentChangeMode |
Example
See Also
ContentChangeMode generationID
Enum SkSurface::BackendHandleAccess
enum BackendHandleAccess { kFlushRead BackendHandleAccess, kFlushWrite BackendHandleAccess, kDiscardWrite BackendHandleAccess, }; static const BackendHandleAccess kFlushRead TextureHandleAccess = kFlushRead BackendHandleAccess; static const BackendHandleAccess kFlushWrite TextureHandleAccess = kFlushWrite BackendHandleAccess; static const BackendHandleAccess kDiscardWrite TextureHandleAccess = kDiscardWrite BackendHandleAccess;
Constants
SkSurface::kFlushRead_BackendHandleAccess | 0 | Caller may read from the back-end object. |
SkSurface::kFlushWrite_BackendHandleAccess | 1 | Caller may write to the back-end object. |
SkSurface::kDiscardWrite_BackendHandleAccess | 2 | Caller must overwrite the entire back-end object. |
SkSurface::kFlushRead_TextureHandleAccess | 0 | Deprecated. |
SkSurface::kFlushWrite_TextureHandleAccess | 1 | Deprecated. |
SkSurface::kDiscardWrite_TextureHandleAccess | 2 | Deprecated. |
Example
See Also
getTextureHandle getRenderTargetHandle
getTextureHandle
GrBackendObject getTextureHandle(BackendHandleAccess backendHandleAccess)
Returns the GPU back-end reference of the texture used by Surface, or zero if Surface is not backed by a GPU texture.
The returned texture handle is only valid until the next draw into Surface, or when Surface is deleted.
Parameters
backendHandleAccess | one of: kFlushRead BackendHandleAccess, kFlushWrite BackendHandleAccess, kDiscardWrite BackendHandleAccess |
Return Value
GPU texture reference
Example
See Also
getRenderTargetHandle GrBackendObject BackendHandleAccess
getRenderTargetHandle
bool getRenderTargetHandle(GrBackendObject* backendObject, BackendHandleAccess backendHandleAccess)
Returns true and stores the GPU back-end reference of the render target used by Surface in backendObject.
Return false if Surface is not backed by a GPU render target, and leaves backendObject unchanged.
The returned render target handle is only valid until the next draw into Surface, or when Surface is deleted.
In OpenGL this returns the frame buffer object ID.
Parameters
backendObject | GPU intermediate memory buffer |
backendHandleAccess | one of: kFlushRead BackendHandleAccess, kFlushWrite BackendHandleAccess, kDiscardWrite BackendHandleAccess |
Return Value
true if Surface is backed by GPU texture
Example
See Also
getTextureHandle GrBackendObject BackendHandleAccess
getCanvas
SkCanvas* getCanvas()
Returns Canvas that draws into Surface. Subsequent calls return the same Canvas. Canvas returned is managed and owned by Surface, and is deleted when Surface is deleted.
Return Value
Example
See Also
makeSurface makeImageSnapshot draw
makeSurface
sk_sp<SkSurface> makeSurface(const SkImageInfo& imageInfo)
Returns a compatible Surface, or nullptr. Returned Surface contains the same raster, GPU, or null properties as the original. Returned Surface does not share the same pixels.
Returns nullptr if imageInfo width or height are zero, or if imageInfo is incompatible with Surface.
Parameters
imageInfo | width, height, Image Color Type, Image Alpha Type, Color Space, of Surface; width and height must be greater than zero |
Return Value
compatible Surface or nullptr
Example
See Also
makeImageSnapshot getCanvas draw
makeImageSnapshot
sk_sp<SkImage> makeImageSnapshot()
Returns Image capturing Surface contents. Subsequent drawing to Surface contents are not captured. Image allocation is accounted for if Surface was created with SkBudgeted::kYes.
Return Value
Image initialized with Surface contents
Example
See Also
draw
void draw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPaint* paint)
Draws Surface contents to canvas, with its top-left corner at (x, y).
If Paint paint is not nullptr, apply Color Filter, Color Alpha, Image Filter, Blend Mode, and Draw Looper.
Parameters
canvas | Canvas drawn into |
x | horizontal offset in Canvas |
y | vertical offset in Canvas |
paint | Paint containing Blend Mode, Color Filter, Image Filter, and so on; or nullptr |
Example
See Also
peekPixels
bool peekPixels(SkPixmap* pixmap)
Copies Surface pixel address, row bytes, and Image Info to Pixmap, if address is available, and returns true. If pixel address is not available, return false and leave Pixmap unchanged.
pixmap contents become invalid on any future change to Surface.
Parameters
pixmap | storage for pixel state if pixels are readable; otherwise, ignored |
Return Value
true if Surface has direct access to pixels
Example
See Also
readPixels
bool readPixels(const SkPixmap& dst, int srcX, int srcY)
Source Rect corners are (srcX, srcY) and Surface (width, height). Destination Rect 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 Surface is raster, or backed by a GPU.
The destination pixel storage must be allocated by the caller.
Pixel values are converted only if Image Color Type and Image Alpha Type do not match. Only pixels within both source and destination rectangles are copied. dst contents outside Rect 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. |
Pixmap pixels could not be allocated. |
dst.rowBytes() is too small to contain one row of pixels. |
Parameters
dst | storage for pixels copied from Surface |
srcX | offset into readable pixels in x; may be negative |
srcY | offset into readable pixels in y; may be negative |
Return Value
true if pixels were copied
Example
See Also
bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes, int srcX, int srcY)
Copies Rect of pixels from Canvas into dstPixels.
Source Rect corners are (srcX, srcY) and Surface (width, height). Destination Rect 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 Surface is raster, or backed by a GPU.
The destination pixel storage must be allocated by the caller.
Pixel values are converted only if Image Color Type and Image Alpha Type do not match. Only pixels within both source and destination rectangles are copied. dstPixels contents outside Rect 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. |
Surface pixels could not be converted to dstInfo.colorType() or dstInfo.alphaType(). |
dstRowBytes is too small to contain one row of pixels. |
Parameters
dstInfo | width, height, Image Color Type, and Image Alpha Type of dstPixels |
dstPixels | storage for pixels; dstInfo.height times dstRowBytes, or larger |
dstRowBytes | size of one destination row; dstInfo.width times pixel size, or larger |
srcX | offset into readable pixels in x; may be negative |
srcY | offset into readable pixels in y; may be negative |
Return Value
true if pixels were copied
Example
See Also
bool readPixels(const SkBitmap& dst, int srcX, int srcY)
Copies Rect of pixels from Surface into bitmap.
Source Rect corners are (srcX, srcY) and Surface (width, height). Destination Rect 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 Surface is raster, or backed by a GPU.
The destination pixel storage must be allocated by the caller.
Pixel values are converted only if Image Color Type and Image Alpha Type do not match. Only pixels within both source and destination rectangles are copied. dst contents outside Rect 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. |
Surface 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
dst | storage for pixels copied from Surface |
srcX | offset into readable pixels in x; may be negative |
srcY | offset into readable pixels in y; may be negative |
Return Value
true if pixels were copied
Example
See Also
props
const SkSurfaceProps& props() const
Returns Surface Properties for surface.
Return Value
LCD striping orientation and setting for device independent fonts
Example
Example Output
surf.props(): kRGB_H_SkPixelGeometry
See Also
prepareForExternalIO
void prepareForExternalIO()
To be deprecated.
flush
void flush()
Issues pending Surface commands to the GPU-backed API and resolves any Surface MSAA.
Skia flushes as needed, so it is not necessary to call this if Skia manages drawing and object lifetime. Call when interleaving Skia calls with native GPU calls.
See Also
flushAndSignalSemaphores
GrSemaphoresSubmitted flushAndSignalSemaphores(int numSemaphores, GrBackendSemaphore signalSemaphores[])
Issues pending Surface commands to the GPU-backed API and resolves any Surface MSAA. After issuing all commands, signalSemaphores of count numSemaphores semaphores are signaled by the GPU.
For each GrBackendSemaphore in signalSemaphores: if GrBackendSemaphore is initialized, the GPU back-end uses the semaphore as is; otherwise, a new semaphore is created and initializes GrBackendSemaphore.
The caller must delete the semaphores created and returned in signalSemaphores. GrBackendSemaphore can be deleted as soon as this function returns.
If the back-end API is OpenGL only uninitialized GrBackendSemaphores are supported.
If the back-end API is Vulkan semaphores may be initialized or uninitialized. If uninitialized, created semaphores are valid only with the VkDevice with which they were created.
If GrSemaphoresSubmitted::kNo is returned, the GPU back-end did not create or add any semaphores to signal on the GPU; the caller should not instruct the GPU to wait on any of the semaphores.
Pending surface commands are flushed regardless of the return result.
Parameters
numSemaphores | size of signalSemaphores array |
signalSemaphores | array of semaphore containers |
Return Value
one of: GrSemaphoresSubmitted::kYes, GrSemaphoresSubmitted::kNo
See Also
wait
bool wait(int numSemaphores, const GrBackendSemaphore* waitSemaphores)
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. Skia will take ownership of the underlying semaphores and delete them once they have been signaled and waited on. 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.
Parameters
numSemaphores | size of waitSemaphores array |
waitSemaphores | array of semaphore containers |
Return Value
true if GPU is waiting on semaphores
Example
See Also
flushAndSignalSemaphores GrBackendSemaphore
characterize
bool characterize(SkSurfaceCharacterization* characterization) const
Initializes Surface Characterization that can be used to perform GPU back-end pre-processing in a separate thread. Typically this is used to divide drawing into multiple tiles. DeferredDisplayListRecorder records the drawing commands for each tile.
Return true if Surface supports characterization. Raster Surface returns false.
Parameters
characterization | properties for parallel drawing |
Return Value
true if supported
Example
See Also
draw SkSurfaceCharacterization SkDeferredDisplayList
bool draw(SkDeferredDisplayList* deferredDisplayList)
Draws deferred display list created using SkDeferredDisplayListRecorder. Has no effect and returns false if Surface Characterization stored in deferredDisplayList is not compatible with Surface.
Raster Surface returns false.
Parameters
deferredDisplayList | drawing commands |
Return Value
false if deferredDisplayList is not compatible
Example
See Also
characterize SkSurfaceCharacterization SkDeferredDisplayList