Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Surface.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 skgpu_graphite_Surface_DEFINED
9#define skgpu_graphite_Surface_DEFINED
10
14
15class SkImage;
16struct SkImageInfo;
17
18namespace skgpu::graphite {
19class BackendTexture;
20class Recorder;
21} // namespace skgpu::graphite
22
23namespace SkSurfaces {
24using ReleaseContext = void*;
25using TextureReleaseProc = void (*)(ReleaseContext);
26
27/**
28 * The 'AsImage' and 'AsImageCopy' API/entry points are currently only available for
29 * Graphite.
30 *
31 * In this API, SkSurface no longer supports copy-on-write behavior. Instead, when creating
32 * an image for a surface, the client must explicitly indicate if a copy should be made.
33 * In both of the below calls the resource backing the surface will never change.
34 *
35 * The 'AsImage' entry point has some major ramifications for the mutability of the
36 * returned SkImage. Since the originating surface and the returned image share the
37 * same backing, care must be taken by the client to ensure that the contents of the image
38 * reflect the desired contents when it is consumed by the gpu.
39 * Note: if the backing GPU buffer isn't textureable this method will return null. Graphite
40 * will not attempt to make a copy.
41 * Note: For 'AsImage', the mipmapping of the image will match that of the source surface.
42 *
43 * The 'AsImageCopy' entry point allows subsetting and the addition of mipmaps (since
44 * a copy is already being made).
45 *
46 * In Graphite, the legacy API call (i.e., makeImageSnapshot) will just always make a copy.
47 */
50 const SkIRect* subset = nullptr,
51 skgpu::Mipmapped = skgpu::Mipmapped::kNo);
52
53/**
54 * In Graphite, while clients hold a ref on an SkSurface, the backing gpu object does _not_
55 * count against the budget. Once an SkSurface is freed, the backing gpu object may or may
56 * not become a scratch (i.e., reusable) resource but, if it does, it will be counted against
57 * the budget.
58 */
60 const SkImageInfo& imageInfo,
61 skgpu::Mipmapped = skgpu::Mipmapped::kNo,
62 const SkSurfaceProps* surfaceProps = nullptr);
63
64/**
65 * Wraps a GPU-backed texture in an SkSurface. Depending on the backend gpu API, the caller may
66 * be required to ensure the texture is valid for the lifetime of the returned SkSurface. The
67 * required lifetimes for the specific apis are:
68 * Metal: Skia will call retain on the underlying MTLTexture so the caller can drop it once
69 * this call returns.
70 *
71 * SkSurface is returned if all the parameters are valid. The backendTexture is valid if its
72 * format agrees with colorSpace and recorder; for instance, if backendTexture has an sRGB
73 * configuration, then the recorder must support sRGB, and colorSpace must be present. Further,
74 * backendTexture's width and height must not exceed the recorder's capabilities, and the
75 * recorder must be able to support the back-end texture.
76 */
80 sk_sp<SkColorSpace> colorSpace,
81 const SkSurfaceProps* props,
82 TextureReleaseProc = nullptr,
83 ReleaseContext = nullptr);
84} // namespace SkSurfaces
85
86#endif // skgpu_graphite_Surface_DEFINED
#define SK_API
Definition SkAPI.h:35
SkColorType
Definition SkColorType.h:19
static SkColorType colorType(AImageDecoder *decoder, const AImageDecoderHeaderInfo *headerInfo)
void * ReleaseContext
SK_API sk_sp< SkImage > AsImage(sk_sp< const SkSurface >)
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)
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 sk_sp< SkImage > AsImageCopy(sk_sp< const SkSurface >, const SkIRect *subset=nullptr, skgpu::Mipmapped=skgpu::Mipmapped::kNo)
Mipmapped
Definition GpuTypes.h:53