1cb93a386Sopenharmony_ci/* 2cb93a386Sopenharmony_ci * Copyright 2020 Google LLC 3cb93a386Sopenharmony_ci * 4cb93a386Sopenharmony_ci * Use of this source code is governed by a BSD-style license that can be 5cb93a386Sopenharmony_ci * found in the LICENSE file. 6cb93a386Sopenharmony_ci */ 7cb93a386Sopenharmony_ci 8cb93a386Sopenharmony_ci#ifndef SkYUVAPixmaps_DEFINED 9cb93a386Sopenharmony_ci#define SkYUVAPixmaps_DEFINED 10cb93a386Sopenharmony_ci 11cb93a386Sopenharmony_ci#include "include/core/SkData.h" 12cb93a386Sopenharmony_ci#include "include/core/SkImageInfo.h" 13cb93a386Sopenharmony_ci#include "include/core/SkPixmap.h" 14cb93a386Sopenharmony_ci#include "include/core/SkYUVAInfo.h" 15cb93a386Sopenharmony_ci#include "include/private/SkTo.h" 16cb93a386Sopenharmony_ci 17cb93a386Sopenharmony_ci#include <array> 18cb93a386Sopenharmony_ci#include <bitset> 19cb93a386Sopenharmony_ci 20cb93a386Sopenharmony_ciclass GrImageContext; 21cb93a386Sopenharmony_ci 22cb93a386Sopenharmony_ci/** 23cb93a386Sopenharmony_ci * SkYUVAInfo combined with per-plane SkColorTypes and row bytes. Fully specifies the SkPixmaps 24cb93a386Sopenharmony_ci * for a YUVA image without the actual pixel memory and data. 25cb93a386Sopenharmony_ci */ 26cb93a386Sopenharmony_ciclass SK_API SkYUVAPixmapInfo { 27cb93a386Sopenharmony_cipublic: 28cb93a386Sopenharmony_ci static constexpr auto kMaxPlanes = SkYUVAInfo::kMaxPlanes; 29cb93a386Sopenharmony_ci 30cb93a386Sopenharmony_ci using PlaneConfig = SkYUVAInfo::PlaneConfig; 31cb93a386Sopenharmony_ci using Subsampling = SkYUVAInfo::Subsampling; 32cb93a386Sopenharmony_ci 33cb93a386Sopenharmony_ci /** 34cb93a386Sopenharmony_ci * Data type for Y, U, V, and possibly A channels independent of how values are packed into 35cb93a386Sopenharmony_ci * planes. 36cb93a386Sopenharmony_ci **/ 37cb93a386Sopenharmony_ci enum class DataType { 38cb93a386Sopenharmony_ci kUnorm8, ///< 8 bit unsigned normalized 39cb93a386Sopenharmony_ci kUnorm16, ///< 16 bit unsigned normalized 40cb93a386Sopenharmony_ci kFloat16, ///< 16 bit (half) floating point 41cb93a386Sopenharmony_ci kUnorm10_Unorm2, ///< 10 bit unorm for Y, U, and V. 2 bit unorm for alpha (if present). 42cb93a386Sopenharmony_ci 43cb93a386Sopenharmony_ci kLast = kUnorm10_Unorm2 44cb93a386Sopenharmony_ci }; 45cb93a386Sopenharmony_ci static constexpr int kDataTypeCnt = static_cast<int>(DataType::kLast) + 1; 46cb93a386Sopenharmony_ci 47cb93a386Sopenharmony_ci class SK_API SupportedDataTypes { 48cb93a386Sopenharmony_ci public: 49cb93a386Sopenharmony_ci /** Defaults to nothing supported. */ 50cb93a386Sopenharmony_ci constexpr SupportedDataTypes() = default; 51cb93a386Sopenharmony_ci 52cb93a386Sopenharmony_ci /** Init based on texture formats supported by the context. */ 53cb93a386Sopenharmony_ci SupportedDataTypes(const GrImageContext&); 54cb93a386Sopenharmony_ci 55cb93a386Sopenharmony_ci /** All legal combinations of PlaneConfig and DataType are supported. */ 56cb93a386Sopenharmony_ci static constexpr SupportedDataTypes All(); 57cb93a386Sopenharmony_ci 58cb93a386Sopenharmony_ci /** 59cb93a386Sopenharmony_ci * Checks whether there is a supported combination of color types for planes structured 60cb93a386Sopenharmony_ci * as indicated by PlaneConfig with channel data types as indicated by DataType. 61cb93a386Sopenharmony_ci */ 62cb93a386Sopenharmony_ci constexpr bool supported(PlaneConfig, DataType) const; 63cb93a386Sopenharmony_ci 64cb93a386Sopenharmony_ci /** 65cb93a386Sopenharmony_ci * Update to add support for pixmaps with numChannel channels where each channel is 66cb93a386Sopenharmony_ci * represented as DataType. 67cb93a386Sopenharmony_ci */ 68cb93a386Sopenharmony_ci void enableDataType(DataType, int numChannels); 69cb93a386Sopenharmony_ci 70cb93a386Sopenharmony_ci private: 71cb93a386Sopenharmony_ci // The bit for DataType dt with n channels is at index kDataTypeCnt*(n-1) + dt. 72cb93a386Sopenharmony_ci std::bitset<kDataTypeCnt*4> fDataTypeSupport = {}; 73cb93a386Sopenharmony_ci }; 74cb93a386Sopenharmony_ci 75cb93a386Sopenharmony_ci /** 76cb93a386Sopenharmony_ci * Gets the default SkColorType to use with numChannels channels, each represented as DataType. 77cb93a386Sopenharmony_ci * Returns kUnknown_SkColorType if no such color type. 78cb93a386Sopenharmony_ci */ 79cb93a386Sopenharmony_ci static constexpr SkColorType DefaultColorTypeForDataType(DataType dataType, int numChannels); 80cb93a386Sopenharmony_ci 81cb93a386Sopenharmony_ci /** 82cb93a386Sopenharmony_ci * If the SkColorType is supported for YUVA pixmaps this will return the number of YUVA channels 83cb93a386Sopenharmony_ci * that can be stored in a plane of this color type and what the DataType is of those channels. 84cb93a386Sopenharmony_ci * If the SkColorType is not supported as a YUVA plane the number of channels is reported as 0 85cb93a386Sopenharmony_ci * and the DataType returned should be ignored. 86cb93a386Sopenharmony_ci */ 87cb93a386Sopenharmony_ci static std::tuple<int, DataType> NumChannelsAndDataType(SkColorType); 88cb93a386Sopenharmony_ci 89cb93a386Sopenharmony_ci /** Default SkYUVAPixmapInfo is invalid. */ 90cb93a386Sopenharmony_ci SkYUVAPixmapInfo() = default; 91cb93a386Sopenharmony_ci 92cb93a386Sopenharmony_ci /** 93cb93a386Sopenharmony_ci * Initializes the SkYUVAPixmapInfo from a SkYUVAInfo with per-plane color types and row bytes. 94cb93a386Sopenharmony_ci * This will be invalid if the colorTypes aren't compatible with the SkYUVAInfo or if a 95cb93a386Sopenharmony_ci * rowBytes entry is not valid for the plane dimensions and color type. Color type and 96cb93a386Sopenharmony_ci * row byte values beyond the number of planes in SkYUVAInfo are ignored. All SkColorTypes 97cb93a386Sopenharmony_ci * must have the same DataType or this will be invalid. 98cb93a386Sopenharmony_ci * 99cb93a386Sopenharmony_ci * If rowBytes is nullptr then bpp*width is assumed for each plane. 100cb93a386Sopenharmony_ci */ 101cb93a386Sopenharmony_ci SkYUVAPixmapInfo(const SkYUVAInfo&, 102cb93a386Sopenharmony_ci const SkColorType[kMaxPlanes], 103cb93a386Sopenharmony_ci const size_t rowBytes[kMaxPlanes]); 104cb93a386Sopenharmony_ci /** 105cb93a386Sopenharmony_ci * Like above but uses DefaultColorTypeForDataType to determine each plane's SkColorType. If 106cb93a386Sopenharmony_ci * rowBytes is nullptr then bpp*width is assumed for each plane. 107cb93a386Sopenharmony_ci */ 108cb93a386Sopenharmony_ci SkYUVAPixmapInfo(const SkYUVAInfo&, DataType, const size_t rowBytes[kMaxPlanes]); 109cb93a386Sopenharmony_ci 110cb93a386Sopenharmony_ci SkYUVAPixmapInfo(const SkYUVAPixmapInfo&) = default; 111cb93a386Sopenharmony_ci 112cb93a386Sopenharmony_ci SkYUVAPixmapInfo& operator=(const SkYUVAPixmapInfo&) = default; 113cb93a386Sopenharmony_ci 114cb93a386Sopenharmony_ci bool operator==(const SkYUVAPixmapInfo&) const; 115cb93a386Sopenharmony_ci bool operator!=(const SkYUVAPixmapInfo& that) const { return !(*this == that); } 116cb93a386Sopenharmony_ci 117cb93a386Sopenharmony_ci const SkYUVAInfo& yuvaInfo() const { return fYUVAInfo; } 118cb93a386Sopenharmony_ci 119cb93a386Sopenharmony_ci SkYUVColorSpace yuvColorSpace() const { return fYUVAInfo.yuvColorSpace(); } 120cb93a386Sopenharmony_ci 121cb93a386Sopenharmony_ci /** The number of SkPixmap planes, 0 if this SkYUVAPixmapInfo is invalid. */ 122cb93a386Sopenharmony_ci int numPlanes() const { return fYUVAInfo.numPlanes(); } 123cb93a386Sopenharmony_ci 124cb93a386Sopenharmony_ci /** The per-YUV[A] channel data type. */ 125cb93a386Sopenharmony_ci DataType dataType() const { return fDataType; } 126cb93a386Sopenharmony_ci 127cb93a386Sopenharmony_ci /** 128cb93a386Sopenharmony_ci * Row bytes for the ith plane. Returns zero if i >= numPlanes() or this SkYUVAPixmapInfo is 129cb93a386Sopenharmony_ci * invalid. 130cb93a386Sopenharmony_ci */ 131cb93a386Sopenharmony_ci size_t rowBytes(int i) const { return fRowBytes[static_cast<size_t>(i)]; } 132cb93a386Sopenharmony_ci 133cb93a386Sopenharmony_ci /** Image info for the ith plane, or default SkImageInfo if i >= numPlanes() */ 134cb93a386Sopenharmony_ci const SkImageInfo& planeInfo(int i) const { return fPlaneInfos[static_cast<size_t>(i)]; } 135cb93a386Sopenharmony_ci 136cb93a386Sopenharmony_ci /** 137cb93a386Sopenharmony_ci * Determine size to allocate for all planes. Optionally retrieves the per-plane sizes in 138cb93a386Sopenharmony_ci * planeSizes if not null. If total size overflows will return SIZE_MAX and set all planeSizes 139cb93a386Sopenharmony_ci * to SIZE_MAX. Returns 0 and fills planesSizes with 0 if this SkYUVAPixmapInfo is not valid. 140cb93a386Sopenharmony_ci */ 141cb93a386Sopenharmony_ci size_t computeTotalBytes(size_t planeSizes[kMaxPlanes] = nullptr) const; 142cb93a386Sopenharmony_ci 143cb93a386Sopenharmony_ci /** 144cb93a386Sopenharmony_ci * Takes an allocation that is assumed to be at least computeTotalBytes() in size and configures 145cb93a386Sopenharmony_ci * the first numPlanes() entries in pixmaps array to point into that memory. The remaining 146cb93a386Sopenharmony_ci * entries of pixmaps are default initialized. Fails if this SkYUVAPixmapInfo not valid. 147cb93a386Sopenharmony_ci */ 148cb93a386Sopenharmony_ci bool initPixmapsFromSingleAllocation(void* memory, SkPixmap pixmaps[kMaxPlanes]) const; 149cb93a386Sopenharmony_ci 150cb93a386Sopenharmony_ci /** 151cb93a386Sopenharmony_ci * Returns true if this has been configured with a non-empty dimensioned SkYUVAInfo with 152cb93a386Sopenharmony_ci * compatible color types and row bytes. 153cb93a386Sopenharmony_ci */ 154cb93a386Sopenharmony_ci bool isValid() const { return fYUVAInfo.isValid(); } 155cb93a386Sopenharmony_ci 156cb93a386Sopenharmony_ci /** Is this valid and does it use color types allowed by the passed SupportedDataTypes? */ 157cb93a386Sopenharmony_ci bool isSupported(const SupportedDataTypes&) const; 158cb93a386Sopenharmony_ci 159cb93a386Sopenharmony_ciprivate: 160cb93a386Sopenharmony_ci SkYUVAInfo fYUVAInfo; 161cb93a386Sopenharmony_ci std::array<SkImageInfo, kMaxPlanes> fPlaneInfos = {}; 162cb93a386Sopenharmony_ci std::array<size_t, kMaxPlanes> fRowBytes = {}; 163cb93a386Sopenharmony_ci DataType fDataType = DataType::kUnorm8; 164cb93a386Sopenharmony_ci static_assert(kUnknown_SkColorType == 0, "default init isn't kUnknown"); 165cb93a386Sopenharmony_ci}; 166cb93a386Sopenharmony_ci 167cb93a386Sopenharmony_ci/** 168cb93a386Sopenharmony_ci * Helper to store SkPixmap planes as described by a SkYUVAPixmapInfo. Can be responsible for 169cb93a386Sopenharmony_ci * allocating/freeing memory for pixmaps or use external memory. 170cb93a386Sopenharmony_ci */ 171cb93a386Sopenharmony_ciclass SK_API SkYUVAPixmaps { 172cb93a386Sopenharmony_cipublic: 173cb93a386Sopenharmony_ci using DataType = SkYUVAPixmapInfo::DataType; 174cb93a386Sopenharmony_ci static constexpr auto kMaxPlanes = SkYUVAPixmapInfo::kMaxPlanes; 175cb93a386Sopenharmony_ci 176cb93a386Sopenharmony_ci static SkColorType RecommendedRGBAColorType(DataType); 177cb93a386Sopenharmony_ci 178cb93a386Sopenharmony_ci /** Allocate space for pixmaps' pixels in the SkYUVAPixmaps. */ 179cb93a386Sopenharmony_ci static SkYUVAPixmaps Allocate(const SkYUVAPixmapInfo& yuvaPixmapInfo); 180cb93a386Sopenharmony_ci 181cb93a386Sopenharmony_ci /** 182cb93a386Sopenharmony_ci * Use storage in SkData as backing store for pixmaps' pixels. SkData is retained by the 183cb93a386Sopenharmony_ci * SkYUVAPixmaps. 184cb93a386Sopenharmony_ci */ 185cb93a386Sopenharmony_ci static SkYUVAPixmaps FromData(const SkYUVAPixmapInfo&, sk_sp<SkData>); 186cb93a386Sopenharmony_ci 187cb93a386Sopenharmony_ci /** 188cb93a386Sopenharmony_ci * Makes a deep copy of the src SkYUVAPixmaps. The returned SkYUVAPixmaps owns its planes' 189cb93a386Sopenharmony_ci * backing stores. 190cb93a386Sopenharmony_ci */ 191cb93a386Sopenharmony_ci static SkYUVAPixmaps MakeCopy(const SkYUVAPixmaps& src); 192cb93a386Sopenharmony_ci 193cb93a386Sopenharmony_ci /** 194cb93a386Sopenharmony_ci * Use passed in memory as backing store for pixmaps' pixels. Caller must ensure memory remains 195cb93a386Sopenharmony_ci * allocated while pixmaps are in use. There must be at least 196cb93a386Sopenharmony_ci * SkYUVAPixmapInfo::computeTotalBytes() allocated starting at memory. 197cb93a386Sopenharmony_ci */ 198cb93a386Sopenharmony_ci static SkYUVAPixmaps FromExternalMemory(const SkYUVAPixmapInfo&, void* memory); 199cb93a386Sopenharmony_ci 200cb93a386Sopenharmony_ci /** 201cb93a386Sopenharmony_ci * Wraps existing SkPixmaps. The SkYUVAPixmaps will have no ownership of the SkPixmaps' pixel 202cb93a386Sopenharmony_ci * memory so the caller must ensure it remains valid. Will return an invalid SkYUVAPixmaps if 203cb93a386Sopenharmony_ci * the SkYUVAInfo isn't compatible with the SkPixmap array (number of planes, plane dimensions, 204cb93a386Sopenharmony_ci * sufficient color channels in planes, ...). 205cb93a386Sopenharmony_ci */ 206cb93a386Sopenharmony_ci static SkYUVAPixmaps FromExternalPixmaps(const SkYUVAInfo&, const SkPixmap[kMaxPlanes]); 207cb93a386Sopenharmony_ci 208cb93a386Sopenharmony_ci /** Default SkYUVAPixmaps is invalid. */ 209cb93a386Sopenharmony_ci SkYUVAPixmaps() = default; 210cb93a386Sopenharmony_ci ~SkYUVAPixmaps() = default; 211cb93a386Sopenharmony_ci 212cb93a386Sopenharmony_ci SkYUVAPixmaps(SkYUVAPixmaps&& that) = default; 213cb93a386Sopenharmony_ci SkYUVAPixmaps& operator=(SkYUVAPixmaps&& that) = default; 214cb93a386Sopenharmony_ci SkYUVAPixmaps(const SkYUVAPixmaps&) = default; 215cb93a386Sopenharmony_ci SkYUVAPixmaps& operator=(const SkYUVAPixmaps& that) = default; 216cb93a386Sopenharmony_ci 217cb93a386Sopenharmony_ci /** Does have initialized pixmaps compatible with its SkYUVAInfo. */ 218cb93a386Sopenharmony_ci bool isValid() const { return !fYUVAInfo.dimensions().isEmpty(); } 219cb93a386Sopenharmony_ci 220cb93a386Sopenharmony_ci const SkYUVAInfo& yuvaInfo() const { return fYUVAInfo; } 221cb93a386Sopenharmony_ci 222cb93a386Sopenharmony_ci DataType dataType() const { return fDataType; } 223cb93a386Sopenharmony_ci 224cb93a386Sopenharmony_ci SkYUVAPixmapInfo pixmapsInfo() const; 225cb93a386Sopenharmony_ci 226cb93a386Sopenharmony_ci /** Number of pixmap planes or 0 if this SkYUVAPixmaps is invalid. */ 227cb93a386Sopenharmony_ci int numPlanes() const { return this->isValid() ? fYUVAInfo.numPlanes() : 0; } 228cb93a386Sopenharmony_ci 229cb93a386Sopenharmony_ci /** 230cb93a386Sopenharmony_ci * Access the SkPixmap planes. They are default initialized if this is not a valid 231cb93a386Sopenharmony_ci * SkYUVAPixmaps. 232cb93a386Sopenharmony_ci */ 233cb93a386Sopenharmony_ci const std::array<SkPixmap, kMaxPlanes>& planes() const { return fPlanes; } 234cb93a386Sopenharmony_ci 235cb93a386Sopenharmony_ci /** 236cb93a386Sopenharmony_ci * Get the ith SkPixmap plane. SkPixmap will be default initialized if i >= numPlanes or this 237cb93a386Sopenharmony_ci * SkYUVAPixmaps is invalid. 238cb93a386Sopenharmony_ci */ 239cb93a386Sopenharmony_ci const SkPixmap& plane(int i) const { return fPlanes[SkToSizeT(i)]; } 240cb93a386Sopenharmony_ci 241cb93a386Sopenharmony_ci /** 242cb93a386Sopenharmony_ci * Computes a YUVALocations representation of the planar layout. The result is guaranteed to be 243cb93a386Sopenharmony_ci * valid if this->isValid(). 244cb93a386Sopenharmony_ci */ 245cb93a386Sopenharmony_ci SkYUVAInfo::YUVALocations toYUVALocations() const; 246cb93a386Sopenharmony_ci 247cb93a386Sopenharmony_ci /** Does this SkPixmaps own the backing store of the planes? */ 248cb93a386Sopenharmony_ci bool ownsStorage() const { return SkToBool(fData); } 249cb93a386Sopenharmony_ci 250cb93a386Sopenharmony_ciprivate: 251cb93a386Sopenharmony_ci SkYUVAPixmaps(const SkYUVAPixmapInfo&, sk_sp<SkData>); 252cb93a386Sopenharmony_ci SkYUVAPixmaps(const SkYUVAInfo&, DataType, const SkPixmap[kMaxPlanes]); 253cb93a386Sopenharmony_ci 254cb93a386Sopenharmony_ci std::array<SkPixmap, kMaxPlanes> fPlanes = {}; 255cb93a386Sopenharmony_ci sk_sp<SkData> fData; 256cb93a386Sopenharmony_ci SkYUVAInfo fYUVAInfo; 257cb93a386Sopenharmony_ci DataType fDataType; 258cb93a386Sopenharmony_ci}; 259cb93a386Sopenharmony_ci 260cb93a386Sopenharmony_ci////////////////////////////////////////////////////////////////////////////// 261cb93a386Sopenharmony_ci 262cb93a386Sopenharmony_ciconstexpr SkYUVAPixmapInfo::SupportedDataTypes SkYUVAPixmapInfo::SupportedDataTypes::All() { 263cb93a386Sopenharmony_ci using ULL = unsigned long long; // bitset cons. takes this. 264cb93a386Sopenharmony_ci ULL bits = 0; 265cb93a386Sopenharmony_ci for (ULL c = 1; c <= 4; ++c) { 266cb93a386Sopenharmony_ci for (ULL dt = 0; dt <= ULL(kDataTypeCnt); ++dt) { 267cb93a386Sopenharmony_ci if (DefaultColorTypeForDataType(static_cast<DataType>(dt), 268cb93a386Sopenharmony_ci static_cast<int>(c)) != kUnknown_SkColorType) { 269cb93a386Sopenharmony_ci bits |= ULL(1) << (dt + static_cast<ULL>(kDataTypeCnt)*(c - 1)); 270cb93a386Sopenharmony_ci } 271cb93a386Sopenharmony_ci } 272cb93a386Sopenharmony_ci } 273cb93a386Sopenharmony_ci SupportedDataTypes combinations; 274cb93a386Sopenharmony_ci combinations.fDataTypeSupport = bits; 275cb93a386Sopenharmony_ci return combinations; 276cb93a386Sopenharmony_ci} 277cb93a386Sopenharmony_ci 278cb93a386Sopenharmony_ciconstexpr bool SkYUVAPixmapInfo::SupportedDataTypes::supported(PlaneConfig config, 279cb93a386Sopenharmony_ci DataType type) const { 280cb93a386Sopenharmony_ci int n = SkYUVAInfo::NumPlanes(config); 281cb93a386Sopenharmony_ci for (int i = 0; i < n; ++i) { 282cb93a386Sopenharmony_ci auto c = static_cast<size_t>(SkYUVAInfo::NumChannelsInPlane(config, i)); 283cb93a386Sopenharmony_ci SkASSERT(c >= 1 && c <= 4); 284cb93a386Sopenharmony_ci if (!fDataTypeSupport[static_cast<size_t>(type) + 285cb93a386Sopenharmony_ci (c - 1)*static_cast<size_t>(kDataTypeCnt)]) { 286cb93a386Sopenharmony_ci return false; 287cb93a386Sopenharmony_ci } 288cb93a386Sopenharmony_ci } 289cb93a386Sopenharmony_ci return true; 290cb93a386Sopenharmony_ci} 291cb93a386Sopenharmony_ci 292cb93a386Sopenharmony_ciconstexpr SkColorType SkYUVAPixmapInfo::DefaultColorTypeForDataType(DataType dataType, 293cb93a386Sopenharmony_ci int numChannels) { 294cb93a386Sopenharmony_ci switch (numChannels) { 295cb93a386Sopenharmony_ci case 1: 296cb93a386Sopenharmony_ci switch (dataType) { 297cb93a386Sopenharmony_ci case DataType::kUnorm8: return kGray_8_SkColorType; 298cb93a386Sopenharmony_ci case DataType::kUnorm16: return kA16_unorm_SkColorType; 299cb93a386Sopenharmony_ci case DataType::kFloat16: return kA16_float_SkColorType; 300cb93a386Sopenharmony_ci case DataType::kUnorm10_Unorm2: return kUnknown_SkColorType; 301cb93a386Sopenharmony_ci } 302cb93a386Sopenharmony_ci break; 303cb93a386Sopenharmony_ci case 2: 304cb93a386Sopenharmony_ci switch (dataType) { 305cb93a386Sopenharmony_ci case DataType::kUnorm8: return kR8G8_unorm_SkColorType; 306cb93a386Sopenharmony_ci case DataType::kUnorm16: return kR16G16_unorm_SkColorType; 307cb93a386Sopenharmony_ci case DataType::kFloat16: return kR16G16_float_SkColorType; 308cb93a386Sopenharmony_ci case DataType::kUnorm10_Unorm2: return kUnknown_SkColorType; 309cb93a386Sopenharmony_ci } 310cb93a386Sopenharmony_ci break; 311cb93a386Sopenharmony_ci case 3: 312cb93a386Sopenharmony_ci // None of these are tightly packed. The intended use case is for interleaved YUVA 313cb93a386Sopenharmony_ci // planes where we're forcing opaqueness by ignoring the alpha values. 314cb93a386Sopenharmony_ci // There are "x" rather than "A" variants for Unorm8 and Unorm10_Unorm2 but we don't 315cb93a386Sopenharmony_ci // choose them because 1) there is no inherent advantage and 2) there is better support 316cb93a386Sopenharmony_ci // in the GPU backend for the "A" versions. 317cb93a386Sopenharmony_ci switch (dataType) { 318cb93a386Sopenharmony_ci case DataType::kUnorm8: return kRGBA_8888_SkColorType; 319cb93a386Sopenharmony_ci case DataType::kUnorm16: return kR16G16B16A16_unorm_SkColorType; 320cb93a386Sopenharmony_ci case DataType::kFloat16: return kRGBA_F16_SkColorType; 321cb93a386Sopenharmony_ci case DataType::kUnorm10_Unorm2: return kRGBA_1010102_SkColorType; 322cb93a386Sopenharmony_ci } 323cb93a386Sopenharmony_ci break; 324cb93a386Sopenharmony_ci case 4: 325cb93a386Sopenharmony_ci switch (dataType) { 326cb93a386Sopenharmony_ci case DataType::kUnorm8: return kRGBA_8888_SkColorType; 327cb93a386Sopenharmony_ci case DataType::kUnorm16: return kR16G16B16A16_unorm_SkColorType; 328cb93a386Sopenharmony_ci case DataType::kFloat16: return kRGBA_F16_SkColorType; 329cb93a386Sopenharmony_ci case DataType::kUnorm10_Unorm2: return kRGBA_1010102_SkColorType; 330cb93a386Sopenharmony_ci } 331cb93a386Sopenharmony_ci break; 332cb93a386Sopenharmony_ci } 333cb93a386Sopenharmony_ci return kUnknown_SkColorType; 334cb93a386Sopenharmony_ci} 335cb93a386Sopenharmony_ci 336cb93a386Sopenharmony_ci#endif 337