diff options
-rw-r--r-- | expectations/gm/ignored-tests.txt | 3 | ||||
-rw-r--r-- | include/gpu/GrContext.h | 34 | ||||
-rw-r--r-- | include/gpu/GrCoordTransform.h | 7 | ||||
-rw-r--r-- | src/core/SkImageFilter.cpp | 2 | ||||
-rw-r--r-- | src/effects/SkBlurMaskFilter.cpp | 4 | ||||
-rw-r--r-- | src/effects/SkGpuBlurUtils.cpp | 8 | ||||
-rw-r--r-- | src/effects/SkMorphologyImageFilter.cpp | 2 | ||||
-rwxr-xr-x | src/gpu/GrContext.cpp | 11 | ||||
-rw-r--r-- | src/gpu/SkGpuDevice.cpp | 38 | ||||
-rw-r--r-- | src/gpu/effects/GrConfigConversionEffect.cpp | 6 | ||||
-rw-r--r-- | src/gpu/gl/GrGLProgram.cpp | 3 | ||||
-rw-r--r-- | src/gpu/gl/GrGLProgramDesc.cpp | 7 | ||||
-rw-r--r-- | src/gpu/gl/builders/GrGLProgramBuilder.cpp | 6 | ||||
-rw-r--r-- | src/gpu/gl/builders/GrGLProgramBuilder.h | 6 | ||||
-rw-r--r-- | src/gpu/gl/builders/GrGLVertexShaderBuilder.cpp | 35 |
15 files changed, 109 insertions, 63 deletions
diff --git a/expectations/gm/ignored-tests.txt b/expectations/gm/ignored-tests.txt index 44577413b8..b87402f9d5 100644 --- a/expectations/gm/ignored-tests.txt +++ b/expectations/gm/ignored-tests.txt @@ -51,6 +51,9 @@ imagemagnifier #reed modecolorfilters +#joshualitt +bleed + #humper skia:2049 dashcubics diff --git a/include/gpu/GrContext.h b/include/gpu/GrContext.h index 4df1dac381..ead8ded762 100644 --- a/include/gpu/GrContext.h +++ b/include/gpu/GrContext.h @@ -436,20 +436,30 @@ public: const GrStrokeInfo* strokeInfo = NULL); /** - * Maps a rect of local coordinates onto the a rect of destination - * coordinates. The localRect is stretched over the dstRect. The dstRect is - * transformed by the context's matrix. An additional optional matrix can be - * provided to transform the local rect. + * Maps a rectangle of shader coordinates to a rectangle and draws that rectangle * * @param paint describes how to color pixels. - * @param viewMatrix transformation matrix - * @param dstRect the destination rect to draw. - * @param localRect rect of local coordinates to be mapped onto dstRect - */ - void drawRectToRect(const GrPaint& paint, - const SkMatrix& viewMatrix, - const SkRect& dstRect, - const SkRect& localRect); + * @param viewMatrix transformation matrix which applies to rectToDraw + * @param rectToDraw the rectangle to draw + * @param localRect the rectangle of shader coordinates applied to rectToDraw + * @param localMatrix an optional matrix to transform the shader coordinates before applying + * to rectToDraw + */ + void drawNonAARectToRect(const GrPaint& paint, + const SkMatrix& viewMatrix, + const SkRect& rectToDraw, + const SkRect& localRect, + const SkMatrix* localMatrix = NULL); + + /** + * Draws a non-AA rect with paint and a localMatrix + */ + void drawNonAARectWithLocalMatrix(const GrPaint& paint, + const SkMatrix& viewMatrix, + const SkRect& rect, + const SkMatrix& localMatrix) { + this->drawNonAARectToRect(paint, viewMatrix, rect, rect, &localMatrix); + } /** * Draw a roundrect using a paint. diff --git a/include/gpu/GrCoordTransform.h b/include/gpu/GrCoordTransform.h index e97de0d8a8..b2632c4118 100644 --- a/include/gpu/GrCoordTransform.h +++ b/include/gpu/GrCoordTransform.h @@ -34,7 +34,12 @@ enum GrCoordSet { * specified by the caller, as it may have transformed vertices into another space. These are * usually not the coordinates a GrProcessor wants. */ - kPosition_GrCoordSet + kPosition_GrCoordSet, + + /** + * The position after it has been transformed by the view matrix. + */ + kDevice_GrCoordSet, }; /** diff --git a/src/core/SkImageFilter.cpp b/src/core/SkImageFilter.cpp index 9366ebafa8..3285e220de 100644 --- a/src/core/SkImageFilter.cpp +++ b/src/core/SkImageFilter.cpp @@ -268,7 +268,7 @@ bool SkImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const Cont SkASSERT(fp); GrPaint paint; paint.addColorProcessor(fp)->unref(); - context->drawRectToRect(paint, SkMatrix::I(), dstRect, srcRect); + context->drawNonAARectToRect(paint, SkMatrix::I(), dstRect, srcRect); WrapTexture(dst, bounds.width(), bounds.height(), result); return true; diff --git a/src/effects/SkBlurMaskFilter.cpp b/src/effects/SkBlurMaskFilter.cpp index d880d28304..b849c74805 100644 --- a/src/effects/SkBlurMaskFilter.cpp +++ b/src/effects/SkBlurMaskFilter.cpp @@ -650,7 +650,7 @@ private: virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVERRIDE; static bool CreateBlurProfileTexture(GrContext *context, float sigma, - GrTexture **blurProfileTexture); + GrTexture **blurProfileTexture); SkRect fRect; float fSigma; @@ -753,7 +753,7 @@ void GrGLRectBlurEffect::setData(const GrGLProgramDataManager& pdman, } bool GrRectBlurEffect::CreateBlurProfileTexture(GrContext *context, float sigma, - GrTexture **blurProfileTexture) { + GrTexture **blurProfileTexture) { GrTextureParams params; GrSurfaceDesc texDesc; diff --git a/src/effects/SkGpuBlurUtils.cpp b/src/effects/SkGpuBlurUtils.cpp index a58972aba1..b22286b25f 100644 --- a/src/effects/SkGpuBlurUtils.cpp +++ b/src/effects/SkGpuBlurUtils.cpp @@ -58,7 +58,7 @@ static void convolve_gaussian_1d(GrContext* context, texture, direction, radius, sigma, useBounds, bounds)); paint.reset(); paint.addColorProcessor(conv); - context->drawRectToRect(paint, SkMatrix::I(), dstRect, srcRect); + context->drawNonAARectToRect(paint, SkMatrix::I(), dstRect, srcRect); } static void convolve_gaussian_2d(GrContext* context, @@ -81,7 +81,7 @@ static void convolve_gaussian_2d(GrContext* context, true, sigmaX, sigmaY)); paint.reset(); paint.addColorProcessor(conv); - context->drawRectToRect(paint, SkMatrix::I(), dstRect, srcRect); + context->drawNonAARectToRect(paint, SkMatrix::I(), dstRect, srcRect); } static void convolve_gaussian(GrContext* context, @@ -217,7 +217,7 @@ GrTexture* GaussianBlur(GrContext* context, } scale_rect(&dstRect, i < scaleFactorX ? 0.5f : 1.0f, i < scaleFactorY ? 0.5f : 1.0f); - context->drawRectToRect(paint, SkMatrix::I(), dstRect, srcRect); + context->drawNonAARectToRect(paint, SkMatrix::I(), dstRect, srcRect); srcRect = dstRect; srcTexture = dstTexture; SkTSwap(dstTexture, tempTexture); @@ -296,7 +296,7 @@ GrTexture* GaussianBlur(GrContext* context, SkRect dstRect(srcRect); scale_rect(&dstRect, (float) scaleFactorX, (float) scaleFactorY); - context->drawRectToRect(paint, SkMatrix::I(), dstRect, srcRect); + context->drawNonAARectToRect(paint, SkMatrix::I(), dstRect, srcRect); srcRect = dstRect; srcTexture = dstTexture; SkTSwap(dstTexture, tempTexture); diff --git a/src/effects/SkMorphologyImageFilter.cpp b/src/effects/SkMorphologyImageFilter.cpp index b8853c7356..d533448fe0 100644 --- a/src/effects/SkMorphologyImageFilter.cpp +++ b/src/effects/SkMorphologyImageFilter.cpp @@ -482,7 +482,7 @@ void apply_morphology_pass(GrContext* context, direction, radius, morphType))->unref(); - context->drawRectToRect(paint, SkMatrix::I(), SkRect::Make(dstRect), + context->drawNonAARectToRect(paint, SkMatrix::I(), SkRect::Make(dstRect), SkRect::Make(srcRect)); } diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp index cb68374c72..cc6a637267 100755 --- a/src/gpu/GrContext.cpp +++ b/src/gpu/GrContext.cpp @@ -795,10 +795,11 @@ void GrContext::drawRect(const GrPaint& paint, } } -void GrContext::drawRectToRect(const GrPaint& paint, - const SkMatrix& viewMatrix, - const SkRect& dstRect, - const SkRect& localRect) { +void GrContext::drawNonAARectToRect(const GrPaint& paint, + const SkMatrix& viewMatrix, + const SkRect& rectToDraw, + const SkRect& localRect, + const SkMatrix* localMatrix) { AutoCheckFlush acf(this); GrDrawState drawState; GrDrawTarget* target = this->prepareToDraw(&drawState, &paint, &viewMatrix, &acf); @@ -808,7 +809,7 @@ void GrContext::drawRectToRect(const GrPaint& paint, GR_CREATE_TRACE_MARKER("GrContext::drawRectToRect", target); - target->drawRect(&drawState, paint.getColor(), dstRect, &localRect, NULL); + target->drawRect(&drawState, paint.getColor(), rectToDraw, &localRect, localMatrix); } static const GrGeometryProcessor* set_vertex_attributes(const SkPoint* texCoords, diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp index 040cea8356..5f4713245e 100644 --- a/src/gpu/SkGpuDevice.cpp +++ b/src/gpu/SkGpuDevice.cpp @@ -574,16 +574,18 @@ namespace { // Return true if the mask was successfully drawn. bool draw_mask(GrContext* context, const SkMatrix& viewMatrix, const SkRect& maskRect, GrPaint* grp, GrTexture* mask) { - if (!grp->localCoordChangeInverse(viewMatrix)) { - return false; - } - SkMatrix matrix; matrix.setTranslate(-maskRect.fLeft, -maskRect.fTop); matrix.postIDiv(mask->width(), mask->height()); - grp->addCoverageProcessor(GrSimpleTextureEffect::Create(mask, matrix))->unref(); - context->drawRect(*grp, SkMatrix::I(), maskRect); + grp->addCoverageProcessor(GrSimpleTextureEffect::Create(mask, matrix, + kDevice_GrCoordSet))->unref(); + + SkMatrix inverse; + if (!viewMatrix.invert(&inverse)) { + return false; + } + context->drawNonAARectWithLocalMatrix(*grp, SkMatrix::I(), maskRect, inverse); return true; } @@ -1381,7 +1383,7 @@ void SkGpuDevice::internalDrawBitmap(const SkBitmap& bitmap, SkColor2GrColor(paint.getColor()); SkPaint2GrPaintNoShader(this->context(), paint, paintColor, false, &grPaint); - fContext->drawRectToRect(grPaint, viewMatrix, dstRect, paintRect); + fContext->drawNonAARectToRect(grPaint, viewMatrix, dstRect, paintRect); } bool SkGpuDevice::filterTexture(GrContext* context, GrTexture* texture, @@ -1452,16 +1454,16 @@ void SkGpuDevice::drawSprite(const SkDraw& draw, const SkBitmap& bitmap, SkPaint2GrPaintNoShader(this->context(), paint, SkColor2GrColorJustAlpha(paint.getColor()), false, &grPaint); - fContext->drawRectToRect(grPaint, - SkMatrix::I(), - SkRect::MakeXYWH(SkIntToScalar(left), - SkIntToScalar(top), - SkIntToScalar(w), - SkIntToScalar(h)), - SkRect::MakeXYWH(0, - 0, - SK_Scalar1 * w / texture->width(), - SK_Scalar1 * h / texture->height())); + fContext->drawNonAARectToRect(grPaint, + SkMatrix::I(), + SkRect::MakeXYWH(SkIntToScalar(left), + SkIntToScalar(top), + SkIntToScalar(w), + SkIntToScalar(h)), + SkRect::MakeXYWH(0, + 0, + SK_Scalar1 * w / texture->width(), + SK_Scalar1 * h / texture->height())); } void SkGpuDevice::drawBitmapRect(const SkDraw& origDraw, const SkBitmap& bitmap, @@ -1574,7 +1576,7 @@ void SkGpuDevice::drawDevice(const SkDraw& draw, SkBaseDevice* device, SkRect srcRect = SkRect::MakeWH(SK_Scalar1 * w / devTex->width(), SK_Scalar1 * h / devTex->height()); - fContext->drawRectToRect(grPaint, SkMatrix::I(), dstRect, srcRect); + fContext->drawNonAARectToRect(grPaint, SkMatrix::I(), dstRect, srcRect); } bool SkGpuDevice::canHandleImageFilter(const SkImageFilter* filter) { diff --git a/src/gpu/effects/GrConfigConversionEffect.cpp b/src/gpu/effects/GrConfigConversionEffect.cpp index 3a658ace26..4412c43736 100644 --- a/src/gpu/effects/GrConfigConversionEffect.cpp +++ b/src/gpu/effects/GrConfigConversionEffect.cpp @@ -231,19 +231,19 @@ void GrConfigConversionEffect::TestForPreservingPMConversions(GrContext* context context->setRenderTarget(readTex->asRenderTarget()); GrPaint paint1; paint1.addColorProcessor(pmToUPM1); - context->drawRectToRect(paint1, SkMatrix::I(), kDstRect, kSrcRect); + context->drawNonAARectToRect(paint1, SkMatrix::I(), kDstRect, kSrcRect); readTex->readPixels(0, 0, 256, 256, kRGBA_8888_GrPixelConfig, firstRead); context->setRenderTarget(tempTex->asRenderTarget()); GrPaint paint2; paint2.addColorProcessor(upmToPM); - context->drawRectToRect(paint2, SkMatrix::I(), kDstRect, kSrcRect); + context->drawNonAARectToRect(paint2, SkMatrix::I(), kDstRect, kSrcRect); context->setRenderTarget(readTex->asRenderTarget()); GrPaint paint3; paint3.addColorProcessor(pmToUPM2); - context->drawRectToRect(paint3, SkMatrix::I(), kDstRect, kSrcRect); + context->drawNonAARectToRect(paint3, SkMatrix::I(), kDstRect, kSrcRect); readTex->readPixels(0, 0, 256, 256, kRGBA_8888_GrPixelConfig, secondRead); diff --git a/src/gpu/gl/GrGLProgram.cpp b/src/gpu/gl/GrGLProgram.cpp index 0f4b70de2b..f8770b3664 100644 --- a/src/gpu/gl/GrGLProgram.cpp +++ b/src/gpu/gl/GrGLProgram.cpp @@ -32,7 +32,8 @@ static SkMatrix get_transform_matrix(const GrPendingFragmentStage& stage, int tr SkMatrix combined; if (kLocal_GrCoordSet == coordTransform.sourceCoords()) { - // If we have explicit local coords then we shouldn't need a coord change. + // If we have explicit local coords or are in device coords then we shouldn't need a coord + // change. const SkMatrix& ccm = stage.getCoordChangeMatrix(); combined.setConcat(coordTransform.getMatrix(), ccm); } else { diff --git a/src/gpu/gl/GrGLProgramDesc.cpp b/src/gpu/gl/GrGLProgramDesc.cpp index 06377c758e..6e3128ceaf 100644 --- a/src/gpu/gl/GrGLProgramDesc.cpp +++ b/src/gpu/gl/GrGLProgramDesc.cpp @@ -52,8 +52,9 @@ enum { kPrecisionShift = kMatrixTypeKeyBits, kPositionCoords_Flag = (1 << (kPrecisionShift + kPrecisionBits)), + kDeviceCoords_Flag = kPositionCoords_Flag + kPositionCoords_Flag, - kTransformKeyBits = kMatrixTypeKeyBits + kPrecisionBits + 1, + kTransformKeyBits = kMatrixTypeKeyBits + kPrecisionBits + 2, }; GR_STATIC_ASSERT(kHigh_GrSLPrecision < (1 << kPrecisionBits)); @@ -78,8 +79,10 @@ static uint32_t gen_transform_key(const GrPendingFragmentStage& stage, bool useE } const GrCoordTransform& coordTransform = stage.getProcessor()->coordTransform(t); - if (kLocal_GrCoordSet != coordTransform.sourceCoords() && useExplicitLocalCoords) { + if (kLocal_GrCoordSet == coordTransform.sourceCoords() && !useExplicitLocalCoords) { key |= kPositionCoords_Flag; + } else if (kDevice_GrCoordSet == coordTransform.sourceCoords()) { + key |= kDeviceCoords_Flag; } GR_STATIC_ASSERT(kGrSLPrecisionCount <= (1 << kPrecisionBits)); diff --git a/src/gpu/gl/builders/GrGLProgramBuilder.cpp b/src/gpu/gl/builders/GrGLProgramBuilder.cpp index 6f3214f23a..861410bf13 100644 --- a/src/gpu/gl/builders/GrGLProgramBuilder.cpp +++ b/src/gpu/gl/builders/GrGLProgramBuilder.cpp @@ -401,12 +401,10 @@ void GrGLProgramBuilder::emitTransforms(const GrPendingFragmentStage& stage, varyingName = suffixedVaryingName.c_str(); } - bool useLocalCoords = kLocal_GrCoordSet == processor->coordTransform(t).sourceCoords(); - const char* coords = useLocalCoords ? fVS.localCoords() : fVS.positionCoords(); - + GrCoordSet coordType = processor->coordTransform(t).sourceCoords(); GrGLVertToFrag v(varyingType); this->addVarying(varyingName, &v, precision); - fCoordVaryings.push_back(TransformVarying(v, uniName, coords)); + fCoordVaryings.push_back(TransformVarying(v, uniName, coordType)); SkASSERT(kVec2f_GrSLType == varyingType || kVec3f_GrSLType == varyingType); SkNEW_APPEND_TO_TARRAY(outCoords, GrGLProcessor::TransformedCoords, diff --git a/src/gpu/gl/builders/GrGLProgramBuilder.h b/src/gpu/gl/builders/GrGLProgramBuilder.h index 3fdccca393..032fa57fa2 100644 --- a/src/gpu/gl/builders/GrGLProgramBuilder.h +++ b/src/gpu/gl/builders/GrGLProgramBuilder.h @@ -352,11 +352,11 @@ protected: int stageIndex() const { return fStageIndex; } struct TransformVarying { - TransformVarying(const GrGLVarying& v, const char* uniName, const char* sourceCoords) - : fV(v), fUniName(uniName), fSourceCoords(sourceCoords) {} + TransformVarying(const GrGLVarying& v, const char* uniName, GrCoordSet coordSet) + : fV(v), fUniName(uniName), fCoordSet(coordSet) {} GrGLVarying fV; SkString fUniName; - SkString fSourceCoords; + GrCoordSet fCoordSet; }; const char* rtAdjustment() const { return "rtAdjustment"; } diff --git a/src/gpu/gl/builders/GrGLVertexShaderBuilder.cpp b/src/gpu/gl/builders/GrGLVertexShaderBuilder.cpp index 1d97e85234..317657e61f 100644 --- a/src/gpu/gl/builders/GrGLVertexShaderBuilder.cpp +++ b/src/gpu/gl/builders/GrGLVertexShaderBuilder.cpp @@ -53,16 +53,39 @@ void GrGLVertexBuilder::transformToNormalizedDeviceSpace() { SkTArray<GrGLProgramBuilder::TransformVarying, true>& transVs = fProgramBuilder->fCoordVaryings; int transformCount = transVs.count(); for (int i = 0; i < transformCount; i++) { - const char* coords = transVs[i].fSourceCoords.c_str(); + GrCoordSet coordSet = transVs[i].fCoordSet; + const char* coords; + switch (coordSet) { + default: + SkFAIL("Case missing"); + case kPosition_GrCoordSet: + coords = this->positionCoords(); + break; + case kLocal_GrCoordSet: + coords = this->localCoords(); + break; + case kDevice_GrCoordSet: + coords = this->glPosition(); + break; + } // varying = matrix * coords (logically) const GrGLVarying& v = transVs[i].fV; - if (kVec2f_GrSLType == v.fType) { - this->codeAppendf("%s = (%s * vec3(%s, 1)).xy;", v.fVsOut, transVs[i].fUniName.c_str(), - coords); + if (kDevice_GrCoordSet == coordSet) { + if (kVec2f_GrSLType == v.fType) { + this->codeAppendf("%s = (%s * %s).xy;", v.fVsOut, transVs[i].fUniName.c_str(), + coords); + } else { + this->codeAppendf("%s = %s * %s;", v.fVsOut, transVs[i].fUniName.c_str(), coords); + } } else { - this->codeAppendf("%s = %s * vec3(%s, 1);", v.fVsOut, transVs[i].fUniName.c_str(), - coords); + if (kVec2f_GrSLType == v.fType) { + this->codeAppendf("%s = (%s * vec3(%s, 1)).xy;", v.fVsOut, transVs[i].fUniName.c_str(), + coords); + } else { + this->codeAppendf("%s = %s * vec3(%s, 1);", v.fVsOut, transVs[i].fUniName.c_str(), + coords); + } } } |