blob: b93a8fe9b6a9f2292861a028cb3c7b5bbf1928fb [file] [log] [blame]
Greg Daniel173464d2019-02-06 15:30:34 -05001/*
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
Mike Kleinc0bd9f92019-04-23 12:05:21 -050010#include "include/core/SkTypes.h"
Greg Daniel173464d2019-02-06 15:30:34 -050011
12#if defined(SK_BUILD_FOR_ANDROID) && __ANDROID_API__ >= 26
13
Mike Kleinc0bd9f92019-04-23 12:05:21 -050014#include "include/gpu/GrBackendSurface.h"
15#include "include/gpu/GrTypes.h"
Greg Daniel173464d2019-02-06 15:30:34 -050016
Adlai Hollerb2705682020-10-20 10:11:53 -040017class GrDirectContext;
Greg Daniel173464d2019-02-06 15:30:34 -050018
19extern "C" {
20 typedef struct AHardwareBuffer AHardwareBuffer;
21}
22
23namespace GrAHardwareBufferUtils {
24
25SkColorType GetSkColorTypeFromBufferFormat(uint32_t bufferFormat);
26
Adlai Holler1fc76ce2020-10-07 11:36:49 -040027GrBackendFormat GetBackendFormat(GrDirectContext* context, AHardwareBuffer* hardwareBuffer,
Greg Daniel173464d2019-02-06 15:30:34 -050028 uint32_t bufferFormat, bool requireKnownFormat);
29
Stan Ilieva56b04a2019-08-01 14:22:34 -040030typedef void* TexImageCtx;
31typedef void (*DeleteImageProc)(TexImageCtx);
Adlai Holler1fc76ce2020-10-07 11:36:49 -040032typedef void (*UpdateImageProc)(TexImageCtx, GrDirectContext*);
Greg Daniel173464d2019-02-06 15:30:34 -050033
Stan Ilieva56b04a2019-08-01 14:22:34 -040034/**
35 * Create a GrBackendTexture from AHardwareBuffer
36 *
37 * @param context GPU context
38 * @param hardwareBuffer AHB
39 * @param width texture width
40 * @param height texture height
41 * @param deleteProc returns a function that deletes the texture and
42 * other GPU resources. Must be invoked on the same
43 * thread as MakeBackendTexture
44 * @param updateProc returns a function, that needs to be invoked, when
45 * AHB buffer content has changed. Must be invoked on
46 * the same thread as MakeBackendTexture
47 * @param imageCtx returns an opaque image context, that is passed as
48 * first argument to deleteProc and updateProc
49 * @param isProtectedContent if true, GL backend uses EXT_protected_content
50 * @param backendFormat backend format, usually created with helper
51 * function GetBackendFormat
52 * @param isRenderable true if GrBackendTexture can be used as a color
53 * attachment
54 * @return valid GrBackendTexture object on success
55 */
Adlai Holler1fc76ce2020-10-07 11:36:49 -040056GrBackendTexture MakeBackendTexture(GrDirectContext* context, AHardwareBuffer* hardwareBuffer,
Stan Ilieva56b04a2019-08-01 14:22:34 -040057 int width, int height,
58 DeleteImageProc* deleteProc,
59 UpdateImageProc* updateProc,
60 TexImageCtx* imageCtx,
Greg Daniel173464d2019-02-06 15:30:34 -050061 bool isProtectedContent,
62 const GrBackendFormat& backendFormat,
63 bool isRenderable);
64
65} // GrAHardwareBufferUtils
66
67
68#endif
69#endif