Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Unified Diff: src/gpu/GrDrawTarget.h

Issue 13468004: Make drawRect preserve vertex attrib state and push/pop the geom sources. (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/gpu/GrDrawState.h ('k') | src/gpu/GrDrawTarget.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/GrDrawTarget.h
===================================================================
--- src/gpu/GrDrawTarget.h (revision 8471)
+++ src/gpu/GrDrawTarget.h (working copy)
@@ -331,17 +331,9 @@
void stencilPath(const GrPath*, const SkStrokeRec& stroke, SkPath::FillType fill);
/**
- * Helper function for drawing rects. This does not use the current index
- * and vertex sources. After returning, the vertex and index sources may
- * have changed. They should be reestablished before the next draw call.
- * This cannot be called between reserving and releasing
- * geometry.
+ * Helper function for drawing rects. It performs a geometry src push and pop
+ * and thus will finalize any reserved geometry.
*
- * A subclass may override this to perform more optimal rect rendering. Its
- * draws should be funneled through one of the public GrDrawTarget draw methods
- * (e.g. drawNonIndexed, drawIndexedInstances, ...). The base class draws a two
- * triangle fan using drawNonIndexed from reserved vertex space.
- *
* @param rect the rect to draw
* @param matrix optional matrix applied to rect (before viewMatrix)
* @param localRect optional rect that specifies local coords to map onto
@@ -351,10 +343,13 @@
* then srcRect will be transformed by srcMatrix.
* srcMatrix can be NULL when no srcMatrix is desired.
*/
- virtual void drawRect(const GrRect& rect,
- const SkMatrix* matrix,
- const GrRect* localRect,
- const SkMatrix* localMatrix);
+ void drawRect(const GrRect& rect,
+ const SkMatrix* matrix,
+ const GrRect* localRect,
+ const SkMatrix* localMatrix) {
+ AutoGeometryPush agp(this);
+ this->onDrawRect(rect, matrix, localRect, localMatrix);
+ }
/**
* Helper for drawRect when the caller doesn't need separate local rects or matrices.
@@ -533,20 +528,47 @@
////////////////////////////////////////////////////////////////////////////
+ /**
+ * Saves the geometry src state at construction and restores in the destructor. It also saves
+ * and then restores the vertex attrib state.
+ */
+ class AutoGeometryPush : ::GrNoncopyable {
+ public:
+ AutoGeometryPush(GrDrawTarget* target)
+ : fAttribRestore(target->drawState()) {
+ GrAssert(NULL != target);
+ fTarget = target;
+ target->pushGeometrySource();
+ }
+
+ ~AutoGeometryPush() { fTarget->popGeometrySource(); }
+
+ private:
+ GrDrawTarget* fTarget;
+ GrDrawState::AutoVertexAttribRestore fAttribRestore;
+ };
+
+ /**
+ * Combination of AutoGeometryPush and AutoStateRestore. The vertex attribs will be in default
+ * state regardless of ASRInit value.
jvanverth1 2013/04/02 18:45:35 Maybe I'm misunderstanding. What happens if the pu
bsalomon 2013/04/02 18:47:39 It's already using an AutoStateRestore. So it will
+ */
class AutoGeometryAndStatePush : ::GrNoncopyable {
public:
AutoGeometryAndStatePush(GrDrawTarget* target, ASRInit init)
- : fState(target, init) {
+ : fState(target, init){
GrAssert(NULL != target);
fTarget = target;
target->pushGeometrySource();
+ if (kPreserve_ASRInit == init) {
+ target->drawState()->setDefaultVertexAttribs();
+ }
}
- ~AutoGeometryAndStatePush() {
- fTarget->popGeometrySource();
- }
+
+ ~AutoGeometryAndStatePush() { fTarget->popGeometrySource(); }
+
private:
+ AutoStateRestore fState;
GrDrawTarget* fTarget;
- AutoStateRestore fState;
};
protected:
@@ -717,6 +739,16 @@
virtual void geometrySourceWillPop(const GeometrySrcState& restoredState) = 0;
// subclass called to perform drawing
virtual void onDraw(const DrawInfo&) = 0;
+ // Implementation of drawRect. The geometry src and vertex attribs will already
+ // be saved before this is called and restored afterwards. A subclass may override
+ // this to perform more optimal rect rendering. Its draws should be funneled through
+ // one of the public GrDrawTarget draw methods (e.g. drawNonIndexed,
+ // drawIndexedInstances, ...). The base class draws a two triangle fan using
+ // drawNonIndexed from reserved vertex space.
+ virtual void onDrawRect(const GrRect& rect,
+ const SkMatrix* matrix,
+ const GrRect* localRect,
+ const SkMatrix* localMatrix);
virtual void onStencilPath(const GrPath*, const SkStrokeRec& stroke, SkPath::FillType fill) = 0;
// helpers for reserving vertex and index space.
« no previous file with comments | « src/gpu/GrDrawState.h ('k') | src/gpu/GrDrawTarget.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698