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

Unified Diff: src/gpu/GrDrawContext.cpp

Issue 1276173003: Revert of Move GrDrawAtlasBatch to separate file (Closed) Base URL: https://skia.googlesource.com/skia.git@drawAtlas-08-06
Patch Set: Created 5 years, 4 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/GrDrawAtlasBatch.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/GrDrawContext.cpp
diff --git a/src/gpu/GrDrawContext.cpp b/src/gpu/GrDrawContext.cpp
index 9eba080cbc149f03ec4d2b6ff07315ff02e00973..c3d2548d18f69024cd1d93b31dea9991b7731258 100644
--- a/src/gpu/GrDrawContext.cpp
+++ b/src/gpu/GrDrawContext.cpp
@@ -12,7 +12,6 @@
#include "GrBatchTest.h"
#include "GrColor.h"
#include "GrDefaultGeoProcFactory.h"
-#include "GrDrawAtlasBatch.h"
#include "GrDrawContext.h"
#include "GrOvalRenderer.h"
#include "GrPathRenderer.h"
@@ -695,6 +694,167 @@
///////////////////////////////////////////////////////////////////////////////
+class DrawAtlasBatch : public GrBatch {
+public:
+ struct Geometry {
+ GrColor fColor;
+ SkTDArray<SkPoint> fPositions;
+ SkTDArray<GrColor> fColors;
+ SkTDArray<SkPoint> fLocalCoords;
+ };
+
+ static GrBatch* Create(const Geometry& geometry, const SkMatrix& viewMatrix,
+ const SkPoint* positions, int vertexCount,
+ const GrColor* colors, const SkPoint* localCoords,
+ const SkRect& bounds) {
+ return SkNEW_ARGS(DrawAtlasBatch, (geometry, viewMatrix, positions,
+ vertexCount, colors, localCoords, bounds));
+ }
+
+ const char* name() const override { return "DrawAtlasBatch"; }
+
+ void getInvariantOutputColor(GrInitInvariantOutput* out) const override {
+ // When this is called on a batch, there is only one geometry bundle
+ if (this->hasColors()) {
+ out->setUnknownFourComponents();
+ } else {
+ out->setKnownFourComponents(fGeoData[0].fColor);
+ }
+ }
+
+ void getInvariantOutputCoverage(GrInitInvariantOutput* out) const override {
+ out->setKnownSingleComponent(0xff);
+ }
+
+ void initBatchTracker(const GrPipelineInfo& init) override {
+ // Handle any color overrides
+ if (!init.readsColor()) {
+ fGeoData[0].fColor = GrColor_ILLEGAL;
+ }
+ init.getOverrideColorIfSet(&fGeoData[0].fColor);
+
+ // setup batch properties
+ fColorIgnored = !init.readsColor();
+ fColor = fGeoData[0].fColor;
+ SkASSERT(init.readsLocalCoords());
+ fCoverageIgnored = !init.readsCoverage();
+ }
+
+ void generateGeometry(GrBatchTarget* batchTarget) override {
+ int colorOffset = -1, texOffset = -1;
+ // Setup geometry processor
+ SkAutoTUnref<const GrGeometryProcessor> gp(
+ set_vertex_attributes(true, this->hasColors(), &colorOffset,
+ &texOffset, this->color(), this->viewMatrix(),
+ this->coverageIgnored()));
+
+ batchTarget->initDraw(gp, this->pipeline());
+
+ int instanceCount = fGeoData.count();
+ size_t vertexStride = gp->getVertexStride();
+ SkASSERT(vertexStride == sizeof(SkPoint) + sizeof(SkPoint)
+ + (this->hasColors() ? sizeof(GrColor) : 0));
+
+ QuadHelper helper;
+ int numQuads = this->vertexCount()/4;
+ void* verts = helper.init(batchTarget, vertexStride, numQuads);
+ if (!verts) {
+ SkDebugf("Could not allocate vertices\n");
+ return;
+ }
+
+ int vertexOffset = 0;
+ for (int i = 0; i < instanceCount; i++) {
+ const Geometry& args = fGeoData[i];
+
+ for (int j = 0; j < args.fPositions.count(); ++j) {
+ *((SkPoint*)verts) = args.fPositions[j];
+ if (this->hasColors()) {
+ *(GrColor*)((intptr_t)verts + colorOffset) = args.fColors[j];
+ }
+ *(SkPoint*)((intptr_t)verts + texOffset) = args.fLocalCoords[j];
+ verts = (void*)((intptr_t)verts + vertexStride);
+ vertexOffset++;
+ }
+ }
+ helper.issueDraw(batchTarget);
+ }
+
+ SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; }
+
+private:
+ DrawAtlasBatch(const Geometry& geometry, const SkMatrix& viewMatrix,
+ const SkPoint* positions, int vertexCount,
+ const GrColor* colors, const SkPoint* localCoords, const SkRect& bounds) {
+ this->initClassID<DrawVerticesBatch>();
+ SkASSERT(positions);
+ SkASSERT(localCoords);
+
+ fViewMatrix = viewMatrix;
+ Geometry& installedGeo = fGeoData.push_back(geometry);
+
+ installedGeo.fPositions.append(vertexCount, positions);
+
+ if (colors) {
+ installedGeo.fColors.append(vertexCount, colors);
+ fHasColors = true;
+ } else {
+ fHasColors = false;
+ }
+
+ installedGeo.fLocalCoords.append(vertexCount, localCoords);
+ fVertexCount = vertexCount;
+
+ this->setBounds(bounds);
+ }
+
+ GrColor color() const { return fColor; }
+ bool colorIgnored() const { return fColorIgnored; }
+ const SkMatrix& viewMatrix() const { return fViewMatrix; }
+ bool hasColors() const { return fHasColors; }
+ int vertexCount() const { return fVertexCount; }
+ bool coverageIgnored() const { return fCoverageIgnored; }
+
+ bool onCombineIfPossible(GrBatch* t) override {
+ if (!this->pipeline()->isEqual(*t->pipeline())) {
+ return false;
+ }
+
+ DrawAtlasBatch* that = t->cast<DrawAtlasBatch>();
+
+ // We currently use a uniform viewmatrix for this batch
+ if (!this->viewMatrix().cheapEqualTo(that->viewMatrix())) {
+ return false;
+ }
+
+ if (this->hasColors() != that->hasColors()) {
+ return false;
+ }
+
+ if (!this->hasColors() && this->color() != that->color()) {
+ return false;
+ }
+
+ if (this->color() != that->color()) {
+ fColor = GrColor_ILLEGAL;
+ }
+ fGeoData.push_back_n(that->geoData()->count(), that->geoData()->begin());
+ fVertexCount += that->vertexCount();
+
+ this->joinBounds(that->bounds());
+ return true;
+ }
+
+ SkSTArray<1, Geometry, true> fGeoData;
+
+ SkMatrix fViewMatrix;
+ GrColor fColor;
+ int fVertexCount;
+ bool fColorIgnored;
+ bool fCoverageIgnored;
+ bool fHasColors;
+};
+
void GrDrawContext::drawAtlas(GrRenderTarget* rt,
const GrClip& clip,
const GrPaint& paint,
@@ -764,10 +924,10 @@
texs = verts + vertCount;
vertCols = colorStorage.get();
- GrDrawAtlasBatch::Geometry geometry;
+ DrawAtlasBatch::Geometry geometry;
geometry.fColor = paint.getColor();
- SkAutoTUnref<GrBatch> batch(GrDrawAtlasBatch::Create(geometry, viewMatrix, verts, vertCount,
- vertCols, texs, bounds));
+ SkAutoTUnref<GrBatch> batch(DrawAtlasBatch::Create(geometry, viewMatrix, verts, vertCount,
+ vertCols, texs, bounds));
fDrawTarget->drawBatch(pipelineBuilder, batch);
}
« no previous file with comments | « src/gpu/GrDrawAtlasBatch.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698