Minor refactoring to make GrAutoMatrix a nested sub-class of GrContext
http://codereview.appspot.com/6356092/ git-svn-id: http://skia.googlecode.com/svn/trunk@4549 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
parent
19393dff0c
commit
fea85ac3e3
@ -662,6 +662,44 @@ public:
|
||||
GrRenderTarget* fPrevTarget;
|
||||
};
|
||||
|
||||
/**
|
||||
* Save/restore the view-matrix in the context.
|
||||
*/
|
||||
class AutoMatrix : GrNoncopyable {
|
||||
public:
|
||||
AutoMatrix() : fContext(NULL) {}
|
||||
AutoMatrix(GrContext* ctx) : fContext(ctx) {
|
||||
fMatrix = ctx->getMatrix();
|
||||
}
|
||||
AutoMatrix(GrContext* ctx, const GrMatrix& matrix) : fContext(ctx) {
|
||||
fMatrix = ctx->getMatrix();
|
||||
ctx->setMatrix(matrix);
|
||||
}
|
||||
void set(GrContext* ctx) {
|
||||
if (NULL != fContext) {
|
||||
fContext->setMatrix(fMatrix);
|
||||
}
|
||||
fMatrix = ctx->getMatrix();
|
||||
fContext = ctx;
|
||||
}
|
||||
void set(GrContext* ctx, const GrMatrix& matrix) {
|
||||
if (NULL != fContext) {
|
||||
fContext->setMatrix(fMatrix);
|
||||
}
|
||||
fMatrix = ctx->getMatrix();
|
||||
ctx->setMatrix(matrix);
|
||||
fContext = ctx;
|
||||
}
|
||||
~AutoMatrix() {
|
||||
if (NULL != fContext) {
|
||||
fContext->setMatrix(fMatrix);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
GrContext* fContext;
|
||||
GrMatrix fMatrix;
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Functions intended for internal use only.
|
||||
@ -781,45 +819,6 @@ private:
|
||||
typedef GrRefCnt INHERITED;
|
||||
};
|
||||
|
||||
/**
|
||||
* Save/restore the view-matrix in the context.
|
||||
*/
|
||||
class GrAutoMatrix : GrNoncopyable {
|
||||
public:
|
||||
GrAutoMatrix() : fContext(NULL) {}
|
||||
GrAutoMatrix(GrContext* ctx) : fContext(ctx) {
|
||||
fMatrix = ctx->getMatrix();
|
||||
}
|
||||
GrAutoMatrix(GrContext* ctx, const GrMatrix& matrix) : fContext(ctx) {
|
||||
fMatrix = ctx->getMatrix();
|
||||
ctx->setMatrix(matrix);
|
||||
}
|
||||
void set(GrContext* ctx) {
|
||||
if (NULL != fContext) {
|
||||
fContext->setMatrix(fMatrix);
|
||||
}
|
||||
fMatrix = ctx->getMatrix();
|
||||
fContext = ctx;
|
||||
}
|
||||
void set(GrContext* ctx, const GrMatrix& matrix) {
|
||||
if (NULL != fContext) {
|
||||
fContext->setMatrix(fMatrix);
|
||||
}
|
||||
fMatrix = ctx->getMatrix();
|
||||
ctx->setMatrix(matrix);
|
||||
fContext = ctx;
|
||||
}
|
||||
~GrAutoMatrix() {
|
||||
if (NULL != fContext) {
|
||||
fContext->setMatrix(fMatrix);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
GrContext* fContext;
|
||||
GrMatrix fMatrix;
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets and locks a scratch texture from a descriptor using
|
||||
* either exact or approximate criteria. Unlocks texture in
|
||||
|
@ -643,7 +643,7 @@ void GrContext::drawPaint(const GrPaint& paint) {
|
||||
GrMatrix inverse;
|
||||
SkTLazy<GrPaint> tmpPaint;
|
||||
const GrPaint* p = &paint;
|
||||
GrAutoMatrix am;
|
||||
AutoMatrix am;
|
||||
|
||||
// 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
|
||||
@ -1824,7 +1824,7 @@ GrTexture* GrContext::gaussianBlur(GrTexture* srcTexture,
|
||||
GrRenderTarget* oldRenderTarget = this->getRenderTarget();
|
||||
GrClip oldClip = this->getClip();
|
||||
GrTexture* origTexture = srcTexture;
|
||||
GrAutoMatrix avm(this, GrMatrix::I());
|
||||
AutoMatrix avm(this, GrMatrix::I());
|
||||
SkIRect clearRect;
|
||||
int scaleFactorX, radiusX;
|
||||
int scaleFactorY, radiusY;
|
||||
@ -1949,7 +1949,7 @@ GrTexture* GrContext::applyMorphology(GrTexture* srcTexture,
|
||||
SkISize radius) {
|
||||
ASSERT_OWNED_RESOURCE(srcTexture);
|
||||
GrRenderTarget* oldRenderTarget = this->getRenderTarget();
|
||||
GrAutoMatrix avm(this, GrMatrix::I());
|
||||
AutoMatrix avm(this, GrMatrix::I());
|
||||
GrClip oldClip = this->getClip();
|
||||
|
||||
GrClip newClip(GrRect::MakeWH(SkIntToScalar(srcTexture->width()),
|
||||
|
@ -822,7 +822,7 @@ bool drawWithGPUMaskFilter(GrContext* context, const SkPath& path,
|
||||
GrPaint tempPaint;
|
||||
tempPaint.reset();
|
||||
|
||||
GrAutoMatrix avm(context, GrMatrix::I());
|
||||
GrContext::AutoMatrix avm(context, GrMatrix::I());
|
||||
tempPaint.fAntiAlias = grp->fAntiAlias;
|
||||
if (tempPaint.fAntiAlias) {
|
||||
// AA uses the "coverage" stages on GrDrawTarget. Coverage with a dst
|
||||
@ -929,7 +929,7 @@ bool drawWithMaskFilter(GrContext* context, const SkPath& path,
|
||||
// used to compute inverse view, if necessary
|
||||
GrMatrix ivm = matrix;
|
||||
|
||||
GrAutoMatrix avm(context, GrMatrix::I());
|
||||
GrContext::AutoMatrix avm(context, GrMatrix::I());
|
||||
|
||||
GrTextureDesc desc;
|
||||
desc.fWidth = dstM.fBounds.width();
|
||||
@ -1435,7 +1435,7 @@ void apply_custom_stage(GrContext* context,
|
||||
const GrRect& rect,
|
||||
GrCustomStage* stage) {
|
||||
SkASSERT(srcTexture && srcTexture->getContext() == context);
|
||||
GrAutoMatrix avm(context, GrMatrix::I());
|
||||
GrContext::AutoMatrix avm(context, GrMatrix::I());
|
||||
GrContext::AutoRenderTarget art(context, dstTexture->asRenderTarget());
|
||||
GrClip oldClip = context->getClip();
|
||||
|
||||
@ -1516,7 +1516,7 @@ void SkGpuDevice::drawSprite(const SkDraw& draw, const SkBitmap& bitmap,
|
||||
return;
|
||||
}
|
||||
|
||||
GrAutoMatrix avm(fContext, GrMatrix::I());
|
||||
GrContext::AutoMatrix avm(fContext, GrMatrix::I());
|
||||
|
||||
GrSamplerState* sampler = grPaint.textureSampler(kBitmapTextureIdx);
|
||||
|
||||
@ -1582,7 +1582,7 @@ void SkGpuDevice::drawDevice(const SkDraw& draw, SkDevice* device,
|
||||
int w = bm.width();
|
||||
int h = bm.height();
|
||||
|
||||
GrAutoMatrix avm(fContext, GrMatrix::I());
|
||||
GrContext::AutoMatrix avm(fContext, GrMatrix::I());
|
||||
|
||||
grPaint.textureSampler(kBitmapTextureIdx)->reset();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user