Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(313)

Unified Diff: include/gpu/GrInvariantOutput.h

Issue 978713002: Add constant color GrFP. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: include/gpu/GrInvariantOutput.h
diff --git a/include/gpu/GrInvariantOutput.h b/include/gpu/GrInvariantOutput.h
index 4977333de4e80779432c0eb20289ad5065f47ae3..be2fe533b689a70e8f8984ac04e5170454d77986 100644
--- a/include/gpu/GrInvariantOutput.h
+++ b/include/gpu/GrInvariantOutput.h
@@ -116,10 +116,76 @@ public:
SkMulDiv255Round(GrColorUnpackG(fColor), alpha),
SkMulDiv255Round(GrColorUnpackB(fColor), alpha),
SkMulDiv255Round(GrColorUnpackA(fColor), alpha));
+ // We don't need to change fIsSingleComponent in this case
}
}
}
+ void mulByKnownFourComponents(GrColor color) {
+ GrColor a = GrColorUnpackA(color);
+ if (a == GrColorUnpackR(color) &&
+ a == GrColorUnpackG(color) &&
+ a == GrColorUnpackB(color)) {
+ this->mulByKnownSingleComponent(a);
+ } else {
+ if (color != 0xffffffff) {
+ fColor = GrColorPackRGBA(
+ SkMulDiv255Round(GrColorUnpackR(fColor), GrColorUnpackR(color)),
+ SkMulDiv255Round(GrColorUnpackG(fColor), GrColorUnpackG(color)),
+ SkMulDiv255Round(GrColorUnpackB(fColor), GrColorUnpackB(color)),
+ SkMulDiv255Round(GrColorUnpackA(fColor), GrColorUnpackA(color)));
+ if (kRGBA_GrColorComponentFlags == fValidFlags) {
+ GrColor a = GrColorUnpackA(fColor);
+ fIsSingleComponent = a == GrColorUnpackR(fColor) &&
+ a == GrColorUnpackG(fColor) &&
+ a == GrColorUnpackB(fColor);
+ }
+ }
+ }
+ }
+
+ // Ignores the incoming color's RGB and muls its alpha by color.
+ void mulAlphaByKnownFourComponents(GrColor color) {
+ GrColor a = GrColorUnpackA(color);
+ if (a == GrColorUnpackR(color) &&
+ a == GrColorUnpackG(color) &&
+ a == GrColorUnpackB(color)) {
+ this->mulAlphaByKnownSingleComponent(a);
+ } else if (fValidFlags & kA_GrColorComponentFlag) {
+ GrColor alpha = GrColorUnpackA(fColor);
+ if (0 == alpha) {
+ this->internalSetToTransparentBlack();
+ } else {
+ fColor = GrColorPackRGBA(
+ SkMulDiv255Round(alpha, GrColorUnpackR(color)),
+ SkMulDiv255Round(alpha, GrColorUnpackG(color)),
+ SkMulDiv255Round(alpha, GrColorUnpackB(color)),
+ SkMulDiv255Round(alpha, GrColorUnpackA(color)));
+ fValidFlags = kRGBA_GrColorComponentFlags;
+ }
+ } else {
+ fValidFlags = 0;
+ }
+ }
+
+ // Ignores the incoming color's RGB and muls its alpha by the alpha param and sets all channels
+ // equal to that value.
+ void mulAlphaByKnownSingleComponent(uint8_t alpha) {
+ if (0 == alpha || 0 == this->hasZeroAlpha()) {
+ this->internalSetToTransparentBlack();
+ } else {
+ if (fValidFlags & kA_GrColorComponentFlag) {
+ GrColor a = GrColorUnpackA(fColor);
+ a = SkMulDiv255Round(alpha, a);
+ fColor = GrColorPackRGBA(a, a, a, a);
+ fValidFlags = kRGBA_GrColorComponentFlags;
+ } else {
+ fValidFlags = 0;
+ }
+ fIsSingleComponent = true;
+ }
+ }
+
void invalidateComponents(uint8_t invalidateFlags, ReadInput readsInput) {
fValidFlags &= ~invalidateFlags;
fIsSingleComponent = false;
@@ -137,6 +203,25 @@ public:
if (kWillNot_ReadInput == readsInput) {
fWillUseInputColor = false;
}
+ if (kRGBA_GrColorComponentFlags == fValidFlags) {
+ GrColor a = GrColorUnpackA(fColor);
egdaniel 2015/03/31 21:02:54 Maybe we should create some shared helper that can
bsalomon 2015/04/01 19:54:27 Done.
+ if (GrColorUnpackR(fColor) == a &&
+ GrColorUnpackG(fColor) == a &&
+ GrColorUnpackB(fColor) == a) {
+ fIsSingleComponent = true;
+ }
+ } else if (kA_GrColorComponentFlag & fValidFlags) {
+ // Assuming fColor is premul means if a is 0 the color
+ // must be all 0s.
+ if (!GrColorUnpackA(fColor)) {
+ SkASSERT(!(kR_GrColorComponentFlag & fValidFlags) || !GrColorUnpackR(fColor));
egdaniel 2015/03/31 21:02:54 are there asserts really needed? seems like we are
bsalomon 2015/04/01 19:54:26 I think if we're going to assume that we're always
+ SkASSERT(!(kG_GrColorComponentFlag & fValidFlags) || !GrColorUnpackG(fColor));
+ SkASSERT(!(kB_GrColorComponentFlag & fValidFlags) || !GrColorUnpackB(fColor));
+ fColor = 0;
egdaniel 2015/03/31 21:02:54 just call internalSetToTransparentBlacK()?
+ fIsSingleComponent = true;
+ fValidFlags = kRGBA_GrColorComponentFlags;
+ }
+ }
}
void setToUnknown(ReadInput readsInput) {

Powered by Google App Engine
This is Rietveld 408576698