xref: /aosp_15_r20/external/skia/include/gpu/graphite/Image.h (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1*c8dee2aaSAndroid Build Coastguard Worker /*
2*c8dee2aaSAndroid Build Coastguard Worker  * Copyright 2023 Google LLC
3*c8dee2aaSAndroid Build Coastguard Worker  *
4*c8dee2aaSAndroid Build Coastguard Worker  * Use of this source code is governed by a BSD-style license that can be
5*c8dee2aaSAndroid Build Coastguard Worker  * found in the LICENSE file.
6*c8dee2aaSAndroid Build Coastguard Worker  */
7*c8dee2aaSAndroid Build Coastguard Worker 
8*c8dee2aaSAndroid Build Coastguard Worker #ifndef skgpu_graphite_Image_DEFINED
9*c8dee2aaSAndroid Build Coastguard Worker #define skgpu_graphite_Image_DEFINED
10*c8dee2aaSAndroid Build Coastguard Worker 
11*c8dee2aaSAndroid Build Coastguard Worker #include "include/core/SkColorSpace.h"
12*c8dee2aaSAndroid Build Coastguard Worker #include "include/core/SkImage.h"
13*c8dee2aaSAndroid Build Coastguard Worker #include "include/core/SkRefCnt.h"
14*c8dee2aaSAndroid Build Coastguard Worker #include "include/core/SkSpan.h"
15*c8dee2aaSAndroid Build Coastguard Worker #include "include/gpu/GpuTypes.h"
16*c8dee2aaSAndroid Build Coastguard Worker 
17*c8dee2aaSAndroid Build Coastguard Worker #include <string_view>
18*c8dee2aaSAndroid Build Coastguard Worker 
19*c8dee2aaSAndroid Build Coastguard Worker class SkYUVAInfo;
20*c8dee2aaSAndroid Build Coastguard Worker class SkYUVAPixmaps;
21*c8dee2aaSAndroid Build Coastguard Worker struct SkIRect;
22*c8dee2aaSAndroid Build Coastguard Worker 
23*c8dee2aaSAndroid Build Coastguard Worker namespace skgpu::graphite {
24*c8dee2aaSAndroid Build Coastguard Worker     class BackendTexture;
25*c8dee2aaSAndroid Build Coastguard Worker     class Recorder;
26*c8dee2aaSAndroid Build Coastguard Worker     class TextureInfo;
27*c8dee2aaSAndroid Build Coastguard Worker     class YUVABackendTextureInfo;
28*c8dee2aaSAndroid Build Coastguard Worker     class YUVABackendTextures;
29*c8dee2aaSAndroid Build Coastguard Worker     enum class Volatile : bool;
30*c8dee2aaSAndroid Build Coastguard Worker }
31*c8dee2aaSAndroid Build Coastguard Worker 
32*c8dee2aaSAndroid Build Coastguard Worker namespace SkImages {
33*c8dee2aaSAndroid Build Coastguard Worker enum class GenerateMipmapsFromBase : bool { kNo, kYes };
34*c8dee2aaSAndroid Build Coastguard Worker 
35*c8dee2aaSAndroid Build Coastguard Worker using TextureReleaseProc = void (*)(ReleaseContext);
36*c8dee2aaSAndroid Build Coastguard Worker 
37*c8dee2aaSAndroid Build Coastguard Worker // Passed to imageRelease
38*c8dee2aaSAndroid Build Coastguard Worker using GraphitePromiseImageContext = void*;
39*c8dee2aaSAndroid Build Coastguard Worker // Passed to fulfill; for non-YUVA promise images, the image context is used as the fulfill context,
40*c8dee2aaSAndroid Build Coastguard Worker // while YUVA promise images have a per-plane fulfill context.
41*c8dee2aaSAndroid Build Coastguard Worker using GraphitePromiseTextureFulfillContext = void*;
42*c8dee2aaSAndroid Build Coastguard Worker // Returned from fulfill and passed into textureRelease
43*c8dee2aaSAndroid Build Coastguard Worker using GraphitePromiseTextureReleaseContext = void*;
44*c8dee2aaSAndroid Build Coastguard Worker 
45*c8dee2aaSAndroid Build Coastguard Worker using GraphitePromiseTextureFulfillProc =
46*c8dee2aaSAndroid Build Coastguard Worker         std::tuple<skgpu::graphite::BackendTexture, GraphitePromiseTextureReleaseContext> (*)(
47*c8dee2aaSAndroid Build Coastguard Worker                 GraphitePromiseTextureFulfillContext);
48*c8dee2aaSAndroid Build Coastguard Worker using GraphitePromiseImageReleaseProc = void (*)(GraphitePromiseImageContext);
49*c8dee2aaSAndroid Build Coastguard Worker using GraphitePromiseTextureReleaseProc = void (*)(GraphitePromiseTextureReleaseContext);
50*c8dee2aaSAndroid Build Coastguard Worker 
51*c8dee2aaSAndroid Build Coastguard Worker /** Creates an SkImage from a GPU texture associated with the recorder. The client is still
52*c8dee2aaSAndroid Build Coastguard Worker     responsible for managing the backend texture's lifetime.
53*c8dee2aaSAndroid Build Coastguard Worker 
54*c8dee2aaSAndroid Build Coastguard Worker     SkImage is returned if the format of backendTexture is recognized and supported.
55*c8dee2aaSAndroid Build Coastguard Worker     Recognized formats vary by GPU back-end.
56*c8dee2aaSAndroid Build Coastguard Worker 
57*c8dee2aaSAndroid Build Coastguard Worker     @param recorder                The recorder
58*c8dee2aaSAndroid Build Coastguard Worker     @param backendTexture          texture residing on GPU
59*c8dee2aaSAndroid Build Coastguard Worker     @param colorSpace              This describes the color space of this image's contents, as
60*c8dee2aaSAndroid Build Coastguard Worker                                    seen after sampling. In general, if the format of the backend
61*c8dee2aaSAndroid Build Coastguard Worker                                    texture is SRGB, some linear colorSpace should be supplied
62*c8dee2aaSAndroid Build Coastguard Worker                                    (e.g., SkColorSpace::MakeSRGBLinear()). If the format of the
63*c8dee2aaSAndroid Build Coastguard Worker                                    backend texture is linear, then the colorSpace should include
64*c8dee2aaSAndroid Build Coastguard Worker                                    a description of the transfer function as
65*c8dee2aaSAndroid Build Coastguard Worker                                    well (e.g., SkColorSpace::MakeSRGB()).
66*c8dee2aaSAndroid Build Coastguard Worker     @param origin                  Whether the Texture logically treats the origin as TopLeft or
67*c8dee2aaSAndroid Build Coastguard Worker                                    BottomLeft
68*c8dee2aaSAndroid Build Coastguard Worker     @param generateMipmapsFromBase If kYes then the pixel contents of the textures upper mipmap
69*c8dee2aaSAndroid Build Coastguard Worker                                    levels are generated by successive downsampling of the base
70*c8dee2aaSAndroid Build Coastguard Worker                                    level. If the texture is not mipmapped or isn't renderable then
71*c8dee2aaSAndroid Build Coastguard Worker                                    image creation will fail. If kNo and the texture is mipmapped
72*c8dee2aaSAndroid Build Coastguard Worker                                    then the contents of upper levels are assumed to already be
73*c8dee2aaSAndroid Build Coastguard Worker                                    valid.
74*c8dee2aaSAndroid Build Coastguard Worker     @return                        created SkImage, or nullptr
75*c8dee2aaSAndroid Build Coastguard Worker */
76*c8dee2aaSAndroid Build Coastguard Worker SK_API sk_sp<SkImage> WrapTexture(skgpu::graphite::Recorder*,
77*c8dee2aaSAndroid Build Coastguard Worker                                   const skgpu::graphite::BackendTexture&,
78*c8dee2aaSAndroid Build Coastguard Worker                                   SkColorType colorType,
79*c8dee2aaSAndroid Build Coastguard Worker                                   SkAlphaType alphaType,
80*c8dee2aaSAndroid Build Coastguard Worker                                   sk_sp<SkColorSpace> colorSpace,
81*c8dee2aaSAndroid Build Coastguard Worker                                   skgpu::Origin origin,
82*c8dee2aaSAndroid Build Coastguard Worker                                   GenerateMipmapsFromBase generateMipmapsFromBase,
83*c8dee2aaSAndroid Build Coastguard Worker                                   TextureReleaseProc = nullptr,
84*c8dee2aaSAndroid Build Coastguard Worker                                   ReleaseContext = nullptr,
85*c8dee2aaSAndroid Build Coastguard Worker                                   std::string_view label = {});
86*c8dee2aaSAndroid Build Coastguard Worker 
87*c8dee2aaSAndroid Build Coastguard Worker SK_API sk_sp<SkImage> WrapTexture(skgpu::graphite::Recorder*,
88*c8dee2aaSAndroid Build Coastguard Worker                                   const skgpu::graphite::BackendTexture&,
89*c8dee2aaSAndroid Build Coastguard Worker                                   SkColorType colorType,
90*c8dee2aaSAndroid Build Coastguard Worker                                   SkAlphaType alphaType,
91*c8dee2aaSAndroid Build Coastguard Worker                                   sk_sp<SkColorSpace> colorSpace,
92*c8dee2aaSAndroid Build Coastguard Worker                                   skgpu::Origin origin,
93*c8dee2aaSAndroid Build Coastguard Worker                                   TextureReleaseProc = nullptr,
94*c8dee2aaSAndroid Build Coastguard Worker                                   ReleaseContext = nullptr,
95*c8dee2aaSAndroid Build Coastguard Worker                                   std::string_view label = {});
96*c8dee2aaSAndroid Build Coastguard Worker 
97*c8dee2aaSAndroid Build Coastguard Worker SK_API sk_sp<SkImage> WrapTexture(skgpu::graphite::Recorder*,
98*c8dee2aaSAndroid Build Coastguard Worker                                   const skgpu::graphite::BackendTexture&,
99*c8dee2aaSAndroid Build Coastguard Worker                                   SkColorType colorType,
100*c8dee2aaSAndroid Build Coastguard Worker                                   SkAlphaType alphaType,
101*c8dee2aaSAndroid Build Coastguard Worker                                   sk_sp<SkColorSpace> colorSpace,
102*c8dee2aaSAndroid Build Coastguard Worker                                   TextureReleaseProc = nullptr,
103*c8dee2aaSAndroid Build Coastguard Worker                                   ReleaseContext = nullptr,
104*c8dee2aaSAndroid Build Coastguard Worker                                   std::string_view label = {});
105*c8dee2aaSAndroid Build Coastguard Worker 
106*c8dee2aaSAndroid Build Coastguard Worker /** Create a new SkImage that is very similar to an SkImage created by WrapTexture. The difference
107*c8dee2aaSAndroid Build Coastguard Worker     is that the caller need not have created the backend texture nor populated it with data when
108*c8dee2aaSAndroid Build Coastguard Worker     creating the image. Instead of passing a BackendTexture to the factory the client supplies a
109*c8dee2aaSAndroid Build Coastguard Worker     description of the texture consisting of dimensions, TextureInfo, SkColorInfo and Volatility.
110*c8dee2aaSAndroid Build Coastguard Worker 
111*c8dee2aaSAndroid Build Coastguard Worker     In general, 'fulfill' must return a BackendTexture that matches the properties provided at
112*c8dee2aaSAndroid Build Coastguard Worker     SkImage creation time. The BackendTexture must refer to a valid existing texture in the backend
113*c8dee2aaSAndroid Build Coastguard Worker     API context/device, and already be populated with data. The texture cannot be deleted until
114*c8dee2aaSAndroid Build Coastguard Worker     'textureRelease' is called. 'textureRelease' will be called with the textureReleaseContext
115*c8dee2aaSAndroid Build Coastguard Worker     returned by 'fulfill'.
116*c8dee2aaSAndroid Build Coastguard Worker 
117*c8dee2aaSAndroid Build Coastguard Worker     Wrt when and how often the fulfill, imageRelease, and textureRelease callbacks will be called:
118*c8dee2aaSAndroid Build Coastguard Worker 
119*c8dee2aaSAndroid Build Coastguard Worker     For non-volatile promise images, 'fulfill' will be called at Context::insertRecording time.
120*c8dee2aaSAndroid Build Coastguard Worker     Regardless of whether 'fulfill' succeeded or failed, 'imageRelease' will always be called only
121*c8dee2aaSAndroid Build Coastguard Worker     once - when Skia will no longer try calling 'fulfill' to get a backend texture. If 'fulfill'
122*c8dee2aaSAndroid Build Coastguard Worker     failed (i.e., it didn't return a valid backend texture) then 'textureRelease' will never be
123*c8dee2aaSAndroid Build Coastguard Worker     called. If 'fulfill' was successful then 'textureRelease' will be called only once when the GPU
124*c8dee2aaSAndroid Build Coastguard Worker     is done with the contents of the promise image. This will usually occur during a Context::submit
125*c8dee2aaSAndroid Build Coastguard Worker     call but it could occur earlier due to error conditions. 'fulfill' can be called multiple times
126*c8dee2aaSAndroid Build Coastguard Worker     if the promise image is used in multiple recordings. If 'fulfill' fails, the insertRecording
127*c8dee2aaSAndroid Build Coastguard Worker     itself will fail. Subsequent insertRecording calls (with Recordings that use the promise image)
128*c8dee2aaSAndroid Build Coastguard Worker     will keep calling 'fulfill' until it succeeds.
129*c8dee2aaSAndroid Build Coastguard Worker 
130*c8dee2aaSAndroid Build Coastguard Worker     For volatile promise images, 'fulfill' will be called each time the Recording is inserted into a
131*c8dee2aaSAndroid Build Coastguard Worker     Context. Regardless of whether 'fulfill' succeeded or failed, 'imageRelease' will always be
132*c8dee2aaSAndroid Build Coastguard Worker     called only once just like the non-volatile case. If 'fulfill' fails at insertRecording-time,
133*c8dee2aaSAndroid Build Coastguard Worker     'textureRelease' will never be called. If 'fulfill' was successful then a 'textureRelease'
134*c8dee2aaSAndroid Build Coastguard Worker     matching that 'fulfill' will be called when the GPU is done with the contents of the promise
135*c8dee2aaSAndroid Build Coastguard Worker     image. This will usually occur during a Context::submit call but it could occur earlier due to
136*c8dee2aaSAndroid Build Coastguard Worker     error conditions.
137*c8dee2aaSAndroid Build Coastguard Worker 
138*c8dee2aaSAndroid Build Coastguard Worker     @param recorder       the recorder that will capture the commands creating the image
139*c8dee2aaSAndroid Build Coastguard Worker     @param dimensions     width & height of promised gpu texture
140*c8dee2aaSAndroid Build Coastguard Worker     @param textureInfo    structural information for the promised gpu texture
141*c8dee2aaSAndroid Build Coastguard Worker     @param colorInfo      color type, alpha type and colorSpace information for the image
142*c8dee2aaSAndroid Build Coastguard Worker     @param origin         Whether the Texture logically treats the origin as TopLeft or BottomLeft
143*c8dee2aaSAndroid Build Coastguard Worker     @param isVolatile     volatility of the promise image
144*c8dee2aaSAndroid Build Coastguard Worker     @param fulfill        function called to get the actual backend texture,
145*c8dee2aaSAndroid Build Coastguard Worker                           and the instance for the GraphitePromiseTextureReleaseProc
146*c8dee2aaSAndroid Build Coastguard Worker     @param imageRelease   function called when any image-centric data can be deleted
147*c8dee2aaSAndroid Build Coastguard Worker     @param textureRelease function called when the backend texture can be deleted
148*c8dee2aaSAndroid Build Coastguard Worker     @param imageContext   state passed to fulfill and imageRelease
149*c8dee2aaSAndroid Build Coastguard Worker     @return               created SkImage, or nullptr
150*c8dee2aaSAndroid Build Coastguard Worker */
151*c8dee2aaSAndroid Build Coastguard Worker SK_API sk_sp<SkImage> PromiseTextureFrom(skgpu::graphite::Recorder*,
152*c8dee2aaSAndroid Build Coastguard Worker                                          SkISize dimensions,
153*c8dee2aaSAndroid Build Coastguard Worker                                          const skgpu::graphite::TextureInfo&,
154*c8dee2aaSAndroid Build Coastguard Worker                                          const SkColorInfo&,
155*c8dee2aaSAndroid Build Coastguard Worker                                          skgpu::Origin origin,
156*c8dee2aaSAndroid Build Coastguard Worker                                          skgpu::graphite::Volatile,
157*c8dee2aaSAndroid Build Coastguard Worker                                          GraphitePromiseTextureFulfillProc,
158*c8dee2aaSAndroid Build Coastguard Worker                                          GraphitePromiseImageReleaseProc,
159*c8dee2aaSAndroid Build Coastguard Worker                                          GraphitePromiseTextureReleaseProc,
160*c8dee2aaSAndroid Build Coastguard Worker                                          GraphitePromiseImageContext,
161*c8dee2aaSAndroid Build Coastguard Worker                                          std::string_view label = {});
162*c8dee2aaSAndroid Build Coastguard Worker 
163*c8dee2aaSAndroid Build Coastguard Worker SK_API sk_sp<SkImage> PromiseTextureFrom(skgpu::graphite::Recorder*,
164*c8dee2aaSAndroid Build Coastguard Worker                                          SkISize dimensions,
165*c8dee2aaSAndroid Build Coastguard Worker                                          const skgpu::graphite::TextureInfo&,
166*c8dee2aaSAndroid Build Coastguard Worker                                          const SkColorInfo&,
167*c8dee2aaSAndroid Build Coastguard Worker                                          skgpu::graphite::Volatile,
168*c8dee2aaSAndroid Build Coastguard Worker                                          GraphitePromiseTextureFulfillProc,
169*c8dee2aaSAndroid Build Coastguard Worker                                          GraphitePromiseImageReleaseProc,
170*c8dee2aaSAndroid Build Coastguard Worker                                          GraphitePromiseTextureReleaseProc,
171*c8dee2aaSAndroid Build Coastguard Worker                                          GraphitePromiseImageContext);
172*c8dee2aaSAndroid Build Coastguard Worker 
173*c8dee2aaSAndroid Build Coastguard Worker /** This is similar to 'PromiseTextureFrom' but it creates a GPU-backed SkImage from YUV[A] data.
174*c8dee2aaSAndroid Build Coastguard Worker     The source data may be planar (i.e. spread across multiple textures). In the extreme Y, U, V,
175*c8dee2aaSAndroid Build Coastguard Worker     and A are all in different planes and thus the image is specified by four textures.
176*c8dee2aaSAndroid Build Coastguard Worker     'backendTextureInfo' describes the planar arrangement, texture formats, and conversion to RGB.
177*c8dee2aaSAndroid Build Coastguard Worker     Separate 'fulfill' and 'textureRelease' calls are made for each texture. Each texture has its
178*c8dee2aaSAndroid Build Coastguard Worker     own GraphitePromiseFulfillContext. The GraphitePromiseImageReleaseProc will be made even on
179*c8dee2aaSAndroid Build Coastguard Worker     failure. 'planeContexts' has one entry for each of the up to four textures, as indicated by
180*c8dee2aaSAndroid Build Coastguard Worker     'backendTextureInfo'. Currently the mipmapped property of 'backendTextureInfo' is ignored.
181*c8dee2aaSAndroid Build Coastguard Worker     However, in the near future it will be required that if it is kYes then the fulfillProc must
182*c8dee2aaSAndroid Build Coastguard Worker     return a mip mapped texture for each plane in order to successfully draw the image.
183*c8dee2aaSAndroid Build Coastguard Worker 
184*c8dee2aaSAndroid Build Coastguard Worker     @param recorder            the recorder that will capture the commands creating the image
185*c8dee2aaSAndroid Build Coastguard Worker     @param backendTextureInfo  info about the promised yuva gpu texture(s)
186*c8dee2aaSAndroid Build Coastguard Worker     @param imageColorSpace     range of colors; may be nullptr
187*c8dee2aaSAndroid Build Coastguard Worker     @param isVolatile          volatility of the promise image
188*c8dee2aaSAndroid Build Coastguard Worker     @param fulfill             function called to get the actual backend texture for
189*c8dee2aaSAndroid Build Coastguard Worker                                a given GraphitePromiseTextureContext, and the instance
190*c8dee2aaSAndroid Build Coastguard Worker                                for the GraphitePromiseTextureReleaseProc
191*c8dee2aaSAndroid Build Coastguard Worker     @param imageRelease        function called when any image-centric data can be deleted
192*c8dee2aaSAndroid Build Coastguard Worker     @param textureRelease      function called when the backend texture can be deleted
193*c8dee2aaSAndroid Build Coastguard Worker     @param imageContext        state passed to imageRelease
194*c8dee2aaSAndroid Build Coastguard Worker     @param planeContexts       states passed to fulfill for each plane
195*c8dee2aaSAndroid Build Coastguard Worker     @return                    created SkImage, or nullptr
196*c8dee2aaSAndroid Build Coastguard Worker */
197*c8dee2aaSAndroid Build Coastguard Worker SK_API sk_sp<SkImage> PromiseTextureFromYUVA(skgpu::graphite::Recorder*,
198*c8dee2aaSAndroid Build Coastguard Worker                                              const skgpu::graphite::YUVABackendTextureInfo&,
199*c8dee2aaSAndroid Build Coastguard Worker                                              sk_sp<SkColorSpace> imageColorSpace,
200*c8dee2aaSAndroid Build Coastguard Worker                                              skgpu::graphite::Volatile,
201*c8dee2aaSAndroid Build Coastguard Worker                                              GraphitePromiseTextureFulfillProc,
202*c8dee2aaSAndroid Build Coastguard Worker                                              GraphitePromiseImageReleaseProc,
203*c8dee2aaSAndroid Build Coastguard Worker                                              GraphitePromiseTextureReleaseProc,
204*c8dee2aaSAndroid Build Coastguard Worker                                              GraphitePromiseImageContext imageContext,
205*c8dee2aaSAndroid Build Coastguard Worker                                              GraphitePromiseTextureFulfillContext planeContexts[],
206*c8dee2aaSAndroid Build Coastguard Worker                                              std::string_view label = {});
207*c8dee2aaSAndroid Build Coastguard Worker 
208*c8dee2aaSAndroid Build Coastguard Worker 
209*c8dee2aaSAndroid Build Coastguard Worker /** Returns an SkImage backed by a Graphite texture, using the provided Recorder for creation and
210*c8dee2aaSAndroid Build Coastguard Worker     uploads if necessary. The returned SkImage respects the required image properties' mipmap
211*c8dee2aaSAndroid Build Coastguard Worker     setting for non-Graphite SkImages; i.e., if mipmapping is required, the backing Graphite texture
212*c8dee2aaSAndroid Build Coastguard Worker     will have allocated mip map levels.
213*c8dee2aaSAndroid Build Coastguard Worker 
214*c8dee2aaSAndroid Build Coastguard Worker     It is assumed that MIP maps are always supported by the GPU.
215*c8dee2aaSAndroid Build Coastguard Worker 
216*c8dee2aaSAndroid Build Coastguard Worker     Returns original SkImage if the image is already Graphite-backed and the required mipmapping is
217*c8dee2aaSAndroid Build Coastguard Worker     compatible with the backing Graphite texture. If the required mipmapping is not compatible,
218*c8dee2aaSAndroid Build Coastguard Worker     nullptr will be returned.
219*c8dee2aaSAndroid Build Coastguard Worker 
220*c8dee2aaSAndroid Build Coastguard Worker     Returns nullptr if no Recorder is provided, or if SkImage was created with another Recorder and
221*c8dee2aaSAndroid Build Coastguard Worker     work on that Recorder has not been submitted.
222*c8dee2aaSAndroid Build Coastguard Worker 
223*c8dee2aaSAndroid Build Coastguard Worker     @param Recorder            the Recorder to use for storing commands
224*c8dee2aaSAndroid Build Coastguard Worker     @param RequiredProperties  properties the returned SkImage must possess (e.g. mipmaps)
225*c8dee2aaSAndroid Build Coastguard Worker     @return                    created SkImage, or nullptr
226*c8dee2aaSAndroid Build Coastguard Worker */
227*c8dee2aaSAndroid Build Coastguard Worker SK_API sk_sp<SkImage> TextureFromImage(skgpu::graphite::Recorder*,
228*c8dee2aaSAndroid Build Coastguard Worker                                        const SkImage*,
229*c8dee2aaSAndroid Build Coastguard Worker                                        SkImage::RequiredProperties = {});
230*c8dee2aaSAndroid Build Coastguard Worker 
231*c8dee2aaSAndroid Build Coastguard Worker inline sk_sp<SkImage> TextureFromImage(skgpu::graphite::Recorder* r,
232*c8dee2aaSAndroid Build Coastguard Worker                                        const sk_sp<const SkImage>& img,
233*c8dee2aaSAndroid Build Coastguard Worker                                        SkImage::RequiredProperties props = {}) {
234*c8dee2aaSAndroid Build Coastguard Worker     return TextureFromImage(r, img.get(), props);
235*c8dee2aaSAndroid Build Coastguard Worker }
236*c8dee2aaSAndroid Build Coastguard Worker 
237*c8dee2aaSAndroid Build Coastguard Worker /** Creates SkImage from SkYUVAPixmaps.
238*c8dee2aaSAndroid Build Coastguard Worker 
239*c8dee2aaSAndroid Build Coastguard Worker     The image will remain planar with each plane converted to a texture using the passed Recorder.
240*c8dee2aaSAndroid Build Coastguard Worker 
241*c8dee2aaSAndroid Build Coastguard Worker     SkYUVAPixmaps has a SkYUVAInfo which specifies the transformation from YUV to RGB. The
242*c8dee2aaSAndroid Build Coastguard Worker     SkColorSpace of the resulting RGB values is specified by imgColorSpace. This will be the
243*c8dee2aaSAndroid Build Coastguard Worker     SkColorSpace reported by the image and when drawn the RGB values will be converted from this
244*c8dee2aaSAndroid Build Coastguard Worker     space into the destination space (if the destination is tagged).
245*c8dee2aaSAndroid Build Coastguard Worker 
246*c8dee2aaSAndroid Build Coastguard Worker     This is only supported using the GPU backend and will fail if recorder is nullptr.
247*c8dee2aaSAndroid Build Coastguard Worker 
248*c8dee2aaSAndroid Build Coastguard Worker     SkYUVAPixmaps does not need to remain valid after this returns.
249*c8dee2aaSAndroid Build Coastguard Worker 
250*c8dee2aaSAndroid Build Coastguard Worker     @param Recorder                 The Recorder to use for storing commands
251*c8dee2aaSAndroid Build Coastguard Worker     @param pixmaps                  The planes as pixmaps with supported SkYUVAInfo that
252*c8dee2aaSAndroid Build Coastguard Worker                                     specifies conversion to RGB.
253*c8dee2aaSAndroid Build Coastguard Worker     @param RequiredProperties       Properties the returned SkImage must possess (e.g. mipmaps)
254*c8dee2aaSAndroid Build Coastguard Worker     @param limitToMaxTextureSize    Downscale image to GPU maximum texture size, if necessary
255*c8dee2aaSAndroid Build Coastguard Worker     @param imgColorSpace            Range of colors of the resulting image; may be nullptr
256*c8dee2aaSAndroid Build Coastguard Worker     @return                         Created SkImage, or nullptr
257*c8dee2aaSAndroid Build Coastguard Worker */
258*c8dee2aaSAndroid Build Coastguard Worker SK_API sk_sp<SkImage> TextureFromYUVAPixmaps(skgpu::graphite::Recorder*,
259*c8dee2aaSAndroid Build Coastguard Worker                                              const SkYUVAPixmaps& pixmaps,
260*c8dee2aaSAndroid Build Coastguard Worker                                              SkImage::RequiredProperties = {},
261*c8dee2aaSAndroid Build Coastguard Worker                                              bool limitToMaxTextureSize = false,
262*c8dee2aaSAndroid Build Coastguard Worker                                              sk_sp<SkColorSpace> imgColorSpace = nullptr,
263*c8dee2aaSAndroid Build Coastguard Worker                                              std::string_view label = {});
264*c8dee2aaSAndroid Build Coastguard Worker 
265*c8dee2aaSAndroid Build Coastguard Worker /** Creates an SkImage from YUV[A] planar textures associated with the recorder.
266*c8dee2aaSAndroid Build Coastguard Worker      @param recorder            The recorder.
267*c8dee2aaSAndroid Build Coastguard Worker      @param yuvaBackendTextures A set of textures containing YUVA data and a description of the
268*c8dee2aaSAndroid Build Coastguard Worker                                 data and transformation to RGBA.
269*c8dee2aaSAndroid Build Coastguard Worker      @param imageColorSpace     range of colors of the resulting image after conversion to RGB;
270*c8dee2aaSAndroid Build Coastguard Worker                                 may be nullptr
271*c8dee2aaSAndroid Build Coastguard Worker      @param TextureReleaseProc  called when the backend textures can be released
272*c8dee2aaSAndroid Build Coastguard Worker      @param ReleaseContext      state passed to TextureReleaseProc
273*c8dee2aaSAndroid Build Coastguard Worker      @return                    created SkImage, or nullptr
274*c8dee2aaSAndroid Build Coastguard Worker  */
275*c8dee2aaSAndroid Build Coastguard Worker SK_API sk_sp<SkImage> TextureFromYUVATextures(
276*c8dee2aaSAndroid Build Coastguard Worker         skgpu::graphite::Recorder* recorder,
277*c8dee2aaSAndroid Build Coastguard Worker         const skgpu::graphite::YUVABackendTextures& yuvaBackendTextures,
278*c8dee2aaSAndroid Build Coastguard Worker         sk_sp<SkColorSpace> imageColorSpace,
279*c8dee2aaSAndroid Build Coastguard Worker         TextureReleaseProc = nullptr,
280*c8dee2aaSAndroid Build Coastguard Worker         ReleaseContext = nullptr,
281*c8dee2aaSAndroid Build Coastguard Worker         std::string_view label = {});
282*c8dee2aaSAndroid Build Coastguard Worker 
283*c8dee2aaSAndroid Build Coastguard Worker /** Creates an SkImage from YUV[A] planar SkImages associated with the recorder.
284*c8dee2aaSAndroid Build Coastguard Worker 
285*c8dee2aaSAndroid Build Coastguard Worker     The images should have kGraphite type, and the result will be nullptr if any are not. The
286*c8dee2aaSAndroid Build Coastguard Worker     resulting SkImage will not take a ref on the given SkImages but will take a ref on the
287*c8dee2aaSAndroid Build Coastguard Worker     underlying TextureProxies. The releaseProcs, if any, for those Textures will be the ones set
288*c8dee2aaSAndroid Build Coastguard Worker     when the given SkImages were created.
289*c8dee2aaSAndroid Build Coastguard Worker 
290*c8dee2aaSAndroid Build Coastguard Worker      @param recorder            The recorder.
291*c8dee2aaSAndroid Build Coastguard Worker      @param yuvaInfo            Structure describing the YUVA format
292*c8dee2aaSAndroid Build Coastguard Worker      @param images              A set of SkImages containing YUVA data
293*c8dee2aaSAndroid Build Coastguard Worker      @param imageColorSpace     Range of colors of the resulting image after conversion to RGB;
294*c8dee2aaSAndroid Build Coastguard Worker                                 may be nullptr
295*c8dee2aaSAndroid Build Coastguard Worker      @return                    created SkImage, or nullptr
296*c8dee2aaSAndroid Build Coastguard Worker  */
297*c8dee2aaSAndroid Build Coastguard Worker SK_API sk_sp<SkImage> TextureFromYUVAImages(
298*c8dee2aaSAndroid Build Coastguard Worker         skgpu::graphite::Recorder* recorder,
299*c8dee2aaSAndroid Build Coastguard Worker         const SkYUVAInfo& yuvaInfo,
300*c8dee2aaSAndroid Build Coastguard Worker         SkSpan<const sk_sp<SkImage>> images,
301*c8dee2aaSAndroid Build Coastguard Worker         sk_sp<SkColorSpace> imageColorSpace);
302*c8dee2aaSAndroid Build Coastguard Worker 
303*c8dee2aaSAndroid Build Coastguard Worker /** Returns subset of this image as a texture-backed image.
304*c8dee2aaSAndroid Build Coastguard Worker 
305*c8dee2aaSAndroid Build Coastguard Worker     Returns nullptr if any of the following are true:
306*c8dee2aaSAndroid Build Coastguard Worker       - Subset is empty
307*c8dee2aaSAndroid Build Coastguard Worker       - Subset is not contained inside the image's bounds
308*c8dee2aaSAndroid Build Coastguard Worker       - Pixels in the source image could not be read or copied
309*c8dee2aaSAndroid Build Coastguard Worker       - The source image is texture-backed and context does not match the source image's context.
310*c8dee2aaSAndroid Build Coastguard Worker 
311*c8dee2aaSAndroid Build Coastguard Worker     @param recorder the non-null recorder in which to create the new image.
312*c8dee2aaSAndroid Build Coastguard Worker     @param img     Source image
313*c8dee2aaSAndroid Build Coastguard Worker     @param subset  bounds of returned SkImage
314*c8dee2aaSAndroid Build Coastguard Worker     @param props   properties the returned SkImage must possess (e.g. mipmaps)
315*c8dee2aaSAndroid Build Coastguard Worker     @return        the subsetted image, uploaded as a texture, or nullptr
316*c8dee2aaSAndroid Build Coastguard Worker */
317*c8dee2aaSAndroid Build Coastguard Worker SK_API sk_sp<SkImage> SubsetTextureFrom(skgpu::graphite::Recorder* recorder,
318*c8dee2aaSAndroid Build Coastguard Worker                                         const SkImage* img,
319*c8dee2aaSAndroid Build Coastguard Worker                                         const SkIRect& subset,
320*c8dee2aaSAndroid Build Coastguard Worker                                         SkImage::RequiredProperties props = {});
321*c8dee2aaSAndroid Build Coastguard Worker 
322*c8dee2aaSAndroid Build Coastguard Worker /** Creates a filtered SkImage on the GPU. filter processes the src image, potentially changing
323*c8dee2aaSAndroid Build Coastguard Worker     color, position, and size. subset is the bounds of src that are processed by filter. clipBounds
324*c8dee2aaSAndroid Build Coastguard Worker     is the expected bounds of the filtered SkImage. outSubset is required storage for the actual
325*c8dee2aaSAndroid Build Coastguard Worker     bounds of the filtered SkImage. offset is required storage for translation of returned SkImage.
326*c8dee2aaSAndroid Build Coastguard Worker 
327*c8dee2aaSAndroid Build Coastguard Worker     Returns nullptr if SkImage could not be created. If nullptr is returned, outSubset and offset
328*c8dee2aaSAndroid Build Coastguard Worker     are undefined.
329*c8dee2aaSAndroid Build Coastguard Worker 
330*c8dee2aaSAndroid Build Coastguard Worker     Useful for animation of SkImageFilter that varies size from frame to frame. Returned SkImage is
331*c8dee2aaSAndroid Build Coastguard Worker     created larger than required by filter so that GPU texture can be reused with different sized
332*c8dee2aaSAndroid Build Coastguard Worker     effects. outSubset describes the valid bounds of GPU texture returned. offset translates the
333*c8dee2aaSAndroid Build Coastguard Worker     returned SkImage to keep subsequent animation frames aligned with respect to each other.
334*c8dee2aaSAndroid Build Coastguard Worker 
335*c8dee2aaSAndroid Build Coastguard Worker     @param recorder    the recorder in which the filtering operation is to be performed
336*c8dee2aaSAndroid Build Coastguard Worker     @param filter      how SkImage is sampled when transformed
337*c8dee2aaSAndroid Build Coastguard Worker     @param subset      bounds of SkImage processed by filter
338*c8dee2aaSAndroid Build Coastguard Worker     @param clipBounds  expected bounds of filtered SkImage
339*c8dee2aaSAndroid Build Coastguard Worker     @param outSubset   storage for returned SkImage bounds
340*c8dee2aaSAndroid Build Coastguard Worker     @param offset      storage for returned SkImage translation
341*c8dee2aaSAndroid Build Coastguard Worker     @return            filtered SkImage, or nullptr
342*c8dee2aaSAndroid Build Coastguard Worker */
343*c8dee2aaSAndroid Build Coastguard Worker SK_API sk_sp<SkImage> MakeWithFilter(skgpu::graphite::Recorder* recorder,
344*c8dee2aaSAndroid Build Coastguard Worker                                      sk_sp<SkImage> src,
345*c8dee2aaSAndroid Build Coastguard Worker                                      const SkImageFilter* filter,
346*c8dee2aaSAndroid Build Coastguard Worker                                      const SkIRect& subset,
347*c8dee2aaSAndroid Build Coastguard Worker                                      const SkIRect& clipBounds,
348*c8dee2aaSAndroid Build Coastguard Worker                                      SkIRect* outSubset,
349*c8dee2aaSAndroid Build Coastguard Worker                                      SkIPoint* offset);
350*c8dee2aaSAndroid Build Coastguard Worker 
351*c8dee2aaSAndroid Build Coastguard Worker } // namespace SkImages
352*c8dee2aaSAndroid Build Coastguard Worker 
353*c8dee2aaSAndroid Build Coastguard Worker 
354*c8dee2aaSAndroid Build Coastguard Worker #endif // skgpu_graphite_Image_DEFINED
355