Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkSurfaceGanesh.h
Go to the documentation of this file.
1/*
2 * Copyright 2023 Google LLC
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef SkSurfaceGanesh_DEFINED
9#define SkSurfaceGanesh_DEFINED
10
14#include "include/gpu/GrTypes.h"
16
20class SkColorSpace;
22class SkSurfaceProps;
23enum SkColorType : int;
24namespace skgpu {
25enum class Budgeted : bool;
26}
27
28namespace SkSurfaces {
29
30/** Caller data passed to RenderTarget/TextureReleaseProc; may be nullptr. */
31using ReleaseContext = void*;
32
33/** User function called when supplied render target may be deleted. */
35
36/** User function called when supplied texture may be deleted. */
38
39/** Returns SkSurface on GPU indicated by context. Allocates memory for
40 pixels, based on the width, height, and SkColorType in SkImageInfo. budgeted
41 selects whether allocation for pixels is tracked by context. imageInfo
42 describes the pixel format in SkColorType, and transparency in
43 SkAlphaType, and color matching in SkColorSpace.
44
45 sampleCount requests the number of samples per pixel.
46 Pass zero to disable multi-sample anti-aliasing. The request is rounded
47 up to the next supported count, or rounded down if it is larger than the
48 maximum supported count.
49
50 surfaceOrigin pins either the top-left or the bottom-left corner to the origin.
51
52 shouldCreateWithMips hints that SkImage returned by makeImageSnapshot() is mip map.
53
54 @param context GPU context
55 @param imageInfo width, height, SkColorType, SkAlphaType, SkColorSpace;
56 width, or height, or both, may be zero
57 @param sampleCount samples per pixel, or 0 to disable full scene anti-aliasing
58 @param surfaceOrigin How to align the pixel data.
59 @param surfaceProps LCD striping orientation and setting for device independent
60 fonts; may be nullptr
61 @param shouldCreateWithMips hint that SkSurface will host mip map images
62 @return SkSurface if all parameters are valid; otherwise, nullptr
63*/
65 skgpu::Budgeted budgeted,
66 const SkImageInfo& imageInfo,
67 int sampleCount,
68 GrSurfaceOrigin surfaceOrigin,
69 const SkSurfaceProps* surfaceProps,
70 bool shouldCreateWithMips = false,
71 bool isProtected = false);
73 skgpu::Budgeted budgeted,
74 const SkImageInfo& imageInfo,
75 int sampleCount,
76 const SkSurfaceProps* surfaceProps) {
77 return RenderTarget(
78 context, budgeted, imageInfo, sampleCount, kBottomLeft_GrSurfaceOrigin, surfaceProps);
79}
81 skgpu::Budgeted budgeted,
82 const SkImageInfo& imageInfo) {
83 if (!imageInfo.width() || !imageInfo.height()) {
84 return nullptr;
85 }
86 return RenderTarget(context, budgeted, imageInfo, 0, kBottomLeft_GrSurfaceOrigin, nullptr);
87}
88
89/** Returns SkSurface on GPU indicated by context that is compatible with the provided
90 characterization. budgeted selects whether allocation for pixels is tracked by context.
91
92 @param context GPU context
93 @param characterization description of the desired SkSurface
94 @return SkSurface if all parameters are valid; otherwise, nullptr
95*/
97 const GrSurfaceCharacterization& characterization,
98 skgpu::Budgeted budgeted);
99
100/** Wraps a GPU-backed texture into SkSurface. Caller must ensure the texture is
101 valid for the lifetime of returned SkSurface. If sampleCnt greater than zero,
102 creates an intermediate MSAA SkSurface which is used for drawing backendTexture.
103
104 SkSurface is returned if all parameters are valid. backendTexture is valid if
105 its pixel configuration agrees with colorSpace and context; for instance, if
106 backendTexture has an sRGB configuration, then context must support sRGB,
107 and colorSpace must be present. Further, backendTexture width and height must
108 not exceed context capabilities, and the context must be able to support
109 back-end textures.
110
111 Upon success textureReleaseProc is called when it is safe to delete the texture in the
112 backend API (accounting only for use of the texture by this surface). If SkSurface creation
113 fails textureReleaseProc is called before this function returns.
114
115 @param context GPU context
116 @param backendTexture texture residing on GPU
117 @param sampleCnt samples per pixel, or 0 to disable full scene anti-aliasing
118 @param colorSpace range of colors; may be nullptr
119 @param surfaceProps LCD striping orientation and setting for device independent
120 fonts; may be nullptr
121 @param textureReleaseProc function called when texture can be released
122 @param releaseContext state passed to textureReleaseProc
123 @return SkSurface if all parameters are valid; otherwise, nullptr
124*/
126 const GrBackendTexture& backendTexture,
127 GrSurfaceOrigin origin,
128 int sampleCnt,
130 sk_sp<SkColorSpace> colorSpace,
131 const SkSurfaceProps* surfaceProps,
132 TextureReleaseProc textureReleaseProc = nullptr,
133 ReleaseContext releaseContext = nullptr);
134
135/** Wraps a GPU-backed buffer into SkSurface. Caller must ensure backendRenderTarget
136 is valid for the lifetime of returned SkSurface.
137
138 SkSurface is returned if all parameters are valid. backendRenderTarget is valid if
139 its pixel configuration agrees with colorSpace and context; for instance, if
140 backendRenderTarget has an sRGB configuration, then context must support sRGB,
141 and colorSpace must be present. Further, backendRenderTarget width and height must
142 not exceed context capabilities, and the context must be able to support
143 back-end render targets.
144
145 Upon success releaseProc is called when it is safe to delete the render target in the
146 backend API (accounting only for use of the render target by this surface). If SkSurface
147 creation fails releaseProc is called before this function returns.
148
149 @param context GPU context
150 @param backendRenderTarget GPU intermediate memory buffer
151 @param colorSpace range of colors
152 @param surfaceProps LCD striping orientation and setting for device independent
153 fonts; may be nullptr
154 @param releaseProc function called when backendRenderTarget can be released
155 @param releaseContext state passed to releaseProc
156 @return SkSurface if all parameters are valid; otherwise, nullptr
157*/
159 const GrBackendRenderTarget& backendRenderTarget,
160 GrSurfaceOrigin origin,
162 sk_sp<SkColorSpace> colorSpace,
163 const SkSurfaceProps* surfaceProps,
165 ReleaseContext releaseContext = nullptr);
166
168
169/** Retrieves the back-end texture. If SkSurface has no back-end texture, an invalid
170 object is returned. Call GrBackendTexture::isValid to determine if the result
171 is valid.
172
173 The returned GrBackendTexture should be discarded if the SkSurface is drawn to or deleted.
174
175 @return GPU texture reference; invalid on failure
176*/
178
179/** Retrieves the back-end render target. If SkSurface has no back-end render target, an invalid
180 object is returned. Call GrBackendRenderTarget::isValid to determine if the result
181 is valid.
182
183 The returned GrBackendRenderTarget should be discarded if the SkSurface is drawn to
184 or deleted.
185
186 @return GPU render target reference; invalid on failure
187*/
189
190/** If a surface is a Ganesh-backed surface, is being drawn with MSAA, and there is a resolve
191 texture, this call will insert a resolve command into the stream of gpu commands. In order
192 for the resolve to actually have an effect, the work still needs to be flushed and submitted
193 to the GPU after recording the resolve command. If a resolve is not supported or the
194 SkSurface has no dirty work to resolve, then this call is a no-op.
195
196 This call is most useful when the SkSurface is created by wrapping a single sampled gpu
197 texture, but asking Skia to render with MSAA. If the client wants to use the wrapped texture
198 outside of Skia, the only way to trigger a resolve is either to call this command or use
199 GrDirectContext::flush.
200 */
203 return ResolveMSAA(surface.get());
204}
205
206} // namespace SkSurfaces
207
208namespace skgpu::ganesh {
209// Clients should strive to call GrDirectContext::flush directly. However, there exist some
210// places where the GrDirectContext is hard to find, these helpers allow for the flushing of the
211// provided surface. This is a no-op if the surface is nullptr or not GPU backed.
216} // namespace skgpu::ganesh
217
218#endif
GrSurfaceOrigin
Definition GrTypes.h:147
@ kBottomLeft_GrSurfaceOrigin
Definition GrTypes.h:149
GrSemaphoresSubmitted
Definition GrTypes.h:229
#define SK_API
Definition SkAPI.h:35
SkColorType
Definition SkColorType.h:19
static void releaseProc(const void *ptr, void *context)
static SkColorType colorType(AImageDecoder *decoder, const AImageDecoderHeaderInfo *headerInfo)
Type::kYUV Type::kRGBA() int(0.7 *637)
BackendHandleAccess
Definition SkSurface.h:229
VkSurfaceKHR surface
Definition main.cc:49
SK_API sk_sp< SkSurface > WrapBackendRenderTarget(GrRecordingContext *context, const GrBackendRenderTarget &backendRenderTarget, GrSurfaceOrigin origin, SkColorType colorType, sk_sp< SkColorSpace > colorSpace, const SkSurfaceProps *surfaceProps, RenderTargetReleaseProc releaseProc=nullptr, ReleaseContext releaseContext=nullptr)
void * ReleaseContext
SK_API void ResolveMSAA(SkSurface *surface)
SK_API GrBackendTexture GetBackendTexture(SkSurface *, BackendHandleAccess)
void(*)(ReleaseContext) RenderTargetReleaseProc
SK_API sk_sp< SkSurface > 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)
SK_API GrBackendRenderTarget GetBackendRenderTarget(SkSurface *, BackendHandleAccess)
void(*)(ReleaseContext) TextureReleaseProc
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)
SK_API void FlushAndSubmit(sk_sp< SkSurface >)
SK_API GrSemaphoresSubmitted Flush(sk_sp< SkSurface >)
Budgeted
Definition GpuTypes.h:35
int width() const
int height() const