Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
GrAHardwareBufferUtils.cpp
Go to the documentation of this file.
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
9
10#if defined(SK_BUILD_FOR_ANDROID) && __ANDROID_API__ >= 26
11#define GL_GLEXT_PROTOTYPES
12#define EGL_EGLEXT_PROTOTYPES
13
15
16#if !defined(SK_DISABLE_LEGACY_ANDROID_HW_UTILS)
18#endif
19
20// TODO: remove this once Android is using the AHardwareBufferUtils version of
21// GetSkColorTypeFromBufferFormat
23
24namespace GrAHardwareBufferUtils {
25
26SkColorType GetSkColorTypeFromBufferFormat(uint32_t bufferFormat) {
27 return AHardwareBufferUtils::GetSkColorTypeFromBufferFormat(bufferFormat);
28}
29
30#if !defined(SK_DISABLE_LEGACY_ANDROID_HW_UTILS)
31GrBackendFormat GetBackendFormat(GrDirectContext* dContext, AHardwareBuffer* hardwareBuffer,
32 uint32_t bufferFormat, bool requireKnownFormat) {
33 GrBackendApi backend = dContext->backend();
34
35 if (backend == GrBackendApi::kOpenGL) {
36#ifdef SK_GL
37 return GetGLBackendFormat(dContext, bufferFormat, requireKnownFormat);
38#else // SK_GL
39 return GrBackendFormat();
40#endif // SK_GL
41 } else if (backend == GrBackendApi::kVulkan) {
42#ifdef SK_VULKAN
43 return GetVulkanBackendFormat(dContext, hardwareBuffer, bufferFormat, requireKnownFormat);
44#else // SK_VULKAN
45 return GrBackendFormat();
46#endif // SK_VULKAN
47 }
48 return GrBackendFormat();
49}
50
51GrBackendTexture MakeBackendTexture(GrDirectContext* dContext,
52 AHardwareBuffer* hardwareBuffer,
53 int width, int height,
54 DeleteImageProc* deleteProc,
55 UpdateImageProc* updateProc,
56 TexImageCtx* imageCtx,
57 bool isProtectedContent,
58 const GrBackendFormat& backendFormat,
59 bool isRenderable,
60 bool fromAndroidWindow) {
61 SkASSERT(dContext);
62 if (!dContext || dContext->abandoned()) {
63 return GrBackendTexture();
64 }
65
66 if (GrBackendApi::kOpenGL == dContext->backend()) {
67#ifdef SK_GL
68 return MakeGLBackendTexture(dContext, hardwareBuffer, width, height, deleteProc,
69 updateProc, imageCtx, isProtectedContent, backendFormat,
70 isRenderable);
71#else
72 return GrBackendTexture();
73#endif // SK_GL
74 } else {
76#ifdef SK_VULKAN
77 return MakeVulkanBackendTexture(dContext, hardwareBuffer, width, height, deleteProc,
78 updateProc, imageCtx, isProtectedContent, backendFormat,
79 isRenderable, fromAndroidWindow);
80#else
81 return GrBackendTexture();
82#endif // SK_VULKAN
83 }
84}
85#endif
86
87} // namespace GrAHardwareBufferUtils
88
89#endif
const char * backend
struct AHardwareBuffer AHardwareBuffer
GrBackendApi
Definition GrTypes.h:95
#define SkASSERT(cond)
Definition SkAssert.h:116
SkColorType
Definition SkColorType.h:19
SK_API GrBackendApi backend() const
bool abandoned() override
int32_t height
int32_t width