1 #pragma once 2 3 #include <aidl/android/hardware/graphics/common/PlaneLayout.h> 4 #include <pixel-gralloc/format.h> 5 #include <pixel-gralloc/usage.h> 6 #include <cstdint> 7 #include <optional> 8 #include <vector> 9 10 using FrameworkPlaneLayout = aidl::android::hardware::graphics::common::PlaneLayout; 11 12 namespace pixel::graphics::utils { 13 14 std::optional<std::vector<FrameworkPlaneLayout>> get_plane_layouts(FrameworkFormat format, 15 uint64_t usage, uint32_t width, 16 uint32_t height); 17 18 enum class Compression { 19 UNCOMPRESSED, 20 }; 21 get_usage_from_compression(Compression compression)22inline Usage get_usage_from_compression(Compression compression) { 23 switch (compression) { 24 case Compression::UNCOMPRESSED: 25 return static_cast<Usage>(Usage::CPU_READ_OFTEN | Usage::CPU_WRITE_OFTEN | 26 Usage::GPU_TEXTURE | Usage::GPU_RENDER_TARGET | 27 Usage::COMPOSER_OVERLAY); 28 } 29 } 30 31 #define FormatCase(f) \ 32 case Format::f: \ 33 return #f 34 get_string_from_format(Format format)35inline std::string get_string_from_format(Format format) { 36 switch (format) { 37 FormatCase(UNSPECIFIED); 38 FormatCase(RGBA_8888); 39 FormatCase(RGBX_8888); 40 FormatCase(RGB_888); 41 FormatCase(RGB_565); 42 FormatCase(BGRA_8888); 43 FormatCase(YCBCR_422_SP); 44 FormatCase(YCRCB_420_SP); 45 FormatCase(YCBCR_422_I); 46 FormatCase(RGBA_FP16); 47 FormatCase(RAW16); 48 FormatCase(BLOB); 49 FormatCase(IMPLEMENTATION_DEFINED); 50 FormatCase(YCBCR_420_888); 51 FormatCase(RAW_OPAQUE); 52 FormatCase(RAW10); 53 FormatCase(RAW12); 54 FormatCase(RGBA_1010102); 55 FormatCase(Y8); 56 FormatCase(Y16); 57 FormatCase(YV12); 58 FormatCase(DEPTH_16); 59 FormatCase(DEPTH_24); 60 FormatCase(DEPTH_24_STENCIL_8); 61 FormatCase(DEPTH_32F); 62 FormatCase(DEPTH_32F_STENCIL_8); 63 FormatCase(STENCIL_8); 64 FormatCase(YCBCR_P010); 65 FormatCase(HSV_888); 66 FormatCase(R_8); 67 FormatCase(R_16_UINT); 68 FormatCase(RG_1616_UINT); 69 FormatCase(RGBA_10101010); 70 71 // Pixel specific formats 72 FormatCase(GOOGLE_NV12); 73 FormatCase(GOOGLE_R8); 74 75 // Unknown formats 76 default: 77 return "Unknown"; 78 } 79 } 80 81 #undef FormatCase 82 } // namespace pixel::graphics::utils 83