aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu
diff options
context:
space:
mode:
authorGravatar joshualitt <joshualitt@chromium.org>2014-12-17 15:50:11 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2014-12-17 15:50:11 -0800
commit5531d51ce7426bdae7563547326fcf0bf926a083 (patch)
tree111625235b55e016756b32d9904d6d3bf059c73c /src/gpu
parent1b28a3a4890e3b84b43181b3fe3690ac565930dc (diff)
remove view matrix from context
Diffstat (limited to 'src/gpu')
-rwxr-xr-xsrc/gpu/GrBitmapTextContext.cpp31
-rw-r--r--src/gpu/GrBitmapTextContext.h7
-rwxr-xr-xsrc/gpu/GrContext.cpp101
-rwxr-xr-xsrc/gpu/GrDistanceFieldTextContext.cpp41
-rw-r--r--src/gpu/GrDistanceFieldTextContext.h8
-rw-r--r--src/gpu/GrOvalRenderer.cpp54
-rw-r--r--src/gpu/GrOvalRenderer.h14
-rw-r--r--src/gpu/GrStencilAndCoverTextContext.cpp36
-rw-r--r--src/gpu/GrStencilAndCoverTextContext.h14
-rw-r--r--src/gpu/GrTextContext.cpp12
-rw-r--r--src/gpu/GrTextContext.h14
-rw-r--r--src/gpu/SkGpuDevice.cpp196
-rw-r--r--src/gpu/SkGpuDevice.h8
-rw-r--r--src/gpu/SkGr.cpp33
-rw-r--r--src/gpu/effects/GrConfigConversionEffect.cpp6
15 files changed, 288 insertions, 287 deletions
diff --git a/src/gpu/GrBitmapTextContext.cpp b/src/gpu/GrBitmapTextContext.cpp
index bf27584f26..921c198eeb 100755
--- a/src/gpu/GrBitmapTextContext.cpp
+++ b/src/gpu/GrBitmapTextContext.cpp
@@ -66,8 +66,8 @@ GrBitmapTextContext* GrBitmapTextContext::Create(GrContext* context,
return SkNEW_ARGS(GrBitmapTextContext, (context, props));
}
-bool GrBitmapTextContext::canDraw(const SkPaint& paint) {
- return !SkDraw::ShouldDrawTextAsPaths(paint, fContext->getMatrix());
+bool GrBitmapTextContext::canDraw(const SkPaint& paint, const SkMatrix& viewMatrix) {
+ return !SkDraw::ShouldDrawTextAsPaths(paint, viewMatrix);
}
inline void GrBitmapTextContext::init(const GrPaint& paint, const SkPaint& skPaint) {
@@ -84,6 +84,7 @@ inline void GrBitmapTextContext::init(const GrPaint& paint, const SkPaint& skPai
}
void GrBitmapTextContext::onDrawText(const GrPaint& paint, const SkPaint& skPaint,
+ const SkMatrix& viewMatrix,
const char text[], size_t byteLength,
SkScalar x, SkScalar y) {
SkASSERT(byteLength == 0 || text != NULL);
@@ -97,14 +98,14 @@ void GrBitmapTextContext::onDrawText(const GrPaint& paint, const SkPaint& skPain
SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc();
- SkAutoGlyphCache autoCache(fSkPaint, &fDeviceProperties, &fContext->getMatrix());
+ SkAutoGlyphCache autoCache(fSkPaint, &fDeviceProperties, &viewMatrix);
SkGlyphCache* cache = autoCache.getCache();
GrFontScaler* fontScaler = GetGrFontScaler(cache);
// transform our starting point
{
SkPoint loc;
- fContext->getMatrix().mapXY(x, y, &loc);
+ viewMatrix.mapXY(x, y, &loc);
x = loc.fX;
y = loc.fY;
}
@@ -138,7 +139,7 @@ void GrBitmapTextContext::onDrawText(const GrPaint& paint, const SkPaint& skPain
SkFixed halfSampleX, halfSampleY;
if (cache->isSubpixel()) {
halfSampleX = halfSampleY = (SK_FixedHalf >> SkGlyph::kSubBits);
- SkAxisAlignment baseline = SkComputeAxisAlignmentForHText(fContext->getMatrix());
+ SkAxisAlignment baseline = SkComputeAxisAlignmentForHText(viewMatrix);
if (kX_SkAxisAlignment == baseline) {
fyMask = 0;
halfSampleY = SK_FixedHalf;
@@ -153,8 +154,9 @@ void GrBitmapTextContext::onDrawText(const GrPaint& paint, const SkPaint& skPain
SkFixed fx = SkScalarToFixed(x) + halfSampleX;
SkFixed fy = SkScalarToFixed(y) + halfSampleY;
- GrContext::AutoMatrix autoMatrix;
- autoMatrix.setIdentity(fContext, &fPaint);
+ if (!fPaint.localCoordChangeInverse(viewMatrix)) {
+ SkDebugf("Cannot invert viewmatrix\n");
+ }
while (text < stop) {
const SkGlyph& glyph = glyphCacheProc(cache, &text, fx & fxMask, fy & fyMask);
@@ -178,6 +180,7 @@ void GrBitmapTextContext::onDrawText(const GrPaint& paint, const SkPaint& skPain
}
void GrBitmapTextContext::onDrawPosText(const GrPaint& paint, const SkPaint& skPaint,
+ const SkMatrix& viewMatrix,
const char text[], size_t byteLength,
const SkScalar pos[], int scalarsPerPosition,
const SkPoint& offset) {
@@ -193,14 +196,15 @@ void GrBitmapTextContext::onDrawPosText(const GrPaint& paint, const SkPaint& skP
SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc();
- SkAutoGlyphCache autoCache(fSkPaint, &fDeviceProperties, &fContext->getMatrix());
+ SkAutoGlyphCache autoCache(fSkPaint, &fDeviceProperties, &viewMatrix);
SkGlyphCache* cache = autoCache.getCache();
GrFontScaler* fontScaler = GetGrFontScaler(cache);
// store original matrix before we reset, so we can use it to transform positions
- SkMatrix ctm = fContext->getMatrix();
- GrContext::AutoMatrix autoMatrix;
- autoMatrix.setIdentity(fContext, &fPaint);
+ SkMatrix ctm = viewMatrix;
+ if (!fPaint.localCoordChangeInverse(viewMatrix)) {
+ SkDebugf("Cannot invert viewmatrix\n");
+ }
int numGlyphs = fSkPaint.textToGlyphs(text, byteLength, NULL);
fTotalVertexCount = kVerticesPerGlyph*numGlyphs;
@@ -440,14 +444,13 @@ void GrBitmapTextContext::appendGlyph(GrGlyph::PackedID packed,
// flush any accumulated draws before drawing this glyph as a path.
this->flush();
- GrContext::AutoMatrix am;
SkMatrix translate;
translate.setTranslate(SkFixedToScalar(vx - SkIntToFixed(glyph->fBounds.fLeft)),
SkFixedToScalar(vy - SkIntToFixed(glyph->fBounds.fTop)));
GrPaint tmpPaint(fPaint);
- am.setPreConcat(fContext, translate, &tmpPaint);
+ tmpPaint.localCoordChange(translate);
GrStrokeInfo strokeInfo(SkStrokeRec::kFill_InitStyle);
- fContext->drawPath(tmpPaint, *glyph->fPath, strokeInfo);
+ fContext->drawPath(tmpPaint, translate, *glyph->fPath, strokeInfo);
// remove this glyph from the vertices we need to allocate
fTotalVertexCount -= kVerticesPerGlyph;
diff --git a/src/gpu/GrBitmapTextContext.h b/src/gpu/GrBitmapTextContext.h
index 9aa5dbdc63..ad21a2ffda 100644
--- a/src/gpu/GrBitmapTextContext.h
+++ b/src/gpu/GrBitmapTextContext.h
@@ -38,11 +38,12 @@ private:
GrBitmapTextContext(GrContext*, const SkDeviceProperties&);
- virtual bool canDraw(const SkPaint& paint) SK_OVERRIDE;
+ virtual bool canDraw(const SkPaint& paint, const SkMatrix& viewMatrix) SK_OVERRIDE;
- virtual void onDrawText(const GrPaint&, const SkPaint&, const char text[], size_t byteLength,
+ virtual void onDrawText(const GrPaint&, const SkPaint&, const SkMatrix& viewMatrix,
+ const char text[], size_t byteLength,
SkScalar x, SkScalar y) SK_OVERRIDE;
- virtual void onDrawPosText(const GrPaint&, const SkPaint&,
+ virtual void onDrawPosText(const GrPaint&, const SkPaint&, const SkMatrix& viewMatrix,
const char text[], size_t byteLength,
const SkScalar pos[], int scalarsPerPosition,
const SkPoint& offset) SK_OVERRIDE;
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index d6431f0750..cb68374c72 100755
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -103,7 +103,6 @@ GrContext::GrContext(const Options& opts) : fOptions(opts) {
fFlushToReduceCacheSize = false;
fAARectRenderer = NULL;
fOvalRenderer = NULL;
- fViewMatrix.reset();
fMaxTextureSizeOverride = 1 << 20;
}
@@ -127,7 +126,7 @@ void GrContext::initCommon() {
fLayerCache.reset(SkNEW_ARGS(GrLayerCache, (this)));
fAARectRenderer = SkNEW_ARGS(GrAARectRenderer, (fGpu));
- fOvalRenderer = SkNEW(GrOvalRenderer);
+ fOvalRenderer = SkNEW_ARGS(GrOvalRenderer, (fGpu));
fDidTestPMConversions = false;
@@ -541,36 +540,35 @@ void GrContext::clear(const SkIRect* rect,
AutoCheckFlush acf(this);
GR_CREATE_TRACE_MARKER_CONTEXT("GrContext::clear", this);
- GrDrawTarget* target = this->prepareToDraw(NULL, NULL, &acf);
+ GrDrawTarget* target = this->prepareToDraw(NULL, NULL, NULL, &acf);
if (NULL == target) {
return;
}
target->clear(rect, color, canIgnoreRect, renderTarget);
}
-void GrContext::drawPaint(const GrPaint& origPaint) {
+void GrContext::drawPaint(const GrPaint& origPaint, const SkMatrix& viewMatrix) {
// set rect to be big enough to fill the space, but not super-huge, so we
// don't overflow fixed-point implementations
SkRect r;
r.setLTRB(0, 0,
SkIntToScalar(getRenderTarget()->width()),
SkIntToScalar(getRenderTarget()->height()));
- SkMatrix inverse;
SkTCopyOnFirstWrite<GrPaint> paint(origPaint);
- AutoMatrix am;
GR_CREATE_TRACE_MARKER_CONTEXT("GrContext::drawPaint", this);
// We attempt to map r by the inverse matrix and draw that. mapRect will
// map the four corners and bound them with a new rect. This will not
// produce a correct result for some perspective matrices.
- if (!this->getMatrix().hasPerspective()) {
- if (!fViewMatrix.invert(&inverse)) {
+ if (!viewMatrix.hasPerspective()) {
+ SkMatrix inverse;
+ if (!viewMatrix.invert(&inverse)) {
SkDebugf("Could not invert matrix\n");
return;
}
inverse.mapRect(&r);
} else {
- if (!am.setIdentity(this, paint.writable())) {
+ if (!paint.writable()->localCoordChangeInverse(viewMatrix)) {
SkDebugf("Could not invert matrix\n");
return;
}
@@ -579,7 +577,7 @@ void GrContext::drawPaint(const GrPaint& origPaint) {
if (paint->isAntiAlias()) {
paint.writable()->setAntiAlias(false);
}
- this->drawRect(*paint, r);
+ this->drawRect(*paint, viewMatrix.hasPerspective() ? SkMatrix::I() : viewMatrix, r);
}
#ifdef SK_DEVELOPER
@@ -669,18 +667,19 @@ static inline bool rect_contains_inclusive(const SkRect& rect, const SkPoint& po
}
void GrContext::drawRect(const GrPaint& paint,
+ const SkMatrix& viewMatrix,
const SkRect& rect,
const GrStrokeInfo* strokeInfo) {
if (strokeInfo && strokeInfo->isDashed()) {
SkPath path;
path.addRect(rect);
- this->drawPath(paint, path, *strokeInfo);
+ this->drawPath(paint, viewMatrix, path, *strokeInfo);
return;
}
AutoCheckFlush acf(this);
GrDrawState drawState;
- GrDrawTarget* target = this->prepareToDraw(&drawState, &paint, &acf);
+ GrDrawTarget* target = this->prepareToDraw(&drawState, &paint, &viewMatrix, &acf);
if (NULL == target) {
return;
}
@@ -797,19 +796,19 @@ void GrContext::drawRect(const GrPaint& paint,
}
void GrContext::drawRectToRect(const GrPaint& paint,
+ const SkMatrix& viewMatrix,
const SkRect& dstRect,
- const SkRect& localRect,
- const SkMatrix* localMatrix) {
+ const SkRect& localRect) {
AutoCheckFlush acf(this);
GrDrawState drawState;
- GrDrawTarget* target = this->prepareToDraw(&drawState, &paint, &acf);
+ GrDrawTarget* target = this->prepareToDraw(&drawState, &paint, &viewMatrix, &acf);
if (NULL == target) {
return;
}
GR_CREATE_TRACE_MARKER("GrContext::drawRectToRect", target);
- target->drawRect(&drawState, paint.getColor(), dstRect, &localRect, localMatrix);
+ target->drawRect(&drawState, paint.getColor(), dstRect, &localRect, NULL);
}
static const GrGeometryProcessor* set_vertex_attributes(const SkPoint* texCoords,
@@ -836,6 +835,7 @@ static const GrGeometryProcessor* set_vertex_attributes(const SkPoint* texCoords
}
void GrContext::drawVertices(const GrPaint& paint,
+ const SkMatrix& viewMatrix,
GrPrimitiveType primitiveType,
int vertexCount,
const SkPoint positions[],
@@ -847,7 +847,7 @@ void GrContext::drawVertices(const GrPaint& paint,
GrDrawState drawState;
GrDrawTarget::AutoReleaseGeometry geo; // must be inside AutoCheckFlush scope
- GrDrawTarget* target = this->prepareToDraw(&drawState, &paint, &acf);
+ GrDrawTarget* target = this->prepareToDraw(&drawState, &paint, &viewMatrix, &acf);
if (NULL == target) {
return;
}
@@ -895,6 +895,7 @@ void GrContext::drawVertices(const GrPaint& paint,
///////////////////////////////////////////////////////////////////////////////
void GrContext::drawRRect(const GrPaint& paint,
+ const SkMatrix& viewMatrix,
const SkRRect& rrect,
const GrStrokeInfo& strokeInfo) {
if (rrect.isEmpty()) {
@@ -904,13 +905,13 @@ void GrContext::drawRRect(const GrPaint& paint,
if (strokeInfo.isDashed()) {
SkPath path;
path.addRRect(rrect);
- this->drawPath(paint, path, strokeInfo);
+ this->drawPath(paint, viewMatrix, path, strokeInfo);
return;
}
AutoCheckFlush acf(this);
GrDrawState drawState;
- GrDrawTarget* target = this->prepareToDraw(&drawState, &paint, &acf);
+ GrDrawTarget* target = this->prepareToDraw(&drawState, &paint, &viewMatrix, &acf);
if (NULL == target) {
return;
}
@@ -920,17 +921,19 @@ void GrContext::drawRRect(const GrPaint& paint,
const SkStrokeRec& strokeRec = strokeInfo.getStrokeRec();
GrColor color = paint.getColor();
- if (!fOvalRenderer->drawRRect(target, &drawState, color, this, paint.isAntiAlias(), rrect,
+ if (!fOvalRenderer->drawRRect(target, &drawState, color, paint.isAntiAlias(), rrect,
strokeRec)) {
SkPath path;
path.addRRect(rrect);
- this->internalDrawPath(target, &drawState, color, paint.isAntiAlias(), path, strokeInfo);
+ this->internalDrawPath(target, &drawState, viewMatrix, color, paint.isAntiAlias(), path,
+ strokeInfo);
}
}
///////////////////////////////////////////////////////////////////////////////
void GrContext::drawDRRect(const GrPaint& paint,
+ const SkMatrix& viewMatrix,
const SkRRect& outer,
const SkRRect& inner) {
if (outer.isEmpty()) {
@@ -939,26 +942,27 @@ void GrContext::drawDRRect(const GrPaint& paint,
AutoCheckFlush acf(this);
GrDrawState drawState;
- GrDrawTarget* target = this->prepareToDraw(&drawState, &paint, &acf);
+ GrDrawTarget* target = this->prepareToDraw(&drawState, &paint, &viewMatrix, &acf);
GR_CREATE_TRACE_MARKER("GrContext::drawDRRect", target);
GrColor color = paint.getColor();
- if (!fOvalRenderer->drawDRRect(target, &drawState, color, this, paint.isAntiAlias(), outer,
- inner)) {
+ if (!fOvalRenderer->drawDRRect(target, &drawState, color, paint.isAntiAlias(), outer, inner)) {
SkPath path;
path.addRRect(inner);
path.addRRect(outer);
path.setFillType(SkPath::kEvenOdd_FillType);
GrStrokeInfo fillRec(SkStrokeRec::kFill_InitStyle);
- this->internalDrawPath(target, &drawState, color, paint.isAntiAlias(), path, fillRec);
+ this->internalDrawPath(target, &drawState, viewMatrix, color, paint.isAntiAlias(), path,
+ fillRec);
}
}
///////////////////////////////////////////////////////////////////////////////
void GrContext::drawOval(const GrPaint& paint,
+ const SkMatrix& viewMatrix,
const SkRect& oval,
const GrStrokeInfo& strokeInfo) {
if (oval.isEmpty()) {
@@ -968,13 +972,13 @@ void GrContext::drawOval(const GrPaint& paint,
if (strokeInfo.isDashed()) {
SkPath path;
path.addOval(oval);
- this->drawPath(paint, path, strokeInfo);
+ this->drawPath(paint, viewMatrix, path, strokeInfo);
return;
}
AutoCheckFlush acf(this);
GrDrawState drawState;
- GrDrawTarget* target = this->prepareToDraw(&drawState, &paint, &acf);
+ GrDrawTarget* target = this->prepareToDraw(&drawState, &paint, &viewMatrix, &acf);
if (NULL == target) {
return;
}
@@ -984,11 +988,11 @@ void GrContext::drawOval(const GrPaint& paint,
const SkStrokeRec& strokeRec = strokeInfo.getStrokeRec();
GrColor color = paint.getColor();
- if (!fOvalRenderer->drawOval(target, &drawState, color, this, paint.isAntiAlias(), oval,
- strokeRec)) {
+ if (!fOvalRenderer->drawOval(target, &drawState, color, paint.isAntiAlias(), oval, strokeRec)) {
SkPath path;
path.addOval(oval);
- this->internalDrawPath(target, &drawState, color, paint.isAntiAlias(), path, strokeInfo);
+ this->internalDrawPath(target, &drawState, viewMatrix, color, paint.isAntiAlias(), path,
+ strokeInfo);
}
}
@@ -1049,11 +1053,14 @@ static bool is_nested_rects(GrDrawTarget* target,
return allEq || allGoE1;
}
-void GrContext::drawPath(const GrPaint& paint, const SkPath& path, const GrStrokeInfo& strokeInfo) {
+void GrContext::drawPath(const GrPaint& paint,
+ const SkMatrix& viewMatrix,
+ const SkPath& path,
+ const GrStrokeInfo& strokeInfo) {
if (path.isEmpty()) {
if (path.isInverseFillType()) {
- this->drawPaint(paint);
+ this->drawPaint(paint, viewMatrix);
}
return;
}
@@ -1064,7 +1071,7 @@ void GrContext::drawPath(const GrPaint& paint, const SkPath& path, const GrStrok
if (path.isLine(pts)) {
AutoCheckFlush acf(this);
GrDrawState drawState;
- GrDrawTarget* target = this->prepareToDraw(&drawState, &paint, &acf);
+ GrDrawTarget* target = this->prepareToDraw(&drawState, &paint, &viewMatrix, &acf);
if (NULL == target) {
return;
};
@@ -1085,11 +1092,11 @@ void GrContext::drawPath(const GrPaint& paint, const SkPath& path, const GrStrok
GrStrokeInfo newStrokeInfo(strokeInfo, false);
SkStrokeRec* stroke = newStrokeInfo.getStrokeRecPtr();
if (SkDashPath::FilterDashPath(effectPath.init(), path, stroke, NULL, info)) {
- this->drawPath(paint, *effectPath.get(), newStrokeInfo);
+ this->drawPath(paint, viewMatrix, *effectPath.get(), newStrokeInfo);
return;
}
- this->drawPath(paint, path, newStrokeInfo);
+ this->drawPath(paint, viewMatrix, path, newStrokeInfo);
return;
}
@@ -1100,7 +1107,7 @@ void GrContext::drawPath(const GrPaint& paint, const SkPath& path, const GrStrok
// OK.
AutoCheckFlush acf(this);
GrDrawState drawState;
- GrDrawTarget* target = this->prepareToDraw(&drawState, &paint, &acf);
+ GrDrawTarget* target = this->prepareToDraw(&drawState, &paint, &viewMatrix, &acf);
if (NULL == target) {
return;
}
@@ -1131,14 +1138,16 @@ void GrContext::drawPath(const GrPaint& paint, const SkPath& path, const GrStrok
bool isOval = path.isOval(&ovalRect);
if (!isOval || path.isInverseFillType()
- || !fOvalRenderer->drawOval(target, &drawState, color, this, paint.isAntiAlias(), ovalRect,
+ || !fOvalRenderer->drawOval(target, &drawState, color, paint.isAntiAlias(), ovalRect,
strokeRec)) {
- this->internalDrawPath(target, &drawState, color, paint.isAntiAlias(), path, strokeInfo);
+ this->internalDrawPath(target, &drawState, viewMatrix, color, paint.isAntiAlias(), path,
+ strokeInfo);
}
}
void GrContext::internalDrawPath(GrDrawTarget* target,
GrDrawState* drawState,
+ const SkMatrix& viewMatrix,
GrColor color,
bool useAA,
const SkPath& path,
@@ -1169,7 +1178,7 @@ void GrContext::internalDrawPath(GrDrawTarget* target,
GrPathRenderer* pr = this->getPathRenderer(target, drawState, *pathPtr, *stroke, false, type);
if (NULL == pr) {
- if (!GrPathRenderer::IsStrokeHairlineOrEquivalent(*stroke, this->getMatrix(), NULL)) {
+ if (!GrPathRenderer::IsStrokeHairlineOrEquivalent(*stroke, viewMatrix, NULL)) {
// It didn't work the 1st time, so try again with the stroked path
if (stroke->applyToPath(tmpPath.init(), *pathPtr)) {
pathPtr = tmpPath.get();
@@ -1326,7 +1335,7 @@ bool GrContext::writeSurfacePixels(GrSurface* surface,
// drawing a rect to the render target.
// The bracket ensures we pop the stack if we wind up flushing below.
{
- GrDrawTarget* drawTarget = this->prepareToDraw(NULL, NULL, NULL);
+ GrDrawTarget* drawTarget = this->prepareToDraw(NULL, NULL, NULL, NULL);
GrDrawTarget::AutoGeometryPush agp(drawTarget);
GrDrawState drawState(matrix);
@@ -1507,7 +1516,7 @@ void GrContext::discardRenderTarget(GrRenderTarget* renderTarget) {
SkASSERT(renderTarget);
ASSERT_OWNED_RESOURCE(renderTarget);
AutoCheckFlush acf(this);
- GrDrawTarget* target = this->prepareToDraw(NULL, NULL, &acf);
+ GrDrawTarget* target = this->prepareToDraw(NULL, NULL, NULL, &acf);
if (NULL == target) {
return;
}
@@ -1525,7 +1534,7 @@ void GrContext::copySurface(GrSurface* dst, GrSurface* src, const SkIRect& srcRe
// Since we're going to the draw target and not GPU, no need to check kNoFlush
// here.
- GrDrawTarget* target = this->prepareToDraw(NULL, NULL, NULL);
+ GrDrawTarget* target = this->prepareToDraw(NULL, NULL, NULL, NULL);
if (NULL == target) {
return;
}
@@ -1544,6 +1553,7 @@ void GrContext::flushSurfaceWrites(GrSurface* surface) {
GrDrawTarget* GrContext::prepareToDraw(GrDrawState* ds,
const GrPaint* paint,
+ const SkMatrix* viewMatrix,
const AutoCheckFlush* acf) {
if (NULL == fGpu) {
return NULL;
@@ -1551,9 +1561,10 @@ GrDrawTarget* GrContext::prepareToDraw(GrDrawState* ds,
ASSERT_OWNED_RESOURCE(fRenderTarget.get());
if (ds) {
+ SkASSERT(viewMatrix);
if (paint) {
SkASSERT(acf);
- ds->setFromPaint(*paint, fViewMatrix, fRenderTarget.get());
+ ds->setFromPaint(*paint, *viewMatrix, fRenderTarget.get());
#if GR_DEBUG_PARTIAL_COVERAGE_CHECK
if ((paint->hasMask()) &&
!fDrawState->canUseFracCoveragePrimProc(paint.getColor(), fGpu->caps())) {
@@ -1561,7 +1572,7 @@ GrDrawTarget* GrContext::prepareToDraw(GrDrawState* ds,
}
#endif
} else {
- ds->reset(fViewMatrix);
+ ds->reset(*viewMatrix);
ds->setRenderTarget(fRenderTarget.get());
}
ds->setState(GrDrawState::kClip_StateBit, fClip && !fClip->fClipStack->isWideOpen());
@@ -1647,7 +1658,7 @@ void GrContext::setupDrawBuffer() {
}
GrDrawTarget* GrContext::getTextTarget() {
- return this->prepareToDraw(NULL, NULL, NULL);
+ return this->prepareToDraw(NULL, NULL, NULL, NULL);
}
const GrIndexBuffer* GrContext::getQuadIndexBuffer() const {
diff --git a/src/gpu/GrDistanceFieldTextContext.cpp b/src/gpu/GrDistanceFieldTextContext.cpp
index a052b641f6..a6cb285a70 100755
--- a/src/gpu/GrDistanceFieldTextContext.cpp
+++ b/src/gpu/GrDistanceFieldTextContext.cpp
@@ -79,7 +79,7 @@ GrDistanceFieldTextContext::~GrDistanceFieldTextContext() {
SkSafeSetNull(fGammaTexture);
}
-bool GrDistanceFieldTextContext::canDraw(const SkPaint& paint) {
+bool GrDistanceFieldTextContext::canDraw(const SkPaint& paint, const SkMatrix& viewMatrix) {
if (!fEnableDFRendering && !paint.isDistanceFieldTextTEMP()) {
return false;
}
@@ -98,7 +98,7 @@ bool GrDistanceFieldTextContext::canDraw(const SkPaint& paint) {
// TODO: choose an appropriate maximum scale for distance fields and
// enable perspective
- if (SkDraw::ShouldDrawTextAsPaths(paint, fContext->getMatrix())) {
+ if (SkDraw::ShouldDrawTextAsPaths(paint, viewMatrix)) {
return false;
}
@@ -110,7 +110,7 @@ inline void GrDistanceFieldTextContext::init(const GrPaint& paint, const SkPaint
fStrike = NULL;
- const SkMatrix& ctm = fContext->getMatrix();
+ const SkMatrix& ctm = fViewMatrix;
// getMaxScale doesn't support perspective, so neither do we at the moment
SkASSERT(!ctm.hasPerspective());
@@ -200,8 +200,9 @@ static void setup_gamma_texture(GrContext* context, const SkGlyphCache* cache,
}
void GrDistanceFieldTextContext::onDrawText(const GrPaint& paint, const SkPaint& skPaint,
- const char text[], size_t byteLength,
- SkScalar x, SkScalar y) {
+ const SkMatrix& viewMatrix,
+ const char text[], size_t byteLength,
+ SkScalar x, SkScalar y) {
SkASSERT(byteLength == 0 || text != NULL);
// nothing to draw
@@ -209,6 +210,7 @@ void GrDistanceFieldTextContext::onDrawText(const GrPaint& paint, const SkPaint&
return;
}
+ fViewMatrix = viewMatrix;
SkDrawCacheProc glyphCacheProc = skPaint.getDrawCacheProc();
SkAutoGlyphCache autoCache(skPaint, &fDeviceProperties, NULL);
SkGlyphCache* cache = autoCache.getCache();
@@ -258,13 +260,14 @@ void GrDistanceFieldTextContext::onDrawText(const GrPaint& paint, const SkPaint&
y -= alignY;
SkPoint offset = SkPoint::Make(x, y);
- this->drawPosText(paint, skPaint, text, byteLength, positions.begin(), 2, offset);
+ this->drawPosText(paint, skPaint, viewMatrix, text, byteLength, positions.begin(), 2, offset);
}
void GrDistanceFieldTextContext::onDrawPosText(const GrPaint& paint, const SkPaint& skPaint,
- const char text[], size_t byteLength,
- const SkScalar pos[], int scalarsPerPosition,
- const SkPoint& offset) {
+ const SkMatrix& viewMatrix,
+ const char text[], size_t byteLength,
+ const SkScalar pos[], int scalarsPerPosition,
+ const SkPoint& offset) {
SkASSERT(byteLength == 0 || text != NULL);
SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition);
@@ -274,6 +277,7 @@ void GrDistanceFieldTextContext::onDrawPosText(const GrPaint& paint, const SkPai
return;
}
+ fViewMatrix = viewMatrix;
this->init(paint, skPaint);
SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc();
@@ -349,8 +353,9 @@ void GrDistanceFieldTextContext::onDrawPosText(const GrPaint& paint, const SkPai
this->finish();
if (fallbackTxt.count() > 0) {
- fFallbackTextContext->drawPosText(paint, skPaint, fallbackTxt.begin(), fallbackTxt.count(),
- fallbackPos.begin(), scalarsPerPosition, offset);
+ fFallbackTextContext->drawPosText(paint, skPaint, viewMatrix, fallbackTxt.begin(),
+ fallbackTxt.count(), fallbackPos.begin(),
+ scalarsPerPosition, offset);
}
}
@@ -388,7 +393,7 @@ void GrDistanceFieldTextContext::setupCoverageEffect(const SkColor& filteredColo
GrTextureParams gammaParams(SkShader::kClamp_TileMode, GrTextureParams::kNone_FilterMode);
uint32_t textureUniqueID = fCurrTexture->getUniqueID();
- const SkMatrix& ctm = fContext->getMatrix();
+ const SkMatrix& ctm = fViewMatrix;
// set up any flags
uint32_t flags = 0;
@@ -517,7 +522,7 @@ bool GrDistanceFieldTextContext::appendGlyph(GrGlyph::PackedID packed,
// check if we clipped out
SkRect dstRect;
- const SkMatrix& ctm = fContext->getMatrix();
+ const SkMatrix& ctm = fViewMatrix;
(void) ctm.mapRect(&dstRect, glyphRect);
if (fClipRect.quickReject(SkScalarTruncToInt(dstRect.left()),
SkScalarTruncToInt(dstRect.top()),
@@ -544,14 +549,16 @@ bool GrDistanceFieldTextContext::appendGlyph(GrGlyph::PackedID packed,
// flush any accumulated draws before drawing this glyph as a path.
this->flush();
- GrContext::AutoMatrix am;
SkMatrix ctm;
ctm.setScale(fTextRatio, fTextRatio);
ctm.postTranslate(sx - dx, sy - dy);
GrPaint tmpPaint(fPaint);
- am.setPreConcat(fContext, ctm, &tmpPaint);
+ tmpPaint.localCoordChange(ctm);
+
+ SkMatrix viewM = fViewMatrix;
+ viewM.preConcat(ctm);
GrStrokeInfo strokeInfo(SkStrokeRec::kFill_InitStyle);
- fContext->drawPath(tmpPaint, *glyph->fPath, strokeInfo);
+ fContext->drawPath(tmpPaint, viewM, *glyph->fPath, strokeInfo);
// remove this glyph from the vertices we need to allocate
fTotalVertexCount -= kVerticesPerGlyph;
@@ -625,7 +632,7 @@ void GrDistanceFieldTextContext::flush() {
if (fCurrVertex > 0) {
GrDrawState drawState;
- drawState.setFromPaint(fPaint, fContext->getMatrix(), fContext->getRenderTarget());
+ drawState.setFromPaint(fPaint, fViewMatrix, fContext->getRenderTarget());
// setup our sampler state for our text texture/atlas
SkASSERT(SkIsAlign4(fCurrVertex));
diff --git a/src/gpu/GrDistanceFieldTextContext.h b/src/gpu/GrDistanceFieldTextContext.h
index 66774bd015..8f73b06500 100644
--- a/src/gpu/GrDistanceFieldTextContext.h
+++ b/src/gpu/GrDistanceFieldTextContext.h
@@ -46,14 +46,16 @@ private:
int fTotalVertexCount;
GrTexture* fCurrTexture;
SkRect fVertexBounds;
+ SkMatrix fViewMatrix;
GrDistanceFieldTextContext(GrContext*, const SkDeviceProperties&, bool enable);
- virtual bool canDraw(const SkPaint& paint) SK_OVERRIDE;
+ virtual bool canDraw(const SkPaint& paint, const SkMatrix& viewMatrix) SK_OVERRIDE;
- virtual void onDrawText(const GrPaint&, const SkPaint&, const char text[], size_t byteLength,
+ virtual void onDrawText(const GrPaint&, const SkPaint&, const SkMatrix& viewMatrix,
+ const char text[], size_t byteLength,
SkScalar x, SkScalar y) SK_OVERRIDE;
- virtual void onDrawPosText(const GrPaint&, const SkPaint&,
+ virtual void onDrawPosText(const GrPaint&, const SkPaint&, const SkMatrix& viewMatrix,
const char text[], size_t byteLength,
const SkScalar pos[], int scalarsPerPosition,
const SkPoint& offset) SK_OVERRIDE;
diff --git a/src/gpu/GrOvalRenderer.cpp b/src/gpu/GrOvalRenderer.cpp
index 659857a9b2..4e0fed96a1 100644
--- a/src/gpu/GrOvalRenderer.cpp
+++ b/src/gpu/GrOvalRenderer.cpp
@@ -597,7 +597,6 @@ void GrOvalRenderer::reset() {
bool GrOvalRenderer::drawOval(GrDrawTarget* target,
GrDrawState* drawState,
GrColor color,
- const GrContext* context,
bool useAA,
const SkRect& oval,
const SkStrokeRec& stroke)
@@ -610,18 +609,18 @@ bool GrOvalRenderer::drawOval(GrDrawTarget* target,
return false;
}
- const SkMatrix& vm = context->getMatrix();
+ const SkMatrix& vm = drawState->getViewMatrix();
// we can draw circles
if (SkScalarNearlyEqual(oval.width(), oval.height())
&& circle_stays_circle(vm)) {
- this->drawCircle(target, drawState, color, context, useCoverageAA, oval, stroke);
+ this->drawCircle(target, drawState, color, useCoverageAA, oval, stroke);
// if we have shader derivative support, render as device-independent
} else if (target->caps()->shaderDerivativeSupport()) {
- return this->drawDIEllipse(target, drawState, color, context, useCoverageAA, oval, stroke);
+ return this->drawDIEllipse(target, drawState, color, useCoverageAA, oval, stroke);
// otherwise axis-aligned ellipses only
} else if (vm.rectStaysRect()) {
- return this->drawEllipse(target, drawState, color, context, useCoverageAA, oval, stroke);
+ return this->drawEllipse(target, drawState, color, useCoverageAA, oval, stroke);
} else {
return false;
}
@@ -634,7 +633,6 @@ bool GrOvalRenderer::drawOval(GrDrawTarget* target,
void GrOvalRenderer::drawCircle(GrDrawTarget* target,
GrDrawState* drawState,
GrColor color,
- const GrContext* context,
bool useCoverageAA,
const SkRect& circle,
const SkStrokeRec& stroke)
@@ -719,7 +717,7 @@ void GrOvalRenderer::drawCircle(GrDrawTarget* target,
verts[3].fOuterRadius = outerRadius;
verts[3].fInnerRadius = innerRadius;
- target->setIndexSourceToBuffer(context->getGpu()->getQuadIndexBuffer());
+ target->setIndexSourceToBuffer(fGpu->getQuadIndexBuffer());
target->drawIndexedInstances(drawState, gp, kTriangles_GrPrimitiveType, 1, 4, 6, &bounds);
target->resetIndexSource();
}
@@ -729,7 +727,6 @@ void GrOvalRenderer::drawCircle(GrDrawTarget* target,
bool GrOvalRenderer::drawEllipse(GrDrawTarget* target,
GrDrawState* drawState,
GrColor color,
- const GrContext* context,
bool useCoverageAA,
const SkRect& ellipse,
const SkStrokeRec& stroke)
@@ -851,7 +848,7 @@ bool GrOvalRenderer::drawEllipse(GrDrawTarget* target,
verts[3].fOuterRadii = SkPoint::Make(xRadRecip, yRadRecip);
verts[3].fInnerRadii = SkPoint::Make(xInnerRadRecip, yInnerRadRecip);
- target->setIndexSourceToBuffer(context->getGpu()->getQuadIndexBuffer());
+ target->setIndexSourceToBuffer(fGpu->getQuadIndexBuffer());
target->drawIndexedInstances(drawState, gp, kTriangles_GrPrimitiveType, 1, 4, 6, &bounds);
target->resetIndexSource();
@@ -861,7 +858,6 @@ bool GrOvalRenderer::drawEllipse(GrDrawTarget* target,
bool GrOvalRenderer::drawDIEllipse(GrDrawTarget* target,
GrDrawState* drawState,
GrColor color,
- const GrContext* context,
bool useCoverageAA,
const SkRect& ellipse,
const SkStrokeRec& stroke)
@@ -962,7 +958,7 @@ bool GrOvalRenderer::drawDIEllipse(GrDrawTarget* target,
verts[3].fOuterOffset = SkPoint::Make(1.0f + offsetDx, -1.0f - offsetDy);
verts[3].fInnerOffset = SkPoint::Make(innerRatioX + offsetDx, -innerRatioY - offsetDy);
- target->setIndexSourceToBuffer(context->getGpu()->getQuadIndexBuffer());
+ target->setIndexSourceToBuffer(fGpu->getQuadIndexBuffer());
target->drawIndexedInstances(drawState, gp, kTriangles_GrPrimitiveType, 1, 4, 6, &bounds);
target->resetIndexSource();
@@ -994,21 +990,21 @@ static const int kIndicesPerRRect = SK_ARRAY_COUNT(gRRectIndices);
static const int kVertsPerRRect = 16;
static const int kNumRRectsInIndexBuffer = 256;
-GrIndexBuffer* GrOvalRenderer::rRectIndexBuffer(bool isStrokeOnly, GrGpu* gpu) {
+GrIndexBuffer* GrOvalRenderer::rRectIndexBuffer(bool isStrokeOnly) {
if (isStrokeOnly) {
if (NULL == fStrokeRRectIndexBuffer) {
- fStrokeRRectIndexBuffer = gpu->createInstancedIndexBuffer(gRRectIndices,
- kIndicesPerStrokeRRect,
- kNumRRectsInIndexBuffer,
- kVertsPerRRect);
+ fStrokeRRectIndexBuffer = fGpu->createInstancedIndexBuffer(gRRectIndices,
+ kIndicesPerStrokeRRect,
+ kNumRRectsInIndexBuffer,
+ kVertsPerRRect);
}
return fStrokeRRectIndexBuffer;
} else {
if (NULL == fRRectIndexBuffer) {
- fRRectIndexBuffer = gpu->createInstancedIndexBuffer(gRRectIndices,
- kIndicesPerRRect,
- kNumRRectsInIndexBuffer,
- kVertsPerRRect);
+ fRRectIndexBuffer = fGpu->createInstancedIndexBuffer(gRRectIndices,
+ kIndicesPerRRect,
+ kNumRRectsInIndexBuffer,
+ kVertsPerRRect);
}
return fRRectIndexBuffer;
}
@@ -1017,7 +1013,6 @@ GrIndexBuffer* GrOvalRenderer::rRectIndexBuffer(bool isStrokeOnly, GrGpu* gpu) {
bool GrOvalRenderer::drawDRRect(GrDrawTarget* target,
GrDrawState* drawState,
GrColor color,
- GrContext* context,
bool useAA,
const SkRRect& origOuter,
const SkRRect& origInner) {
@@ -1027,8 +1022,8 @@ bool GrOvalRenderer::drawDRRect(GrDrawTarget* target,
GrDrawState::AutoRestoreEffects are;
if (!origInner.isEmpty()) {
SkTCopyOnFirstWrite<SkRRect> inner(origInner);
- if (!context->getMatrix().isIdentity()) {
- if (!origInner.transform(context->getMatrix(), inner.writable())) {
+ if (!drawState->getViewMatrix().isIdentity()) {
+ if (!origInner.transform(drawState->getViewMatrix(), inner.writable())) {
return false;
}
}
@@ -1045,14 +1040,14 @@ bool GrOvalRenderer::drawDRRect(GrDrawTarget* target,
}
SkStrokeRec fillRec(SkStrokeRec::kFill_InitStyle);
- if (this->drawRRect(target, drawState, color, context, useAA, origOuter, fillRec)) {
+ if (this->drawRRect(target, drawState, color, useAA, origOuter, fillRec)) {
return true;
}
SkASSERT(!origOuter.isEmpty());
SkTCopyOnFirstWrite<SkRRect> outer(origOuter);
- if (!context->getMatrix().isIdentity()) {
- if (!origOuter.transform(context->getMatrix(), outer.writable())) {
+ if (!drawState->getViewMatrix().isIdentity()) {
+ if (!origOuter.transform(drawState->getViewMatrix(), outer.writable())) {
return false;
}
}
@@ -1081,12 +1076,11 @@ bool GrOvalRenderer::drawDRRect(GrDrawTarget* target,
bool GrOvalRenderer::drawRRect(GrDrawTarget* target,
GrDrawState* drawState,
GrColor color,
- GrContext* context,
bool useAA,
const SkRRect& rrect,
const SkStrokeRec& stroke) {
if (rrect.isOval()) {
- return this->drawOval(target, drawState, color, context, useAA, rrect.getBounds(), stroke);
+ return this->drawOval(target, drawState, color, useAA, rrect.getBounds(), stroke);
}
bool useCoverageAA = useAA &&
@@ -1098,7 +1092,7 @@ bool GrOvalRenderer::drawRRect(GrDrawTarget* target,
return false;
}
- const SkMatrix& vm = context->getMatrix();
+ const SkMatrix& vm = drawState->getViewMatrix();
if (!vm.rectStaysRect() || !rrect.isSimple()) {
return false;
@@ -1156,7 +1150,7 @@ bool GrOvalRenderer::drawRRect(GrDrawTarget* target,
return false;
}
- GrIndexBuffer* indexBuffer = this->rRectIndexBuffer(isStrokeOnly, context->getGpu());
+ GrIndexBuffer* indexBuffer = this->rRectIndexBuffer(isStrokeOnly);
if (NULL == indexBuffer) {
SkDebugf("Failed to create index buffer!\n");
return false;
diff --git a/src/gpu/GrOvalRenderer.h b/src/gpu/GrOvalRenderer.h
index 85a9354959..c67815c451 100644
--- a/src/gpu/GrOvalRenderer.h
+++ b/src/gpu/GrOvalRenderer.h
@@ -24,7 +24,10 @@ class GrOvalRenderer : public SkRefCnt {
public:
SK_DECLARE_INST_COUNT(GrOvalRenderer)
- GrOvalRenderer() : fRRectIndexBuffer(NULL), fStrokeRRectIndexBuffer(NULL) {}
+ GrOvalRenderer(GrGpu* gpu)
+ : fGpu(gpu)
+ , fRRectIndexBuffer(NULL)
+ , fStrokeRRectIndexBuffer(NULL) {}
~GrOvalRenderer() {
this->reset();
}
@@ -34,21 +37,18 @@ public:
bool drawOval(GrDrawTarget*,
GrDrawState*,
GrColor,
- const GrContext*,
bool useAA,
const SkRect& oval,
const SkStrokeRec& stroke);
bool drawRRect(GrDrawTarget*,
GrDrawState*,
GrColor,
- GrContext*,
bool useAA,
const SkRRect& rrect,
const SkStrokeRec& stroke);
bool drawDRRect(GrDrawTarget* target,
GrDrawState*,
GrColor,
- GrContext* context,
bool useAA,
const SkRRect& outer,
const SkRRect& inner);
@@ -57,27 +57,25 @@ private:
bool drawEllipse(GrDrawTarget* target,
GrDrawState*,
GrColor,
- const GrContext* context,
bool useCoverageAA,
const SkRect& ellipse,
const SkStrokeRec& stroke);
bool drawDIEllipse(GrDrawTarget* target,
GrDrawState*,
GrColor,
- const GrContext* context,
bool useCoverageAA,
const SkRect& ellipse,
const SkStrokeRec& stroke);
void drawCircle(GrDrawTarget* target,
GrDrawState*,
GrColor,
- const GrContext* context,
bool useCoverageAA,
const SkRect& circle,
const SkStrokeRec& stroke);
- GrIndexBuffer* rRectIndexBuffer(bool isStrokeOnly, GrGpu* gpu);
+ GrIndexBuffer* rRectIndexBuffer(bool isStrokeOnly);
+ GrGpu* fGpu;
GrIndexBuffer* fRRectIndexBuffer;
GrIndexBuffer* fStrokeRRectIndexBuffer;
diff --git a/src/gpu/GrStencilAndCoverTextContext.cpp b/src/gpu/GrStencilAndCoverTextContext.cpp
index 42f74ea0f5..7cda4f9f43 100644
--- a/src/gpu/GrStencilAndCoverTextContext.cpp
+++ b/src/gpu/GrStencilAndCoverTextContext.cpp
@@ -40,7 +40,7 @@ GrStencilAndCoverTextContext* GrStencilAndCoverTextContext::Create(GrContext* co
GrStencilAndCoverTextContext::~GrStencilAndCoverTextContext() {
}
-bool GrStencilAndCoverTextContext::canDraw(const SkPaint& paint) {
+bool GrStencilAndCoverTextContext::canDraw(const SkPaint& paint, const SkMatrix& viewMatrix) {
if (paint.getRasterizer()) {
return false;
}
@@ -54,7 +54,7 @@ bool GrStencilAndCoverTextContext::canDraw(const SkPaint& paint) {
// No hairlines unless we can map the 1 px width to the object space.
if (paint.getStyle() == SkPaint::kStroke_Style
&& paint.getStrokeWidth() == 0
- && fContext->getMatrix().hasPerspective()) {
+ && viewMatrix.hasPerspective()) {
return false;
}
@@ -66,6 +66,7 @@ bool GrStencilAndCoverTextContext::canDraw(const SkPaint& paint) {
void GrStencilAndCoverTextContext::onDrawText(const GrPaint& paint,
const SkPaint& skPaint,
+ const SkMatrix& viewMatrix,
const char text[],
size_t byteLength,
SkScalar x, SkScalar y) {
@@ -90,7 +91,7 @@ void GrStencilAndCoverTextContext::onDrawText(const GrPaint& paint,
// will turn off the use of device-space glyphs when perspective transforms
// are in use.
- this->init(paint, skPaint, byteLength, kMaxAccuracy_RenderMode);
+ this->init(paint, skPaint, byteLength, kMaxAccuracy_RenderMode, viewMatrix);
// Transform our starting point.
if (fUsingDeviceSpaceGlyphs) {
@@ -154,6 +155,7 @@ void GrStencilAndCoverTextContext::onDrawText(const GrPaint& paint,
void GrStencilAndCoverTextContext::onDrawPosText(const GrPaint& paint,
const SkPaint& skPaint,
+ const SkMatrix& viewMatrix,
const char text[],
size_t byteLength,
const SkScalar pos[],
@@ -175,7 +177,7 @@ void GrStencilAndCoverTextContext::onDrawPosText(const GrPaint& paint,
// transform is not part of SkPaint::measureText API, and thus we use the
// same glyphs as what were measured.
- this->init(paint, skPaint, byteLength, kMaxPerformance_RenderMode);
+ this->init(paint, skPaint, byteLength, kMaxPerformance_RenderMode, viewMatrix);
SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc();
@@ -226,10 +228,12 @@ static GrPathRange* get_gr_glyphs(GrContext* ctx,
void GrStencilAndCoverTextContext::init(const GrPaint& paint,
const SkPaint& skPaint,
size_t textByteLength,
- RenderMode renderMode) {
+ RenderMode renderMode,
+ const SkMatrix& viewMatrix) {
GrTextContext::init(paint, skPaint);
- fContextInitialMatrix = fContext->getMatrix();
+ fContextInitialMatrix = viewMatrix;
+ fViewMatrix = viewMatrix;
const bool otherBackendsWillDrawAsPaths =
SkDraw::ShouldDrawTextAsPaths(skPaint, fContextInitialMatrix);
@@ -252,7 +256,7 @@ void GrStencilAndCoverTextContext::init(const GrPaint& paint,
// Glyphs loaded by GPU path rendering have an inverted y-direction.
SkMatrix m;
m.setScale(1, -1);
- fContext->setMatrix(m);
+ fViewMatrix = m;
// Post-flip the initial matrix so we're left with just the flip after
// the paint preConcats the inverse.
@@ -328,7 +332,7 @@ void GrStencilAndCoverTextContext::init(const GrPaint& paint,
// Glyphs loaded by GPU path rendering have an inverted y-direction.
textMatrix.setScale(fTextRatio, -fTextRatio);
fPaint.localCoordChange(textMatrix);
- fContext->concatMatrix(textMatrix);
+ fViewMatrix.preConcat(textMatrix);
fGlyphCache = fSkPaint.detachCache(&fDeviceProperties, NULL, true /*ignoreGamma*/);
fGlyphs = canUseRawPaths ?
@@ -339,7 +343,7 @@ void GrStencilAndCoverTextContext::init(const GrPaint& paint,
fStateRestore.set(&fDrawState);
- fDrawState.setFromPaint(fPaint, fContext->getMatrix(), fContext->getRenderTarget());
+ fDrawState.setFromPaint(fPaint, fViewMatrix, fContext->getRenderTarget());
GR_STATIC_CONST_SAME_STENCIL(kStencilPass,
kZero_StencilOp,
@@ -355,15 +359,14 @@ void GrStencilAndCoverTextContext::init(const GrPaint& paint,
SkASSERT(kGlyphBufferSize == fFallbackGlyphsIdx);
}
-bool GrStencilAndCoverTextContext::mapToFallbackContext(GrContext::AutoMatrix& autoMatrix,
- SkMatrix* inverse) {
+bool GrStencilAndCoverTextContext::mapToFallbackContext(SkMatrix* inverse) {
// The current view matrix is flipped because GPU path rendering glyphs have an
// inverted y-direction. Unflip the view matrix for the fallback context. If using
// device-space glyphs, we'll also need to restore the original view matrix since
// we moved that transfomation into our local glyph cache for this scenario. Also
// track the inverse operation so the caller can unmap the paint and glyph positions.
if (fUsingDeviceSpaceGlyphs) {
- autoMatrix.set(fContext, fContextInitialMatrix);
+ fViewMatrix = fContextInitialMatrix;
if (!fContextInitialMatrix.invert(inverse)) {
return false;
}
@@ -371,7 +374,7 @@ bool GrStencilAndCoverTextContext::mapToFallbackContext(GrContext::AutoMatrix& a
} else {
inverse->setScale(1, -1);
const SkMatrix& unflip = *inverse; // unflip is equal to its own inverse.
- autoMatrix.setPreConcat(fContext, unflip);
+ fViewMatrix.preConcat(unflip);
}
return true;
}
@@ -421,14 +424,13 @@ void GrStencilAndCoverTextContext::flush() {
skPaintFallback.setTextAlign(SkPaint::kLeft_Align); // Align has already been accounted for.
skPaintFallback.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
- GrContext::AutoMatrix autoMatrix;
SkMatrix inverse;
- if (this->mapToFallbackContext(autoMatrix, &inverse)) {
+ if (this->mapToFallbackContext(&inverse)) {
paintFallback.localCoordChangeInverse(inverse);
inverse.mapPoints(&fGlyphPositions[fFallbackGlyphsIdx], fallbackGlyphCount);
}
- fFallbackTextContext->drawPosText(paintFallback, skPaintFallback,
+ fFallbackTextContext->drawPosText(paintFallback, skPaintFallback, fViewMatrix,
(char*)&fGlyphIndices[fFallbackGlyphsIdx],
2 * fallbackGlyphCount,
get_xy_scalar_array(&fGlyphPositions[fFallbackGlyphsIdx]),
@@ -449,7 +451,7 @@ void GrStencilAndCoverTextContext::finish() {
fDrawState.stencil()->setDisabled();
fStateRestore.set(NULL);
- fContext->setMatrix(fContextInitialMatrix);
+ fViewMatrix = fContextInitialMatrix;
GrTextContext::finish();
}
diff --git a/src/gpu/GrStencilAndCoverTextContext.h b/src/gpu/GrStencilAndCoverTextContext.h
index 1f608860ed..f053e2ef1c 100644
--- a/src/gpu/GrStencilAndCoverTextContext.h
+++ b/src/gpu/GrStencilAndCoverTextContext.h
@@ -63,22 +63,24 @@ private:
int fQueuedGlyphCount;
int fFallbackGlyphsIdx;
SkMatrix fContextInitialMatrix;
+ SkMatrix fViewMatrix;
bool fUsingDeviceSpaceGlyphs;
GrStencilAndCoverTextContext(GrContext*, const SkDeviceProperties&);
- virtual bool canDraw(const SkPaint& paint) SK_OVERRIDE;
+ virtual bool canDraw(const SkPaint& paint, const SkMatrix& viewMatrix) SK_OVERRIDE;
- virtual void onDrawText(const GrPaint&, const SkPaint&, const char text[],
- size_t byteLength,
+ virtual void onDrawText(const GrPaint&, const SkPaint&, const SkMatrix& viewMatrix,
+ const char text[], size_t byteLength,
SkScalar x, SkScalar y) SK_OVERRIDE;
- virtual void onDrawPosText(const GrPaint&, const SkPaint&,
+ virtual void onDrawPosText(const GrPaint&, const SkPaint&, const SkMatrix& viewMatrix,
const char text[], size_t byteLength,
const SkScalar pos[], int scalarsPerPosition,
const SkPoint& offset) SK_OVERRIDE;
- void init(const GrPaint&, const SkPaint&, size_t textByteLength, RenderMode);
- bool mapToFallbackContext(GrContext::AutoMatrix&, SkMatrix* inverse);
+ void init(const GrPaint&, const SkPaint&, size_t textByteLength, RenderMode,
+ const SkMatrix& viewMatrix);
+ bool mapToFallbackContext(SkMatrix* inverse);
void appendGlyph(const SkGlyph&, const SkPoint&);
void flush();
void finish();
diff --git a/src/gpu/GrTextContext.cpp b/src/gpu/GrTextContext.cpp
index 259ba184aa..e62136507c 100644
--- a/src/gpu/GrTextContext.cpp
+++ b/src/gpu/GrTextContext.cpp
@@ -41,13 +41,14 @@ void GrTextContext::init(const GrPaint& grPaint, const SkPaint& skPaint) {
}
bool GrTextContext::drawText(const GrPaint& paint, const SkPaint& skPaint,
+ const SkMatrix& viewMatrix,
const char text[], size_t byteLength,
SkScalar x, SkScalar y) {
GrTextContext* textContext = this;
do {
- if (textContext->canDraw(skPaint)) {
- textContext->onDrawText(paint, skPaint, text, byteLength, x, y);
+ if (textContext->canDraw(skPaint, viewMatrix)) {
+ textContext->onDrawText(paint, skPaint, viewMatrix, text, byteLength, x, y);
return true;
}
textContext = textContext->fFallbackTextContext;
@@ -57,15 +58,16 @@ bool GrTextContext::drawText(const GrPaint& paint, const SkPaint& skPaint,
}
bool GrTextContext::drawPosText(const GrPaint& paint, const SkPaint& skPaint,
+ const SkMatrix& viewMatrix,
const char text[], size_t byteLength,
const SkScalar pos[], int scalarsPerPosition,
const SkPoint& offset) {
GrTextContext* textContext = this;
do {
- if (textContext->canDraw(skPaint)) {
- textContext->onDrawPosText(paint, skPaint, text, byteLength, pos, scalarsPerPosition,
- offset);
+ if (textContext->canDraw(skPaint, viewMatrix)) {
+ textContext->onDrawPosText(paint, skPaint, viewMatrix, text, byteLength, pos,
+ scalarsPerPosition, offset);
return true;
}
textContext = textContext->fFallbackTextContext;
diff --git a/src/gpu/GrTextContext.h b/src/gpu/GrTextContext.h
index 4f7207b04c..46cede6e87 100644
--- a/src/gpu/GrTextContext.h
+++ b/src/gpu/GrTextContext.h
@@ -25,9 +25,9 @@ class GrTextContext {
public:
virtual ~GrTextContext();
- bool drawText(const GrPaint&, const SkPaint&, const char text[], size_t byteLength,
- SkScalar x, SkScalar y);
- bool drawPosText(const GrPaint&, const SkPaint&,
+ bool drawText(const GrPaint&, const SkPaint&, const SkMatrix& viewMatrix, const char text[],
+ size_t byteLength, SkScalar x, SkScalar y);
+ bool drawPosText(const GrPaint&, const SkPaint&, const SkMatrix& viewMatrix,
const char text[], size_t byteLength,
const SkScalar pos[], int scalarsPerPosition,
const SkPoint& offset);
@@ -44,11 +44,11 @@ protected:
GrTextContext(GrContext*, const SkDeviceProperties&);
- virtual bool canDraw(const SkPaint& paint) = 0;
+ virtual bool canDraw(const SkPaint& paint, const SkMatrix& viewMatrix) = 0;
- virtual void onDrawText(const GrPaint&, const SkPaint&, const char text[], size_t byteLength,
- SkScalar x, SkScalar y) = 0;
- virtual void onDrawPosText(const GrPaint&, const SkPaint&,
+ virtual void onDrawText(const GrPaint&, const SkPaint&, const SkMatrix& viewMatrix,
+ const char text[], size_t byteLength, SkScalar x, SkScalar y) = 0;
+ virtual void onDrawPosText(const GrPaint&, const SkPaint&, const SkMatrix& viewMatrix,
const char text[], size_t byteLength,
const SkScalar pos[], int scalarsPerPosition,
const SkPoint& offset) = 0;
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index 4c9f0e2b7d..040cea8356 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -52,13 +52,13 @@ enum { kDefaultImageFilterCacheSize = 32 * 1024 * 1024 };
#if 0
extern bool (*gShouldDrawProc)();
- #define CHECK_SHOULD_DRAW(draw, forceI) \
+ #define CHECK_SHOULD_DRAW(draw) \
do { \
if (gShouldDrawProc && !gShouldDrawProc()) return; \
- this->prepareDraw(draw, forceI); \
+ this->prepareDraw(draw); \
} while (0)
#else
- #define CHECK_SHOULD_DRAW(draw, forceI) this->prepareDraw(draw, forceI)
+ #define CHECK_SHOULD_DRAW(draw) this->prepareDraw(draw)
#endif
// This constant represents the screen alignment criterion in texels for
@@ -271,18 +271,13 @@ void SkGpuDevice::onDetachFromCanvas() {
// call this every draw call, to ensure that the context reflects our state,
// and not the state from some other canvas/device
-void SkGpuDevice::prepareDraw(const SkDraw& draw, bool forceIdentity) {
+void SkGpuDevice::prepareDraw(const SkDraw& draw) {
SkASSERT(fClipData.fClipStack);
fContext->setRenderTarget(fRenderTarget);
SkASSERT(draw.fClipStack && draw.fClipStack == fClipData.fClipStack);
- if (forceIdentity) {
- fContext->setIdentityMatrix();
- } else {
- fContext->setMatrix(*draw.fMatrix);
- }
fClipData.fOrigin = this->getOrigin();
fContext->setClip(&fClipData);
@@ -319,13 +314,13 @@ SK_COMPILE_ASSERT(SkShader::kLast_BitmapType == 6, shader_type_mismatch);
///////////////////////////////////////////////////////////////////////////////
void SkGpuDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) {
- CHECK_SHOULD_DRAW(draw, false);
+ CHECK_SHOULD_DRAW(draw);
GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawPaint", fContext);
GrPaint grPaint;
- SkPaint2GrPaintShader(this->context(), paint, true, &grPaint);
+ SkPaint2GrPaintShader(this->context(), paint, *draw.fMatrix, true, &grPaint);
- fContext->drawPaint(grPaint);
+ fContext->drawPaint(grPaint, *draw.fMatrix);
}
// must be in SkCanvas::PointMode order
@@ -338,7 +333,7 @@ static const GrPrimitiveType gPointMode2PrimtiveType[] = {
void SkGpuDevice::drawPoints(const SkDraw& draw, SkCanvas::PointMode mode,
size_t count, const SkPoint pts[], const SkPaint& paint) {
CHECK_FOR_ANNOTATION(paint);
- CHECK_SHOULD_DRAW(draw, false);
+ CHECK_SHOULD_DRAW(draw);
SkScalar width = paint.getStrokeWidth();
if (width < 0) {
@@ -348,12 +343,12 @@ void SkGpuDevice::drawPoints(const SkDraw& draw, SkCanvas::PointMode mode,
if (paint.getPathEffect() && 2 == count && SkCanvas::kLines_PointMode == mode) {
GrStrokeInfo strokeInfo(paint, SkPaint::kStroke_Style);
GrPaint grPaint;
- SkPaint2GrPaintShader(this->context(), paint, true, &grPaint);
+ SkPaint2GrPaintShader(this->context(), paint, *draw.fMatrix, true, &grPaint);
SkPath path;
path.setIsVolatile(true);
path.moveTo(pts[0]);
path.lineTo(pts[1]);
- fContext->drawPath(grPaint, path, strokeInfo);
+ fContext->drawPath(grPaint, *draw.fMatrix, path, strokeInfo);
return;
}
@@ -365,9 +360,10 @@ void SkGpuDevice::drawPoints(const SkDraw& draw, SkCanvas::PointMode mode,
}
GrPaint grPaint;
- SkPaint2GrPaintShader(this->context(), paint, true, &grPaint);
+ SkPaint2GrPaintShader(this->context(), paint, *draw.fMatrix, true, &grPaint);
fContext->drawVertices(grPaint,
+ *draw.fMatrix,
gPointMode2PrimtiveType[mode],
SkToS32(count),
(SkPoint*)pts,
@@ -384,7 +380,7 @@ void SkGpuDevice::drawRect(const SkDraw& draw, const SkRect& rect,
GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawRect", fContext);
CHECK_FOR_ANNOTATION(paint);
- CHECK_SHOULD_DRAW(draw, false);
+ CHECK_SHOULD_DRAW(draw);
bool doStroke = paint.getStyle() != SkPaint::kFill_Style;
SkScalar width = paint.getStrokeWidth();
@@ -402,14 +398,14 @@ void SkGpuDevice::drawRect(const SkDraw& draw, const SkRect& rect,
usePath = true;
}
- if (!usePath && paint.isAntiAlias() && !fContext->getMatrix().rectStaysRect()) {
+ if (!usePath && paint.isAntiAlias() && !draw.fMatrix->rectStaysRect()) {
#if defined(SHADER_AA_FILL_RECT) || !defined(IGNORE_ROT_AA_RECT_OPT)
if (doStroke) {
#endif
usePath = true;
#if defined(SHADER_AA_FILL_RECT) || !defined(IGNORE_ROT_AA_RECT_OPT)
} else {
- usePath = !fContext->getMatrix().preservesRightAngles();
+ usePath = !draw.fMatrix->preservesRightAngles();
}
#endif
}
@@ -434,34 +430,34 @@ void SkGpuDevice::drawRect(const SkDraw& draw, const SkRect& rect,
}
GrPaint grPaint;
- SkPaint2GrPaintShader(this->context(), paint, true, &grPaint);
+ SkPaint2GrPaintShader(this->context(), paint, *draw.fMatrix, true, &grPaint);
- fContext->drawRect(grPaint, rect, &strokeInfo);
+ fContext->drawRect(grPaint, *draw.fMatrix, rect, &strokeInfo);
}
///////////////////////////////////////////////////////////////////////////////
void SkGpuDevice::drawRRect(const SkDraw& draw, const SkRRect& rect,
- const SkPaint& paint) {
+ const SkPaint& paint) {
GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawRRect", fContext);
CHECK_FOR_ANNOTATION(paint);
- CHECK_SHOULD_DRAW(draw, false);
+ CHECK_SHOULD_DRAW(draw);
GrPaint grPaint;
- SkPaint2GrPaintShader(this->context(), paint, true, &grPaint);
+ SkPaint2GrPaintShader(this->context(), paint, *draw.fMatrix, true, &grPaint);
GrStrokeInfo strokeInfo(paint);
if (paint.getMaskFilter()) {
// try to hit the fast path for drawing filtered round rects
SkRRect devRRect;
- if (rect.transform(fContext->getMatrix(), &devRRect)) {
+ if (rect.transform(*draw.fMatrix, &devRRect)) {
if (devRRect.allCornersCircular()) {
SkRect maskRect;
if (paint.getMaskFilter()->canFilterMaskGPU(devRRect.rect(),
- draw.fClip->getBounds(),
- fContext->getMatrix(),
- &maskRect)) {
+ draw.fClip->getBounds(),
+ *draw.fMatrix,
+ &maskRect)) {
SkIRect finalIRect;
maskRect.roundOut(&finalIRect);
if (draw.fClip->quickReject(finalIRect)) {
@@ -469,6 +465,7 @@ void SkGpuDevice::drawRRect(const SkDraw& draw, const SkRRect& rect,
return;
}
if (paint.getMaskFilter()->directFilterRRectMaskGPU(fContext, &grPaint,
+ *draw.fMatrix,
strokeInfo.getStrokeRec(),
devRRect)) {
return;
@@ -500,22 +497,22 @@ void SkGpuDevice::drawRRect(const SkDraw& draw, const SkRRect& rect,
return;
}
- fContext->drawRRect(grPaint, rect, strokeInfo);
+ fContext->drawRRect(grPaint, *draw.fMatrix, rect, strokeInfo);
}
void SkGpuDevice::drawDRRect(const SkDraw& draw, const SkRRect& outer,
- const SkRRect& inner, const SkPaint& paint) {
+ const SkRRect& inner, const SkPaint& paint) {
SkStrokeRec stroke(paint);
if (stroke.isFillStyle()) {
CHECK_FOR_ANNOTATION(paint);
- CHECK_SHOULD_DRAW(draw, false);
+ CHECK_SHOULD_DRAW(draw);
GrPaint grPaint;
- SkPaint2GrPaintShader(this->context(), paint, true, &grPaint);
+ SkPaint2GrPaintShader(this->context(), paint, *draw.fMatrix, true, &grPaint);
if (NULL == paint.getMaskFilter() && NULL == paint.getPathEffect()) {
- fContext->drawDRRect(grPaint, outer, inner);
+ fContext->drawDRRect(grPaint, *draw.fMatrix, outer, inner);
return;
}
}
@@ -536,7 +533,7 @@ void SkGpuDevice::drawOval(const SkDraw& draw, const SkRect& oval,
const SkPaint& paint) {
GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawOval", fContext);
CHECK_FOR_ANNOTATION(paint);
- CHECK_SHOULD_DRAW(draw, false);
+ CHECK_SHOULD_DRAW(draw);
GrStrokeInfo strokeInfo(paint);
@@ -560,9 +557,9 @@ void SkGpuDevice::drawOval(const SkDraw& draw, const SkRect& oval,
}
GrPaint grPaint;
- SkPaint2GrPaintShader(this->context(), paint, true, &grPaint);
+ SkPaint2GrPaintShader(this->context(), paint, *draw.fMatrix, true, &grPaint);
- fContext->drawOval(grPaint, oval, strokeInfo);
+ fContext->drawOval(grPaint, *draw.fMatrix, oval, strokeInfo);
}
#include "SkMaskFilter.h"
@@ -575,10 +572,9 @@ namespace {
// Draw a mask using the supplied paint. Since the coverage/geometry
// is already burnt into the mask this boils down to a rect draw.
// Return true if the mask was successfully drawn.
-bool draw_mask(GrContext* context, const SkRect& maskRect,
+bool draw_mask(GrContext* context, const SkMatrix& viewMatrix, const SkRect& maskRect,
GrPaint* grp, GrTexture* mask) {
- GrContext::AutoMatrix am;
- if (!am.setIdentity(context, grp)) {
+ if (!grp->localCoordChangeInverse(viewMatrix)) {
return false;
}
@@ -587,22 +583,22 @@ bool draw_mask(GrContext* context, const SkRect& maskRect,
matrix.postIDiv(mask->width(), mask->height());
grp->addCoverageProcessor(GrSimpleTextureEffect::Create(mask, matrix))->unref();
- context->drawRect(*grp, maskRect);
+ context->drawRect(*grp, SkMatrix::I(), maskRect);
return true;
}
-bool draw_with_mask_filter(GrContext* context, const SkPath& devPath,
+bool draw_with_mask_filter(GrContext* context, const SkMatrix& viewMatrix, const SkPath& devPath,
SkMaskFilter* filter, const SkRegion& clip,
GrPaint* grp, SkPaint::Style style) {
SkMask srcM, dstM;
- if (!SkDraw::DrawToMask(devPath, &clip.getBounds(), filter, &context->getMatrix(), &srcM,
+ if (!SkDraw::DrawToMask(devPath, &clip.getBounds(), filter, &viewMatrix, &srcM,
SkMask::kComputeBoundsAndRenderImage_CreateMode, style)) {
return false;
}
SkAutoMaskFreeImage autoSrc(srcM.fImage);
- if (!filter->filterMask(&dstM, srcM, context->getMatrix(), NULL)) {
+ if (!filter->filterMask(&dstM, srcM, viewMatrix, NULL)) {
return false;
}
// this will free-up dstM when we're done (allocated in filterMask())
@@ -629,7 +625,7 @@ bool draw_with_mask_filter(GrContext* context, const SkPath& devPath,
SkRect maskRect = SkRect::Make(dstM.fBounds);
- return draw_mask(context, maskRect, grp, texture);
+ return draw_mask(context, viewMatrix, maskRect, grp, texture);
}
// Create a mask of 'devPath' and place the result in 'mask'.
@@ -677,13 +673,10 @@ GrTexture* create_mask_GPU(GrContext* context,
tempPaint.setPorterDuffXPFactory(kOne_GrBlendCoeff, kISC_GrBlendCoeff);
}
- GrContext::AutoMatrix am;
-
// Draw the mask into maskTexture with the path's top-left at the origin using tempPaint.
SkMatrix translate;
translate.setTranslate(-maskRect.fLeft, -maskRect.fTop);
- am.set(context, translate);
- context->drawPath(tempPaint, devPath, strokeInfo);
+ context->drawPath(tempPaint, translate, devPath, strokeInfo);
return mask;
}
@@ -700,13 +693,13 @@ void SkGpuDevice::drawPath(const SkDraw& draw, const SkPath& origSrcPath,
const SkPaint& paint, const SkMatrix* prePathMatrix,
bool pathIsMutable) {
CHECK_FOR_ANNOTATION(paint);
- CHECK_SHOULD_DRAW(draw, false);
+ CHECK_SHOULD_DRAW(draw);
GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawPath", fContext);
SkASSERT(!pathIsMutable || origSrcPath.isVolatile());
-
+
GrPaint grPaint;
- SkPaint2GrPaintShader(this->context(), paint, true, &grPaint);
+ SkPaint2GrPaintShader(this->context(), paint, *draw.fMatrix, true, &grPaint);
// If we have a prematrix, apply it to the path, optimizing for the case
// where the original path can in fact be modified in place (even though
@@ -760,16 +753,16 @@ void SkGpuDevice::drawPath(const SkDraw& draw, const SkPath& origSrcPath,
}
// transform the path into device space
- pathPtr->transform(fContext->getMatrix(), devPathPtr);
+ pathPtr->transform(*draw.fMatrix, devPathPtr);
SkRect maskRect;
if (paint.getMaskFilter()->canFilterMaskGPU(devPathPtr->getBounds(),
draw.fClip->getBounds(),
- fContext->getMatrix(),
+ *draw.fMatrix,
&maskRect)) {
// The context's matrix may change while creating the mask, so save the CTM here to
// pass to filterMaskGPU.
- const SkMatrix ctm = fContext->getMatrix();
+ const SkMatrix ctm = *draw.fMatrix;
SkIRect finalIRect;
maskRect.roundOut(&finalIRect);
@@ -778,7 +771,7 @@ void SkGpuDevice::drawPath(const SkDraw& draw, const SkPath& origSrcPath,
return;
}
- if (paint.getMaskFilter()->directFilterMaskGPU(fContext, &grPaint,
+ if (paint.getMaskFilter()->directFilterMaskGPU(fContext, &grPaint, *draw.fMatrix,
stroke, *devPathPtr)) {
// the mask filter was able to draw itself directly, so there's nothing
// left to do.
@@ -795,7 +788,7 @@ void SkGpuDevice::drawPath(const SkDraw& draw, const SkPath& origSrcPath,
if (paint.getMaskFilter()->filterMaskGPU(mask, ctm, maskRect, &filtered, true)) {
// filterMaskGPU gives us ownership of a ref to the result
SkAutoTUnref<GrTexture> atu(filtered);
- if (draw_mask(fContext, maskRect, &grPaint, filtered)) {
+ if (draw_mask(fContext, *draw.fMatrix, maskRect, &grPaint, filtered)) {
// This path is completely drawn
return;
}
@@ -807,12 +800,12 @@ void SkGpuDevice::drawPath(const SkDraw& draw, const SkPath& origSrcPath,
// GPU path fails
SkPaint::Style style = stroke.isHairlineStyle() ? SkPaint::kStroke_Style :
SkPaint::kFill_Style;
- draw_with_mask_filter(fContext, *devPathPtr, paint.getMaskFilter(),
+ draw_with_mask_filter(fContext, *draw.fMatrix, *devPathPtr, paint.getMaskFilter(),
*draw.fClip, &grPaint, style);
return;
}
- fContext->drawPath(grPaint, *pathPtr, strokeInfo);
+ fContext->drawPath(grPaint, *draw.fMatrix, *pathPtr, strokeInfo);
}
static const int kBmpSmallTileSize = 1 << 10;
@@ -844,13 +837,14 @@ static int determine_tile_size(const SkBitmap& bitmap, const SkIRect& src, int m
// Given a bitmap, an optional src rect, and a context with a clip and matrix determine what
// pixels from the bitmap are necessary.
static void determine_clipped_src_rect(const GrContext* context,
+ const SkMatrix& viewMatrix,
const SkBitmap& bitmap,
const SkRect* srcRectPtr,
SkIRect* clippedSrcIRect) {
const GrClipData* clip = context->getClip();
clip->getConservativeBounds(context->getRenderTarget(), clippedSrcIRect, NULL);
SkMatrix inv;
- if (!context->getMatrix().invert(&inv)) {
+ if (!viewMatrix.invert(&inv)) {
clippedSrcIRect->setEmpty();
return;
}
@@ -872,6 +866,7 @@ static void determine_clipped_src_rect(const GrContext* context,
}
bool SkGpuDevice::shouldTileBitmap(const SkBitmap& bitmap,
+ const SkMatrix& viewMatrix,
const GrTextureParams& params,
const SkRect* srcRectPtr,
int maxTileSize,
@@ -884,7 +879,7 @@ bool SkGpuDevice::shouldTileBitmap(const SkBitmap& bitmap,
// if it's larger than the max tile size, then we have no choice but tiling.
if (bitmap.width() > maxTileSize || bitmap.height() > maxTileSize) {
- determine_clipped_src_rect(fContext, bitmap, srcRectPtr, clippedSrcRect);
+ determine_clipped_src_rect(fContext, viewMatrix, bitmap, srcRectPtr, clippedSrcRect);
*tileSize = determine_tile_size(bitmap, *clippedSrcRect, maxTileSize);
return true;
}
@@ -913,7 +908,7 @@ bool SkGpuDevice::shouldTileBitmap(const SkBitmap& bitmap,
}
// Figure out how much of the src we will need based on the src rect and clipping.
- determine_clipped_src_rect(fContext, bitmap, srcRectPtr, clippedSrcRect);
+ determine_clipped_src_rect(fContext, viewMatrix, bitmap, srcRectPtr, clippedSrcRect);
*tileSize = kBmpSmallTileSize; // already know whole bitmap fits in one max sized tile.
size_t usedTileBytes = get_tile_count(*clippedSrcRect, kBmpSmallTileSize) *
kBmpSmallTileSize * kBmpSmallTileSize;
@@ -1041,7 +1036,7 @@ void SkGpuDevice::drawBitmapCommon(const SkDraw& draw,
const SkSize* dstSizePtr,
const SkPaint& paint,
SkCanvas::DrawBitmapRectFlags flags) {
- CHECK_SHOULD_DRAW(draw, false);
+ CHECK_SHOULD_DRAW(draw);
SkRect srcRect;
SkSize dstSize;
@@ -1077,12 +1072,12 @@ void SkGpuDevice::drawBitmapCommon(const SkDraw& draw,
// we check whether dst rect are pixel aligned
if (!directDraw) {
- bool staysRect = fContext->getMatrix().rectStaysRect();
+ bool staysRect = draw.fMatrix->rectStaysRect();
if (staysRect) {
SkRect rect;
SkRect dstRect = SkRect::MakeXYWH(0, 0, dstSize.fWidth, dstSize.fHeight);
- fContext->getMatrix().mapRect(&rect, dstRect);
+ draw.fMatrix->mapRect(&rect, dstRect);
const SkScalar *scalars = rect.asScalars();
bool isDstPixelAligned = true;
for (int i = 0; i < 4; i++) {
@@ -1145,7 +1140,8 @@ void SkGpuDevice::drawBitmapCommon(const SkDraw& draw,
SkMatrix m;
m.setScale(dstSize.fWidth / srcRect.width(),
dstSize.fHeight / srcRect.height());
- fContext->concatMatrix(m);
+ SkMatrix viewM = *draw.fMatrix;
+ viewM.preConcat(m);
GrTextureParams params;
SkPaint::FilterLevel paintFilterLevel = paint.getFilterLevel();
@@ -1161,7 +1157,7 @@ void SkGpuDevice::drawBitmapCommon(const SkDraw& draw,
textureFilterMode = GrTextureParams::kBilerp_FilterMode;
break;
case SkPaint::kMedium_FilterLevel:
- if (fContext->getMatrix().getMinScale() < SK_Scalar1) {
+ if (viewM.getMinScale() < SK_Scalar1) {
textureFilterMode = GrTextureParams::kMipMap_FilterMode;
} else {
// Don't trigger MIP level generation unnecessarily.
@@ -1171,7 +1167,7 @@ void SkGpuDevice::drawBitmapCommon(const SkDraw& draw,
case SkPaint::kHigh_FilterLevel:
// Minification can look bad with the bicubic effect.
doBicubic =
- GrBicubicEffect::ShouldUseBicubic(fContext->getMatrix(), &textureFilterMode);
+ GrBicubicEffect::ShouldUseBicubic(viewM, &textureFilterMode);
break;
default:
SkErrorInternals::SetError( kInvalidPaint_SkError,
@@ -1196,18 +1192,19 @@ void SkGpuDevice::drawBitmapCommon(const SkDraw& draw,
int tileSize;
SkIRect clippedSrcRect;
- if (this->shouldTileBitmap(bitmap, params, srcRectPtr, maxTileSize, &tileSize,
+ if (this->shouldTileBitmap(bitmap, viewM, params, srcRectPtr, maxTileSize, &tileSize,
&clippedSrcRect)) {
- this->drawTiledBitmap(bitmap, srcRect, clippedSrcRect, params, paint, flags, tileSize,
- doBicubic);
+ this->drawTiledBitmap(bitmap, viewM, srcRect, clippedSrcRect, params, paint, flags,
+ tileSize, doBicubic);
} else {
// take the simple case
bool needsTextureDomain = needs_texture_domain(bitmap,
srcRect,
params,
- fContext->getMatrix(),
+ viewM,
doBicubic);
this->internalDrawBitmap(bitmap,
+ viewM,
srcRect,
params,
paint,
@@ -1220,6 +1217,7 @@ void SkGpuDevice::drawBitmapCommon(const SkDraw& draw,
// Break 'bitmap' into several tiles to draw it since it has already
// been determined to be too large to fit in VRAM
void SkGpuDevice::drawTiledBitmap(const SkBitmap& bitmap,
+ const SkMatrix& viewMatrix,
const SkRect& srcRect,
const SkIRect& clippedSrcIRect,
const GrTextureParams& params,
@@ -1259,10 +1257,10 @@ void SkGpuDevice::drawTiledBitmap(const SkBitmap& bitmap,
SkIntToScalar(iTileR.fTop));
// Adjust the context matrix to draw at the right x,y in device space
+ SkMatrix viewM = viewMatrix;
SkMatrix tmpM;
- GrContext::AutoMatrix am;
tmpM.setTranslate(offset.fX - srcRect.fLeft, offset.fY - srcRect.fTop);
- am.setPreConcat(fContext, tmpM);
+ viewM.preConcat(tmpM);
if (GrTextureParams::kNone_FilterMode != params.filterMode() || bicubic) {
SkIRect iClampRect;
@@ -1288,9 +1286,10 @@ void SkGpuDevice::drawTiledBitmap(const SkBitmap& bitmap,
bool needsTextureDomain = needs_texture_domain(bitmap,
srcRect,
paramsTemp,
- fContext->getMatrix(),
+ viewM,
bicubic);
this->internalDrawBitmap(tmpB,
+ viewM,
tileR,
paramsTemp,
paint,
@@ -1311,6 +1310,7 @@ void SkGpuDevice::drawTiledBitmap(const SkBitmap& bitmap,
* and that non-texture portion of the GrPaint has already been setup.
*/
void SkGpuDevice::internalDrawBitmap(const SkBitmap& bitmap,
+ const SkMatrix& viewMatrix,
const SkRect& srcRect,
const GrTextureParams& params,
const SkPaint& paint,
@@ -1359,10 +1359,10 @@ void SkGpuDevice::internalDrawBitmap(const SkBitmap& bitmap,
fp.reset(GrBicubicEffect::Create(texture, SkMatrix::I(), textureDomain));
} else {
fp.reset(GrTextureDomainEffect::Create(texture,
- SkMatrix::I(),
- textureDomain,
- GrTextureDomain::kClamp_Mode,
- params.filterMode()));
+ SkMatrix::I(),
+ textureDomain,
+ GrTextureDomain::kClamp_Mode,
+ params.filterMode()));
}
} else if (bicubic) {
SkASSERT(GrTextureParams::kNone_FilterMode == params.filterMode());
@@ -1381,7 +1381,7 @@ void SkGpuDevice::internalDrawBitmap(const SkBitmap& bitmap,
SkColor2GrColor(paint.getColor());
SkPaint2GrPaintNoShader(this->context(), paint, paintColor, false, &grPaint);
- fContext->drawRectToRect(grPaint, dstRect, paintRect);
+ fContext->drawRectToRect(grPaint, viewMatrix, dstRect, paintRect);
}
bool SkGpuDevice::filterTexture(GrContext* context, GrTexture* texture,
@@ -1407,7 +1407,7 @@ bool SkGpuDevice::filterTexture(GrContext* context, GrTexture* texture,
void SkGpuDevice::drawSprite(const SkDraw& draw, const SkBitmap& bitmap,
int left, int top, const SkPaint& paint) {
// drawSprite is defined to be in device coords.
- CHECK_SHOULD_DRAW(draw, true);
+ CHECK_SHOULD_DRAW(draw);
SkAutoLockPixels alp(bitmap, !bitmap.getTexture());
if (!bitmap.getTexture() && !bitmap.readyToDraw()) {
@@ -1453,6 +1453,7 @@ void SkGpuDevice::drawSprite(const SkDraw& draw, const SkBitmap& bitmap,
false, &grPaint);
fContext->drawRectToRect(grPaint,
+ SkMatrix::I(),
SkRect::MakeXYWH(SkIntToScalar(left),
SkIntToScalar(top),
SkIntToScalar(w),
@@ -1520,7 +1521,7 @@ void SkGpuDevice::drawDevice(const SkDraw& draw, SkBaseDevice* device,
}
// drawDevice is defined to be in device coords.
- CHECK_SHOULD_DRAW(draw, true);
+ CHECK_SHOULD_DRAW(draw);
GrRenderTarget* devRT = dev->accessRenderTarget();
GrTexture* devTex;
@@ -1573,7 +1574,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, dstRect, srcRect);
+ fContext->drawRectToRect(grPaint, SkMatrix::I(), dstRect, srcRect);
}
bool SkGpuDevice::canHandleImageFilter(const SkImageFilter* filter) {
@@ -1616,8 +1617,7 @@ void SkGpuDevice::drawVertices(const SkDraw& draw, SkCanvas::VertexMode vmode,
SkXfermode* xmode,
const uint16_t indices[], int indexCount,
const SkPaint& paint) {
- CHECK_SHOULD_DRAW(draw, false);
-
+ CHECK_SHOULD_DRAW(draw);
GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawVertices", fContext);
const uint16_t* outIndices;
@@ -1678,7 +1678,7 @@ void SkGpuDevice::drawVertices(const SkDraw& draw, SkCanvas::VertexMode vmode,
SkPaint2GrPaintNoShader(this->context(), paint, SkColor2GrColor(paint.getColor()),
NULL == colors, &grPaint);
} else {
- SkPaint2GrPaintShader(this->context(), paint, NULL == colors, &grPaint);
+ SkPaint2GrPaintShader(this->context(), paint, *draw.fMatrix, NULL == colors, &grPaint);
}
}
@@ -1706,6 +1706,7 @@ void SkGpuDevice::drawVertices(const SkDraw& draw, SkCanvas::VertexMode vmode,
colors = convertedColors.get();
}
fContext->drawVertices(grPaint,
+ *draw.fMatrix,
primType,
vertexCount,
vertices,
@@ -1718,17 +1719,18 @@ void SkGpuDevice::drawVertices(const SkDraw& draw, SkCanvas::VertexMode vmode,
///////////////////////////////////////////////////////////////////////////////
void SkGpuDevice::drawText(const SkDraw& draw, const void* text,
- size_t byteLength, SkScalar x, SkScalar y,
- const SkPaint& paint) {
- CHECK_SHOULD_DRAW(draw, false);
+ size_t byteLength, SkScalar x, SkScalar y,
+ const SkPaint& paint) {
+ CHECK_SHOULD_DRAW(draw);
GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawText", fContext);
GrPaint grPaint;
- SkPaint2GrPaintShader(this->context(), paint, true, &grPaint);
+ SkPaint2GrPaintShader(this->context(), paint, *draw.fMatrix, true, &grPaint);
SkDEBUGCODE(this->validate();)
- if (!fTextContext->drawText(grPaint, paint, (const char *)text, byteLength, x, y)) {
+ if (!fTextContext->drawText(grPaint, paint, *draw.fMatrix, (const char *)text, byteLength, x,
+ y)) {
// this will just call our drawPath()
draw.drawText_asPaths((const char*)text, byteLength, x, y, paint);
}
@@ -1738,24 +1740,24 @@ void SkGpuDevice::drawPosText(const SkDraw& draw, const void* text, size_t byteL
const SkScalar pos[], int scalarsPerPos,
const SkPoint& offset, const SkPaint& paint) {
GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawPosText", fContext);
- CHECK_SHOULD_DRAW(draw, false);
+ CHECK_SHOULD_DRAW(draw);
GrPaint grPaint;
- SkPaint2GrPaintShader(this->context(), paint, true, &grPaint);
+ SkPaint2GrPaintShader(this->context(), paint, *draw.fMatrix, true, &grPaint);
SkDEBUGCODE(this->validate();)
- if (!fTextContext->drawPosText(grPaint, paint, (const char *)text, byteLength, pos,
- scalarsPerPos, offset)) {
+ if (!fTextContext->drawPosText(grPaint, paint, *draw.fMatrix, (const char *)text, byteLength,
+ pos, scalarsPerPos, offset)) {
// this will just call our drawPath()
draw.drawPosText_asPaths((const char*)text, byteLength, pos, scalarsPerPos, offset, paint);
}
}
void SkGpuDevice::drawTextOnPath(const SkDraw& draw, const void* text,
- size_t len, const SkPath& path,
- const SkMatrix* m, const SkPaint& paint) {
- CHECK_SHOULD_DRAW(draw, false);
+ size_t len, const SkPath& path,
+ const SkMatrix* m, const SkPaint& paint) {
+ CHECK_SHOULD_DRAW(draw);
SkASSERT(draw.fDevice == this);
draw.drawTextOnPath((const char*)text, len, path, m, paint);
diff --git a/src/gpu/SkGpuDevice.h b/src/gpu/SkGpuDevice.h
index b600f993cd..773110023c 100644
--- a/src/gpu/SkGpuDevice.h
+++ b/src/gpu/SkGpuDevice.h
@@ -163,9 +163,8 @@ private:
virtual bool forceConservativeRasterClip() const SK_OVERRIDE { return true; }
- // sets the render target, clip, and matrix on GrContext. Use forceIdenity to override
- // SkDraw's matrix and draw in device coords.
- void prepareDraw(const SkDraw&, bool forceIdentity);
+ // sets the render target and clip on context
+ void prepareDraw(const SkDraw&);
/**
* Implementation for both drawBitmap and drawBitmapRect.
@@ -184,12 +183,14 @@ private:
// The tileSize and clippedSrcRect will be valid only if true is returned.
bool shouldTileBitmap(const SkBitmap& bitmap,
+ const SkMatrix& viewMatrix,
const GrTextureParams& sampler,
const SkRect* srcRectPtr,
int maxTileSize,
int* tileSize,
SkIRect* clippedSrcRect) const;
void internalDrawBitmap(const SkBitmap&,
+ const SkMatrix& viewMatrix,
const SkRect&,
const GrTextureParams& params,
const SkPaint& paint,
@@ -197,6 +198,7 @@ private:
bool bicubic,
bool needsTextureDomain);
void drawTiledBitmap(const SkBitmap& bitmap,
+ const SkMatrix& viewMatrix,
const SkRect& srcRect,
const SkIRect& clippedSrcRect,
const GrTextureParams& params,
diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp
index 82b1ce4b87..e311ae2ace 100644
--- a/src/gpu/SkGr.cpp
+++ b/src/gpu/SkGr.cpp
@@ -283,10 +283,8 @@ static GrTexture *load_yuv_texture(GrContext* ctx, bool cache, const GrTexturePa
SkRect r = SkRect::MakeWH(SkIntToScalar(yuvSizes[0].fWidth),
SkIntToScalar(yuvSizes[0].fHeight));
GrContext::AutoRenderTarget autoRT(ctx, renderTarget);
- GrContext::AutoMatrix am;
- am.setIdentity(ctx);
GrContext::AutoClip ac(ctx, GrContext::AutoClip::kWideOpen_InitialClip);
- ctx->drawRect(paint, r);
+ ctx->drawRect(paint, SkMatrix::I(), r);
} else {
SkSafeSetNull(result);
}
@@ -522,27 +520,7 @@ void SkPaint2GrPaintNoShader(GrContext* context, const SkPaint& skPaint, GrColor
#endif
}
-/**
- * Unlike GrContext::AutoMatrix, this doesn't require setting a new matrix. GrContext::AutoMatrix
- * likes to set the new matrix in its constructor because it is usually necessary to simulataneously
- * update a GrPaint. This AutoMatrix is used while initially setting up GrPaint, however.
- */
-class AutoMatrix {
-public:
- AutoMatrix(GrContext* context) {
- fMatrix = context->getMatrix();
- fContext = context;
- }
- ~AutoMatrix() {
- SkASSERT(fContext);
- fContext->setMatrix(fMatrix);
- }
-private:
- GrContext* fContext;
- SkMatrix fMatrix;
-};
-
-void SkPaint2GrPaintShader(GrContext* context, const SkPaint& skPaint,
+void SkPaint2GrPaintShader(GrContext* context, const SkPaint& skPaint, const SkMatrix& viewM,
bool constantColor, GrPaint* grPaint) {
SkShader* shader = skPaint.getShader();
if (NULL == shader) {
@@ -558,17 +536,14 @@ void SkPaint2GrPaintShader(GrContext* context, const SkPaint& skPaint,
// want them messing around with the context.
{
// SkShader::asFragmentProcessor() may do offscreen rendering. Save off the current RT,
- // clip, and matrix. We don't reset the matrix on the context because
- // SkShader::asFragmentProcessor may use GrContext::getMatrix() to know the transformation
- // from local coords to device space.
+ // and clip
GrContext::AutoRenderTarget art(context, NULL);
GrContext::AutoClip ac(context, GrContext::AutoClip::kWideOpen_InitialClip);
- AutoMatrix am(context);
// Allow the shader to modify paintColor and also create an effect to be installed as
// the first color effect on the GrPaint.
GrFragmentProcessor* fp = NULL;
- if (shader->asFragmentProcessor(context, skPaint, NULL, &paintColor, &fp) && fp) {
+ if (shader->asFragmentProcessor(context, skPaint, viewM, NULL, &paintColor, &fp) && fp) {
grPaint->addColorProcessor(fp)->unref();
constantColor = false;
}
diff --git a/src/gpu/effects/GrConfigConversionEffect.cpp b/src/gpu/effects/GrConfigConversionEffect.cpp
index 55ae54e9ae..3a658ace26 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, kDstRect, kSrcRect);
+ context->drawRectToRect(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, kDstRect, kSrcRect);
+ context->drawRectToRect(paint2, SkMatrix::I(), kDstRect, kSrcRect);
context->setRenderTarget(readTex->asRenderTarget());
GrPaint paint3;
paint3.addColorProcessor(pmToUPM2);
- context->drawRectToRect(paint3, kDstRect, kSrcRect);
+ context->drawRectToRect(paint3, SkMatrix::I(), kDstRect, kSrcRect);
readTex->readPixels(0, 0, 256, 256, kRGBA_8888_GrPixelConfig, secondRead);