Greg Daniel | 173464d | 2019-02-06 15:30:34 -0500 | [diff] [blame] | 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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 10 | #include "include/core/SkTypes.h" |
Greg Daniel | 173464d | 2019-02-06 15:30:34 -0500 | [diff] [blame] | 11 | |
| 12 | #if defined(SK_BUILD_FOR_ANDROID) && __ANDROID_API__ >= 26 |
| 13 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 14 | #include "include/gpu/GrBackendSurface.h" |
| 15 | #include "include/gpu/GrTypes.h" |
Greg Daniel | 173464d | 2019-02-06 15:30:34 -0500 | [diff] [blame] | 16 | |
Adlai Holler | b270568 | 2020-10-20 10:11:53 -0400 | [diff] [blame] | 17 | class GrDirectContext; |
Greg Daniel | 173464d | 2019-02-06 15:30:34 -0500 | [diff] [blame] | 18 | |
| 19 | extern "C" { |
| 20 | typedef struct AHardwareBuffer AHardwareBuffer; |
| 21 | } |
| 22 | |
| 23 | namespace GrAHardwareBufferUtils { |
| 24 | |
| 25 | SkColorType GetSkColorTypeFromBufferFormat(uint32_t bufferFormat); |
| 26 | |
Adlai Holler | 1fc76ce | 2020-10-07 11:36:49 -0400 | [diff] [blame] | 27 | GrBackendFormat GetBackendFormat(GrDirectContext* context, AHardwareBuffer* hardwareBuffer, |
Greg Daniel | 173464d | 2019-02-06 15:30:34 -0500 | [diff] [blame] | 28 | uint32_t bufferFormat, bool requireKnownFormat); |
| 29 | |
Stan Iliev | a56b04a | 2019-08-01 14:22:34 -0400 | [diff] [blame] | 30 | typedef void* TexImageCtx; |
| 31 | typedef void (*DeleteImageProc)(TexImageCtx); |
Adlai Holler | 1fc76ce | 2020-10-07 11:36:49 -0400 | [diff] [blame] | 32 | typedef void (*UpdateImageProc)(TexImageCtx, GrDirectContext*); |
Greg Daniel | 173464d | 2019-02-06 15:30:34 -0500 | [diff] [blame] | 33 | |
Stan Iliev | a56b04a | 2019-08-01 14:22:34 -0400 | [diff] [blame] | 34 | /** |
| 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 Holler | 1fc76ce | 2020-10-07 11:36:49 -0400 | [diff] [blame] | 56 | GrBackendTexture MakeBackendTexture(GrDirectContext* context, AHardwareBuffer* hardwareBuffer, |
Stan Iliev | a56b04a | 2019-08-01 14:22:34 -0400 | [diff] [blame] | 57 | int width, int height, |
| 58 | DeleteImageProc* deleteProc, |
| 59 | UpdateImageProc* updateProc, |
| 60 | TexImageCtx* imageCtx, |
Greg Daniel | 173464d | 2019-02-06 15:30:34 -0500 | [diff] [blame] | 61 | bool isProtectedContent, |
| 62 | const GrBackendFormat& backendFormat, |
| 63 | bool isRenderable); |
| 64 | |
| 65 | } // GrAHardwareBufferUtils |
| 66 | |
| 67 | |
| 68 | #endif |
| 69 | #endif |