| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "GrDrawAtlasBatch.h" | 8 #include "GrDrawAtlasBatch.h" |
| 9 #include "GrBatchFlushState.h" | 9 #include "GrBatchFlushState.h" |
| 10 #include "GrBatchTest.h" | 10 #include "GrBatchTest.h" |
| 11 #include "SkGr.h" | 11 #include "SkGr.h" |
| 12 #include "SkRandom.h" | 12 #include "SkRandom.h" |
| 13 #include "SkRSXform.h" | 13 #include "SkRSXform.h" |
| 14 | 14 |
| 15 void GrDrawAtlasBatch::initBatchTracker(const GrPipelineOptimizations& opt) { | 15 void GrDrawAtlasBatch::initBatchTracker(const GrPipelineOptimizations& opt) { |
| 16 SkASSERT(fGeoData.count() == 1); |
| 16 // Handle any color overrides | 17 // Handle any color overrides |
| 17 if (!opt.readsColor()) { | 18 if (!opt.readsColor()) { |
| 18 fGeoData[0].fColor = GrColor_ILLEGAL; | 19 fGeoData[0].fColor = GrColor_ILLEGAL; |
| 19 } | 20 } |
| 20 opt.getOverrideColorIfSet(&fGeoData[0].fColor); | 21 if (opt.getOverrideColorIfSet(&fGeoData[0].fColor) && fHasColors) { |
| 21 | 22 size_t vertexStride = sizeof(SkPoint) + sizeof(SkPoint) + |
| 23 (this->hasColors() ? sizeof(GrColor) : 0); |
| 24 uint8_t* currVertex = fGeoData[0].fVerts.begin(); |
| 25 for (int i = 0; i < 4*fQuadCount; ++i) { |
| 26 *(reinterpret_cast<GrColor*>(currVertex + sizeof(SkPoint))) = fGeoDa
ta[0].fColor; |
| 27 currVertex += vertexStride; |
| 28 } |
| 29 } |
| 30 |
| 22 // setup batch properties | 31 // setup batch properties |
| 23 fColorIgnored = !opt.readsColor(); | 32 fColorIgnored = !opt.readsColor(); |
| 24 fColor = fGeoData[0].fColor; | 33 fColor = fGeoData[0].fColor; |
| 25 // We'd like to assert this, but we can't because of GLPrograms test | 34 // We'd like to assert this, but we can't because of GLPrograms test |
| 26 //SkASSERT(init.readsLocalCoords()); | 35 //SkASSERT(init.readsLocalCoords()); |
| 27 fCoverageIgnored = !opt.readsCoverage(); | 36 fCoverageIgnored = !opt.readsCoverage(); |
| 28 } | 37 } |
| 29 | 38 |
| 30 static const GrGeometryProcessor* set_vertex_attributes(bool hasColors, | 39 static const GrGeometryProcessor* set_vertex_attributes(bool hasColors, |
| 31 GrColor color, | 40 GrColor color, |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 const SkRect& currRect = rects[spriteIndex]; | 119 const SkRect& currRect = rects[spriteIndex]; |
| 111 xforms[spriteIndex].toQuad(currRect.width(), currRect.height(), quad); | 120 xforms[spriteIndex].toQuad(currRect.width(), currRect.height(), quad); |
| 112 | 121 |
| 113 // Copy colors if necessary | 122 // Copy colors if necessary |
| 114 if (colors) { | 123 if (colors) { |
| 115 // convert to GrColor | 124 // convert to GrColor |
| 116 SkColor color = colors[spriteIndex]; | 125 SkColor color = colors[spriteIndex]; |
| 117 if (paintAlpha != 255) { | 126 if (paintAlpha != 255) { |
| 118 color = SkColorSetA(color, SkMulDiv255Round(SkColorGetA(color),
paintAlpha)); | 127 color = SkColorSetA(color, SkMulDiv255Round(SkColorGetA(color),
paintAlpha)); |
| 119 } | 128 } |
| 120 GrColor grColor = SkColor2GrColor(color); | 129 GrColor grColor = SkColorToPremulGrColor(color); |
| 121 | 130 |
| 122 *(reinterpret_cast<GrColor*>(currVertex+sizeof(SkPoint))) = grColor; | 131 *(reinterpret_cast<GrColor*>(currVertex+sizeof(SkPoint))) = grColor; |
| 123 *(reinterpret_cast<GrColor*>(currVertex+vertexStride+sizeof(SkPoint)
)) = grColor; | 132 *(reinterpret_cast<GrColor*>(currVertex+vertexStride+sizeof(SkPoint)
)) = grColor; |
| 124 *(reinterpret_cast<GrColor*>(currVertex+2*vertexStride+sizeof(SkPoin
t))) = grColor; | 133 *(reinterpret_cast<GrColor*>(currVertex+2*vertexStride+sizeof(SkPoin
t))) = grColor; |
| 125 *(reinterpret_cast<GrColor*>(currVertex+3*vertexStride+sizeof(SkPoin
t))) = grColor; | 134 *(reinterpret_cast<GrColor*>(currVertex+3*vertexStride+sizeof(SkPoin
t))) = grColor; |
| 126 } | 135 } |
| 127 | 136 |
| 128 // Copy position and uv to verts | 137 // Copy position and uv to verts |
| 129 *(reinterpret_cast<SkPoint*>(currVertex)) = quad[0]; | 138 *(reinterpret_cast<SkPoint*>(currVertex)) = quad[0]; |
| 130 *(reinterpret_cast<SkPoint*>(currVertex+texOffset)) = SkPoint::Make(curr
Rect.fLeft, | 139 *(reinterpret_cast<SkPoint*>(currVertex+texOffset)) = SkPoint::Make(curr
Rect.fLeft, |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 | 258 |
| 250 SkMatrix viewMatrix = GrTest::TestMatrix(random); | 259 SkMatrix viewMatrix = GrTest::TestMatrix(random); |
| 251 | 260 |
| 252 GrDrawAtlasBatch::Geometry geometry; | 261 GrDrawAtlasBatch::Geometry geometry; |
| 253 geometry.fColor = GrRandomColor(random); | 262 geometry.fColor = GrRandomColor(random); |
| 254 return GrDrawAtlasBatch::Create(geometry, viewMatrix, spriteCount, xforms.be
gin(), | 263 return GrDrawAtlasBatch::Create(geometry, viewMatrix, spriteCount, xforms.be
gin(), |
| 255 texRects.begin(), hasColors ? colors.begin()
: nullptr); | 264 texRects.begin(), hasColors ? colors.begin()
: nullptr); |
| 256 } | 265 } |
| 257 | 266 |
| 258 #endif | 267 #endif |
| OLD | NEW |