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

Unified Diff: src/gpu/GrAARectRenderer.cpp

Issue 671993003: Revert of Oval and stroke AA rect now batch (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 2 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/GrAARectRenderer.h ('k') | src/gpu/GrGpu.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/GrAARectRenderer.cpp
diff --git a/src/gpu/GrAARectRenderer.cpp b/src/gpu/GrAARectRenderer.cpp
index e5d1593bc060e06e751a9ec27d1acc5c1f305b26..3b4fd63788286e38fdc7f9b601055d6c8d7d30fa 100644
--- a/src/gpu/GrAARectRenderer.cpp
+++ b/src/gpu/GrAARectRenderer.cpp
@@ -311,6 +311,42 @@
static const int kVertsPerAAFillRect = 8;
static const int kNumAAFillRectsInIndexBuffer = 256;
+GrIndexBuffer* GrAARectRenderer::aaFillRectIndexBuffer(GrGpu* gpu) {
+ static const size_t kAAFillRectIndexBufferSize = kIndicesPerAAFillRect *
+ sizeof(uint16_t) *
+ kNumAAFillRectsInIndexBuffer;
+
+ if (NULL == fAAFillRectIndexBuffer) {
+ fAAFillRectIndexBuffer = gpu->createIndexBuffer(kAAFillRectIndexBufferSize, false);
+ if (fAAFillRectIndexBuffer) {
+ uint16_t* data = (uint16_t*) fAAFillRectIndexBuffer->map();
+ bool useTempData = (NULL == data);
+ if (useTempData) {
+ data = SkNEW_ARRAY(uint16_t, kNumAAFillRectsInIndexBuffer * kIndicesPerAAFillRect);
+ }
+ for (int i = 0; i < kNumAAFillRectsInIndexBuffer; ++i) {
+ // Each AA filled rect is drawn with 8 vertices and 10 triangles (8 around
+ // the inner rect (for AA) and 2 for the inner rect.
+ int baseIdx = i * kIndicesPerAAFillRect;
+ uint16_t baseVert = (uint16_t)(i * kVertsPerAAFillRect);
+ for (int j = 0; j < kIndicesPerAAFillRect; ++j) {
+ data[baseIdx+j] = baseVert + gFillAARectIdx[j];
+ }
+ }
+ if (useTempData) {
+ if (!fAAFillRectIndexBuffer->updateData(data, kAAFillRectIndexBufferSize)) {
+ SkFAIL("Can't get AA Fill Rect indices into buffer!");
+ }
+ SkDELETE_ARRAY(data);
+ } else {
+ fAAFillRectIndexBuffer->unmap();
+ }
+ }
+ }
+
+ return fAAFillRectIndexBuffer;
+}
+
static const uint16_t gMiterStrokeAARectIdx[] = {
0 + 0, 1 + 0, 5 + 0, 5 + 0, 4 + 0, 0 + 0,
1 + 0, 2 + 0, 6 + 0, 6 + 0, 5 + 0, 1 + 0,
@@ -327,10 +363,6 @@
2 + 8, 3 + 8, 7 + 8, 7 + 8, 6 + 8, 2 + 8,
3 + 8, 0 + 8, 4 + 8, 4 + 8, 7 + 8, 3 + 8,
};
-
-static const int kIndicesPerMiterStrokeRect = SK_ARRAY_COUNT(gMiterStrokeAARectIdx);
-static const int kVertsPerMiterStrokeRect = 16;
-static const int kNumMiterStrokeRectsInIndexBuffer = 256;
/**
* As in miter-stroke, index = a + b, and a is the current index, b is the shift
@@ -389,10 +421,6 @@
3 + 16, 0 + 16, 4 + 16, 4 + 16, 7 + 16, 3 + 16,
};
-static const int kIndicesPerBevelStrokeRect = SK_ARRAY_COUNT(gBevelStrokeAARectIdx);
-static const int kVertsPerBevelStrokeRect = 24;
-static const int kNumBevelStrokeRectsInIndexBuffer = 256;
-
int GrAARectRenderer::aaStrokeRectIndexCount(bool miterStroke) {
return miterStroke ? SK_ARRAY_COUNT(gMiterStrokeAARectIdx) :
SK_ARRAY_COUNT(gBevelStrokeAARectIdx);
@@ -402,19 +430,29 @@
if (miterStroke) {
if (NULL == fAAMiterStrokeRectIndexBuffer) {
fAAMiterStrokeRectIndexBuffer =
- gpu->createInstancedIndexBuffer(gMiterStrokeAARectIdx,
- kIndicesPerMiterStrokeRect,
- kNumMiterStrokeRectsInIndexBuffer,
- kVertsPerMiterStrokeRect);
+ gpu->createIndexBuffer(sizeof(gMiterStrokeAARectIdx), false);
+ if (fAAMiterStrokeRectIndexBuffer) {
+#ifdef SK_DEBUG
+ bool updated =
+#endif
+ fAAMiterStrokeRectIndexBuffer->updateData(gMiterStrokeAARectIdx,
+ sizeof(gMiterStrokeAARectIdx));
+ GR_DEBUGASSERT(updated);
+ }
}
return fAAMiterStrokeRectIndexBuffer;
} else {
if (NULL == fAABevelStrokeRectIndexBuffer) {
fAABevelStrokeRectIndexBuffer =
- gpu->createInstancedIndexBuffer(gBevelStrokeAARectIdx,
- kIndicesPerBevelStrokeRect,
- kNumBevelStrokeRectsInIndexBuffer,
- kVertsPerBevelStrokeRect);
+ gpu->createIndexBuffer(sizeof(gBevelStrokeAARectIdx), false);
+ if (fAABevelStrokeRectIndexBuffer) {
+#ifdef SK_DEBUG
+ bool updated =
+#endif
+ fAABevelStrokeRectIndexBuffer->updateData(gBevelStrokeAARectIdx,
+ sizeof(gBevelStrokeAARectIdx));
+ GR_DEBUGASSERT(updated);
+ }
}
return fAABevelStrokeRectIndexBuffer;
}
@@ -440,13 +478,7 @@
return;
}
- if (NULL == fAAFillRectIndexBuffer) {
- fAAFillRectIndexBuffer = gpu->createInstancedIndexBuffer(gFillAARectIdx,
- kIndicesPerAAFillRect,
- kNumAAFillRectsInIndexBuffer,
- kVertsPerAAFillRect);
- }
- GrIndexBuffer* indexBuffer = fAAFillRectIndexBuffer;
+ GrIndexBuffer* indexBuffer = this->aaFillRectIndexBuffer(gpu);
if (NULL == indexBuffer) {
GrPrintf("Failed to create index buffer!\n");
return;
@@ -901,9 +933,8 @@
}
target->setIndexSourceToBuffer(indexBuffer);
- target->drawIndexedInstances(kTriangles_GrPrimitiveType, 1,
- totalVertexNum, aaStrokeRectIndexCount(miterStroke));
- target->resetIndexSource();
+ target->drawIndexed(kTriangles_GrPrimitiveType, 0, 0,
+ totalVertexNum, aaStrokeRectIndexCount(miterStroke));
}
void GrAARectRenderer::fillAANestedRects(GrGpu* gpu,
« no previous file with comments | « src/gpu/GrAARectRenderer.h ('k') | src/gpu/GrGpu.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698