aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-10-05 20:13:28 +0000
committerGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-10-05 20:13:28 +0000
commit5b3e890c376f2211218c43edd11939cfc78fd60a (patch)
tree83fbe3b7080aade2d97934bdf4779b050415791e /src
parentc7448cef098b835d6f9adf8a365fde9de076f178 (diff)
Move some auto restore helpers from GrDrawTarget to GrDrawState.
R=robertphillips@google.com git-svn-id: http://skia.googlecode.com/svn/trunk@5846 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src')
-rw-r--r--src/gpu/GrContext.cpp4
-rw-r--r--src/gpu/GrDrawState.cpp41
-rw-r--r--src/gpu/GrDrawState.h48
-rw-r--r--src/gpu/GrDrawTarget.cpp41
-rw-r--r--src/gpu/GrDrawTarget.h48
-rw-r--r--src/gpu/GrInOrderDrawBuffer.cpp4
-rw-r--r--src/gpu/GrSWMaskHelper.cpp2
-rw-r--r--src/gpu/GrSoftwarePathRenderer.cpp2
8 files changed, 95 insertions, 95 deletions
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index 3e53c19ff8..7e0c915fc9 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -743,7 +743,7 @@ void GrContext::drawRect(const GrPaint& paint,
&useVertexCoverage);
if (doAA) {
- GrDrawTarget::AutoDeviceCoordDraw adcd(target);
+ GrDrawState::AutoDeviceCoordDraw adcd(target->drawState());
if (!adcd.succeeded()) {
return;
}
@@ -1034,7 +1034,7 @@ void GrContext::drawOval(const GrPaint& paint,
return;
}
- GrDrawTarget::AutoDeviceCoordDraw adcd(target);
+ GrDrawState::AutoDeviceCoordDraw adcd(drawState);
if (!adcd.succeeded()) {
return;
}
diff --git a/src/gpu/GrDrawState.cpp b/src/gpu/GrDrawState.cpp
index f798cda59c..b9b708e4bf 100644
--- a/src/gpu/GrDrawState.cpp
+++ b/src/gpu/GrDrawState.cpp
@@ -46,3 +46,44 @@ void GrDrawState::setFromPaint(const GrPaint& paint) {
this->setColorFilter(paint.getColorFilterColor(), paint.getColorFilterMode());
this->setCoverage(paint.getCoverage());
}
+
+////////////////////////////////////////////////////////////////////////////////
+
+GrDrawState::AutoDeviceCoordDraw::AutoDeviceCoordDraw(GrDrawState* drawState,
+ uint32_t explicitCoordStageMask) {
+ GrAssert(NULL != drawState);
+
+ fDrawState = drawState;
+ fViewMatrix = drawState->getViewMatrix();
+ fRestoreMask = 0;
+ GrMatrix invVM;
+ bool inverted = false;
+
+ for (int s = 0; s < GrDrawState::kNumStages; ++s) {
+ if (!(explicitCoordStageMask & (1 << s)) && drawState->isStageEnabled(s)) {
+ if (!inverted && !fViewMatrix.invert(&invVM)) {
+ // sad trombone sound
+ fDrawState = NULL;
+ return;
+ } else {
+ inverted = true;
+ }
+ fRestoreMask |= (1 << s);
+ GrSamplerState* sampler = drawState->sampler(s);
+ fSamplerMatrices[s] = sampler->getMatrix();
+ sampler->preConcatMatrix(invVM);
+ }
+ }
+ drawState->viewMatrix()->reset();
+}
+
+GrDrawState::AutoDeviceCoordDraw::~AutoDeviceCoordDraw() {
+ if (NULL != fDrawState) {
+ fDrawState->setViewMatrix(fViewMatrix);
+ for (int s = 0; s < GrDrawState::kNumStages; ++s) {
+ if (fRestoreMask & (1 << s)) {
+ *fDrawState->sampler(s)->matrix() = fSamplerMatrices[s];
+ }
+ }
+ }
+}
diff --git a/src/gpu/GrDrawState.h b/src/gpu/GrDrawState.h
index ca3b2c18ab..ea8f418364 100644
--- a/src/gpu/GrDrawState.h
+++ b/src/gpu/GrDrawState.h
@@ -135,6 +135,24 @@ public:
GrColor getColorFilterColor() const { return fColorFilterColor; }
SkXfermode::Mode getColorFilterMode() const { return fColorFilterMode; }
+ /**
+ * Constructor sets the color to be 'color' which is undone by the destructor.
+ */
+ class AutoColorRestore : public ::GrNoncopyable {
+ public:
+ AutoColorRestore(GrDrawState* drawState, GrColor color) {
+ fDrawState = drawState;
+ fOldColor = fDrawState->getColor();
+ fDrawState->setColor(color);
+ }
+ ~AutoColorRestore() {
+ fDrawState->setColor(fOldColor);
+ }
+ private:
+ GrDrawState* fDrawState;
+ GrColor fOldColor;
+ };
+
/// @}
///////////////////////////////////////////////////////////////////////////
@@ -446,6 +464,11 @@ public:
return false;
}
+ ////////////////////////////////////////////////////////////////////////////
+
+ /**
+ * TODO: Automatically handle stage matrices.
+ */
class AutoViewMatrixRestore : public ::GrNoncopyable {
public:
AutoViewMatrixRestore() : fDrawState(NULL) {}
@@ -485,6 +508,31 @@ public:
GrMatrix fSavedMatrix;
};
+ ////////////////////////////////////////////////////////////////////////////
+
+ /**
+ * This sets the view matrix to identity and adjusts stage matrices to
+ * compensate. The destructor undoes the changes, restoring the view matrix
+ * that was set before the constructor.
+ */
+ class AutoDeviceCoordDraw : ::GrNoncopyable {
+ public:
+ /**
+ * If a stage's texture matrix is applied to explicit per-vertex coords,
+ * rather than to positions, then we don't want to modify its matrix.
+ * The explicitCoordStageMask is used to specify such stages.
+ */
+ AutoDeviceCoordDraw(GrDrawState* drawState,
+ uint32_t explicitCoordStageMask = 0);
+ bool succeeded() const { return NULL != fDrawState; }
+ ~AutoDeviceCoordDraw();
+ private:
+ GrDrawState* fDrawState;
+ GrMatrix fViewMatrix;
+ GrMatrix fSamplerMatrices[GrDrawState::kNumStages];
+ int fRestoreMask;
+ };
+
/// @}
///////////////////////////////////////////////////////////////////////////
diff --git a/src/gpu/GrDrawTarget.cpp b/src/gpu/GrDrawTarget.cpp
index ab345bc6cb..4c028c3d0a 100644
--- a/src/gpu/GrDrawTarget.cpp
+++ b/src/gpu/GrDrawTarget.cpp
@@ -1160,47 +1160,6 @@ void GrDrawTarget::AutoStateRestore::set(GrDrawTarget* target, ASRInit init) {
////////////////////////////////////////////////////////////////////////////////
-GrDrawTarget::AutoDeviceCoordDraw::AutoDeviceCoordDraw(GrDrawTarget* target,
- uint32_t explicitCoordStageMask) {
- GrAssert(NULL != target);
- GrDrawState* drawState = target->drawState();
-
- fDrawTarget = target;
- fViewMatrix = drawState->getViewMatrix();
- fRestoreMask = 0;
- GrMatrix invVM;
- bool inverted = false;
-
- for (int s = 0; s < GrDrawState::kNumStages; ++s) {
- if (!(explicitCoordStageMask & (1 << s)) && drawState->isStageEnabled(s)) {
- if (!inverted && !fViewMatrix.invert(&invVM)) {
- // sad trombone sound
- fDrawTarget = NULL;
- return;
- } else {
- inverted = true;
- }
- fRestoreMask |= (1 << s);
- GrSamplerState* sampler = drawState->sampler(s);
- fSamplerMatrices[s] = sampler->getMatrix();
- sampler->preConcatMatrix(invVM);
- }
- }
- drawState->viewMatrix()->reset();
-}
-
-GrDrawTarget::AutoDeviceCoordDraw::~AutoDeviceCoordDraw() {
- GrDrawState* drawState = fDrawTarget->drawState();
- drawState->setViewMatrix(fViewMatrix);
- for (int s = 0; s < GrDrawState::kNumStages; ++s) {
- if (fRestoreMask & (1 << s)) {
- *drawState->sampler(s)->matrix() = fSamplerMatrices[s];
- }
- }
-}
-
-////////////////////////////////////////////////////////////////////////////////
-
GrDrawTarget::AutoReleaseGeometry::AutoReleaseGeometry(
GrDrawTarget* target,
GrVertexLayout vertexLayout,
diff --git a/src/gpu/GrDrawTarget.h b/src/gpu/GrDrawTarget.h
index b975f69797..134cccd9de 100644
--- a/src/gpu/GrDrawTarget.h
+++ b/src/gpu/GrDrawTarget.h
@@ -599,54 +599,6 @@ public:
////////////////////////////////////////////////////////////////////////////
- /**
- * Sets the view matrix to I and preconcats all stage matrices enabled in
- * mask by the view inverse. Destructor undoes these changes.
- */
- class AutoDeviceCoordDraw : ::GrNoncopyable {
- public:
- /**
- * If a stage's texture matrix is applied to explicit per-vertex coords,
- * rather than to positions, then we don't want to modify its matrix.
- * The explicitCoordStageMask is used to specify such stages.
- *
- * TODO: Remove this when custom stage's control their own texture
- * matrix and there is a "view matrix has changed" notification to the
- * custom stages.
- */
- AutoDeviceCoordDraw(GrDrawTarget* target,
- uint32_t explicitCoordStageMask = 0);
- bool succeeded() const { return NULL != fDrawTarget; }
- ~AutoDeviceCoordDraw();
- private:
- GrDrawTarget* fDrawTarget;
- GrMatrix fViewMatrix;
- GrMatrix fSamplerMatrices[GrDrawState::kNumStages];
- int fRestoreMask;
- };
-
- ////////////////////////////////////////////////////////////////////////////
-
- /**
- * Constructor sets the color to be 'color' which is undone by the destructor.
- */
- class AutoColorRestore : public ::GrNoncopyable {
- public:
- AutoColorRestore(GrDrawTarget* target, GrColor color) {
- fDrawTarget = target;
- fOldColor = target->drawState()->getColor();
- target->drawState()->setColor(color);
- }
- ~AutoColorRestore() {
- fDrawTarget->drawState()->setColor(fOldColor);
- }
- private:
- GrDrawTarget* fDrawTarget;
- GrColor fOldColor;
- };
-
- ////////////////////////////////////////////////////////////////////////////
-
class AutoReleaseGeometry : ::GrNoncopyable {
public:
AutoReleaseGeometry(GrDrawTarget* target,
diff --git a/src/gpu/GrInOrderDrawBuffer.cpp b/src/gpu/GrInOrderDrawBuffer.cpp
index c3c1e8982a..eaee5c9204 100644
--- a/src/gpu/GrInOrderDrawBuffer.cpp
+++ b/src/gpu/GrInOrderDrawBuffer.cpp
@@ -115,7 +115,7 @@ void GrInOrderDrawBuffer::drawRect(const GrRect& rect,
}
}
}
- GrDrawTarget::AutoDeviceCoordDraw adcd(this, explicitCoordMask);
+ GrDrawState::AutoDeviceCoordDraw adcd(this->drawState(), explicitCoordMask);
if (!adcd.succeeded()) {
return;
}
@@ -129,7 +129,7 @@ void GrInOrderDrawBuffer::drawRect(const GrRect& rect,
// Now that the paint's color is stored in the vertices set it to
// white so that the following code can batch all the rects regardless
// of paint color
- AutoColorRestore acr(this, SK_ColorWHITE);
+ GrDrawState::AutoColorRestore acr(this->drawState(), SK_ColorWHITE);
// we don't want to miss an opportunity to batch rects together
// simply because the clip has changed if the clip doesn't affect
diff --git a/src/gpu/GrSWMaskHelper.cpp b/src/gpu/GrSWMaskHelper.cpp
index 9e7012bfca..ec0dbf188f 100644
--- a/src/gpu/GrSWMaskHelper.cpp
+++ b/src/gpu/GrSWMaskHelper.cpp
@@ -202,7 +202,7 @@ void GrSWMaskHelper::DrawToTargetWithPathMask(GrTexture* texture,
const GrIRect& rect) {
GrDrawState* drawState = target->drawState();
- GrDrawTarget::AutoDeviceCoordDraw adcd(target);
+ GrDrawState::AutoDeviceCoordDraw adcd(drawState);
if (!adcd.succeeded()) {
return;
}
diff --git a/src/gpu/GrSoftwarePathRenderer.cpp b/src/gpu/GrSoftwarePathRenderer.cpp
index edac161c91..a2c5867c51 100644
--- a/src/gpu/GrSoftwarePathRenderer.cpp
+++ b/src/gpu/GrSoftwarePathRenderer.cpp
@@ -75,7 +75,7 @@ bool get_path_and_clip_bounds(const GrDrawTarget* target,
void draw_around_inv_path(GrDrawTarget* target,
const GrIRect& devClipBounds,
const GrIRect& devPathBounds) {
- GrDrawTarget::AutoDeviceCoordDraw adcd(target);
+ GrDrawState::AutoDeviceCoordDraw adcd(target->drawState());
if (!adcd.succeeded()) {
return;
}