1515#include " include/private/SkTo.h"
1616
1717#include < array>
18+ #include < bitset>
1819
20+ class GrImageContext ;
1921struct SkYUVASizeInfo ;
2022struct SkYUVAIndex ;
2123
@@ -27,44 +29,113 @@ class SK_API SkYUVAPixmapInfo {
2729public:
2830 static constexpr auto kMaxPlanes = SkYUVAInfo::kMaxPlanes ;
2931
32+ using PlanarConfig = SkYUVAInfo::PlanarConfig;
33+
34+ /* *
35+ * Data type for Y, U, V, and possibly A channels independent of how values are packed into
36+ * planes.
37+ **/
38+ enum class DataType {
39+ kUnorm8 , // /< 8 bit unsigned normalized
40+ kUnorm16 , // /< 16 bit unsigned normalized
41+ kFloat16 , // /< 16 bit (half) floating point
42+
43+ kLast = kFloat16
44+ };
45+ static constexpr int kDataTypeCnt = static_cast <int >(DataType::kLast ) + 1 ;
46+
47+ class SupportedDataTypes {
48+ public:
49+ /* * Defaults to nothing supported. */
50+ constexpr SupportedDataTypes () = default;
51+
52+ /* * Init based on texture formats supported by the context. */
53+ SupportedDataTypes (const GrImageContext&);
54+
55+ /* * All combinations of PlanarConfig and DataType are supported. */
56+ static constexpr SupportedDataTypes All () {
57+ SupportedDataTypes combinations;
58+ combinations.fDataTypeSupport = std::bitset<kDataTypeCnt >(~(0ULL ));
59+ return combinations;
60+ }
61+
62+ constexpr bool supported (PlanarConfig, DataType type) const {
63+ return fDataTypeSupport [static_cast <size_t >(type)];
64+ }
65+
66+ /* *
67+ * Update to add support for pixmaps with numChannel channels where each channel is
68+ * represented as DataType.
69+ */
70+ void enableDataType (DataType, int numChannels);
71+
72+ private:
73+ // Because all of our PlanarConfigs are currently single channel per-plane, we just need to
74+ // keep track of whether each data type is supported (implicitly as a single channel plane).
75+ // As we add multi-channel per-plane PlanarConfigs this will have to change.
76+ std::bitset<kDataTypeCnt > fDataTypeSupport = {};
77+ };
78+
79+ /* *
80+ * Gets the default SkColorType to use with numChannels channels, each represented as DataType.
81+ * Returns kUnknown_SkColorType if no such color type.
82+ */
83+ static SkColorType DefaultColorTypeForDataType (DataType dataType, int numChannels);
84+
85+ /* *
86+ * If the SkColorType is supported for YUVA pixmaps this will return the number of YUVA channels
87+ * that can be stored in a plane of this color type and what the DataType is of those channels.
88+ * If the SkColorType is not supported as a YUVA plane the number of channels is reported as 0
89+ * and the DataType returned should be ignored.
90+ */
91+ static std::tuple<int , DataType> NumChannelsAndDataType (SkColorType);
92+
3093 /* * Default SkYUVAPixmapInfo is invalid. */
3194 SkYUVAPixmapInfo () = default ;
3295
3396 /* *
3497 * Initializes the SkYUVAPixmapInfo from a SkYUVAInfo with per-plane color types and row bytes.
3598 * This will be invalid if the colorTypes aren't compatible with the SkYUVAInfo or if a
3699 * rowBytes entry is not valid for the plane dimensions and color type. Color type and
37- * row byte values beyond the number of planes in SkYUVAInfo are ignored.
100+ * row byte values beyond the number of planes in SkYUVAInfo are ignored. All SkColorTypes
101+ * must have the same DataType or this will be invalid.
38102 *
39103 * If rowBytes is nullptr then bpp*width is assumed for each plane.
40104 */
41105 SkYUVAPixmapInfo (const SkYUVAInfo&,
42106 const SkColorType[kMaxPlanes ],
43107 const size_t rowBytes[kMaxPlanes ]);
44108 /* *
45- * Like above but uses the same color type for all planes.
109+ * Like above but uses DefaultColorTypeForDataType to determine each plane's SkColorType. If
110+ * rowBytes is nullptr then bpp*width is assumed for each plane.
46111 */
47- SkYUVAPixmapInfo (const SkYUVAInfo&, SkColorType , const size_t rowBytes[kMaxPlanes ]);
112+ SkYUVAPixmapInfo (const SkYUVAInfo&, DataType , const size_t rowBytes[kMaxPlanes ]);
48113
49114 SkYUVAPixmapInfo (const SkYUVAPixmapInfo&) = default ;
50115
51116 SkYUVAPixmapInfo& operator =(const SkYUVAPixmapInfo&) = default ;
52117
118+ bool operator ==(const SkYUVAPixmapInfo&) const ;
119+ bool operator !=(const SkYUVAPixmapInfo& that) const { return !(*this == that); }
120+
53121 const SkYUVAInfo& yuvaInfo () const { return fYUVAInfo ; }
54122
55123 SkYUVColorSpace yuvColorSpace () const { return fYUVAInfo .yuvColorSpace (); }
56124
57125 /* * The number of SkPixmap planes, 0 if this SkYUVAPixmapInfo is invalid. */
58126 int numPlanes () const { return this ->isValid () ? fYUVAInfo .numPlanes () : 0 ; }
59127
128+ /* * The per-YUV[A] channel data type. */
129+ DataType dataType () const { return fDataType ; }
130+
60131 /* *
61132 * Row bytes for the ith plane. Returns zero if i >= numPlanes() or this SkYUVAPixmapInfo is
62133 * invalid.
63134 */
64- size_t rowBytes (int i) const { return fRowBytes [i ]; }
135+ size_t rowBytes (int i) const { return fRowBytes [static_cast < size_t >(i) ]; }
65136
66137 /* * Image info for the ith plane, or default SkImageInfo if i >= numPlanes() */
67- const SkImageInfo& planeInfo (int i) const { return fPlaneInfos [i ]; }
138+ const SkImageInfo& planeInfo (int i) const { return fPlaneInfos [static_cast < size_t >(i) ]; }
68139
69140 /* *
70141 * Determine size to allocate for all planes. Optionally retrieves the per-plane sizes in
@@ -86,10 +157,14 @@ class SK_API SkYUVAPixmapInfo {
86157 */
87158 bool isValid () const { return fPlaneInfos [0 ].colorType () != kUnknown_SkColorType ; }
88159
160+ /* * Is this valid and does it use color types allowed by the passed SupportedDataTypes? */
161+ bool isSupported (const SupportedDataTypes&) const ;
162+
89163private:
90164 SkYUVAInfo fYUVAInfo ;
91- SkImageInfo fPlaneInfos [kMaxPlanes ] = {};
92- size_t fRowBytes [kMaxPlanes ] = {};
165+ std::array<SkImageInfo, kMaxPlanes > fPlaneInfos = {};
166+ std::array<size_t , kMaxPlanes > fRowBytes = {};
167+ DataType fDataType = DataType::kUnorm8 ;
93168 static_assert (kUnknown_SkColorType == 0 , " default init isn't kUnknown" );
94169};
95170
0 commit comments