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