aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-08-07 13:34:14 +0000
committerGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-08-07 13:34:14 +0000
commit75796db3b3f685520eaec2dc0478bdbd4987bae6 (patch)
treefad2ece4a7892fe88b9a68b35426d42fdb9b99a4 /src
parentb334366ad0dfd49403a773e122c740ead3a07e46 (diff)
Revert "Add blend optimization helpers and use to convert rect draws to clears."
This reverts commit r10537. git-svn-id: http://skia.googlecode.com/svn/trunk@10601 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src')
-rw-r--r--src/gpu/GrBlend.cpp154
-rw-r--r--src/gpu/GrBlend.h45
-rw-r--r--src/gpu/GrContext.cpp90
-rw-r--r--src/gpu/GrDrawState.h25
-rw-r--r--src/gpu/GrPaint.cpp57
5 files changed, 58 insertions, 313 deletions
diff --git a/src/gpu/GrBlend.cpp b/src/gpu/GrBlend.cpp
deleted file mode 100644
index c0621a9b3f..0000000000
--- a/src/gpu/GrBlend.cpp
+++ /dev/null
@@ -1,154 +0,0 @@
-
-/*
- * Copyright 2013 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "GrBlend.h"
-
-static inline GrBlendCoeff swap_coeff_src_dst(GrBlendCoeff coeff) {
- switch (coeff) {
- case kDC_GrBlendCoeff:
- return kSC_GrBlendCoeff;
- case kIDC_GrBlendCoeff:
- return kISC_GrBlendCoeff;
- case kDA_GrBlendCoeff:
- return kSA_GrBlendCoeff;
- case kIDA_GrBlendCoeff:
- return kISA_GrBlendCoeff;
- case kSC_GrBlendCoeff:
- return kDC_GrBlendCoeff;
- case kISC_GrBlendCoeff:
- return kIDC_GrBlendCoeff;
- case kSA_GrBlendCoeff:
- return kDA_GrBlendCoeff;
- case kISA_GrBlendCoeff:
- return kIDA_GrBlendCoeff;
- default:
- return coeff;
- }
-}
-
-static inline unsigned saturated_add(unsigned a, unsigned b) {
- SkASSERT(a <= 255);
- SkASSERT(b <= 255);
- unsigned sum = a + b;
- if (sum > 255) {
- sum = 255;
- }
- return sum;
-}
-
-static GrColor add_colors(GrColor src, GrColor dst) {
- unsigned r = saturated_add(GrColorUnpackR(src), GrColorUnpackR(dst));
- unsigned g = saturated_add(GrColorUnpackG(src), GrColorUnpackG(dst));
- unsigned b = saturated_add(GrColorUnpackB(src), GrColorUnpackB(dst));
- unsigned a = saturated_add(GrColorUnpackA(src), GrColorUnpackA(dst));
- return GrColorPackRGBA(r, g, b, a);
-}
-
-static inline bool valid_color(uint32_t compFlags) {
- return (kRGBA_GrColorComponentFlags & compFlags) == kRGBA_GrColorComponentFlags;
-}
-
-static GrColor simplify_blend_term(GrBlendCoeff* srcCoeff,
- GrColor srcColor, uint32_t srcCompFlags,
- GrColor dstColor, uint32_t dstCompFlags,
- GrColor constantColor) {
-
- GrAssert(!GrBlendCoeffRefsSrc(*srcCoeff));
- GrAssert(NULL != srcCoeff);
-
- // Check whether srcCoeff can be reduced to kOne or kZero based on known color inputs.
- // We could pick out the coeff r,g,b,a values here and use them to compute the blend term color,
- // if possible, below but that is not implemented now.
- switch (*srcCoeff) {
- case kIDC_GrBlendCoeff:
- dstColor = ~dstColor; // fallthrough
- case kDC_GrBlendCoeff:
- if (valid_color(dstCompFlags)) {
- if (0xffffffff == dstColor) {
- *srcCoeff = kOne_GrBlendCoeff;
- } else if (0 == dstColor) {
- *srcCoeff = kZero_GrBlendCoeff;
- }
- }
- break;
-
- case kIDA_GrBlendCoeff:
- dstColor = ~dstColor; // fallthrough
- case kDA_GrBlendCoeff:
- if (kA_GrColorComponentFlag & dstCompFlags) {
- if (0xff == GrColorUnpackA(dstColor)) {
- *srcCoeff = kOne_GrBlendCoeff;
- } else if (0 == GrColorUnpackA(dstColor)) {
- *srcCoeff = kZero_GrBlendCoeff;
- }
- }
- break;
-
- case kIConstC_GrBlendCoeff:
- constantColor = ~constantColor; // fallthrough
- case kConstC_GrBlendCoeff:
- if (0xffffffff == constantColor) {
- *srcCoeff = kOne_GrBlendCoeff;
- } else if (0 == constantColor) {
- *srcCoeff = kZero_GrBlendCoeff;
- }
- break;
-
- case kIConstA_GrBlendCoeff:
- constantColor = ~constantColor; // fallthrough
- case kConstA_GrBlendCoeff:
- if (0xff == GrColorUnpackA(constantColor)) {
- *srcCoeff = kOne_GrBlendCoeff;
- } else if (0 == GrColorUnpackA(constantColor)) {
- *srcCoeff = kZero_GrBlendCoeff;
- }
- break;
-
- default:
- break;
- }
- // We may have invalidated these above and shouldn't read them again.
- GR_DEBUGCODE(dstColor = constantColor = GrColor_ILLEGAL;)
-
- if (kZero_GrBlendCoeff == *srcCoeff || (valid_color(srcCompFlags) && 0 == srcColor)) {
- *srcCoeff = kZero_GrBlendCoeff;
- return 0;
- }
-
- if (kOne_GrBlendCoeff == *srcCoeff && valid_color(srcCompFlags)) {
- return srcColor;
- } else {
- return GrColor_ILLEGAL;
- }
-}
-
-GrColor GrSimplifyBlend(GrBlendCoeff* srcCoeff,
- GrBlendCoeff* dstCoeff,
- GrColor srcColor, uint32_t srcCompFlags,
- GrColor dstColor, uint32_t dstCompFlags,
- GrColor constantColor) {
- GrColor srcTermColor = simplify_blend_term(srcCoeff,
- srcColor, srcCompFlags,
- dstColor, dstCompFlags,
- constantColor);
-
- // We call the same function to simplify the dst blend coeff. We trick it out by swapping the
- // src and dst.
- GrBlendCoeff spoofedCoeff = swap_coeff_src_dst(*dstCoeff);
- GrColor dstTermColor = simplify_blend_term(&spoofedCoeff,
- dstColor, dstCompFlags,
- srcColor, srcCompFlags,
- constantColor);
- *dstCoeff = swap_coeff_src_dst(spoofedCoeff);
-
- if (GrColor_ILLEGAL != srcTermColor && GrColor_ILLEGAL != dstTermColor) {
- return add_colors(srcTermColor, dstTermColor);
- } else {
- return GrColor_ILLEGAL;
- }
-}
diff --git a/src/gpu/GrBlend.h b/src/gpu/GrBlend.h
deleted file mode 100644
index e70d945777..0000000000
--- a/src/gpu/GrBlend.h
+++ /dev/null
@@ -1,45 +0,0 @@
-
-/*
- * Copyright 2013 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "GrTypes.h"
-#include "GrColor.h"
-
-#ifndef GrBlend_DEFINED
-#define GrBlend_DEFINED
-
-static inline bool GrBlendCoeffRefsSrc(GrBlendCoeff coeff) {
- switch (coeff) {
- case kSC_GrBlendCoeff:
- case kISC_GrBlendCoeff:
- case kSA_GrBlendCoeff:
- case kISA_GrBlendCoeff:
- return true;
- default:
- return false;
- }
-}
-
-static inline bool GrBlendCoeffRefsDst(GrBlendCoeff coeff) {
- switch (coeff) {
- case kDC_GrBlendCoeff:
- case kIDC_GrBlendCoeff:
- case kDA_GrBlendCoeff:
- case kIDA_GrBlendCoeff:
- return true;
- default:
- return false;
- }
-}
-
-GrColor GrSimplifyBlend(GrBlendCoeff* srcCoeff,
- GrBlendCoeff* dstCoeff,
- GrColor srcColor, uint32_t srcCompFlags,
- GrColor dstColor, uint32_t dstCompFlags,
- GrColor constantColor);
-
-#endif
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index 20320e8ce0..20c633dc67 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -681,8 +681,9 @@ static bool isIRect(const SkRect& r) {
static bool apply_aa_to_rect(GrDrawTarget* target,
const SkRect& rect,
SkScalar strokeWidth,
- const SkMatrix& combinedMatrix,
- SkRect* devBoundRect,
+ const SkMatrix* matrix,
+ SkMatrix* combinedMatrix,
+ SkRect* devRect,
bool* useVertexCoverage) {
// we use a simple coverage ramp to do aa on axis-aligned rects
// we check if the rect will be axis-aligned, and the rect won't land on
@@ -715,32 +716,52 @@ static bool apply_aa_to_rect(GrDrawTarget* target,
#if defined(SHADER_AA_FILL_RECT) || !defined(IGNORE_ROT_AA_RECT_OPT)
if (strokeWidth >= 0) {
#endif
- if (!combinedMatrix.preservesAxisAlignment()) {
+ if (!drawState.getViewMatrix().preservesAxisAlignment()) {
return false;
}
+ if (NULL != matrix && !matrix->preservesAxisAlignment()) {
+ return false;
+ }
#if defined(SHADER_AA_FILL_RECT) || !defined(IGNORE_ROT_AA_RECT_OPT)
} else {
- if (!combinedMatrix.preservesRightAngles()) {
+ if (!drawState.getViewMatrix().preservesAxisAlignment() &&
+ !drawState.getViewMatrix().preservesRightAngles()) {
+ return false;
+ }
+
+ if (NULL != matrix && !matrix->preservesRightAngles()) {
return false;
}
}
#endif
- combinedMatrix.mapRect(devBoundRect, rect);
+ *combinedMatrix = drawState.getViewMatrix();
+ if (NULL != matrix) {
+ combinedMatrix->preConcat(*matrix);
+
+#if GR_DEBUG
+#if defined(SHADER_AA_FILL_RECT) || !defined(IGNORE_ROT_AA_RECT_OPT)
+ if (strokeWidth >= 0) {
+#endif
+ GrAssert(combinedMatrix->preservesAxisAlignment());
+#if defined(SHADER_AA_FILL_RECT) || !defined(IGNORE_ROT_AA_RECT_OPT)
+ } else {
+ GrAssert(combinedMatrix->preservesRightAngles());
+ }
+#endif
+#endif
+ }
+
+ combinedMatrix->mapRect(devRect, rect);
if (strokeWidth < 0) {
- return !isIRect(*devBoundRect);
+ return !isIRect(*devRect);
} else {
return true;
}
}
-static inline bool rect_contains_inclusive(const SkRect& rect, const SkPoint& point) {
- return point.fX >= rect.fLeft && point.fX <= rect.fRight &&
- point.fY >= rect.fTop && point.fY <= rect.fBottom;
-}
-
void GrContext::drawRect(const GrPaint& paint,
const SkRect& rect,
SkScalar width,
@@ -750,48 +771,13 @@ void GrContext::drawRect(const GrPaint& paint,
AutoRestoreEffects are;
GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are);
- SkMatrix combinedMatrix = target->drawState()->getViewMatrix();
- if (NULL != matrix) {
- combinedMatrix.preConcat(*matrix);
- }
-
- // Check if this is a full RT draw and can be replaced with a clear.
- SkRect rtRect;
- target->getDrawState().getRenderTarget()->getBoundsRect(&rtRect);
- SkRect clipSpaceRTRect = rtRect;
- bool checkClip = false;
- if (NULL != this->getClip()) {
- checkClip = true;
- clipSpaceRTRect.offset(SkIntToScalar(this->getClip()->fOrigin.fX),
- SkIntToScalar(this->getClip()->fOrigin.fY));
- }
- // Does the clip contain the entire RT?
- if (!checkClip || target->getClip()->fClipStack->quickContains(clipSpaceRTRect)) {
- SkMatrix invM;
- if (!combinedMatrix.invert(&invM)) {
- return;
- }
- // Does the rect bound the RT?
- SkPoint srcSpaceRTQuad[4];
- invM.mapRectToQuad(srcSpaceRTQuad, rtRect);
- if (rect_contains_inclusive(rect, srcSpaceRTQuad[0]) &&
- rect_contains_inclusive(rect, srcSpaceRTQuad[1]) &&
- rect_contains_inclusive(rect, srcSpaceRTQuad[2]) &&
- rect_contains_inclusive(rect, srcSpaceRTQuad[3])) {
- // Will it blend?
- GrColor clearColor;
- if (paint.isOpaqueAndConstantColor(&clearColor)) {
- target->clear(NULL, clearColor);
- return;
- }
- }
- }
-
- SkRect devBoundRect;
+ SkRect devRect;
+ SkMatrix combinedMatrix;
bool useVertexCoverage;
bool needAA = paint.isAntiAlias() &&
!target->getDrawState().getRenderTarget()->isMultisampled();
- bool doAA = needAA && apply_aa_to_rect(target, rect, width, combinedMatrix, &devBoundRect,
+ bool doAA = needAA && apply_aa_to_rect(target, rect, width, matrix,
+ &combinedMatrix, &devRect,
&useVertexCoverage);
if (doAA) {
GrDrawState::AutoViewMatrixRestore avmr;
@@ -800,12 +786,12 @@ void GrContext::drawRect(const GrPaint& paint,
}
if (width >= 0) {
fAARectRenderer->strokeAARect(this->getGpu(), target,
- rect, combinedMatrix, devBoundRect,
+ rect, combinedMatrix, devRect,
width, useVertexCoverage);
} else {
// filled AA rect
fAARectRenderer->fillAARect(this->getGpu(), target,
- rect, combinedMatrix, devBoundRect,
+ rect, combinedMatrix, devRect,
useVertexCoverage);
}
return;
diff --git a/src/gpu/GrDrawState.h b/src/gpu/GrDrawState.h
index 785be77f58..c006e6c5dd 100644
--- a/src/gpu/GrDrawState.h
+++ b/src/gpu/GrDrawState.h
@@ -9,7 +9,6 @@
#define GrDrawState_DEFINED
#include "GrBackendEffectFactory.h"
-#include "GrBlend.h"
#include "GrColor.h"
#include "GrEffectStage.h"
#include "GrPaint.h"
@@ -470,11 +469,27 @@ public:
fCommon.fSrcBlend = srcCoeff;
fCommon.fDstBlend = dstCoeff;
#if GR_DEBUG
- if (GrBlendCoeffRefsDst(dstCoeff)) {
- GrPrintf("Unexpected dst blend coeff. Won't work correctly with coverage stages.\n");
+ switch (dstCoeff) {
+ case kDC_GrBlendCoeff:
+ case kIDC_GrBlendCoeff:
+ case kDA_GrBlendCoeff:
+ case kIDA_GrBlendCoeff:
+ GrPrintf("Unexpected dst blend coeff. Won't work correctly with"
+ "coverage stages.\n");
+ break;
+ default:
+ break;
}
- if (GrBlendCoeffRefsSrc(srcCoeff)) {
- GrPrintf("Unexpected src blend coeff. Won't work correctly with coverage stages.\n");
+ switch (srcCoeff) {
+ case kSC_GrBlendCoeff:
+ case kISC_GrBlendCoeff:
+ case kSA_GrBlendCoeff:
+ case kISA_GrBlendCoeff:
+ GrPrintf("Unexpected src blend coeff. Won't work correctly with"
+ "coverage stages.\n");
+ break;
+ default:
+ break;
}
#endif
}
diff --git a/src/gpu/GrPaint.cpp b/src/gpu/GrPaint.cpp
index 0522e25085..d67f2e8707 100644
--- a/src/gpu/GrPaint.cpp
+++ b/src/gpu/GrPaint.cpp
@@ -8,7 +8,6 @@
#include "GrPaint.h"
-#include "GrBlend.h"
#include "effects/GrSimpleTextureEffect.h"
void GrPaint::addColorTextureEffect(GrTexture* texture, const SkMatrix& matrix) {
@@ -34,59 +33,3 @@ void GrPaint::addCoverageTextureEffect(GrTexture* texture,
GrEffectRef* effect = GrSimpleTextureEffect::Create(texture, matrix, params);
this->addCoverageEffect(effect)->unref();
}
-
-bool GrPaint::isOpaque() const {
- return this->getOpaqueAndKnownColor(NULL, NULL);
-}
-
-bool GrPaint::isOpaqueAndConstantColor(GrColor* color) const {
- GrColor tempColor;
- uint32_t colorComps;
- if (this->getOpaqueAndKnownColor(&tempColor, &colorComps)) {
- if (kRGBA_GrColorComponentFlags == colorComps) {
- *color = tempColor;
- return true;
- }
- }
- return false;
-}
-
-bool GrPaint::getOpaqueAndKnownColor(GrColor* solidColor,
- uint32_t* solidColorKnownComponents) const {
-
- // TODO: Share this implementation with GrDrawState
-
- // Since fColorFilterXfermode is going away soon, we aren't attempting to handle anything but
- // the default setting.
- if (SkXfermode::kDst_Mode != fColorFilterXfermode) {
- return false;
- }
-
- GrColor coverage = GrColorPackRGBA(fCoverage, fCoverage, fCoverage, fCoverage);
- uint32_t coverageComps = kRGBA_GrColorComponentFlags;
- int count = fCoverageStages.count();
- for (int i = 0; i < count; ++i) {
- (*fCoverageStages[i].getEffect())->getConstantColorComponents(&coverage, &coverageComps);
- }
- if (kRGBA_GrColorComponentFlags != coverageComps || 0xffffffff != coverage) {
- return false;
- }
-
- GrColor color = fColor;
- uint32_t colorComps = kRGBA_GrColorComponentFlags;
- count = fColorStages.count();
- for (int i = 0; i < count; ++i) {
- (*fColorStages[i].getEffect())->getConstantColorComponents(&color, &colorComps);
- }
-
- GrAssert((NULL == solidColor) == (NULL == solidColorKnownComponents));
- if (NULL != solidColor) {
- *solidColor = color;
- *solidColorKnownComponents = colorComps;
- }
-
- GrBlendCoeff srcCoeff = fSrcBlendCoeff;
- GrBlendCoeff dstCoeff = fDstBlendCoeff;
- GrSimplifyBlend(&srcCoeff, &dstCoeff, color, colorComps, 0, 0, 0);
- return kZero_GrBlendCoeff == dstCoeff && !GrBlendCoeffRefsDst(srcCoeff);
-}