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/ganesh/GrBackendSurface.h" 15 #include "include/gpu/ganesh/GrTypes.h" 16 17 class GrDirectContext; 18 19 extern "C" { 20 typedef struct AHardwareBuffer AHardwareBuffer; 21 } 22 23 namespace GrAHardwareBufferUtils { 24 25 // TODO: remove this function once Android has been updated to call the AHardwareBufferUtils 26 // version 27 SkColorType GetSkColorTypeFromBufferFormat(uint32_t bufferFormat); 28 29 #if !defined(SK_DISABLE_LEGACY_ANDROID_HW_UTILS) 30 GrBackendFormat GetBackendFormat(GrDirectContext* dContext, AHardwareBuffer* hardwareBuffer, 31 uint32_t bufferFormat, bool requireKnownFormat); 32 #endif 33 34 GrBackendFormat GetGLBackendFormat(GrDirectContext* dContext, uint32_t bufferFormat, 35 bool requireKnownFormat); 36 GrBackendFormat GetVulkanBackendFormat(GrDirectContext* dContext, AHardwareBuffer* hardwareBuffer, 37 uint32_t bufferFormat, bool requireKnownFormat); 38 39 typedef void* TexImageCtx; 40 typedef void (*DeleteImageProc)(TexImageCtx); 41 typedef 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) 66 GrBackendTexture 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 77 GrBackendTexture 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 87 GrBackendTexture 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 102