Flutter Engine
The Flutter Engine
GrAHardwareBufferUtils.h
Go to the documentation of this file.
1/*
2 * Copyright 2019 Google Inc.
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#ifndef GrAHardwareBufferUtils_DEFINED
8#define GrAHardwareBufferUtils_DEFINED
9
11
12#if defined(SK_BUILD_FOR_ANDROID) && __ANDROID_API__ >= 26
13
15#include "include/gpu/GrTypes.h"
16
17class GrDirectContext;
18
19extern "C" {
20 typedef struct AHardwareBuffer AHardwareBuffer;
21}
22
23namespace GrAHardwareBufferUtils {
24
25// TODO: remove this function once Android has been updated to call the AHardwareBufferUtils
26// version
27SkColorType GetSkColorTypeFromBufferFormat(uint32_t bufferFormat);
28
29#if !defined(SK_DISABLE_LEGACY_ANDROID_HW_UTILS)
30GrBackendFormat GetBackendFormat(GrDirectContext* dContext, AHardwareBuffer* hardwareBuffer,
31 uint32_t bufferFormat, bool requireKnownFormat);
32#endif
33
34GrBackendFormat GetGLBackendFormat(GrDirectContext* dContext, uint32_t bufferFormat,
35 bool requireKnownFormat);
36GrBackendFormat GetVulkanBackendFormat(GrDirectContext* dContext, AHardwareBuffer* hardwareBuffer,
37 uint32_t bufferFormat, bool requireKnownFormat);
38
39typedef void* TexImageCtx;
40typedef void (*DeleteImageProc)(TexImageCtx);
41typedef void (*UpdateImageProc)(TexImageCtx, GrDirectContext*);
42
43/**
44 * Create a GrBackendTexture from AHardwareBuffer
45 *
46 * @param context GPU context
47 * @param hardwareBuffer AHB
48 * @param width texture width
49 * @param height texture height
50 * @param deleteProc returns a function that deletes the texture and
51 * other GPU resources. Must be invoked on the same
52 * thread as MakeBackendTexture
53 * @param updateProc returns a function, that needs to be invoked, when
54 * AHB buffer content has changed. Must be invoked on
55 * the same thread as MakeBackendTexture
56 * @param imageCtx returns an opaque image context, that is passed as
57 * first argument to deleteProc and updateProc
58 * @param isProtectedContent if true, GL backend uses EXT_protected_content
59 * @param backendFormat backend format, usually created with helper
60 * function GetBackendFormat
61 * @param isRenderable true if GrBackendTexture can be used as a color
62 * attachment
63 * @return valid GrBackendTexture object on success
64 */
65#if !defined(SK_DISABLE_LEGACY_ANDROID_HW_UTILS)
66GrBackendTexture MakeBackendTexture(GrDirectContext* dContext, AHardwareBuffer* hardwareBuffer,
67 int width, int height,
68 DeleteImageProc* deleteProc,
69 UpdateImageProc* updateProc,
70 TexImageCtx* imageCtx,
71 bool isProtectedContent,
72 const GrBackendFormat& backendFormat,
73 bool isRenderable,
74 bool fromAndroidWindow = false);
75#endif
76
77GrBackendTexture MakeGLBackendTexture(GrDirectContext* dContext,
78 AHardwareBuffer* hardwareBuffer,
79 int width, int height,
80 DeleteImageProc* deleteProc,
81 UpdateImageProc* updateProc,
82 TexImageCtx* imageCtx,
83 bool isProtectedContent,
84 const GrBackendFormat& backendFormat,
85 bool isRenderable);
86
87GrBackendTexture MakeVulkanBackendTexture(GrDirectContext* dContext,
88 AHardwareBuffer* hardwareBuffer,
89 int width, int height,
90 DeleteImageProc* deleteProc,
91 UpdateImageProc* updateProc,
92 TexImageCtx* imageCtx,
93 bool isProtectedContent,
94 const GrBackendFormat& backendFormat,
95 bool isRenderable,
96 bool fromAndroidWindow = false);
97
98} // namespace GrAHardwareBufferUtils
99
100#endif
101#endif
struct AHardwareBuffer AHardwareBuffer
SkColorType
Definition: SkColorType.h:19
int32_t height
int32_t width