Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit c7fa895

Browse files
lhkbobSkia Commit-Bot
authored andcommitted
Revert "Add idea of DataType to SkYUVAPixmapInfo."
This reverts commit ed63444. Reason for revert: trying to unblock android roller, which incorrectly thinks this has a merge conflict: https://b.corp.google.com/issues/167576324 Original change's description: > Add idea of DataType to SkYUVAPixmapInfo. > > DataType describes the data type of YUVA channels > independent of how they are grouped into planes. > > Adds mapping functions between SkColorType/channel count > and DataType. > > SkYUVAPixmapInfo can be constructed from DataType and will > choose appropriate SkColorTypes for each plane. > > Valid SkYUVAPixmapInfos now have the same DataType for each > plane (could relax this in the future, esp for alpha plane). > > SkYUVAPixmapInfo::SupportedDataTypes specifies the supported > combinations of SkYUVAInfo::PlanarConfig and > kYUVAPixmapInfo::DataType supported by a GrContext (based on > supported texture formats). > > SkImageGenerator/SkCodec YUVA query API now takes a > SupportedDataTypes. > > Change-Id: I8791234638e6ba3396d1e7960b7bc210edc6dd57 > Bug: skia:10632 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/314276 > Reviewed-by: Leon Scroggins <scroggo@google.com> > Reviewed-by: Robert Phillips <robertphillips@google.com> > Commit-Queue: Brian Salomon <bsalomon@google.com> TBR=bsalomon@google.com,robertphillips@google.com,scroggo@google.com Change-Id: I72c39539a4766f10cac3ca3cdef6c503a8319ff1 No-Presubmit: true No-Tree-Checks: true No-Try: true Bug: skia:10632 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/314895 Reviewed-by: Michael Ludwig <michaelludwig@google.com> Commit-Queue: Michael Ludwig <michaelludwig@google.com>
1 parent 370de72 commit c7fa895

19 files changed

+74
-252
lines changed

RELEASE_NOTES.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ Milestone 87
2121
Doesn't assume 8bit planar values.
2222
https://review.skia.org/309658
2323
https://review.skia.org/312886
24-
https://review.skia.org/314276
2524

2625
* Added VkImageUsageFlags to GrVkImageInfo struct.
2726

dm/DMSrcSink.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1814,8 +1814,7 @@ Result GPUDDLSink::ddlDraw(const Src& src,
18141814
// this is our ultimate final drawing area/rect
18151815
SkIRect viewport = SkIRect::MakeWH(size.fWidth, size.fHeight);
18161816

1817-
SkYUVAPixmapInfo::SupportedDataTypes supportedYUVADataTypes(*gpuThreadCtx);
1818-
DDLPromiseImageHelper promiseImageHelper(supportedYUVADataTypes);
1817+
DDLPromiseImageHelper promiseImageHelper;
18191818
sk_sp<SkData> compressedPictureData = promiseImageHelper.deflateSKP(inputPicture.get());
18201819
if (!compressedPictureData) {
18211820
return Result::Fatal("GPUDDLSink: Couldn't deflate SkPicture");
@@ -2271,7 +2270,7 @@ Result ViaDDL::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkStrin
22712270
// this is our ultimate final drawing area/rect
22722271
SkIRect viewport = SkIRect::MakeWH(size.fWidth, size.fHeight);
22732272

2274-
DDLPromiseImageHelper promiseImageHelper(SkYUVAPixmapInfo::SupportedDataTypes::All());
2273+
DDLPromiseImageHelper promiseImageHelper;
22752274
sk_sp<SkData> compressedPictureData = promiseImageHelper.deflateSKP(inputPicture.get());
22762275
if (!compressedPictureData) {
22772276
return Result::Fatal("ViaDDL: Couldn't deflate SkPicture");

include/codec/SkCodec.h

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -381,18 +381,11 @@ class SK_API SkCodec : SkNoncopyable {
381381
}
382382

383383
/**
384-
* If decoding to YUV is supported, this returns true. Otherwise, this
385-
* returns false and the caller will ignore output parameter yuvaPixmapInfo.
386-
*
387-
* @param supportedDataTypes Indicates the data type/planar config combinations that are
388-
* supported by the caller. If the generator supports decoding to
389-
* YUV(A), but not as a type in supportedDataTypes, this method
390-
* returns false.
391-
* @param yuvaPixmapInfo Output parameter that specifies the planar configuration, subsampling,
392-
* orientation, chroma siting, plane color types, and row bytes.
384+
* If decoding to YUVA is supported, this returns true and updates yuvaPixmapInfo to be a
385+
* specification of the planar layout, YUVA->RGBA transformation, per-plane color types and row
386+
* bytes. If YUVA decoding is not supported then returns false.
393387
*/
394-
bool queryYUVAInfo(const SkYUVAPixmapInfo::SupportedDataTypes& supportedDataTypes,
395-
SkYUVAPixmapInfo* yuvaPixmapInfo) const;
388+
bool queryYUVAInfo(SkYUVAPixmapInfo* yuvaPixmapInfo) const;
396389

397390
/**
398391
* Returns kSuccess, or another value explaining the type of failure.
@@ -739,8 +732,7 @@ class SK_API SkCodec : SkNoncopyable {
739732
void* pixels, size_t rowBytes, const Options&,
740733
int* rowsDecoded) = 0;
741734

742-
virtual bool onQueryYUVAInfo(const SkYUVAPixmapInfo::SupportedDataTypes&,
743-
SkYUVAPixmapInfo*) const { return false; }
735+
virtual bool onQueryYUVAInfo(SkYUVAPixmapInfo*) const { return false; }
744736

745737
virtual Result onGetYUVAPlanes(const SkYUVAPixmaps&) { return kUnimplemented; }
746738

include/core/SkImageGenerator.h

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -91,17 +91,12 @@ class SK_API SkImageGenerator {
9191

9292
/**
9393
* If decoding to YUV is supported, this returns true. Otherwise, this
94-
* returns false and the caller will ignore output parameter yuvaPixmapInfo.
95-
*
96-
* @param supportedDataTypes Indicates the data type/planar config combinations that are
97-
* supported by the caller. If the generator supports decoding to
98-
* YUV(A), but not as a type in supportedDataTypes, this method
99-
* returns false.
100-
* @param yuvaPixmapInfo Output parameter that specifies the planar configuration, subsampling,
101-
* orientation, chroma siting, plane color types, and row bytes.
94+
* returns false and does not modify yuvaPixmapInfo.
95+
*
96+
* @param yuvaPixmapInfo Specifies the planar configuration, subsampling, orientation,
97+
* chroma siting, plane color types, and row bytes.
10298
*/
103-
bool queryYUVAInfo(const SkYUVAPixmapInfo::SupportedDataTypes& supportedDataTypes,
104-
SkYUVAPixmapInfo* yuvaPixmapInfo) const;
99+
bool queryYUVAInfo(SkYUVAPixmapInfo* yuvaPixmapInfo) const;
105100

106101
/**
107102
* Returns true on success and false on failure.
@@ -209,8 +204,7 @@ class SK_API SkImageGenerator {
209204
struct Options {};
210205
virtual bool onGetPixels(const SkImageInfo&, void*, size_t, const Options&) { return false; }
211206
virtual bool onIsValid(GrRecordingContext*) const { return true; }
212-
virtual bool onQueryYUVAInfo(const SkYUVAPixmapInfo::SupportedDataTypes&,
213-
SkYUVAPixmapInfo*) const { return false; }
207+
virtual bool onQueryYUVAInfo(SkYUVAPixmapInfo*) const { return false; }
214208
virtual bool onGetYUVAPlanes(const SkYUVAPixmaps&) { return false; }
215209
virtual bool onQueryYUVA8(SkYUVASizeInfo*, SkYUVAIndex[SkYUVAIndex::kIndexCount],
216210
SkYUVColorSpace*) const { return false; }

include/core/SkYUVAPixmaps.h

Lines changed: 7 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@
1515
#include "include/private/SkTo.h"
1616

1717
#include <array>
18-
#include <bitset>
1918

20-
class GrImageContext;
2119
struct SkYUVASizeInfo;
2220
struct SkYUVAIndex;
2321

@@ -29,113 +27,44 @@ class SK_API SkYUVAPixmapInfo {
2927
public:
3028
static constexpr auto kMaxPlanes = SkYUVAInfo::kMaxPlanes;
3129

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-
9330
/** Default SkYUVAPixmapInfo is invalid. */
9431
SkYUVAPixmapInfo() = default;
9532

9633
/**
9734
* Initializes the SkYUVAPixmapInfo from a SkYUVAInfo with per-plane color types and row bytes.
9835
* This will be invalid if the colorTypes aren't compatible with the SkYUVAInfo or if a
9936
* rowBytes entry is not valid for the plane dimensions and color type. Color type and
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.
37+
* row byte values beyond the number of planes in SkYUVAInfo are ignored.
10238
*
10339
* If rowBytes is nullptr then bpp*width is assumed for each plane.
10440
*/
10541
SkYUVAPixmapInfo(const SkYUVAInfo&,
10642
const SkColorType[kMaxPlanes],
10743
const size_t rowBytes[kMaxPlanes]);
10844
/**
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.
45+
* Like above but uses the same color type for all planes.
11146
*/
112-
SkYUVAPixmapInfo(const SkYUVAInfo&, DataType, const size_t rowBytes[kMaxPlanes]);
47+
SkYUVAPixmapInfo(const SkYUVAInfo&, SkColorType, const size_t rowBytes[kMaxPlanes]);
11348

11449
SkYUVAPixmapInfo(const SkYUVAPixmapInfo&) = default;
11550

11651
SkYUVAPixmapInfo& operator=(const SkYUVAPixmapInfo&) = default;
11752

118-
bool operator==(const SkYUVAPixmapInfo&) const;
119-
bool operator!=(const SkYUVAPixmapInfo& that) const { return !(*this == that); }
120-
12153
const SkYUVAInfo& yuvaInfo() const { return fYUVAInfo; }
12254

12355
SkYUVColorSpace yuvColorSpace() const { return fYUVAInfo.yuvColorSpace(); }
12456

12557
/** The number of SkPixmap planes, 0 if this SkYUVAPixmapInfo is invalid. */
12658
int numPlanes() const { return this->isValid() ? fYUVAInfo.numPlanes() : 0; }
12759

128-
/** The per-YUV[A] channel data type. */
129-
DataType dataType() const { return fDataType; }
130-
13160
/**
13261
* Row bytes for the ith plane. Returns zero if i >= numPlanes() or this SkYUVAPixmapInfo is
13362
* invalid.
13463
*/
135-
size_t rowBytes(int i) const { return fRowBytes[static_cast<size_t>(i)]; }
64+
size_t rowBytes(int i) const { return fRowBytes[i]; }
13665

13766
/** Image info for the ith plane, or default SkImageInfo if i >= numPlanes() */
138-
const SkImageInfo& planeInfo(int i) const { return fPlaneInfos[static_cast<size_t>(i)]; }
67+
const SkImageInfo& planeInfo(int i) const { return fPlaneInfos[i]; }
13968

14069
/**
14170
* Determine size to allocate for all planes. Optionally retrieves the per-plane sizes in
@@ -157,14 +86,10 @@ class SK_API SkYUVAPixmapInfo {
15786
*/
15887
bool isValid() const { return fPlaneInfos[0].colorType() != kUnknown_SkColorType; }
15988

160-
/** Is this valid and does it use color types allowed by the passed SupportedDataTypes? */
161-
bool isSupported(const SupportedDataTypes&) const;
162-
16389
private:
16490
SkYUVAInfo fYUVAInfo;
165-
std::array<SkImageInfo, kMaxPlanes> fPlaneInfos = {};
166-
std::array<size_t, kMaxPlanes> fRowBytes = {};
167-
DataType fDataType = DataType::kUnorm8;
91+
SkImageInfo fPlaneInfos[kMaxPlanes] = {};
92+
size_t fRowBytes[kMaxPlanes] = {};
16893
static_assert(kUnknown_SkColorType == 0, "default init isn't kUnknown");
16994
};
17095

src/codec/SkCodec.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,13 +167,11 @@ SkCodec::SkCodec(SkEncodedInfo&& info, XformFormat srcFormat, std::unique_ptr<Sk
167167

168168
SkCodec::~SkCodec() {}
169169

170-
bool SkCodec::queryYUVAInfo(const SkYUVAPixmapInfo::SupportedDataTypes& supportedDataTypes,
171-
SkYUVAPixmapInfo* yuvaPixmapInfo) const {
170+
bool SkCodec::queryYUVAInfo(SkYUVAPixmapInfo* yuvaPixmapInfo) const {
172171
if (!yuvaPixmapInfo) {
173172
return false;
174173
}
175-
return this->onQueryYUVAInfo(supportedDataTypes, yuvaPixmapInfo) &&
176-
yuvaPixmapInfo->isSupported(supportedDataTypes);
174+
return this->onQueryYUVAInfo(yuvaPixmapInfo) && yuvaPixmapInfo->isValid();
177175
}
178176

179177
SkCodec::Result SkCodec::getYUVAPlanes(const SkYUVAPixmaps& yuvaPixmaps) {

src/codec/SkCodecImageGenerator.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,8 @@ bool SkCodecImageGenerator::onGetPixels(const SkImageInfo& requestInfo, void* re
6969
return this->getPixels(requestInfo, requestPixels, requestRowBytes, nullptr);
7070
}
7171

72-
bool SkCodecImageGenerator::onQueryYUVAInfo(
73-
const SkYUVAPixmapInfo::SupportedDataTypes& supportedDataTypes,
74-
SkYUVAPixmapInfo* yuvaPixmapInfo) const {
75-
return fCodec->queryYUVAInfo(supportedDataTypes, yuvaPixmapInfo);
72+
bool SkCodecImageGenerator::onQueryYUVAInfo(SkYUVAPixmapInfo* yuvaPixmapInfo) const {
73+
return fCodec->queryYUVAInfo(yuvaPixmapInfo);
7674
}
7775

7876
bool SkCodecImageGenerator::onGetYUVAPlanes(const SkYUVAPixmaps& yuvaPixmaps) {

src/codec/SkCodecImageGenerator.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,7 @@ class SkCodecImageGenerator : public SkImageGenerator {
9898
size_t rowBytes,
9999
const Options& opts) override;
100100

101-
bool onQueryYUVAInfo(const SkYUVAPixmapInfo::SupportedDataTypes&,
102-
SkYUVAPixmapInfo*) const override;
101+
bool onQueryYUVAInfo(SkYUVAPixmapInfo* yuvaPixmapInfo) const override;
103102

104103
bool onGetYUVAPlanes(const SkYUVAPixmaps& yuvaPixmaps) override;
105104

src/codec/SkJpegCodec.cpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,6 @@ bool SkJpegCodec::onSkipScanlines(int count) {
745745

746746
static bool is_yuv_supported(const jpeg_decompress_struct* dinfo,
747747
const SkJpegCodec& codec,
748-
const SkYUVAPixmapInfo::SupportedDataTypes* supportedDataTypes,
749748
SkYUVAPixmapInfo* yuvaPixmapInfo) {
750749
// Scaling is not supported in raw data mode.
751750
SkASSERT(dinfo->scale_num == dinfo->scale_denom);
@@ -812,10 +811,6 @@ static bool is_yuv_supported(const jpeg_decompress_struct* dinfo,
812811
} else {
813812
return false;
814813
}
815-
if (supportedDataTypes &&
816-
!supportedDataTypes->supported(tempPlanarConfig, SkYUVAPixmapInfo::DataType::kUnorm8)) {
817-
return false;
818-
}
819814
if (yuvaPixmapInfo) {
820815
SkColorType colorTypes[SkYUVAPixmapInfo::kMaxPlanes];
821816
size_t rowBytes[SkYUVAPixmapInfo::kMaxPlanes];
@@ -834,16 +829,15 @@ static bool is_yuv_supported(const jpeg_decompress_struct* dinfo,
834829
return true;
835830
}
836831

837-
bool SkJpegCodec::onQueryYUVAInfo(const SkYUVAPixmapInfo::SupportedDataTypes& supportedDataTypes,
838-
SkYUVAPixmapInfo* yuvaPixmapInfo) const {
832+
bool SkJpegCodec::onQueryYUVAInfo(SkYUVAPixmapInfo* yuvaPixmapInfo) const {
839833
jpeg_decompress_struct* dinfo = fDecoderMgr->dinfo();
840-
return is_yuv_supported(dinfo, *this, &supportedDataTypes, yuvaPixmapInfo);
834+
return is_yuv_supported(dinfo, *this, yuvaPixmapInfo);
841835
}
842836

843837
SkCodec::Result SkJpegCodec::onGetYUVAPlanes(const SkYUVAPixmaps& yuvaPixmaps) {
844838
// Get a pointer to the decompress info since we will use it quite frequently
845839
jpeg_decompress_struct* dinfo = fDecoderMgr->dinfo();
846-
if (!is_yuv_supported(dinfo, *this, nullptr, nullptr)) {
840+
if (!is_yuv_supported(dinfo, *this, nullptr)) {
847841
return fDecoderMgr->returnFailure("onGetYUVAPlanes", kInvalidInput);
848842
}
849843
// Set the jump location for libjpeg errors
@@ -866,7 +860,7 @@ SkCodec::Result SkJpegCodec::onGetYUVAPlanes(const SkYUVAPixmaps& yuvaPixmaps) {
866860
// was caused by a bug in the old code, but we'll be safe and check here.
867861
// Also check that pixmap properties agree with expectations.
868862
SkYUVAPixmapInfo info;
869-
SkASSERT(is_yuv_supported(dinfo, *this, nullptr, &info));
863+
SkASSERT(is_yuv_supported(dinfo, *this, &info));
870864
SkASSERT(info.yuvaInfo() == yuvaPixmaps.yuvaInfo());
871865
for (int i = 0; i < info.numPlanes(); ++i) {
872866
SkASSERT(planes[i].colorType() == kAlpha_8_SkColorType);

src/codec/SkJpegCodec.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ class SkJpegCodec : public SkCodec {
4444
Result onGetPixels(const SkImageInfo& dstInfo, void* dst, size_t dstRowBytes, const Options&,
4545
int*) override;
4646

47-
bool onQueryYUVAInfo(const SkYUVAPixmapInfo::SupportedDataTypes&,
48-
SkYUVAPixmapInfo*) const override;
47+
bool onQueryYUVAInfo(SkYUVAPixmapInfo*) const override;
4948

5049
Result onGetYUVAPlanes(const SkYUVAPixmaps& yuvaPixmaps) override;
5150

0 commit comments

Comments
 (0)