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

Commit bd3d8d3

Browse files
bsalomonSkia Commit-Bot
authored andcommitted
Remove GrPixelConfig from GrColorSpaceInfo.
Replace GrColorInfo with GrColorSpaceInfo. Change-Id: I7abe28203dd7f22162d68c4eee41293f483bb1aa Reviewed-on: https://skia-review.googlesource.com/c/skia/+/225036 Commit-Queue: Brian Salomon <[email protected]> Reviewed-by: Robert Phillips <[email protected]>
1 parent effee20 commit bd3d8d3

22 files changed

+236
-155
lines changed

include/private/GrTypesPriv.h

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,6 +1253,149 @@ static constexpr uint32_t GrColorTypeComponentFlags(GrColorType ct) {
12531253
SkUNREACHABLE;
12541254
}
12551255

1256+
/**
1257+
* Describes the encoding of channel data in a GrColorType.
1258+
*/
1259+
enum class GrColorTypeEncoding {
1260+
kUnorm,
1261+
// kSRGBUnorm,
1262+
// kSnorm,
1263+
kFloat,
1264+
// kSint
1265+
// kUint
1266+
};
1267+
1268+
/**
1269+
* Describes a GrColorType by how many bits are used for each color component and how they are
1270+
* encoded. Currently all the non-zero channels share a single GrColorTypeEncoding. This could be
1271+
* expanded to store separate encodings and to indicate which bits belong to which components.
1272+
*/
1273+
struct GrColorTypeDesc {
1274+
public:
1275+
static constexpr GrColorTypeDesc MakeRGBA(int rgba, GrColorTypeEncoding e) {
1276+
return {rgba, rgba, rgba, rgba, 0, e};
1277+
}
1278+
1279+
static constexpr GrColorTypeDesc MakeRGBA(int rgb, int a, GrColorTypeEncoding e) {
1280+
return {rgb, rgb, rgb, a, 0, e};
1281+
}
1282+
1283+
static constexpr GrColorTypeDesc MakeRGB(int rgb, GrColorTypeEncoding e) {
1284+
return {rgb, rgb, rgb, 0, 0, e};
1285+
}
1286+
1287+
static constexpr GrColorTypeDesc MakeRGB(int r, int g, int b, GrColorTypeEncoding e) {
1288+
return {r, g, b, 0, 0, e};
1289+
}
1290+
1291+
static constexpr GrColorTypeDesc MakeAlpha(int a, GrColorTypeEncoding e) {
1292+
return {0, 0, 0, a, 0, e};
1293+
}
1294+
1295+
static constexpr GrColorTypeDesc MakeR(int r, GrColorTypeEncoding e) {
1296+
return {r, 0, 0, 0, 0, e};
1297+
}
1298+
1299+
static constexpr GrColorTypeDesc MakeRG(int rg, GrColorTypeEncoding e) {
1300+
return {rg, rg, 0, 0, 0, e};
1301+
}
1302+
1303+
static constexpr GrColorTypeDesc MakeGray(int grayBits, GrColorTypeEncoding e) {
1304+
return {0, 0, 0, 0, grayBits, e};
1305+
}
1306+
1307+
static constexpr GrColorTypeDesc MakeInvalid() { return {}; }
1308+
1309+
constexpr int r() const { return fRBits; }
1310+
constexpr int g() const { return fGBits; }
1311+
constexpr int b() const { return fBBits; }
1312+
constexpr int a() const { return fABits; }
1313+
1314+
constexpr int gray() const { return fGrayBits; }
1315+
1316+
constexpr GrColorTypeEncoding encoding() const { return fEncoding; }
1317+
1318+
private:
1319+
int fRBits = 0;
1320+
int fGBits = 0;
1321+
int fBBits = 0;
1322+
int fABits = 0;
1323+
int fGrayBits = 0;
1324+
GrColorTypeEncoding fEncoding = GrColorTypeEncoding::kUnorm;
1325+
1326+
constexpr GrColorTypeDesc() = default;
1327+
1328+
constexpr GrColorTypeDesc(int r, int g, int b, int a, int gray, GrColorTypeEncoding encoding)
1329+
: fRBits(r), fGBits(g), fBBits(b), fABits(a), fGrayBits(gray), fEncoding(encoding) {
1330+
SkASSERT(r >= 0 && g >= 0 && b >= 0 && a >= 0 && gray >= 0);
1331+
SkASSERT(!gray || (!r && !g && !b));
1332+
SkASSERT(r || g || b || a || gray);
1333+
}
1334+
};
1335+
1336+
static constexpr GrColorTypeDesc GrGetColorTypeDesc(GrColorType ct) {
1337+
switch (ct) {
1338+
case GrColorType::kUnknown:
1339+
return GrColorTypeDesc::MakeInvalid();
1340+
case GrColorType::kAlpha_8:
1341+
return GrColorTypeDesc::MakeAlpha(8, GrColorTypeEncoding::kUnorm);
1342+
case GrColorType::kBGR_565:
1343+
return GrColorTypeDesc::MakeRGB(5, 6, 5, GrColorTypeEncoding::kUnorm);
1344+
case GrColorType::kABGR_4444:
1345+
return GrColorTypeDesc::MakeRGBA(4, GrColorTypeEncoding::kUnorm);
1346+
case GrColorType::kRGBA_8888:
1347+
return GrColorTypeDesc::MakeRGBA(8, GrColorTypeEncoding::kUnorm);
1348+
case GrColorType::kRGB_888x:
1349+
return GrColorTypeDesc::MakeRGB(8, GrColorTypeEncoding::kUnorm);
1350+
case GrColorType::kRG_88:
1351+
return GrColorTypeDesc::MakeRG(8, GrColorTypeEncoding::kUnorm);
1352+
case GrColorType::kBGRA_8888:
1353+
return GrColorTypeDesc::MakeRGBA(8, GrColorTypeEncoding::kUnorm);
1354+
case GrColorType::kRGBA_1010102:
1355+
return GrColorTypeDesc::MakeRGBA(10, 2, GrColorTypeEncoding::kUnorm);
1356+
case GrColorType::kGray_8:
1357+
return GrColorTypeDesc::MakeGray(8, GrColorTypeEncoding::kUnorm);
1358+
case GrColorType::kAlpha_F16:
1359+
return GrColorTypeDesc::MakeAlpha(16, GrColorTypeEncoding::kFloat);
1360+
case GrColorType::kRGBA_F16:
1361+
return GrColorTypeDesc::MakeRGBA(16, GrColorTypeEncoding::kFloat);
1362+
case GrColorType::kRGBA_F16_Clamped:
1363+
return GrColorTypeDesc::MakeRGBA(16, GrColorTypeEncoding::kFloat);
1364+
case GrColorType::kRG_F32:
1365+
return GrColorTypeDesc::MakeRG(32, GrColorTypeEncoding::kFloat);
1366+
case GrColorType::kRGBA_F32:
1367+
return GrColorTypeDesc::MakeRGBA(32, GrColorTypeEncoding::kFloat);
1368+
case GrColorType::kR_16:
1369+
return GrColorTypeDesc::MakeR(16, GrColorTypeEncoding::kUnorm);
1370+
case GrColorType::kRG_1616:
1371+
return GrColorTypeDesc::MakeRG(16, GrColorTypeEncoding::kUnorm);
1372+
case GrColorType::kRGBA_16161616:
1373+
return GrColorTypeDesc::MakeRGBA(16, GrColorTypeEncoding::kUnorm);
1374+
case GrColorType::kRG_F16:
1375+
return GrColorTypeDesc::MakeRG(16, GrColorTypeEncoding::kFloat);
1376+
}
1377+
SkUNREACHABLE;
1378+
}
1379+
1380+
static constexpr GrClampType GrColorTypeClampType(GrColorType colorType) {
1381+
if (GrGetColorTypeDesc(colorType).encoding() == GrColorTypeEncoding::kUnorm) {
1382+
return GrClampType::kAuto;
1383+
}
1384+
return GrColorType::kRGBA_F16_Clamped == colorType ? GrClampType::kManual : GrClampType::kNone;
1385+
}
1386+
1387+
// Consider a color type "wider" than n if it has more than n bits for any its representable
1388+
// channels.
1389+
static constexpr bool GrColorTypeIsWiderThan(GrColorType colorType, int n) {
1390+
SkASSERT(n > 0);
1391+
auto desc = GrGetColorTypeDesc(colorType);
1392+
return (desc.r() && desc.r() > n )||
1393+
(desc.g() && desc.g() > n) ||
1394+
(desc.b() && desc.b() > n) ||
1395+
(desc.a() && desc.a() > n) ||
1396+
(desc.gray() && desc.gray() > n);
1397+
}
1398+
12561399
static constexpr bool GrColorTypeIsAlphaOnly(GrColorType ct) {
12571400
return kAlpha_SkColorTypeComponentFlag == GrColorTypeComponentFlags(ct);
12581401
}

src/atlastext/SkAtlasTextTarget.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ void SkAtlasTextTarget::concat(const SkMatrix& matrix) { this->accessCTM()->preC
7373

7474
//////////////////////////////////////////////////////////////////////////////
7575

76-
static const GrColorSpaceInfo kColorSpaceInfo(GrColorType::kRGBA_8888, kPremul_SkAlphaType, nullptr,
77-
kRGBA_8888_GrPixelConfig);
76+
static const GrColorSpaceInfo kColorSpaceInfo(GrColorType::kRGBA_8888, kPremul_SkAlphaType,
77+
nullptr);
7878
static const SkSurfaceProps kProps(
7979
SkSurfaceProps::kUseDistanceFieldFonts_Flag, kUnknown_SkPixelGeometry);
8080

src/effects/SkTableColorFilter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ std::unique_ptr<GrFragmentProcessor> ColorTableEffect::TestCreate(GrProcessorTes
400400
sk_sp<SkColorSpace> colorSpace = GrTest::TestColorSpace(d->fRandom);
401401
auto fp = filter->asFragmentProcessor(
402402
d->context(), GrColorSpaceInfo(GrColorType::kRGBA_8888, kUnknown_SkAlphaType,
403-
std::move(colorSpace), kRGBA_8888_GrPixelConfig));
403+
std::move(colorSpace)));
404404
SkASSERT(fp);
405405
return fp;
406406
}

src/gpu/GrBitmapTextureMaker.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
static GrColorSpaceInfo make_info(const SkBitmap& bm) {
2121
return GrColorSpaceInfo(SkColorTypeToGrColorType(bm.colorType()), bm.alphaType(),
22-
bm.refColorSpace(), SkImageInfo2GrPixelConfig(bm.info()));
22+
bm.refColorSpace());
2323
}
2424

2525
GrBitmapTextureMaker::GrBitmapTextureMaker(GrRecordingContext* context, const SkBitmap& bitmap,

src/gpu/GrColorSpaceInfo.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,8 @@
1010

1111
GrColorSpaceInfo::GrColorSpaceInfo(GrColorType colorType,
1212
SkAlphaType alphaType,
13-
sk_sp<SkColorSpace> colorSpace,
14-
GrPixelConfig config)
15-
: fColorSpace(std::move(colorSpace))
16-
, fColorType(colorType)
17-
, fAlphaType(alphaType)
18-
, fConfig(config)
19-
, fInitializedColorSpaceXformFromSRGB(false) {}
13+
sk_sp<SkColorSpace> colorSpace)
14+
: fColorSpace(std::move(colorSpace)), fColorType(colorType), fAlphaType(alphaType) {}
2015

2116
GrColorSpaceXform* GrColorSpaceInfo::colorSpaceXformFromSRGB() const {
2217
// TODO: Make this atomic if we start accessing this on multiple threads.

src/gpu/GrColorSpaceInfo.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
/** Describes the color space properties of a surface context. */
1717
class GrColorSpaceInfo {
1818
public:
19-
GrColorSpaceInfo(GrColorType, SkAlphaType, sk_sp<SkColorSpace>, GrPixelConfig);
19+
GrColorSpaceInfo() = default;
20+
GrColorSpaceInfo(GrColorType, SkAlphaType, sk_sp<SkColorSpace>);
2021

2122
bool isLinearlyBlended() const { return fColorSpace && fColorSpace->gammaIsLinear(); }
2223

@@ -31,16 +32,16 @@ class GrColorSpaceInfo {
3132
GrColorType colorType() const { return fColorType; }
3233
SkAlphaType alphaType() const { return fAlphaType; }
3334

34-
// TODO: Remove.
35-
GrPixelConfig config() const { return fConfig; }
35+
bool isValid() const {
36+
return fColorType != GrColorType::kUnknown && fAlphaType != kUnknown_SkAlphaType;
37+
}
3638

3739
private:
3840
sk_sp<SkColorSpace> fColorSpace;
3941
mutable sk_sp<GrColorSpaceXform> fColorXformFromSRGB;
40-
GrColorType fColorType;
41-
SkAlphaType fAlphaType;
42-
GrPixelConfig fConfig;
43-
mutable bool fInitializedColorSpaceXformFromSRGB;
42+
GrColorType fColorType = GrColorType::kUnknown;
43+
SkAlphaType fAlphaType = kUnknown_SkAlphaType;
44+
mutable bool fInitializedColorSpaceXformFromSRGB = false;
4445
};
4546

4647
#endif

src/gpu/GrDataUtils.h

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include "include/core/SkColor.h"
1212
#include "include/private/GrTypesPriv.h"
13+
#include "src/gpu/GrColorSpaceInfo.h"
1314
#include "src/gpu/GrSwizzle.h"
1415

1516
size_t GrCompressedDataSize(SkImage::CompressionType, int w, int h);
@@ -25,38 +26,6 @@ void GrFillInData(GrPixelConfig, int baseWidth, int baseHeight,
2526

2627
void GrFillInCompressedData(SkImage::CompressionType, int width, int height, char* dest,
2728
const SkColor4f& color);
28-
29-
// TODO: Replace with GrColorSpaceInfo once GrPixelConfig is excised from that type.
30-
class GrColorInfo {
31-
public:
32-
GrColorInfo() = default;
33-
34-
GrColorInfo(GrColorType ct, SkAlphaType at, sk_sp<SkColorSpace> cs)
35-
: fColorSpace(std::move(cs)), fColorType(ct), fAlphaType(at) {}
36-
37-
GrColorInfo(const GrColorInfo&) = default;
38-
GrColorInfo(GrColorInfo&&) = default;
39-
GrColorInfo& operator=(const GrColorInfo&) = default;
40-
GrColorInfo& operator=(GrColorInfo&&) = default;
41-
42-
GrColorType colorType() const { return fColorType; }
43-
44-
SkAlphaType alphaType() const { return fAlphaType; }
45-
46-
SkColorSpace* colorSpace() const { return fColorSpace.get(); }
47-
48-
sk_sp<SkColorSpace> refColorSpace() const { return fColorSpace; }
49-
50-
bool isValid() const {
51-
return fColorType != GrColorType::kUnknown && fAlphaType != kUnknown_SkAlphaType;
52-
}
53-
54-
private:
55-
sk_sp<SkColorSpace> fColorSpace;
56-
GrColorType fColorType = GrColorType::kUnknown;
57-
SkAlphaType fAlphaType = kUnknown_SkAlphaType;
58-
};
59-
6029
class GrPixelInfo {
6130
public:
6231
GrPixelInfo() = default;
@@ -126,7 +95,7 @@ class GrPixelInfo {
12695
bool isValid() const { return fColorInfo.isValid() && fWidth > 0 && fHeight > 0; }
12796

12897
private:
129-
GrColorInfo fColorInfo = {};
98+
GrColorSpaceInfo fColorInfo = {};
13099
int fWidth = 0;
131100
int fHeight = 0;
132101
};

src/gpu/GrImageTextureMaker.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616
static GrColorSpaceInfo make_info(const SkImage*& image) {
1717
return GrColorSpaceInfo(SkColorTypeToGrColorType(image->colorType()),
1818
image->alphaType(),
19-
image->refColorSpace(),
20-
SkImageInfo2GrPixelConfig(image->imageInfo()));
19+
image->refColorSpace());
2120
}
2221

2322
GrImageTextureMaker::GrImageTextureMaker(GrRecordingContext* context, const SkImage* client,

src/gpu/GrRenderTargetContext.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,7 @@ GrRenderTargetContext::GrRenderTargetContext(GrRecordingContext* context,
147147
sk_sp<SkColorSpace> colorSpace,
148148
const SkSurfaceProps* surfaceProps,
149149
bool managedOpList)
150-
: GrSurfaceContext(context, colorType, kPremul_SkAlphaType, std::move(colorSpace),
151-
rtp->config())
150+
: GrSurfaceContext(context, colorType, kPremul_SkAlphaType, std::move(colorSpace))
152151
, fRenderTargetProxy(std::move(rtp))
153152
, fOpList(sk_ref_sp(fRenderTargetProxy->getLastRenderTargetOpList()))
154153
, fSurfaceProps(SkSurfacePropsCopyOrDefault(surfaceProps))
@@ -833,7 +832,7 @@ void GrRenderTargetContext::setNeedsStencil(bool multisampled) {
833832
// mixed samples.
834833
SkASSERT(fRenderTargetProxy->canUseMixedSamples(*this->caps()));
835834
numRequiredSamples = this->caps()->internalMultisampleCount(
836-
this->colorSpaceInfo().config());
835+
this->asSurfaceProxy()->config());
837836
}
838837
SkASSERT(numRequiredSamples > 0);
839838

@@ -2615,7 +2614,7 @@ void GrRenderTargetContext::addDrawOp(const GrClip& clip, std::unique_ptr<GrDraw
26152614

26162615
SkASSERT((!usesStencil && !appliedClip.hasStencilClip()) || (fNumStencilSamples > 0));
26172616

2618-
GrClampType clampType = GrPixelConfigClampType(this->colorSpaceInfo().config());
2617+
GrClampType clampType = GrColorTypeClampType(this->colorSpaceInfo().colorType());
26192618
// MIXED SAMPLES TODO: If we start using mixed samples for clips we will need to check the clip
26202619
// here as well.
26212620
bool hasMixedSampledCoverage = (usesHWAA && this->numSamples() <= 1);

src/gpu/GrSurfaceContext.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,8 @@
3434
GrSurfaceContext::GrSurfaceContext(GrRecordingContext* context,
3535
GrColorType colorType,
3636
SkAlphaType alphaType,
37-
sk_sp<SkColorSpace> colorSpace,
38-
GrPixelConfig config)
39-
: fContext(context), fColorSpaceInfo(colorType, alphaType, std::move(colorSpace), config) {}
37+
sk_sp<SkColorSpace> colorSpace)
38+
: fContext(context), fColorSpaceInfo(colorType, alphaType, std::move(colorSpace)) {}
4039

4140
GrAuditTrail* GrSurfaceContext::auditTrail() {
4241
return fContext->priv().auditTrail();

0 commit comments

Comments
 (0)