Hash :
74b7ec03
Author :
Date :
2023-09-08T14:26:18
GL: Don't use system info for Android SDK queries. It can be queried directly from the system property without fully gathering system info. System info often uses Vulkan which is known to be unstable on some older devices. Bug: chromium:1479277 Change-Id: Ic6ee1d0182b047b0a3210dd1067f6b7250e3da02 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/4851775 Commit-Queue: Geoff Lang <geofflang@chromium.org> Reviewed-by: Yuxin Hu <yuxinhu@google.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238
//
// Copyright 2018 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// android_util.h: Utilities for the using the Android platform
#ifndef COMMON_ANDROIDUTIL_H_
#define COMMON_ANDROIDUTIL_H_
#include <EGL/egl.h>
#include <EGL/eglext.h>
#include <array>
#include <cstdint>
#include <string>
#include "angle_gl.h"
struct ANativeWindowBuffer;
struct AHardwareBuffer;
namespace angle
{
namespace android
{
// clang-format off
/**
* Buffer pixel formats mirrored from Android to avoid unnecessary complications
* when trying to keep the enums defined, but not redefined, across various build
* systems and across various releases/branches.
*
* Taken from
* https://android.googlesource.com/platform/hardware/interfaces/+/refs/heads/master/graphics/common/aidl/android/hardware/graphics/common/PixelFormat.aidl
*/
enum {
/**
* Corresponding formats:
* Android: AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM
* Vulkan: VK_FORMAT_R8G8B8A8_UNORM
* OpenGL ES: GL_RGBA8
*/
ANGLE_AHB_FORMAT_R8G8B8A8_UNORM = 1,
/**
* 32 bits per pixel, 8 bits per channel format where alpha values are
* ignored (always opaque).
*
* Corresponding formats:
* Android: AHARDWAREBUFFER_FORMAT_R8G8B8X8_UNORM
* Vulkan: VK_FORMAT_R8G8B8A8_UNORM
* OpenGL ES: GL_RGB8
*/
ANGLE_AHB_FORMAT_R8G8B8X8_UNORM = 2,
/**
* Corresponding formats:
* Android: AHARDWAREBUFFER_FORMAT_R8G8B8_UNORM
* Vulkan: VK_FORMAT_R8G8B8_UNORM
* OpenGL ES: GL_RGB8
*/
ANGLE_AHB_FORMAT_R8G8B8_UNORM = 3,
/**
* Corresponding formats:
* Android: AHARDWAREBUFFER_FORMAT_R5G6B5_UNORM
* Vulkan: VK_FORMAT_R5G6B5_UNORM_PACK16
* OpenGL ES: GL_RGB565
*/
ANGLE_AHB_FORMAT_R5G6B5_UNORM = 4,
/**
* Corresponding formats:
* Android: AHARDWAREBUFFER_FORMAT_B8G8R8A8_UNORM (deprecated)
*/
ANGLE_AHB_FORMAT_B8G8R8A8_UNORM = 5,
/**
* Corresponding formats:
* Android: AHARDWAREBUFFER_FORMAT_B5G5R5A1_UNORM (deprecated)
*/
ANGLE_AHB_FORMAT_B5G5R5A1_UNORM = 6,
/**
* Corresponding formats:
* Android: AHARDWAREBUFFER_FORMAT_B4G4R4A4_UNORM (deprecated)
*/
ANGLE_AHB_FORMAT_B4G4R4A4_UNORM = 7,
/**
* Corresponding formats:
* Android: AHARDWAREBUFFER_FORMAT_R16G16B16A16_FLOAT
* Vulkan: VK_FORMAT_R16G16B16A16_SFLOAT
* OpenGL ES: GL_RGBA16F
*/
ANGLE_AHB_FORMAT_R16G16B16A16_FLOAT = 0x16,
/**
* Corresponding formats:
* Android: AHARDWAREBUFFER_FORMAT_R10G10B10A2_UNORM
* Vulkan: VK_FORMAT_A2B10G10R10_UNORM_PACK32
* OpenGL ES: GL_RGB10_A2
*/
ANGLE_AHB_FORMAT_R10G10B10A2_UNORM = 0x2b,
/**
* An opaque binary blob format that must have height 1, with width equal to
* the buffer size in bytes.
*
* Corresponding formats:
* Android: AHARDWAREBUFFER_FORMAT_BLOB
*/
ANGLE_AHB_FORMAT_BLOB = 0x21,
/**
* Corresponding formats:
* Android: AHARDWAREBUFFER_FORMAT_D16_UNORM
* Vulkan: VK_FORMAT_D16_UNORM
* OpenGL ES: GL_DEPTH_COMPONENT16
*/
ANGLE_AHB_FORMAT_D16_UNORM = 0x30,
/**
* Corresponding formats:
* Android: AHARDWAREBUFFER_FORMAT_D24_UNORM
* Vulkan: VK_FORMAT_X8_D24_UNORM_PACK32
* OpenGL ES: GL_DEPTH_COMPONENT24
*/
ANGLE_AHB_FORMAT_D24_UNORM = 0x31,
/**
* Corresponding formats:
* Android: AHARDWAREBUFFER_FORMAT_D24_UNORM_S8_UINT
* Vulkan: VK_FORMAT_D24_UNORM_S8_UINT
* OpenGL ES: GL_DEPTH24_STENCIL8
*/
ANGLE_AHB_FORMAT_D24_UNORM_S8_UINT = 0x32,
/**
* Corresponding formats:
* Android: AHARDWAREBUFFER_FORMAT_D32_FLOAT
* Vulkan: VK_FORMAT_D32_SFLOAT
* OpenGL ES: GL_DEPTH_COMPONENT32F
*/
ANGLE_AHB_FORMAT_D32_FLOAT = 0x33,
/**
* Corresponding formats:
* Android: AHARDWAREBUFFER_FORMAT_D32_FLOAT_S8_UINT
* Vulkan: VK_FORMAT_D32_SFLOAT_S8_UINT
* OpenGL ES: GL_DEPTH32F_STENCIL8
*/
ANGLE_AHB_FORMAT_D32_FLOAT_S8_UINT = 0x34,
/**
* Corresponding formats:
* Android: AHARDWAREBUFFER_FORMAT_D32_FLOAT_S8_UINT
* Vulkan: VK_FORMAT_S8_UINT
* OpenGL ES: GL_STENCIL_INDEX8
*/
ANGLE_AHB_FORMAT_S8_UINT = 0x35,
/**
* YUV 420 888 format.
* Must have an even width and height. Can be accessed in OpenGL
* shaders through an external sampler. Does not support mip-maps
* cube-maps or multi-layered textures.
*
* Corresponding formats:
* Android: AHARDWAREBUFFER_FORMAT_Y8Cb8Cr8_420
*/
ANGLE_AHB_FORMAT_Y8Cb8Cr8_420 = 0x23,
/**
* Corresponding formats:
* Android: AHARDWAREBUFFER_FORMAT_YV12
* Vulkan: VK_FORMAT_S8_UINT
* OpenGL ES: GL_STENCIL_INDEX8
*/
ANGLE_AHB_FORMAT_YV12 = 0x32315659,
/**
* Corresponding formats:
* Android: AHARDWAREBUFFER_FORMAT_IMPLEMENTATION_DEFINED
* Vulkan: VK_FORMAT_S8_UINT
* OpenGL ES: GL_STENCIL_INDEX8
*/
ANGLE_AHB_FORMAT_IMPLEMENTATION_DEFINED = 0x22,
/**
* Corresponding formats:
* Android: AHARDWAREBUFFER_FORMAT_R8_UNORM
* Vulkan: VK_FORMAT_R8_UNORM
* OpenGL ES: GL_R8
*/
ANGLE_AHB_FORMAT_R8_UNORM = 0x38,
};
// clang-format on
constexpr std::array<GLenum, 3> kSupportedSizedInternalFormats = {GL_RGBA8, GL_RGB8, GL_RGB565};
ANativeWindowBuffer *ClientBufferToANativeWindowBuffer(EGLClientBuffer clientBuffer);
EGLClientBuffer AHardwareBufferToClientBuffer(const AHardwareBuffer *hardwareBuffer);
AHardwareBuffer *ClientBufferToAHardwareBuffer(EGLClientBuffer clientBuffer);
EGLClientBuffer CreateEGLClientBufferFromAHardwareBuffer(int width,
int height,
int depth,
int androidFormat,
int usage);
void GetANativeWindowBufferProperties(const ANativeWindowBuffer *buffer,
int *width,
int *height,
int *depth,
int *pixelFormat,
uint64_t *usage);
GLenum NativePixelFormatToGLInternalFormat(int pixelFormat);
int GLInternalFormatToNativePixelFormat(GLenum internalFormat);
bool NativePixelFormatIsYUV(int pixelFormat);
AHardwareBuffer *ANativeWindowBufferToAHardwareBuffer(ANativeWindowBuffer *windowBuffer);
uint64_t GetAHBUsage(int eglNativeBufferUsage);
bool GetSystemProperty(const char *propertyName, std::string *value);
static constexpr const char *kManufacturerSystemPropertyName = "ro.product.manufacturer";
static constexpr const char *kModelSystemPropertyName = "ro.product.model";
static constexpr const char *kSDKSystemPropertyName = "ro.build.version.sdk";
} // namespace android
} // namespace angle
#endif // COMMON_ANDROIDUTIL_H_