1 /* 2 * Copyright 2023 Google LLC 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/AHardwareBufferUtils.h" 9 10 #if __ANDROID_API__ >= 26 11 12 #include <android/hardware_buffer.h> 13 14 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK 15 #include <vndk/hardware_buffer.h> 16 #endif 17 18 namespace AHardwareBufferUtils { 19 GetSkColorTypeFromBufferFormat(uint32_t bufferFormat)20SkColorType GetSkColorTypeFromBufferFormat(uint32_t bufferFormat) { 21 switch (bufferFormat) { 22 case AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM: 23 return kRGBA_8888_SkColorType; 24 case AHARDWAREBUFFER_FORMAT_R8G8B8X8_UNORM: 25 return kRGB_888x_SkColorType; 26 #if __ANDROID_API__ >= 34 27 case AHARDWAREBUFFER_FORMAT_R10G10B10A10_UNORM: 28 return kRGBA_10x6_SkColorType; 29 #endif 30 case AHARDWAREBUFFER_FORMAT_R16G16B16A16_FLOAT: 31 return kRGBA_F16_SkColorType; 32 case AHARDWAREBUFFER_FORMAT_R5G6B5_UNORM: 33 return kRGB_565_SkColorType; 34 case AHARDWAREBUFFER_FORMAT_R8G8B8_UNORM: 35 return kRGB_888x_SkColorType; 36 case AHARDWAREBUFFER_FORMAT_R10G10B10A2_UNORM: 37 return kRGBA_1010102_SkColorType; 38 #if __ANDROID_API__ >= 33 39 case AHARDWAREBUFFER_FORMAT_R8_UNORM: 40 return kAlpha_8_SkColorType; 41 #endif 42 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK 43 case AHARDWAREBUFFER_FORMAT_B8G8R8A8_UNORM: 44 return kBGRA_8888_SkColorType; 45 #endif 46 default: 47 // Given that we only use this texture as a source, colorType will not impact how Skia 48 // uses the texture. The only potential affect this is anticipated to have is that for 49 // some format types if we are not bound as an OES texture we may get invalid results 50 // for SKP capture if we read back the texture. 51 return kRGBA_8888_SkColorType; 52 } 53 } 54 55 } // namespace AHardwareBufferUtils 56 57 #endif 58