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