Make a separate path renderer object. Move enum types to GrTypes.h
Review URL http://codereview.appspot.com/4167067/
git-svn-id: http://skia.googlecode.com/svn/trunk@829 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/gpu/include/GrContext.h b/gpu/include/GrContext.h
index 93c012c..9df7105 100644
--- a/gpu/include/GrContext.h
+++ b/gpu/include/GrContext.h
@@ -27,6 +27,7 @@
class GrVertexBufferAllocPool;
class GrIndexBufferAllocPool;
class GrInOrderDrawBuffer;
+class GrPathRenderer;
class GrContext : public GrRefCnt {
public:
@@ -277,19 +278,6 @@
const GrMatrix* srcMatrix = NULL);
/**
- * Path filling rules
- */
- enum PathFills {
- kWinding_PathFill,
- kEvenOdd_PathFill,
- kInverseWinding_PathFill,
- kInverseEvenOdd_PathFill,
- kHairLine_PathFill,
-
- kPathFillCount
- };
-
- /**
* Tessellates and draws a path.
*
* @param paint describes how to color pixels.
@@ -300,7 +288,7 @@
*/
void drawPath(const GrPaint& paint,
GrPathIter* path,
- PathFills fill,
+ GrPathFill fill,
const GrPoint* translate = NULL);
/**
* Draws vertices with a paint.
@@ -319,7 +307,7 @@
* number of indices.
*/
void drawVertices(const GrPaint& paint,
- GrDrawTarget::PrimitiveType primitiveType,
+ GrPrimitiveType primitiveType,
int vertexCount,
const GrPoint positions[],
const GrPoint texs[],
@@ -358,7 +346,7 @@
typename COL_SRC,
typename IDX_SRC>
void drawCustomVertices(const GrPaint& paint,
- GrDrawTarget::PrimitiveType primitiveType,
+ GrPrimitiveType primitiveType,
const POS_SRC& posSrc,
const TEX_SRC* texCoordSrc,
const COL_SRC* colorSrc,
@@ -369,16 +357,16 @@
*/
template <typename POS_SRC>
void drawCustomVertices(const GrPaint& paint,
- GrDrawTarget::PrimitiveType primitiveType,
+ GrPrimitiveType primitiveType,
const POS_SRC& posSrc);
template <typename POS_SRC, typename TEX_SRC>
void drawCustomVertices(const GrPaint& paint,
- GrDrawTarget::PrimitiveType primitiveType,
+ GrPrimitiveType primitiveType,
const POS_SRC& posSrc,
const TEX_SRC* texCoordSrc);
template <typename POS_SRC, typename TEX_SRC, typename COL_SRC>
void drawCustomVertices(const GrPaint& paint,
- GrDrawTarget::PrimitiveType primitiveType,
+ GrPrimitiveType primitiveType,
const POS_SRC& posSrc,
const TEX_SRC* texCoordSrc,
const COL_SRC* colorSrc);
@@ -466,6 +454,7 @@
GrGpu* fGpu;
GrTextureCache* fTextureCache;
GrFontCache* fFontCache;
+ GrPathRenderer* fPathRenderer;
GrVertexBufferAllocPool* fDrawBufferVBAllocPool;
GrIndexBufferAllocPool* fDrawBufferIBAllocPool;
diff --git a/gpu/include/GrContext_impl.h b/gpu/include/GrContext_impl.h
index 8af38e6..c0a2107 100644
--- a/gpu/include/GrContext_impl.h
+++ b/gpu/include/GrContext_impl.h
@@ -20,7 +20,7 @@
template <typename POS_SRC, typename TEX_SRC,
typename COL_SRC, typename IDX_SRC>
inline void GrContext::drawCustomVertices(const GrPaint& paint,
- GrDrawTarget::PrimitiveType primitiveType,
+ GrPrimitiveType primitiveType,
const POS_SRC& posSrc,
const TEX_SRC* texCoordSrc,
const COL_SRC* colorSrc,
@@ -101,7 +101,7 @@
template <typename POS_SRC>
inline void GrContext::drawCustomVertices(const GrPaint& paint,
- GrDrawTarget::PrimitiveType primitiveType,
+ GrPrimitiveType primitiveType,
const POS_SRC& posSrc) {
this->drawCustomVertices<POS_SRC,
GrNullTexCoordSource,
@@ -112,7 +112,7 @@
template <typename POS_SRC, typename TEX_SRC>
inline void GrContext::drawCustomVertices(const GrPaint& paint,
- GrDrawTarget::PrimitiveType primitiveType,
+ GrPrimitiveType primitiveType,
const POS_SRC& posSrc,
const TEX_SRC* texCoordSrc) {
this->drawCustomVertices<POS_SRC, TEX_SRC,
@@ -123,7 +123,7 @@
template <typename POS_SRC, typename TEX_SRC, typename COL_SRC>
inline void GrContext::drawCustomVertices(const GrPaint& paint,
- GrDrawTarget::PrimitiveType primitiveType,
+ GrPrimitiveType primitiveType,
const POS_SRC& posSrc,
const TEX_SRC* texCoordSrc,
const COL_SRC* colorSrc) {
diff --git a/gpu/include/GrDrawTarget.h b/gpu/include/GrDrawTarget.h
index 9c78902..929b9ff 100644
--- a/gpu/include/GrDrawTarget.h
+++ b/gpu/include/GrDrawTarget.h
@@ -52,16 +52,10 @@
};
/**
- * Geometric primitives used for drawing.
+ * Bitfield used to indicate which stages are in use.
*/
- enum PrimitiveType {
- kTriangles_PrimitiveType,
- kTriangleStrip_PrimitiveType,
- kTriangleFan_PrimitiveType,
- kPoints_PrimitiveType,
- kLines_PrimitiveType,
- kLineStrip_PrimitiveType
- };
+ typedef int StageBitfield;
+ GR_STATIC_ASSERT(sizeof(StageBitfield)*8 >= kNumStages);
/**
* Flags that affect rendering. Controlled using enable/disableState(). All
@@ -81,22 +75,6 @@
};
/**
- * Coeffecients for alpha-blending.
- */
- enum BlendCoeff {
- kZero_BlendCoeff, //<! 0
- kOne_BlendCoeff, //<! 1
- kSC_BlendCoeff, //<! src color
- kISC_BlendCoeff, //<! one minus src color
- kDC_BlendCoeff, //<! dst color
- kIDC_BlendCoeff, //<! one minus dst color
- kSA_BlendCoeff, //<! src alpha
- kISA_BlendCoeff, //<! one minus src alpha
- kDA_BlendCoeff, //<! dst alpha
- kIDA_BlendCoeff, //<! one minus dst alpha
- };
-
- /**
* StencilPass
*
* Sets the stencil state for subsequent draw calls. Used to fill paths.
@@ -145,8 +123,8 @@
struct DrState {
uint32_t fFlagBits;
- BlendCoeff fSrcBlend;
- BlendCoeff fDstBlend;
+ GrBlendCoeff fSrcBlend;
+ GrBlendCoeff fDstBlend;
GrTexture* fTextures[kNumStages];
GrSamplerState fSamplerStates[kNumStages];
GrRenderTarget* fRenderTarget;
@@ -362,7 +340,7 @@
* @param srcCoef coeffecient applied to the src color.
* @param dstCoef coeffecient applied to the dst color.
*/
- void setBlendFunc(BlendCoeff srcCoef, BlendCoeff dstCoef);
+ void setBlendFunc(GrBlendCoeff srcCoef, GrBlendCoeff dstCoef);
/**
* Used to save and restore the GrGpu's drawing state
@@ -645,7 +623,7 @@
* is effectively trimmed to the last completely
* specified primitive.
*/
- virtual void drawIndexed(PrimitiveType type,
+ virtual void drawIndexed(GrPrimitiveType type,
int startVertex,
int startIndex,
int vertexCount,
@@ -660,7 +638,7 @@
* to index 0
* @param vertexCount one greater than the max index.
*/
- virtual void drawNonIndexed(PrimitiveType type,
+ virtual void drawNonIndexed(GrPrimitiveType type,
int startVertex,
int vertexCount) = 0;
@@ -674,8 +652,8 @@
* drawNonIndexed.
* @param rect the rect to draw
* @param matrix optional matrix applied to rect (before viewMatrix)
- * @param stageEnableMask bitmask indicating which stages are enabled.
- * Bit i indicates whether stage i is enabled.
+ * @param stageEnableBitfield bitmask indicating which stages are enabled.
+ * Bit i indicates whether stage i is enabled.
* @param srcRects specifies rects for stages enabled by stageEnableMask.
* if stageEnableMask bit i is 1, srcRects is not NULL,
* and srcRects[i] is not NULL, then srcRects[i] will be
@@ -689,7 +667,7 @@
*/
virtual void drawRect(const GrRect& rect,
const GrMatrix* matrix,
- int stageEnableMask,
+ StageBitfield stageEnableBitfield,
const GrRect* srcRects[],
const GrMatrix* srcMatrices[]);
@@ -699,8 +677,8 @@
*/
void drawSimpleRect(const GrRect& rect,
const GrMatrix* matrix,
- int stageEnableMask) {
- drawRect(rect, matrix, stageEnableMask, NULL, NULL);
+ StageBitfield stageEnableBitfield) {
+ drawRect(rect, matrix, stageEnableBitfield, NULL, NULL);
}
///////////////////////////////////////////////////////////////////////////
@@ -1003,7 +981,7 @@
// Helpers for drawRect, protected so subclasses that override drawRect
// can use them.
- static GrVertexLayout GetRectVertexLayout(int stageEnableMask,
+ static GrVertexLayout GetRectVertexLayout(StageBitfield stageEnableBitfield,
const GrRect* srcRects[]);
static void SetRectVertices(const GrRect& rect,
diff --git a/gpu/include/GrGpu.h b/gpu/include/GrGpu.h
index cfa1509..661708b 100644
--- a/gpu/include/GrGpu.h
+++ b/gpu/include/GrGpu.h
@@ -284,13 +284,13 @@
int maxTextureDimension() const { return fMaxTextureDimension; }
// GrDrawTarget overrides
- virtual void drawIndexed(PrimitiveType type,
+ virtual void drawIndexed(GrPrimitiveType type,
int startVertex,
int startIndex,
int vertexCount,
int indexCount);
- virtual void drawNonIndexed(PrimitiveType type,
+ virtual void drawNonIndexed(GrPrimitiveType type,
int startVertex,
int vertexCount);
@@ -351,7 +351,7 @@
virtual void clipWillBeSet(const GrClip& newClip);
// prepares clip flushes gpu state before a draw
- bool setupClipAndFlushState(PrimitiveType type);
+ bool setupClipAndFlushState(GrPrimitiveType type);
// defaults to false, subclass can set true to support palleted textures
bool f8bitPaletteSupport;
@@ -398,13 +398,13 @@
void finalizeReservedIndices();
// overridden by API specific GrGpu-derived class to perform the draw call.
- virtual void drawIndexedHelper(PrimitiveType type,
+ virtual void drawIndexedHelper(GrPrimitiveType type,
uint32_t startVertex,
uint32_t startIndex,
uint32_t vertexCount,
uint32_t indexCount) = 0;
- virtual void drawNonIndexedHelper(PrimitiveType type,
+ virtual void drawNonIndexedHelper(GrPrimitiveType type,
uint32_t vertexCount,
uint32_t numVertices) = 0;
@@ -421,7 +421,7 @@
// deltas from previous state at draw time. This function does the
// API-specific flush of the state
// returns false if current state is unsupported.
- virtual bool flushGraphicsState(PrimitiveType type) = 0;
+ virtual bool flushGraphicsState(GrPrimitiveType type) = 0;
// Sets the scissor rect, or disables if rect is NULL.
virtual void flushScissor(const GrIRect* rect) = 0;
diff --git a/gpu/include/GrInOrderDrawBuffer.h b/gpu/include/GrInOrderDrawBuffer.h
index 0dba8e3..d59eb96 100644
--- a/gpu/include/GrInOrderDrawBuffer.h
+++ b/gpu/include/GrInOrderDrawBuffer.h
@@ -81,12 +81,12 @@
void playback(GrDrawTarget* target);
// overrides from GrDrawTarget
- virtual void drawIndexed(PrimitiveType primitiveType,
+ virtual void drawIndexed(GrPrimitiveType primitiveType,
int startVertex,
int startIndex,
int vertexCount,
int indexCount);
- virtual void drawNonIndexed(PrimitiveType primitiveType,
+ virtual void drawNonIndexed(GrPrimitiveType primitiveType,
int startVertex,
int vertexCount);
@@ -103,7 +103,7 @@
private:
struct Draw {
- PrimitiveType fPrimitiveType;
+ GrPrimitiveType fPrimitiveType;
int fStartVertex;
int fStartIndex;
int fVertexCount;
diff --git a/gpu/include/GrPaint.h b/gpu/include/GrPaint.h
index 770647a..a34cbaf 100644
--- a/gpu/include/GrPaint.h
+++ b/gpu/include/GrPaint.h
@@ -18,8 +18,8 @@
#define GrPaint_DEFINED
#include "GrTexture.h"
+#include "GrColor.h"
#include "GrSamplerState.h"
-#include "GrDrawTarget.h"
/**
* The paint describes how pixels are colored when the context draws to
@@ -29,8 +29,8 @@
public:
// All the paint fields are public except texture (it's ref-counted)
- GrDrawTarget::BlendCoeff fSrcBlendCoeff;
- GrDrawTarget::BlendCoeff fDstBlendCoeff;
+ GrBlendCoeff fSrcBlendCoeff;
+ GrBlendCoeff fDstBlendCoeff;
bool fAntiAlias;
bool fDither;
@@ -80,8 +80,8 @@
GrTexture* fTexture;
void resetBlend() {
- fSrcBlendCoeff = GrDrawTarget::kOne_BlendCoeff;
- fDstBlendCoeff = GrDrawTarget::kZero_BlendCoeff;
+ fSrcBlendCoeff = kOne_BlendCoeff;
+ fDstBlendCoeff = kZero_BlendCoeff;
}
void resetOptions() {
diff --git a/gpu/include/GrTextContext.h b/gpu/include/GrTextContext.h
index 3dc9c7a..a598251 100644
--- a/gpu/include/GrTextContext.h
+++ b/gpu/include/GrTextContext.h
@@ -26,6 +26,7 @@
class GrContext;
class GrTextStrike;
class GrFontScaler;
+class GrDrawTarget;
class GrTextContext {
public:
diff --git a/gpu/include/GrTypes.h b/gpu/include/GrTypes.h
index 8311239..02a652a 100644
--- a/gpu/include/GrTypes.h
+++ b/gpu/include/GrTypes.h
@@ -160,6 +160,47 @@
*/
typedef uint16_t GrVertexLayout;
+/**
+ * Path filling rules
+ */
+enum GrPathFill {
+ kWinding_PathFill,
+ kEvenOdd_PathFill,
+ kInverseWinding_PathFill,
+ kInverseEvenOdd_PathFill,
+ kHairLine_PathFill,
+
+ kPathFillCount
+};
+
+/**
+* Geometric primitives used for drawing.
+*/
+enum GrPrimitiveType {
+ kTriangles_PrimitiveType,
+ kTriangleStrip_PrimitiveType,
+ kTriangleFan_PrimitiveType,
+ kPoints_PrimitiveType,
+ kLines_PrimitiveType,
+ kLineStrip_PrimitiveType
+};
+
+/**
+ * Coeffecients for alpha-blending.
+ */
+enum GrBlendCoeff {
+ kZero_BlendCoeff, //<! 0
+ kOne_BlendCoeff, //<! 1
+ kSC_BlendCoeff, //<! src color
+ kISC_BlendCoeff, //<! one minus src color
+ kDC_BlendCoeff, //<! dst color
+ kIDC_BlendCoeff, //<! one minus dst color
+ kSA_BlendCoeff, //<! src alpha
+ kISA_BlendCoeff, //<! one minus src alpha
+ kDA_BlendCoeff, //<! dst alpha
+ kIDA_BlendCoeff, //<! one minus dst alpha
+};
+
///////////////////////////////////////////////////////////////////////////////
// this is included only to make it easy to use this debugging facility