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