aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/batches/GrDrawAtlasBatch.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/gpu/batches/GrDrawAtlasBatch.cpp')
-rw-r--r--src/gpu/batches/GrDrawAtlasBatch.cpp54
1 files changed, 27 insertions, 27 deletions
diff --git a/src/gpu/batches/GrDrawAtlasBatch.cpp b/src/gpu/batches/GrDrawAtlasBatch.cpp
index f3b497a132..3884ef200f 100644
--- a/src/gpu/batches/GrDrawAtlasBatch.cpp
+++ b/src/gpu/batches/GrDrawAtlasBatch.cpp
@@ -45,7 +45,7 @@ static const GrGeometryProcessor* set_vertex_attributes(bool hasColors,
if (hasColors) {
gpColor.fType = Color::kAttribute_Type;
}
-
+
Coverage coverage(coverageIgnored ? Coverage::kNone_Type : Coverage::kSolid_Type);
LocalCoords localCoords(LocalCoords::kHasExplicit_Type);
return GrDefaultGeoProcFactory::Create(gpColor, coverage, localCoords, viewMatrix);
@@ -57,14 +57,14 @@ void GrDrawAtlasBatch::onPrepareDraws(Target* target) const {
this->color(),
this->viewMatrix(),
this->coverageIgnored()));
-
+
target->initDraw(gp);
-
+
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->quadCount();
void* verts = helper.init(target, vertexStride, numQuads);
@@ -72,11 +72,11 @@ void GrDrawAtlasBatch::onPrepareDraws(Target* target) const {
SkDebugf("Could not allocate vertices\n");
return;
}
-
+
uint8_t* vertPtr = reinterpret_cast<uint8_t*>(verts);
for (int i = 0; i < instanceCount; i++) {
const Geometry& args = fGeoData[i];
-
+
size_t allocSize = args.fVerts.count();
memcpy(vertPtr, args.fVerts.begin(), allocSize);
vertPtr += allocSize;
@@ -90,10 +90,10 @@ GrDrawAtlasBatch::GrDrawAtlasBatch(const Geometry& geometry, const SkMatrix& vie
: INHERITED(ClassID()) {
SkASSERT(xforms);
SkASSERT(rects);
-
+
fViewMatrix = viewMatrix;
Geometry& installedGeo = fGeoData.push_back(geometry);
-
+
// Figure out stride and offsets
// Order within the vertex is: position [color] texCoord
size_t texOffset = sizeof(SkPoint);
@@ -103,13 +103,13 @@ GrDrawAtlasBatch::GrDrawAtlasBatch(const Geometry& geometry, const SkMatrix& vie
texOffset += sizeof(GrColor);
vertexStride += sizeof(GrColor);
}
-
+
// Compute buffer size and alloc buffer
fQuadCount = spriteCount;
int allocSize = static_cast<int>(4*vertexStride*spriteCount);
installedGeo.fVerts.reset(allocSize);
uint8_t* currVertex = installedGeo.fVerts.begin();
-
+
SkRect bounds;
bounds.setLargestInverted();
int paintAlpha = GrColorUnpackA(installedGeo.fColor);
@@ -118,7 +118,7 @@ GrDrawAtlasBatch::GrDrawAtlasBatch(const Geometry& geometry, const SkMatrix& vie
SkPoint quad[4];
const SkRect& currRect = rects[spriteIndex];
xforms[spriteIndex].toQuad(currRect.width(), currRect.height(), quad);
-
+
// Copy colors if necessary
if (colors) {
// convert to GrColor
@@ -127,13 +127,13 @@ GrDrawAtlasBatch::GrDrawAtlasBatch(const Geometry& geometry, const SkMatrix& vie
color = SkColorSetA(color, SkMulDiv255Round(SkColorGetA(color), paintAlpha));
}
GrColor grColor = SkColorToPremulGrColor(color);
-
+
*(reinterpret_cast<GrColor*>(currVertex+sizeof(SkPoint))) = grColor;
*(reinterpret_cast<GrColor*>(currVertex+vertexStride+sizeof(SkPoint))) = grColor;
*(reinterpret_cast<GrColor*>(currVertex+2*vertexStride+sizeof(SkPoint))) = grColor;
*(reinterpret_cast<GrColor*>(currVertex+3*vertexStride+sizeof(SkPoint))) = grColor;
}
-
+
// Copy position and uv to verts
*(reinterpret_cast<SkPoint*>(currVertex)) = quad[0];
*(reinterpret_cast<SkPoint*>(currVertex+texOffset)) = SkPoint::Make(currRect.fLeft,
@@ -146,26 +146,26 @@ GrDrawAtlasBatch::GrDrawAtlasBatch(const Geometry& geometry, const SkMatrix& vie
currRect.fTop);
bounds.growToInclude(quad[1].fX, quad[1].fY);
currVertex += vertexStride;
-
+
*(reinterpret_cast<SkPoint*>(currVertex)) = quad[2];
*(reinterpret_cast<SkPoint*>(currVertex+texOffset)) = SkPoint::Make(currRect.fRight,
currRect.fBottom);
bounds.growToInclude(quad[2].fX, quad[2].fY);
currVertex += vertexStride;
-
+
*(reinterpret_cast<SkPoint*>(currVertex)) = quad[3];
*(reinterpret_cast<SkPoint*>(currVertex+texOffset)) = SkPoint::Make(currRect.fLeft,
currRect.fBottom);
bounds.growToInclude(quad[3].fX, quad[3].fY);
currVertex += vertexStride;
}
-
+
viewMatrix.mapRect(&bounds);
// Outset for a half pixel in each direction to account for snapping in non-AA case
bounds.outset(0.5f, 0.5f);
this->setBounds(bounds);
}
-
+
bool GrDrawAtlasBatch::onCombineIfPossible(GrBatch* t, const GrCaps& caps) {
GrDrawAtlasBatch* that = t->cast<GrDrawAtlasBatch>();
@@ -178,21 +178,21 @@ bool GrDrawAtlasBatch::onCombineIfPossible(GrBatch* t, const GrCaps& caps) {
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());
fQuadCount += that->quadCount();
-
+
this->joinBounds(that->bounds());
return true;
}
@@ -219,7 +219,7 @@ static SkRSXform random_xform(SkRandom* random) {
static SkRect random_texRect(SkRandom* random) {
static const SkScalar kMinCoord = 0.0f;
static const SkScalar kMaxCoord = 1024.f;
-
+
SkRect texRect = SkRect::MakeLTRB(random->nextRangeScalar(kMinCoord, kMaxCoord),
random->nextRangeScalar(kMinCoord, kMaxCoord),
random->nextRangeScalar(kMinCoord, kMaxCoord),
@@ -243,21 +243,21 @@ static void randomize_params(uint32_t count, SkRandom* random,
DRAW_BATCH_TEST_DEFINE(GrDrawAtlasBatch) {
uint32_t spriteCount = random->nextRangeU(1, 100);
-
+
SkTArray<SkRSXform> xforms(spriteCount);
SkTArray<SkRect> texRects(spriteCount);
SkTArray<GrColor> colors;
-
+
bool hasColors = random->nextBool();
-
+
randomize_params(spriteCount,
random,
&xforms,
&texRects,
&colors, hasColors);
-
+
SkMatrix viewMatrix = GrTest::TestMatrix(random);
-
+
GrDrawAtlasBatch::Geometry geometry;
geometry.fColor = GrRandomColor(random);
return GrDrawAtlasBatch::Create(geometry, viewMatrix, spriteCount, xforms.begin(),