| 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 |  | 
|---|
| 10 | #include "include/core/SkTypes.h" | 
|---|
| 11 |  | 
|---|
| 12 | #if defined(SK_BUILD_FOR_ANDROID) && __ANDROID_API__ >= 26 | 
|---|
| 13 |  | 
|---|
| 14 | #include "include/gpu/GrBackendSurface.h" | 
|---|
| 15 | #include "include/gpu/GrTypes.h" | 
|---|
| 16 |  | 
|---|
| 17 | class GrContext; | 
|---|
| 18 |  | 
|---|
| 19 | extern "C"{ | 
|---|
| 20 | typedef struct AHardwareBuffer AHardwareBuffer; | 
|---|
| 21 | } | 
|---|
| 22 |  | 
|---|
| 23 | namespace GrAHardwareBufferUtils { | 
|---|
| 24 |  | 
|---|
| 25 | SkColorType GetSkColorTypeFromBufferFormat(uint32_t bufferFormat); | 
|---|
| 26 |  | 
|---|
| 27 | GrBackendFormat GetBackendFormat(GrContext* context, AHardwareBuffer* hardwareBuffer, | 
|---|
| 28 | uint32_t bufferFormat, bool requireKnownFormat); | 
|---|
| 29 |  | 
|---|
| 30 | typedef void* TexImageCtx; | 
|---|
| 31 | typedef void (*DeleteImageProc)(TexImageCtx); | 
|---|
| 32 | typedef void (*UpdateImageProc)(TexImageCtx, GrContext*); | 
|---|
| 33 |  | 
|---|
| 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 | */ | 
|---|
| 56 | GrBackendTexture MakeBackendTexture(GrContext* context, AHardwareBuffer* hardwareBuffer, | 
|---|
| 57 | int width, int height, | 
|---|
| 58 | DeleteImageProc* deleteProc, | 
|---|
| 59 | UpdateImageProc* updateProc, | 
|---|
| 60 | TexImageCtx* imageCtx, | 
|---|
| 61 | bool isProtectedContent, | 
|---|
| 62 | const GrBackendFormat& backendFormat, | 
|---|
| 63 | bool isRenderable); | 
|---|
| 64 |  | 
|---|
| 65 | } // GrAHardwareBufferUtils | 
|---|
| 66 |  | 
|---|
| 67 |  | 
|---|
| 68 | #endif | 
|---|
| 69 | #endif | 
|---|
| 70 |  | 
|---|