Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Typedefs | Enumerations | Functions
SkSurfaces Namespace Reference

Typedefs

using ReleaseContext = void *
 
using BufferReleaseProc = void(*)(ReleaseContext)
 
using PixelsReleaseProc = void(void *pixels, void *context)
 
using RenderTargetReleaseProc = void(*)(ReleaseContext)
 
using TextureReleaseProc = void(*)(ReleaseContext)
 
using BackendHandleAccess = SkSurface::BackendHandleAccess
 

Enumerations

enum class  BackendSurfaceAccess { kNoAccess , kPresent }
 

Functions

SK_API sk_sp< SkSurfaceWrapAndroidHardwareBuffer (skgpu::graphite::Recorder *recorder, AHardwareBuffer *hardwareBuffer, sk_sp< SkColorSpace > colorSpace, const SkSurfaceProps *surfaceProps, BufferReleaseProc=nullptr, ReleaseContext=nullptr, bool fromWindow=false)
 
SK_API sk_sp< SkSurfaceWrapAndroidHardwareBuffer (GrDirectContext *context, AHardwareBuffer *hardwareBuffer, GrSurfaceOrigin origin, sk_sp< SkColorSpace > colorSpace, const SkSurfaceProps *surfaceProps, bool fromWindow=false)
 
SK_API sk_sp< SkSurfaceNull (int width, int height)
 
SK_API sk_sp< SkSurfaceRaster (const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
 
sk_sp< SkSurfaceRaster (const SkImageInfo &imageInfo, const SkSurfaceProps *props=nullptr)
 
SK_API sk_sp< SkSurfaceWrapPixels (const SkImageInfo &imageInfo, void *pixels, size_t rowBytes, const SkSurfaceProps *surfaceProps=nullptr)
 
sk_sp< SkSurfaceWrapPixels (const SkPixmap &pm, const SkSurfaceProps *props=nullptr)
 
SK_API sk_sp< SkSurfaceWrapPixels (const SkImageInfo &imageInfo, void *pixels, size_t rowBytes, PixelsReleaseProc, void *context, const SkSurfaceProps *surfaceProps=nullptr)
 
SK_API sk_sp< SkSurfaceWrapCAMetalLayer (GrRecordingContext *context, GrMTLHandle layer, GrSurfaceOrigin origin, int sampleCnt, SkColorType colorType, sk_sp< SkColorSpace > colorSpace, const SkSurfaceProps *surfaceProps, GrMTLHandle *drawable) SK_API_AVAILABLE_CA_METAL_LAYER
 
SK_API sk_sp< SkSurfaceWrapMTKView (GrRecordingContext *context, GrMTLHandle mtkView, GrSurfaceOrigin origin, int sampleCnt, SkColorType colorType, sk_sp< SkColorSpace > colorSpace, const SkSurfaceProps *surfaceProps) SK_API_AVAILABLE(macos(10.11)
 
SK_API sk_sp< SkSurfaceios (9.0)
 
SK_API sk_sp< SkSurfacetvos (9.0))
 
SK_API sk_sp< SkSurfaceRenderTarget (GrRecordingContext *context, skgpu::Budgeted budgeted, const SkImageInfo &imageInfo, int sampleCount, GrSurfaceOrigin surfaceOrigin, const SkSurfaceProps *surfaceProps, bool shouldCreateWithMips=false, bool isProtected=false)
 
sk_sp< SkSurfaceRenderTarget (GrRecordingContext *context, skgpu::Budgeted budgeted, const SkImageInfo &imageInfo, int sampleCount, const SkSurfaceProps *surfaceProps)
 
sk_sp< SkSurfaceRenderTarget (GrRecordingContext *context, skgpu::Budgeted budgeted, const SkImageInfo &imageInfo)
 
SK_API sk_sp< SkSurfaceRenderTarget (GrRecordingContext *context, const GrSurfaceCharacterization &characterization, skgpu::Budgeted budgeted)
 
SK_API sk_sp< SkSurfaceWrapBackendTexture (GrRecordingContext *context, const GrBackendTexture &backendTexture, GrSurfaceOrigin origin, int sampleCnt, SkColorType colorType, sk_sp< SkColorSpace > colorSpace, const SkSurfaceProps *surfaceProps, TextureReleaseProc textureReleaseProc=nullptr, ReleaseContext releaseContext=nullptr)
 
SK_API sk_sp< SkSurfaceWrapBackendRenderTarget (GrRecordingContext *context, const GrBackendRenderTarget &backendRenderTarget, GrSurfaceOrigin origin, SkColorType colorType, sk_sp< SkColorSpace > colorSpace, const SkSurfaceProps *surfaceProps, RenderTargetReleaseProc releaseProc=nullptr, ReleaseContext releaseContext=nullptr)
 
SK_API GrBackendTexture GetBackendTexture (SkSurface *, BackendHandleAccess)
 
SK_API GrBackendRenderTarget GetBackendRenderTarget (SkSurface *, BackendHandleAccess)
 
SK_API void ResolveMSAA (SkSurface *surface)
 
void ResolveMSAA (const sk_sp< SkSurface > &surface)
 
SK_API sk_sp< SkImageAsImage (sk_sp< const SkSurface >)
 
SK_API sk_sp< SkImageAsImageCopy (sk_sp< const SkSurface >, const SkIRect *subset=nullptr, skgpu::Mipmapped=skgpu::Mipmapped::kNo)
 
SK_API sk_sp< SkSurfaceRenderTarget (skgpu::graphite::Recorder *, const SkImageInfo &imageInfo, skgpu::Mipmapped=skgpu::Mipmapped::kNo, const SkSurfaceProps *surfaceProps=nullptr)
 
SK_API sk_sp< SkSurfaceWrapBackendTexture (skgpu::graphite::Recorder *, const skgpu::graphite::BackendTexture &, SkColorType colorType, sk_sp< SkColorSpace > colorSpace, const SkSurfaceProps *props, TextureReleaseProc=nullptr, ReleaseContext=nullptr)
 

Typedef Documentation

◆ BackendHandleAccess

Definition at line 167 of file SkSurfaceGanesh.h.

◆ BufferReleaseProc

using SkSurfaces::BufferReleaseProc = typedef void (*)(ReleaseContext)

Definition at line 25 of file SurfaceAndroid.h.

◆ PixelsReleaseProc

using SkSurfaces::PixelsReleaseProc = typedef void(void* pixels, void* context)

Definition at line 116 of file SkSurface.h.

◆ ReleaseContext

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

Definition at line 24 of file SurfaceAndroid.h.

◆ RenderTargetReleaseProc

User function called when supplied render target may be deleted.

Definition at line 34 of file SkSurfaceGanesh.h.

◆ TextureReleaseProc

User function called when supplied texture may be deleted.

Definition at line 37 of file SkSurfaceGanesh.h.

Enumeration Type Documentation

◆ BackendSurfaceAccess

Enumerator
kNoAccess 

back-end surface will not be used by client

kPresent 

back-end surface will be used for presenting to screen

Definition at line 44 of file SkSurface.h.

44 {
45 kNoAccess, //!< back-end surface will not be used by client
46 kPresent, //!< back-end surface will be used for presenting to screen
47};
@ kPresent
back-end surface will be used for presenting to screen
@ kNoAccess
back-end surface will not be used by client

Function Documentation

◆ AsImage()

sk_sp< SkImage > SkSurfaces::AsImage ( sk_sp< const SkSurface surface)

The 'AsImage' and 'AsImageCopy' API/entry points are currently only available for Graphite.

In this API, SkSurface no longer supports copy-on-write behavior. Instead, when creating an image for a surface, the client must explicitly indicate if a copy should be made. In both of the below calls the resource backing the surface will never change.

The 'AsImage' entry point has some major ramifications for the mutability of the returned SkImage. Since the originating surface and the returned image share the same backing, care must be taken by the client to ensure that the contents of the image reflect the desired contents when it is consumed by the gpu. Note: if the backing GPU buffer isn't textureable this method will return null. Graphite will not attempt to make a copy. Note: For 'AsImage', the mipmapping of the image will match that of the source surface.

The 'AsImageCopy' entry point allows subsetting and the addition of mipmaps (since a copy is already being made).

In Graphite, the legacy API call (i.e., makeImageSnapshot) will just always make a copy.

Definition at line 192 of file Surface_Graphite.cpp.

192 {
193 if (!surface) {
194 return nullptr;
195 }
196 auto sb = asConstSB(surface.get());
197 if (!sb->isGraphiteBacked()) {
198 return nullptr;
199 }
200 auto gs = static_cast<const Surface*>(surface.get());
201 return gs->asImage();
202}
static const SkSurface_Base * asConstSB(const SkSurface *surface)
VkSurfaceKHR surface
Definition main.cc:49

◆ AsImageCopy()

sk_sp< SkImage > SkSurfaces::AsImageCopy ( sk_sp< const SkSurface surface,
const SkIRect subset = nullptr,
skgpu::Mipmapped  mipmapped = skgpu::Mipmapped::kNo 
)

Definition at line 204 of file Surface_Graphite.cpp.

206 {
207 if (!surface) {
208 return nullptr;
209 }
210 auto sb = asConstSB(surface.get());
211 if (!sb->isGraphiteBacked()) {
212 return nullptr;
213 }
214 auto gs = static_cast<const Surface*>(surface.get());
215 return gs->makeImageCopy(subset, mipmapped);
216}

◆ GetBackendRenderTarget()

GrBackendRenderTarget SkSurfaces::GetBackendRenderTarget ( SkSurface surface,
BackendHandleAccess  access 
)

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

Definition at line 751 of file SkSurface_Ganesh.cpp.

751 {
752 if (surface == nullptr) {
753 return GrBackendRenderTarget();
754 }
755 auto sb = asSB(surface);
756 if (!sb->isGaneshBacked()) {
757 return GrBackendRenderTarget();
758 }
759 return static_cast<SkSurface_Ganesh*>(surface)->getBackendRenderTarget(access);
760}
static SkSurface_Base * asSB(SkSurface *surface)

◆ GetBackendTexture()

GrBackendTexture SkSurfaces::GetBackendTexture ( SkSurface surface,
BackendHandleAccess  access 
)

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

Definition at line 740 of file SkSurface_Ganesh.cpp.

740 {
741 if (surface == nullptr) {
742 return GrBackendTexture();
743 }
744 auto sb = asSB(surface);
745 if (!sb->isGaneshBacked()) {
746 return GrBackendTexture();
747 }
748 return static_cast<SkSurface_Ganesh*>(surface)->getBackendTexture(access);
749}

◆ ios()

SK_API sk_sp< SkSurface > SkSurfaces::ios ( 9.  0)

◆ Null()

sk_sp< SkSurface > SkSurfaces::Null ( int  width,
int  height 
)

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

Definition at line 52 of file SkSurface_Null.cpp.

52 {
53 if (width < 1 || height < 1) {
54 return nullptr;
55 }
57}
int32_t height
int32_t width

◆ Raster() [1/2]

sk_sp< SkSurface > SkSurfaces::Raster ( const SkImageInfo imageInfo,
const SkSurfaceProps props = nullptr 
)
inline

Definition at line 80 of file SkSurface.h.

81 {
82 return Raster(imageInfo, 0, props);
83}
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)

◆ Raster() [2/2]

sk_sp< SkSurface > SkSurfaces::Raster ( const SkImageInfo imageInfo,
size_t  rowBytes,
const SkSurfaceProps surfaceProps 
)

Allocates raster SkSurface. SkCanvas returned by SkSurface draws directly into those allocated pixels, which are zeroed before use. Pixel memory size is imageInfo.height() times imageInfo.minRowBytes() or rowBytes, if provided and non-zero.

Pixel memory is deleted when SkSurface is deleted.

Validity constraints 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
rowBytesinterval from one SkSurface row to the next.
propsLCD striping orientation and setting for device independent fonts; may be nullptr
Returns
SkSurface if parameters are valid and memory was allocated, else nullptr.

Definition at line 186 of file SkSurface_Raster.cpp.

186 {
188 return nullptr;
189 }
190
192 if (!pr) {
193 return nullptr;
194 }
195 if (rowBytes) {
196 SkASSERT(pr->rowBytes() == rowBytes);
197 }
198 return sk_make_sp<SkSurface_Raster>(info, std::move(pr), props);
199}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
#define SkASSERT(cond)
Definition SkAssert.h:116
bool SkSurfaceValidateRasterInfo(const SkImageInfo &info, size_t rowBytes)
SK_API sk_sp< SkPixelRef > MakeAllocate(const SkImageInfo &, size_t rowBytes)

◆ RenderTarget() [1/5]

sk_sp< SkSurface > SkSurfaces::RenderTarget ( GrRecordingContext context,
const GrSurfaceCharacterization characterization,
skgpu::Budgeted  budgeted 
)

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

Definition at line 553 of file SkSurface_Ganesh.cpp.

555 {
556 if (!rContext || !c.isValid()) {
557 return nullptr;
558 }
559
560 if (c.usesGLFBO0()) {
561 // If we are making the surface we will never use FBO0.
562 return nullptr;
563 }
564
565 if (c.vulkanSecondaryCBCompatible()) {
566 return nullptr;
567 }
568
569 auto device = rContext->priv().createDevice(budgeted,
570 c.imageInfo(),
572 c.sampleCount(),
573 skgpu::Mipmapped(c.isMipMapped()),
574 c.isProtected(),
575 c.origin(),
576 c.surfaceProps(),
578 if (!device) {
579 return nullptr;
580 }
581
582 sk_sp<SkSurface> result = sk_make_sp<SkSurface_Ganesh>(std::move(device));
583#ifdef SK_DEBUG
584 if (result) {
585 SkASSERT(result->isCompatible(c));
586 }
587#endif
588
589 return result;
590}
VkDevice device
Definition main.cc:53
GAsyncResult * result
Mipmapped
Definition GpuTypes.h:53

◆ RenderTarget() [2/5]

sk_sp< SkSurface > SkSurfaces::RenderTarget ( GrRecordingContext context,
skgpu::Budgeted  budgeted,
const SkImageInfo imageInfo 
)
inline

Definition at line 80 of file SkSurfaceGanesh.h.

82 {
83 if (!imageInfo.width() || !imageInfo.height()) {
84 return nullptr;
85 }
86 return RenderTarget(context, budgeted, imageInfo, 0, kBottomLeft_GrSurfaceOrigin, nullptr);
87}
@ kBottomLeft_GrSurfaceOrigin
Definition GrTypes.h:149
int width() const
int height() const

◆ RenderTarget() [3/5]

sk_sp< SkSurface > SkSurfaces::RenderTarget ( GrRecordingContext context,
skgpu::Budgeted  budgeted,
const SkImageInfo imageInfo,
int  sampleCount,
const SkSurfaceProps surfaceProps 
)
inline

Definition at line 72 of file SkSurfaceGanesh.h.

76 {
77 return RenderTarget(
78 context, budgeted, imageInfo, sampleCount, kBottomLeft_GrSurfaceOrigin, surfaceProps);
79}
SK_API sk_sp< SkSurface > RenderTarget(GrRecordingContext *context, skgpu::Budgeted budgeted, const SkImageInfo &imageInfo, int sampleCount, GrSurfaceOrigin surfaceOrigin, const SkSurfaceProps *surfaceProps, bool shouldCreateWithMips=false, bool isProtected=false)

◆ RenderTarget() [4/5]

sk_sp< SkSurface > SkSurfaces::RenderTarget ( GrRecordingContext context,
skgpu::Budgeted  budgeted,
const SkImageInfo imageInfo,
int  sampleCount,
GrSurfaceOrigin  surfaceOrigin,
const SkSurfaceProps surfaceProps,
bool  shouldCreateWithMips = false,
bool  isProtected = false 
)

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.

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
surfaceOriginHow to align the pixel data.
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

Definition at line 592 of file SkSurface_Ganesh.cpp.

599 {
600 if (!rContext) {
601 return nullptr;
602 }
603 sampleCount = std::max(1, sampleCount);
604 skgpu::Mipmapped mipmapped =
605 shouldCreateWithMips ? skgpu::Mipmapped::kYes : skgpu::Mipmapped::kNo;
606
607 if (!rContext->priv().caps()->mipmapSupport()) {
608 mipmapped = skgpu::Mipmapped::kNo;
609 }
610
611 auto device = rContext->priv().createDevice(budgeted,
612 info,
614 sampleCount,
615 mipmapped,
616 GrProtected(isProtected),
617 origin,
620 if (!device) {
621 return nullptr;
622 }
623 return sk_make_sp<SkSurface_Ganesh>(std::move(device));
624}
skgpu::Protected GrProtected
Definition GrTypes.h:139
static SkSurfaceProps SkSurfacePropsCopyOrDefault(const SkSurfaceProps *props)

◆ RenderTarget() [5/5]

sk_sp< SkSurface > SkSurfaces::RenderTarget ( skgpu::graphite::Recorder recorder,
const SkImageInfo imageInfo,
skgpu::Mipmapped  mipmapped = skgpu::Mipmapped::kNo,
const SkSurfaceProps surfaceProps = nullptr 
)

In Graphite, while clients hold a ref on an SkSurface, the backing gpu object does not count against the budget. Once an SkSurface is freed, the backing gpu object may or may not become a scratch (i.e., reusable) resource but, if it does, it will be counted against the budget.

Definition at line 218 of file Surface_Graphite.cpp.

221 {
222 // The client is getting the ref on this surface so it must be unbudgeted.
224 recorder, info, skgpu::Budgeted::kNo, mipmapped, SkBackingFit::kExact, props);
225}
static sk_sp< Surface > Make(Recorder *recorder, const SkImageInfo &info, Budgeted budgeted, Mipmapped mipmapped=Mipmapped::kNo, SkBackingFit backingFit=SkBackingFit::kExact, const SkSurfaceProps *props=nullptr)

◆ ResolveMSAA() [1/2]

void SkSurfaces::ResolveMSAA ( const sk_sp< SkSurface > &  surface)
inline

Definition at line 202 of file SkSurfaceGanesh.h.

202 {
203 return ResolveMSAA(surface.get());
204}
SK_API void ResolveMSAA(SkSurface *surface)

◆ ResolveMSAA() [2/2]

void SkSurfaces::ResolveMSAA ( SkSurface surface)

If a surface is a Ganesh-backed surface, is being drawn with MSAA, and there is a resolve texture, this call will insert a resolve command into the stream of gpu commands. In order for the resolve to actually have an effect, the work still needs to be flushed and submitted to the GPU after recording the resolve command. If a resolve is not supported or the SkSurface has no dirty work to resolve, then this call is a no-op.

This call is most useful when the SkSurface is created by wrapping a single sampled gpu texture, but asking Skia to render with MSAA. If the client wants to use the wrapped texture outside of Skia, the only way to trigger a resolve is either to call this command or use GrDirectContext::flush.

Definition at line 762 of file SkSurface_Ganesh.cpp.

762 {
763 if (!surface) {
764 return;
765 }
766 auto sb = asSB(surface);
767 if (!sb->isGaneshBacked()) {
768 return;
769 }
770 auto gs = static_cast<SkSurface_Ganesh*>(surface);
771 gs->resolveMSAA();
772}

◆ tvos()

SK_API sk_sp< SkSurface > SkSurfaces::tvos ( 9.  0)

◆ WrapAndroidHardwareBuffer() [1/2]

SK_API sk_sp< SkSurface > SkSurfaces::WrapAndroidHardwareBuffer ( GrDirectContext context,
AHardwareBuffer hardwareBuffer,
GrSurfaceOrigin  origin,
sk_sp< SkColorSpace colorSpace,
const SkSurfaceProps surfaceProps,
bool  fromWindow = false 
)

Private; only to be used by Android Framework. Creates SkSurface from Android hardware buffer. Returned SkSurface takes a reference on the buffer. The ref on the buffer will be released when the SkSurface is destroyed and there is no pending work on the GPU involving the buffer.

Currently this is only supported for buffers that can be textured as well as rendered to. In other words that must have both AHARDWAREBUFFER_USAGE_GPU_COLOR_OUTPUT and AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE usage bits.

Parameters
contextGPU context
hardwareBufferAHardwareBuffer Android hardware buffer
colorSpacerange of colors; may be nullptr
surfacePropsLCD striping orientation and setting for device independent fonts; may be nullptr
fromWindowWhether or not the AHardwareBuffer is part of an Android Window. Currently only used with Vulkan backend.
Returns
created SkSurface, or nullptr

◆ WrapAndroidHardwareBuffer() [2/2]

SK_API sk_sp< SkSurface > SkSurfaces::WrapAndroidHardwareBuffer ( skgpu::graphite::Recorder recorder,
AHardwareBuffer hardwareBuffer,
sk_sp< SkColorSpace colorSpace,
const SkSurfaceProps surfaceProps,
BufferReleaseProc  = nullptr,
ReleaseContext  = nullptr,
bool  fromWindow = false 
)

Private; only to be used by Android Framework. Creates an SkSurface from an Android hardware buffer.

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

Currently this is only supported for buffers that can be textured as well as rendered to. In other words the buffer must have both AHARDWAREBUFFER_USAGE_GPU_COLOR_OUTPUT and AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE usage bits.

Parameters
recorderthe applicable Graphite recorder
hardwareBufferan Android hardware buffer
colorSpacerange of colors; may be nullptr
surfacePropsLCD striping orientation and setting for device independent fonts; may be nullptr
bufferReleaseProcfunction called when the buffer can be released
ReleaseContextstate passed to bufferReleaseProc
fromWindowWhether or not the AHardwareBuffer is part of an Android Window. Currently only used with Vulkan backend.
Returns
created SkSurface, or nullptr

◆ WrapBackendRenderTarget()

sk_sp< SkSurface > SkSurfaces::WrapBackendRenderTarget ( 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. 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.

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

Definition at line 698 of file SkSurface_Ganesh.cpp.

705 {
706 auto releaseHelper = skgpu::RefCntedCallback::Make(relProc, releaseContext);
707
708 if (!rContext) {
709 return nullptr;
710 }
711
713 if (grColorType == GrColorType::kUnknown) {
714 return nullptr;
715 }
716
717 if (!validate_backend_render_target(rContext->priv().caps(), rt, grColorType)) {
718 return nullptr;
719 }
720
721 auto proxyProvider = rContext->priv().proxyProvider();
722 auto proxy = proxyProvider->wrapBackendRenderTarget(rt, std::move(releaseHelper));
723 if (!proxy) {
724 return nullptr;
725 }
726
727 auto device = rContext->priv().createDevice(grColorType,
728 std::move(proxy),
729 std::move(colorSpace),
730 origin,
733 if (!device) {
734 return nullptr;
735 }
736
737 return sk_make_sp<SkSurface_Ganesh>(std::move(device));
738}
GrColorType
static constexpr GrColorType SkColorTypeToGrColorType(SkColorType ct)
static SkColorType colorType(AImageDecoder *decoder, const AImageDecoderHeaderInfo *headerInfo)
bool validate_backend_render_target(const GrCaps *caps, const GrBackendRenderTarget &rt, GrColorType grCT)
static sk_sp< RefCntedCallback > Make(Callback proc, Context ctx)

◆ WrapBackendTexture() [1/2]

sk_sp< SkSurface > SkSurfaces::WrapBackendTexture ( 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. 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.

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

Definition at line 626 of file SkSurface_Ganesh.cpp.

634 {
635 auto releaseHelper = skgpu::RefCntedCallback::Make(textureReleaseProc, releaseContext);
636
637 if (!rContext) {
638 RENDERENGINE_ABORTF("%s failed due to a null context ", __func__);
639 return nullptr;
640 }
641 sampleCnt = std::max(1, sampleCnt);
642
644 if (grColorType == GrColorType::kUnknown) {
645 RENDERENGINE_ABORTF("%s failed due to an unsupported colorType %d", __func__, colorType);
646 return nullptr;
647 }
648
649 if (!validate_backend_texture(rContext->priv().caps(), tex, sampleCnt, grColorType, true)) {
650 return nullptr;
651 }
652
653 sk_sp<GrTextureProxy> proxy(rContext->priv().proxyProvider()->wrapRenderableBackendTexture(
654 tex,
655 sampleCnt,
658 std::move(releaseHelper)));
659 if (!proxy) {
660 // TODO(scroggo,kjlubick) inline this into Android's AutoBackendTexture.cpp so we
661 // don't have a sometimes-dependency on the GL backend.
662#ifdef SK_IN_RENDERENGINE
663 GrGLTextureInfo textureInfo;
664 bool retrievedTextureInfo = GrBackendTextures::GetGLTextureInfo(tex, &textureInfo);
666 "%s failed to wrap the texture into a renderable target "
667 "\n\tGrBackendTexture: (%i x %i) hasMipmaps: %i isProtected: %i texType: %i"
668 "\n\t\tGrGLTextureInfo: success: %i fTarget: %u fFormat: %u"
669 "\n\tmaxRenderTargetSize: %d",
670 __func__,
671 tex.width(),
672 tex.height(),
673 tex.hasMipmaps(),
674 tex.isProtected(),
675 static_cast<int>(tex.textureType()),
676 retrievedTextureInfo,
677 textureInfo.fTarget,
678 textureInfo.fFormat,
679 rContext->priv().caps()->maxRenderTargetSize());
680#endif
681 return nullptr;
682 }
683
684 auto device = rContext->priv().createDevice(grColorType,
685 std::move(proxy),
686 std::move(colorSpace),
687 origin,
690 if (!device) {
691 RENDERENGINE_ABORTF("%s failed to wrap the renderTarget into a surface", __func__);
692 return nullptr;
693 }
694
695 return sk_make_sp<SkSurface_Ganesh>(std::move(device));
696}
@ kBorrow_GrWrapOwnership
Definition GrTypesPriv.h:78
#define RENDERENGINE_ABORTF(...)
static bool validate_backend_texture(const GrCaps *caps, const GrBackendTexture &tex, int sampleCnt, GrColorType grCT, bool texturable)
SK_API bool GetGLTextureInfo(const GrBackendTexture &, GrGLTextureInfo *)
GrGLenum fFormat
Definition GrGLTypes.h:183
GrGLenum fTarget
Definition GrGLTypes.h:181

◆ WrapBackendTexture() [2/2]

sk_sp< SkSurface > SkSurfaces::WrapBackendTexture ( skgpu::graphite::Recorder recorder,
const skgpu::graphite::BackendTexture backendTex,
SkColorType  colorType,
sk_sp< SkColorSpace colorSpace,
const SkSurfaceProps props,
TextureReleaseProc  releaseP = nullptr,
ReleaseContext  releaseC = nullptr 
)

Wraps a GPU-backed texture in an SkSurface. Depending on the backend gpu API, the caller may be required to ensure the texture is valid for the lifetime of the returned SkSurface. The required lifetimes for the specific apis are: Metal: Skia will call retain on the underlying MTLTexture so the caller can drop it once this call returns.

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

Definition at line 227 of file Surface_Graphite.cpp.

233 {
234 auto releaseHelper = skgpu::RefCntedCallback::Make(releaseP, releaseC);
235
236 if (!recorder) {
237 return nullptr;
238 }
239
240 const Caps* caps = recorder->priv().caps();
241
242 SkColorInfo info(ct, kPremul_SkAlphaType, std::move(cs));
243
244 if (!validate_backend_texture(caps, backendTex, info)) {
245 SKGPU_LOG_E("validate_backend_texture failed: backendTex.info = %s; colorType = %d",
246 backendTex.info().toString().c_str(),
247 info.colorType());
248 return nullptr;
249 }
250
252 if (!texture) {
253 return nullptr;
254 }
255 texture->setReleaseCallback(std::move(releaseHelper));
256
258 SkISize deviceSize = proxy->dimensions();
259 // Use kLoad for this device to preserve the existing contents of the wrapped backend texture.
261 std::move(proxy),
262 deviceSize,
263 info,
265 LoadOp::kLoad);
266 return device ? sk_make_sp<Surface>(std::move(device)) : nullptr;
267}
#define SKGPU_LOG_E(fmt,...)
Definition Log.h:38
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition SkAlphaType.h:29
const char * c_str() const
Definition SkString.h:133
const TextureInfo & info() const
static sk_sp< Device > Make(Recorder *recorder, sk_sp< TextureProxy >, SkISize deviceSize, const SkColorInfo &, const SkSurfaceProps &, LoadOp initialLoadOp, bool registerWithRecorder=true)
Definition Device.cpp:268
const Caps * caps() const
ResourceProvider * resourceProvider()
virtual sk_sp< Texture > createWrappedTexture(const BackendTexture &)=0
static sk_sp< TextureProxy > Wrap(sk_sp< Texture >)
FlTexture * texture

◆ WrapCAMetalLayer()

sk_sp< SkSurface > SkSurfaces::WrapCAMetalLayer ( GrRecordingContext context,
GrMTLHandle  layer,
GrSurfaceOrigin  origin,
int  sampleCnt,
SkColorType  colorType,
sk_sp< SkColorSpace colorSpace,
const SkSurfaceProps surfaceProps,
GrMTLHandle drawable 
)

Creates SkSurface from CAMetalLayer. Returned SkSurface takes a reference on the CAMetalLayer. The ref on the layer will be released when the SkSurface is destroyed.

Only available when Metal API is enabled.

Will grab the current drawable from the layer and use its texture as a backendRT to create a renderable surface.

Parameters
contextGPU context
layerGrMTLHandle (expected to be a CAMetalLayer*)
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
drawablePointer to drawable to be filled in when this surface is instantiated; may not be nullptr
Returns
created SkSurface, or nullptr

Definition at line 31 of file SkSurface_GaneshMtl.mm.

38 {
39 GrProxyProvider* proxyProvider = rContext->priv().proxyProvider();
40
41 CAMetalLayer* metalLayer = (__bridge CAMetalLayer*)layer;
42 GrBackendFormat backendFormat = GrBackendFormats::MakeMtl(metalLayer.pixelFormat);
43
45
46 SkISize dims = {(int)metalLayer.drawableSize.width, (int)metalLayer.drawableSize.height};
47
49 texInfo.fMipmapped = skgpu::Mipmapped::kNo;
51
53 [layer, drawable](GrResourceProvider* resourceProvider,
55 CAMetalLayer* metalLayer = (__bridge CAMetalLayer*)layer;
56 id<CAMetalDrawable> currentDrawable = [metalLayer nextDrawable];
57
58 GrMtlGpu* mtlGpu = (GrMtlGpu*)resourceProvider->priv().gpu();
60 if (metalLayer.framebufferOnly) {
62 mtlGpu, desc.fDimensions, desc.fSampleCnt, currentDrawable.texture);
63 } else {
65 mtlGpu,
66 desc.fDimensions,
67 desc.fSampleCnt,
68 currentDrawable.texture,
70 }
71 if (surface && desc.fSampleCnt > 1) {
72 surface->setRequiresManualMSAAResolve();
73 }
74
75 *drawable = (__bridge_retained GrMTLHandle)currentDrawable;
77 },
78 backendFormat,
79 dims,
80 sampleCnt,
83 metalLayer.framebufferOnly ? nullptr : &texInfo,
87 GrProtected::kNo,
88 false,
90
91 auto device = rContext->priv().createDevice(grColorType,
92 std::move(proxy),
93 std::move(colorSpace),
94 origin,
95 SkSurfacePropsCopyOrDefault(surfaceProps),
97 if (!device) {
98 return nullptr;
99 }
100
101 return sk_make_sp<SkSurface_Ganesh>(std::move(device));
102}
const void * GrMTLHandle
Definition GrMtlTypes.h:20
Type::kYUV Type::kRGBA() int(0.7 *637)
static sk_sp< GrMtlRenderTarget > MakeWrappedRenderTarget(GrMtlGpu *, SkISize, int sampleCnt, id< MTLTexture >)
static sk_sp< GrMtlTextureRenderTarget > MakeWrappedTextureRenderTarget(GrMtlGpu *, SkISize, int sampleCnt, id< MTLTexture >, GrWrapCacheable)
sk_sp< GrRenderTargetProxy > createLazyRenderTargetProxy(LazyInstantiateCallback &&, const GrBackendFormat &, SkISize dimensions, int renderTargetSampleCnt, GrInternalSurfaceFlags, const TextureInfo *, GrMipmapStatus, SkBackingFit, skgpu::Budgeted, GrProtected, bool wrapsVkSecondaryCB, UseAllocator useAllocator)
GrResourceProviderPriv priv()
GrSurfaceProxyPriv priv()
SK_API GrBackendFormat MakeMtl(GrMTLPixelFormat format)
constexpr int32_t width() const
Definition SkSize.h:36

◆ WrapMTKView()

sk_sp< SkSurface > SkSurfaces::WrapMTKView ( GrRecordingContext context,
GrMTLHandle  mtkView,
GrSurfaceOrigin  origin,
int  sampleCnt,
SkColorType  colorType,
sk_sp< SkColorSpace colorSpace,
const SkSurfaceProps surfaceProps 
)

Creates SkSurface from MTKView. Returned SkSurface takes a reference on the MTKView. The ref on the layer will be released when the SkSurface is destroyed.

Only available when Metal API is enabled.

Will grab the current drawable from the layer and use its texture as a backendRT to create a renderable surface.

Parameters
contextGPU context
layerGrMTLHandle (expected to be a MTKView*)
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
Returns
created SkSurface, or nullptr

Definition at line 104 of file SkSurface_GaneshMtl.mm.

110 {
111 GrProxyProvider* proxyProvider = rContext->priv().proxyProvider();
112
113 MTKView* mtkView = (__bridge MTKView*)view;
114 GrBackendFormat backendFormat = GrBackendFormats::MakeMtl(mtkView.colorPixelFormat);
115
117
118 SkISize dims = {(int)mtkView.drawableSize.width, (int)mtkView.drawableSize.height};
119
121 texInfo.fMipmapped = skgpu::Mipmapped::kNo;
123
125 [view](GrResourceProvider* resourceProvider,
127 MTKView* mtkView = (__bridge MTKView*)view;
128 id<CAMetalDrawable> currentDrawable = [mtkView currentDrawable];
129
130 GrMtlGpu* mtlGpu = (GrMtlGpu*)resourceProvider->priv().gpu();
132 if (mtkView.framebufferOnly) {
134 mtlGpu, desc.fDimensions, desc.fSampleCnt, currentDrawable.texture);
135 } else {
137 mtlGpu,
138 desc.fDimensions,
139 desc.fSampleCnt,
140 currentDrawable.texture,
142 }
143 if (surface && desc.fSampleCnt > 1) {
144 surface->setRequiresManualMSAAResolve();
145 }
146
148 },
149 backendFormat,
150 dims,
151 sampleCnt,
154 mtkView.framebufferOnly ? nullptr : &texInfo,
158 GrProtected::kNo,
159 false,
161
162 auto device = rContext->priv().createDevice(grColorType,
163 std::move(proxy),
164 std::move(colorSpace),
165 origin,
166 SkSurfacePropsCopyOrDefault(surfaceProps),
168 if (!device) {
169 return nullptr;
170 }
171
172 return sk_make_sp<SkSurface_Ganesh>(std::move(device));
173}

◆ WrapPixels() [1/3]

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

Allocates raster SkSurface. SkCanvas returned by SkSurface draws directly into the provided 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

Definition at line 179 of file SkSurface_Raster.cpp.

182 {
183 return WrapPixels(info, pixels, rowBytes, nullptr, nullptr, props);
184}
SK_API sk_sp< SkSurface > WrapPixels(const SkImageInfo &imageInfo, void *pixels, size_t rowBytes, const SkSurfaceProps *surfaceProps=nullptr)

◆ WrapPixels() [2/3]

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

Allocates raster SkSurface. SkCanvas returned by SkSurface draws directly into the provided 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

Definition at line 160 of file SkSurface_Raster.cpp.

165 {
166 if (nullptr == releaseProc) {
167 context = nullptr;
168 }
169 if (!SkSurfaceValidateRasterInfo(info, rowBytes)) {
170 return nullptr;
171 }
172 if (nullptr == pixels) {
173 return nullptr;
174 }
175
176 return sk_make_sp<SkSurface_Raster>(info, pixels, rowBytes, releaseProc, context, props);
177}
static void releaseProc(const void *ptr, void *context)

◆ WrapPixels() [3/3]

sk_sp< SkSurface > SkSurfaces::WrapPixels ( const SkPixmap pm,
const SkSurfaceProps props = nullptr 
)
inline

Definition at line 112 of file SkSurface.h.

112 {
113 return WrapPixels(pm.info(), pm.writable_addr(), pm.rowBytes(), props);
114}
size_t rowBytes() const
Definition SkPixmap.h:145
const SkImageInfo & info() const
Definition SkPixmap.h:135
void * writable_addr() const
Definition SkPixmap.h:483