xref: /aosp_15_r20/external/skia/include/android/graphite/SurfaceAndroid.h (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
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 SurfaceAndroid_DEFINED
9 #define SurfaceAndroid_DEFINED
10 
11 #include "include/core/SkRefCnt.h"
12 
13 struct AHardwareBuffer;
14 class SkColorSpace;
15 class SkSurface;
16 class SkSurfaceProps;
17 
18 namespace skgpu::graphite {
19     class Recorder;
20 }
21 
22 namespace SkSurfaces {
23 
24 using ReleaseContext = void*;
25 using BufferReleaseProc = void (*)(ReleaseContext);
26 
27 /** Private; only to be used by Android Framework.
28     Creates an SkSurface from an Android hardware buffer.
29 
30     Upon success bufferReleaseProc is called when it is safe to delete the buffer in the
31     backend API (accounting only for use of the buffer by this surface). If SkSurface creation
32     fails bufferReleaseProc is called before this function returns.
33 
34     Currently this is only supported for buffers that can be textured as well as rendered to.
35     In other words the buffer must have both AHARDWAREBUFFER_USAGE_GPU_COLOR_OUTPUT and
36     AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE usage bits.
37 
38     @param recorder          the applicable Graphite recorder
39     @param hardwareBuffer    an Android hardware buffer
40     @param colorSpace        range of colors; may be nullptr
41     @param surfaceProps      LCD striping orientation and setting for device independent
42                              fonts; may be nullptr
43     @param bufferReleaseProc function called when the buffer can be released
44     @param ReleaseContext    state passed to bufferReleaseProc
45     @param fromWindow        Whether or not the AHardwareBuffer is part of an Android Window.
46                              Currently only used with Vulkan backend.
47     @return                  created SkSurface, or nullptr
48 */
49 SK_API sk_sp<SkSurface> WrapAndroidHardwareBuffer(skgpu::graphite::Recorder* recorder,
50                                                   AHardwareBuffer* hardwareBuffer,
51                                                   sk_sp<SkColorSpace> colorSpace,
52                                                   const SkSurfaceProps* surfaceProps,
53                                                   BufferReleaseProc = nullptr,
54                                                   ReleaseContext = nullptr,
55                                                   bool fromWindow = false);
56 
57 }  // namespace SkSurfaces
58 
59 #endif // SurfaceAndroid_DEFINED
60