Debian Codegraph @

include/android/SkImageAndroid.h

raw
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 SkImageAndroid_DEFINED
9 #define SkImageAndroid_DEFINED
10
11 #include "include/core/SkImage.h"
12 #include "include/core/SkRefCnt.h"
13 #include "include/gpu/ganesh/GrTypes.h"
14
15 class SkColorSpace;
16 class GrDirectContext;
17 class GrRecordingContext;
18 class SkPixmap;
19 struct AHardwareBuffer;
20
21 namespace SkImages {
22
23 /** (See skbug.com/40038695)
24 Creates SkImage from Android hardware buffer.
25 Returned SkImage takes a reference on the buffer.
26 Only available on Android, when __ANDROID_API__ is defined to be 26 or greater.
27 @param hardwareBuffer AHardwareBuffer Android hardware buffer
28 @param colorSpace range of colors; may be nullptr
29 @return created SkImage, or nullptr
30 */
31 SK_API sk_sp<SkImage> DeferredFromAHardwareBuffer(AHardwareBuffer* hardwareBuffer,
32 SkAlphaType alphaType = kPremul_SkAlphaType);
33 SK_API sk_sp<SkImage> DeferredFromAHardwareBuffer(
34 AHardwareBuffer* hardwareBuffer,
35 SkAlphaType alphaType,
36 sk_sp<SkColorSpace> colorSpace,
37 GrSurfaceOrigin surfaceOrigin = kTopLeft_GrSurfaceOrigin);
38
39 /** Creates SkImage from Android hardware buffer and uploads the data from the SkPixmap to it.
40 Returned SkImage takes a reference on the buffer.
41 Only available on Android, when __ANDROID_API__ is defined to be 26 or greater.
42 @param context GPU context
43 @param pixmap SkPixmap that contains data to be uploaded to the AHardwareBuffer
44 @param hardwareBuffer AHardwareBuffer Android hardware buffer
45 @param surfaceOrigin surface origin for resulting image
46 @return created SkImage, or nullptr
47 */
48 SK_API sk_sp<SkImage> TextureFromAHardwareBufferWithData(
49 GrDirectContext* context,
50 const SkPixmap& pixmap,
51 AHardwareBuffer* hardwareBuffer,
52 GrSurfaceOrigin surfaceOrigin = kTopLeft_GrSurfaceOrigin);
53
54 /**
55 * Like SkImage::MakeFromBitmap, except this can be pinned using
56 * skgpu::ganesh::PinAsTexture and Skia will *not* copy the bitmap.
57 */
58 SK_API sk_sp<SkImage> PinnableRasterFromBitmap(const SkBitmap&);
59
60 /**
61 * Like SkImage::MakeFromBitmap, except and Skia will *not* copy the bitmap.
62 */
63 SK_API sk_sp<SkImage> RasterFromBitmapNoCopy(const SkBitmap&);
64
65 } // namespace SkImages
66
67 namespace skgpu::ganesh {
68 /**
69 * Will attempt to upload and lock the contents of the image as a texture, so that subsequent
70 * draws to a gpu-target will come from that texture (and not by looking at the original image
71 * src). In particular this is intended to use the texture even if the image's original content
72 * changes subsequent to this call (i.e. the src is mutable!).
73 *
74 * Only compatible with SkImages created from SkImages::PinnableRasterFromBitmap.
75 *
76 * All successful calls must be balanced by an equal number of calls to UnpinTexture().
77 *
78 * Once in this "pinned" state, the image has all of the same thread restrictions that exist
79 * for a natively created gpu image (e.g. SkImage::MakeFromTexture)
80 * - all drawing, pinning, unpinning must happen in the same thread as the GrContext.
81 *
82 * @return true if the image was successfully uploaded and locked into a texture
83 */
84 bool PinAsTexture(GrRecordingContext*, SkImage*);
85
86 /**
87 * The balancing call to a successful invocation of PinAsTexture. When a balanced
88 * number of calls have been made, then the "pinned" texture is free to be purged, etc. This
89 * also means that a subsequent "pin" call will look at the original content again, and if
90 * its uniqueID/generationID has changed, then a newer texture will be uploaded/pinned.
91 *
92 * Only compatible with SkImages created from SkImages::PinnableRasterFromBitmap.
93 *
94 * The context passed to unpin must match the one passed to pin.
95 */
96 void UnpinTexture(GrRecordingContext*, SkImage*);
97
98 } // namespace skgpu::ganesh
99
100 #endif