Debian Codegraph @

src/gpu/ganesh/GrAHardwareBufferUtils.cpp

raw
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
8 #include "include/android/GrAHardwareBufferUtils.h"
9
10 #if defined(SK_BUILD_FOR_ANDROID) && __ANDROID_API__ >= 26
11 #define GL_GLEXT_PROTOTYPES
12 #define EGL_EGLEXT_PROTOTYPES
13
14 #include <android/hardware_buffer.h>
15
16 #if !defined(SK_DISABLE_LEGACY_ANDROID_HW_UTILS)
17 #include "include/gpu/ganesh/GrDirectContext.h"
18 #endif
19
20 namespace GrAHardwareBufferUtils {
21
22 #if !defined(SK_DISABLE_LEGACY_ANDROID_HW_UTILS)
23 GrBackendFormat GetBackendFormat(GrDirectContext* dContext, AHardwareBuffer* hardwareBuffer,
24 uint32_t bufferFormat, bool requireKnownFormat) {
25 GrBackendApi backend = dContext->backend();
26
27 if (backend == GrBackendApi::kOpenGL) {
28 #ifdef SK_GL
29 return GetGLBackendFormat(dContext, bufferFormat, requireKnownFormat);
30 #else // SK_GL
31 return GrBackendFormat();
32 #endif // SK_GL
33 } else if (backend == GrBackendApi::kVulkan) {
34 #ifdef SK_VULKAN
35 return GetVulkanBackendFormat(dContext, hardwareBuffer, bufferFormat, requireKnownFormat);
36 #else // SK_VULKAN
37 return GrBackendFormat();
38 #endif // SK_VULKAN
39 }
40 return GrBackendFormat();
41 }
42
43 GrBackendTexture MakeBackendTexture(GrDirectContext* dContext,
44 AHardwareBuffer* hardwareBuffer,
45 int width, int height,
46 DeleteImageProc* deleteProc,
47 UpdateImageProc* updateProc,
48 TexImageCtx* imageCtx,
49 bool isProtectedContent,
50 const GrBackendFormat& backendFormat,
51 bool isRenderable,
52 bool fromAndroidWindow) {
53 SkASSERT(dContext);
54 if (!dContext || dContext->abandoned()) {
55 return GrBackendTexture();
56 }
57
58 if (GrBackendApi::kOpenGL == dContext->backend()) {
59 #ifdef SK_GL
60 return MakeGLBackendTexture(dContext, hardwareBuffer, width, height, deleteProc,
61 updateProc, imageCtx, isProtectedContent, backendFormat,
62 isRenderable);
63 #else
64 return GrBackendTexture();
65 #endif // SK_GL
66 } else {
67 SkASSERT(GrBackendApi::kVulkan == dContext->backend());
68 #ifdef SK_VULKAN
69 return MakeVulkanBackendTexture(dContext, hardwareBuffer, width, height, deleteProc,
70 updateProc, imageCtx, isProtectedContent, backendFormat,
71 isRenderable, fromAndroidWindow);
72 #else
73 return GrBackendTexture();
74 #endif // SK_VULKAN
75 }
76 }
77 #endif
78
79 } // namespace GrAHardwareBufferUtils
80
81 #endif