}
SetRectVertices(rect, matrix, srcRects,
- srcMatrices, layout, geo.vertices());
-
+ srcMatrices, SK_ColorBLACK, layout, geo.vertices());
+
drawNonIndexed(kTriangleFan_GrPrimitiveType, 0, 4);
}
return layout;
}
+// This method fills int the four vertices for drawing 'rect'.
+// matrix - is applied to each vertex
+// srcRects - provide the uvs for each vertex
+// srcMatrices - are applied to the corresponding 'srcRect'
+// color - vertex color (replicated in each vertex)
+// layout - specifies which uvs and/or color are present
+// vertices - storage for the resulting vertices
+// Note: the color parameter will only be used when kColor_VertexLayoutBit
+// is present in 'layout'
void GrDrawTarget::SetRectVertices(const GrRect& rect,
const GrMatrix* matrix,
const GrRect* srcRects[],
const GrMatrix* srcMatrices[],
+ GrColor color,
GrVertexLayout layout,
void* vertices) {
#if GR_DEBUG
}
#endif
- int stageOffsets[GrDrawState::kNumStages];
+ int stageOffsets[GrDrawState::kNumStages], colorOffset;
int vsize = VertexSizeAndOffsetsByStage(layout, stageOffsets,
- NULL, NULL, NULL);
+ &colorOffset, NULL, NULL);
GrTCast<GrPoint*>(vertices)->setRectFan(rect.fLeft, rect.fTop,
rect.fRight, rect.fBottom,
}
}
}
+
+ if (layout & kColor_VertexLayoutBit) {
+
+ GrColor* vertCol = GrTCast<GrColor*>(GrTCast<intptr_t>(vertices) + colorOffset);
+
+ for (int i = 0; i < 4; ++i) {
+ *vertCol = color;
+ vertCol = (GrColor*) ((intptr_t) vertCol + vsize);
+ }
+ }
}
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
+ /**
+ * 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,
const GrMatrix* matrix,
const GrRect* srcRects[],
const GrMatrix* srcMatrices[],
+ GrColor color,
GrVertexLayout layout,
void* vertices);
bool appendToPreviousDraw = false;
GrVertexLayout layout = GetRectVertexLayout(srcRects);
+
+ // When we batch rects we store the color at each vertex in order
+ // to allow batching when only the draw color is changing (the usual case)
+ layout |= kColor_VertexLayoutBit;
+
AutoReleaseGeometry geo(this, layout, 4, 0);
if (!geo.succeeded()) {
GrPrintf("Failed to get space for vertices!\n");
GrMatrix combinedMatrix = drawState->getViewMatrix();
// We go to device space so that matrix changes allow us to concat
// rect draws. When the caller has provided explicit source rects
- // then we don't want to modify the sampler matrices. Otherwise we do
+ // then we don't want to modify the sampler matrices. Otherwise
// we have to account for the view matrix change in the sampler
// matrices.
uint32_t explicitCoordMask = 0;
combinedMatrix.preConcat(*matrix);
}
- SetRectVertices(rect, &combinedMatrix, srcRects, srcMatrices, layout, geo.vertices());
+ SetRectVertices(rect, &combinedMatrix, srcRects, srcMatrices,
+ this->getDrawState().getColor(), layout, geo.vertices());
+
+ // 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);
// we don't want to miss an opportunity to batch rects together
// simply because the clip has changed if the clip doesn't affect