#reed
modecolorfilters
+#joshualitt
+bleed
+
#humper skia:2049
dashcubics
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.
* 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,
};
/**
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;
virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVERRIDE;
static bool CreateBlurProfileTexture(GrContext *context, float sigma,
- GrTexture **blurProfileTexture);
+ GrTexture **blurProfileTexture);
SkRect fRect;
float fSigma;
}
bool GrRectBlurEffect::CreateBlurProfileTexture(GrContext *context, float sigma,
- GrTexture **blurProfileTexture) {
+ GrTexture **blurProfileTexture) {
GrTextureParams params;
GrSurfaceDesc texDesc;
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,
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,
}
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);
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);
direction,
radius,
morphType))->unref();
- context->drawRectToRect(paint, SkMatrix::I(), SkRect::Make(dstRect),
+ context->drawNonAARectToRect(paint, SkMatrix::I(), SkRect::Make(dstRect),
SkRect::Make(srcRect));
}
}
}
-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);
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,
// 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;
}
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,
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,
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) {
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);
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 {
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));
}
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));
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,
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"; }
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);
+ }
}
}