| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "GrAARectRenderer.h" | 8 #include "GrAARectRenderer.h" |
| 9 #include "GrBatch.h" | 9 #include "GrBatch.h" |
| 10 #include "GrBatchTarget.h" | 10 #include "GrBatchTarget.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 | 25 |
| 26 /////////////////////////////////////////////////////////////////////////////// | 26 /////////////////////////////////////////////////////////////////////////////// |
| 27 | 27 |
| 28 static void set_inset_fan(SkPoint* pts, size_t stride, | 28 static void set_inset_fan(SkPoint* pts, size_t stride, |
| 29 const SkRect& r, SkScalar dx, SkScalar dy) { | 29 const SkRect& r, SkScalar dx, SkScalar dy) { |
| 30 pts->setRectFan(r.fLeft + dx, r.fTop + dy, | 30 pts->setRectFan(r.fLeft + dx, r.fTop + dy, |
| 31 r.fRight - dx, r.fBottom - dy, stride); | 31 r.fRight - dx, r.fBottom - dy, stride); |
| 32 } | 32 } |
| 33 | 33 |
| 34 static const GrGeometryProcessor* create_fill_rect_gp(bool tweakAlphaForCoverage
, | 34 static const GrGeometryProcessor* create_fill_rect_gp(bool tweakAlphaForCoverage
, |
| 35 const SkMatrix& viewMatrix
, | 35 const SkMatrix& localMatri
x, |
| 36 bool usesLocalCoords, | 36 bool usesLocalCoords, |
| 37 bool coverageIgnored) { | 37 bool coverageIgnored, |
| 38 bool transformCoords) { |
| 38 using namespace GrDefaultGeoProcFactory; | 39 using namespace GrDefaultGeoProcFactory; |
| 39 | 40 |
| 40 Color color(Color::kAttribute_Type); | 41 Color color(Color::kAttribute_Type); |
| 41 Coverage::Type coverageType; | 42 Coverage::Type coverageType; |
| 42 // TODO remove coverage if coverage is ignored | 43 // TODO remove coverage if coverage is ignored |
| 43 /*if (coverageIgnored) { | 44 /*if (coverageIgnored) { |
| 44 coverageType = Coverage::kNone_Type; | 45 coverageType = Coverage::kNone_Type; |
| 45 } else*/ if (tweakAlphaForCoverage) { | 46 } else*/ if (tweakAlphaForCoverage) { |
| 46 coverageType = Coverage::kSolid_Type; | 47 coverageType = Coverage::kSolid_Type; |
| 47 } else { | 48 } else { |
| 48 coverageType = Coverage::kAttribute_Type; | 49 coverageType = Coverage::kAttribute_Type; |
| 49 } | 50 } |
| 50 Coverage coverage(coverageType); | 51 Coverage coverage(coverageType); |
| 51 LocalCoords localCoords(usesLocalCoords ? LocalCoords::kUsePosition_Type : | 52 LocalCoords::Type localCoordsType; |
| 52 LocalCoords::kUnused_Type); | 53 if (usesLocalCoords) { |
| 53 return CreateForDeviceSpace(color, coverage, localCoords, viewMatrix); | 54 localCoordsType = transformCoords ? LocalCoords::kHasTransformed_Type : |
| 55 LocalCoords::kUsePosition_Type; |
| 56 } else { |
| 57 localCoordsType = LocalCoords::kUnused_Type; |
| 58 } |
| 59 LocalCoords localCoords(localCoordsType); |
| 60 if (usesLocalCoords && !transformCoords) { |
| 61 localCoords.fMatrix = &localMatrix; |
| 62 } |
| 63 return Create(color, coverage, localCoords, SkMatrix::I()); |
| 54 } | 64 } |
| 55 | 65 |
| 56 GR_DECLARE_STATIC_UNIQUE_KEY(gAAFillRectIndexBufferKey); | 66 GR_DECLARE_STATIC_UNIQUE_KEY(gAAFillRectIndexBufferKey); |
| 57 | 67 |
| 58 class AAFillRectBatch : public GrBatch { | 68 class AAFillRectBatch : public GrBatch { |
| 59 public: | 69 public: |
| 60 struct Geometry { | 70 struct Geometry { |
| 61 GrColor fColor; | 71 GrColor fColor; |
| 62 SkMatrix fViewMatrix; | 72 SkMatrix fViewMatrix; |
| 63 SkRect fRect; | 73 SkRect fRect; |
| 64 SkRect fDevRect; | 74 SkRect fDevRect; |
| 75 const SkTArray<const GrCoordTransform*, true>* fCoordTransforms; |
| 65 }; | 76 }; |
| 66 | 77 |
| 67 static GrBatch* Create(const Geometry& geometry) { | 78 static GrBatch* Create(const Geometry& geometry) { |
| 68 return SkNEW_ARGS(AAFillRectBatch, (geometry)); | 79 return SkNEW_ARGS(AAFillRectBatch, (geometry)); |
| 69 } | 80 } |
| 70 | 81 |
| 71 const char* name() const override { return "AAFillRectBatch"; } | 82 const char* name() const override { return "AAFillRectBatch"; } |
| 72 | 83 |
| 73 void getInvariantOutputColor(GrInitInvariantOutput* out) const override { | 84 void getInvariantOutputColor(GrInitInvariantOutput* out) const override { |
| 74 // When this is called on a batch, there is only one geometry bundle | 85 // When this is called on a batch, there is only one geometry bundle |
| (...skipping 15 matching lines...) Expand all Loading... |
| 90 fBatch.fColorIgnored = !init.readsColor(); | 101 fBatch.fColorIgnored = !init.readsColor(); |
| 91 fBatch.fColor = fGeoData[0].fColor; | 102 fBatch.fColor = fGeoData[0].fColor; |
| 92 fBatch.fUsesLocalCoords = init.readsLocalCoords(); | 103 fBatch.fUsesLocalCoords = init.readsLocalCoords(); |
| 93 fBatch.fCoverageIgnored = !init.readsCoverage(); | 104 fBatch.fCoverageIgnored = !init.readsCoverage(); |
| 94 fBatch.fCanTweakAlphaForCoverage = init.canTweakAlphaForCoverage(); | 105 fBatch.fCanTweakAlphaForCoverage = init.canTweakAlphaForCoverage(); |
| 95 } | 106 } |
| 96 | 107 |
| 97 void generateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeline
) override { | 108 void generateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeline
) override { |
| 98 bool canTweakAlphaForCoverage = this->canTweakAlphaForCoverage(); | 109 bool canTweakAlphaForCoverage = this->canTweakAlphaForCoverage(); |
| 99 | 110 |
| 100 SkAutoTUnref<const GrGeometryProcessor> gp(create_fill_rect_gp(canTweakA
lphaForCoverage, | 111 SkMatrix localMatrix; |
| 101 this->vie
wMatrix(), | 112 if (this->usesLocalCoords() && !this->viewMatrix().invert(&localMatrix))
{ |
| 102 this->use
sLocalCoords(), | 113 SkDebugf("could not invert viewmatrix\n"); |
| 103 this->cov
erageIgnored())); | |
| 104 if (!gp) { | |
| 105 SkDebugf("Couldn't create GrGeometryProcessor\n"); | |
| 106 return; | 114 return; |
| 107 } | 115 } |
| 108 | 116 |
| 117 SkAutoTUnref<const GrGeometryProcessor> gp(create_fill_rect_gp(canTweakA
lphaForCoverage, |
| 118 localMatr
ix, |
| 119 this->use
sLocalCoords(), |
| 120 this->cov
erageIgnored(), |
| 121 fTransfor
mLocalCoords)); |
| 122 |
| 109 batchTarget->initDraw(gp, pipeline); | 123 batchTarget->initDraw(gp, pipeline); |
| 110 | 124 |
| 111 size_t vertexStride = gp->getVertexStride(); | 125 size_t vertexStride = gp->getVertexStride(); |
| 112 SkASSERT(canTweakAlphaForCoverage ? | 126 #ifdef SK_DEBUG |
| 113 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorAt
tr) : | 127 size_t testStride = sizeof(SkPoint) + sizeof(GrColor); |
| 114 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorCo
verageAttr)); | 128 testStride += canTweakAlphaForCoverage ? 0 : sizeof(GrColor); |
| 129 testStride += fTransformLocalCoords ? sizeof(SkPoint) : 0; |
| 130 SkASSERT(testStride == vertexStride); |
| 131 #endif |
| 115 int instanceCount = fGeoData.count(); | 132 int instanceCount = fGeoData.count(); |
| 116 | 133 |
| 117 SkAutoTUnref<const GrIndexBuffer> indexBuffer(this->getIndexBuffer( | 134 SkAutoTUnref<const GrIndexBuffer> indexBuffer(this->getIndexBuffer( |
| 118 batchTarget->resourceProvider())); | 135 batchTarget->resourceProvider())); |
| 119 InstancedHelper helper; | 136 InstancedHelper helper; |
| 120 void* vertices = helper.init(batchTarget, kTriangles_GrPrimitiveType, ve
rtexStride, | 137 void* vertices = helper.init(batchTarget, kTriangles_GrPrimitiveType, ve
rtexStride, |
| 121 indexBuffer, kVertsPerAAFillRect, kIndicesP
erAAFillRect, | 138 indexBuffer, kVertsPerAAFillRect, kIndicesP
erAAFillRect, |
| 122 instanceCount); | 139 instanceCount); |
| 123 if (!vertices || !indexBuffer) { | 140 if (!vertices || !indexBuffer) { |
| 124 SkDebugf("Could not allocate vertices\n"); | 141 SkDebugf("Could not allocate vertices\n"); |
| 125 return; | 142 return; |
| 126 } | 143 } |
| 127 | 144 |
| 128 for (int i = 0; i < instanceCount; i++) { | 145 for (int i = 0; i < instanceCount; i++) { |
| 129 const Geometry& args = fGeoData[i]; | 146 const Geometry& args = fGeoData[i]; |
| 130 this->generateAAFillRectGeometry(vertices, | 147 this->generateAAFillRectGeometry(vertices, |
| 131 i * kVertsPerAAFillRect * vertexStr
ide, | 148 i * kVertsPerAAFillRect * vertexStr
ide, |
| 132 vertexStride, | 149 vertexStride, |
| 133 args.fColor, | 150 args.fColor, |
| 134 args.fViewMatrix, | 151 args.fViewMatrix, |
| 152 localMatrix, |
| 135 args.fRect, | 153 args.fRect, |
| 136 args.fDevRect, | 154 args.fDevRect, |
| 155 *args.fCoordTransforms, |
| 137 canTweakAlphaForCoverage); | 156 canTweakAlphaForCoverage); |
| 138 } | 157 } |
| 139 | 158 |
| 140 helper.issueDraw(batchTarget); | 159 helper.issueDraw(batchTarget); |
| 141 } | 160 } |
| 142 | 161 |
| 143 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } | 162 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } |
| 144 | 163 |
| 145 private: | 164 private: |
| 146 AAFillRectBatch(const Geometry& geometry) { | 165 AAFillRectBatch(const Geometry& geometry) { |
| 147 this->initClassID<AAFillRectBatch>(); | 166 this->initClassID<AAFillRectBatch>(); |
| 148 fGeoData.push_back(geometry); | 167 fGeoData.push_back(geometry); |
| 149 | 168 |
| 150 this->setBounds(geometry.fDevRect); | 169 this->setBounds(geometry.fDevRect); |
| 151 } | 170 } |
| 152 | 171 |
| 172 void onSetPipeline() override { |
| 173 fTransformLocalCoords = this->pipeline()->coordTransforms().count() == 1
&& |
| 174 this->usesLocalCoords(); |
| 175 fGeoData[0].fCoordTransforms = &this->pipeline()->coordTransforms(); |
| 176 } |
| 177 |
| 153 static const int kNumAAFillRectsInIndexBuffer = 256; | 178 static const int kNumAAFillRectsInIndexBuffer = 256; |
| 154 static const int kVertsPerAAFillRect = 8; | 179 static const int kVertsPerAAFillRect = 8; |
| 155 static const int kIndicesPerAAFillRect = 30; | 180 static const int kIndicesPerAAFillRect = 30; |
| 156 | 181 |
| 157 const GrIndexBuffer* getIndexBuffer(GrResourceProvider* resourceProvider) { | 182 const GrIndexBuffer* getIndexBuffer(GrResourceProvider* resourceProvider) { |
| 158 GR_DEFINE_STATIC_UNIQUE_KEY(gAAFillRectIndexBufferKey); | 183 GR_DEFINE_STATIC_UNIQUE_KEY(gAAFillRectIndexBufferKey); |
| 159 | 184 |
| 160 static const uint16_t gFillAARectIdx[] = { | 185 static const uint16_t gFillAARectIdx[] = { |
| 161 0, 1, 5, 5, 4, 0, | 186 0, 1, 5, 5, 4, 0, |
| 162 1, 2, 6, 6, 5, 1, | 187 1, 2, 6, 6, 5, 1, |
| 163 2, 3, 7, 7, 6, 2, | 188 2, 3, 7, 7, 6, 2, |
| 164 3, 0, 4, 4, 7, 3, | 189 3, 0, 4, 4, 7, 3, |
| 165 4, 5, 6, 6, 7, 4, | 190 4, 5, 6, 6, 7, 4, |
| 166 }; | 191 }; |
| 167 GR_STATIC_ASSERT(SK_ARRAY_COUNT(gFillAARectIdx) == kIndicesPerAAFillRect
); | 192 GR_STATIC_ASSERT(SK_ARRAY_COUNT(gFillAARectIdx) == kIndicesPerAAFillRect
); |
| 168 return resourceProvider->findOrCreateInstancedIndexBuffer(gFillAARectIdx
, | 193 return resourceProvider->findOrCreateInstancedIndexBuffer(gFillAARectIdx
, |
| 169 kIndicesPerAAFillRect, kNumAAFillRectsInIndexBuffer, kVertsPerAAFill
Rect, | 194 kIndicesPerAAFillRect, kNumAAFillRectsInIndexBuffer, kVertsPerAAFill
Rect, |
| 170 gAAFillRectIndexBufferKey); | 195 gAAFillRectIndexBufferKey); |
| 171 } | 196 } |
| 172 | 197 |
| 173 GrColor color() const { return fBatch.fColor; } | 198 GrColor color() const { return fBatch.fColor; } |
| 174 bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; } | 199 bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; } |
| 175 bool canTweakAlphaForCoverage() const { return fBatch.fCanTweakAlphaForCover
age; } | 200 bool canTweakAlphaForCoverage() const { return fBatch.fCanTweakAlphaForCover
age; } |
| 176 bool colorIgnored() const { return fBatch.fColorIgnored; } | 201 bool colorIgnored() const { return fBatch.fColorIgnored; } |
| 177 const SkMatrix& viewMatrix() const { return fGeoData[0].fViewMatrix; } | 202 const SkMatrix& viewMatrix() const { return fGeoData[0].fViewMatrix; } |
| 178 bool coverageIgnored() const { return fBatch.fCoverageIgnored; } | 203 bool coverageIgnored() const { return fBatch.fCoverageIgnored; } |
| 179 | 204 |
| 180 bool onCombineIfPossible(GrBatch* t) override { | 205 bool onCombineIfPossible(GrBatch* t) override { |
| 181 if (!this->pipeline()->isEqual(*t->pipeline())) { | 206 // If we have one coord transform then we will transform on the cpu |
| 207 if (!this->pipeline()->isEqual(*t->pipeline(), fTransformLocalCoords)) { |
| 182 return false; | 208 return false; |
| 183 } | 209 } |
| 184 | 210 |
| 185 AAFillRectBatch* that = t->cast<AAFillRectBatch>(); | 211 AAFillRectBatch* that = t->cast<AAFillRectBatch>(); |
| 186 | 212 |
| 187 SkASSERT(this->usesLocalCoords() == that->usesLocalCoords()); | 213 SkASSERT(this->usesLocalCoords() == that->usesLocalCoords()); |
| 188 // We apply the viewmatrix to the rect points on the cpu. However, if t
he pipeline uses | 214 // We apply the viewmatrix to the rect points on the cpu. However, if t
he pipeline uses |
| 189 // local coords then we won't be able to batch. We could actually uploa
d the viewmatrix | 215 // local coords then we won't be able to batch. We could actually uploa
d the viewmatrix |
| 190 // using vertex attributes in these cases, but haven't investigated that | 216 // using vertex attributes in these cases, but haven't investigated that |
| 191 if (this->usesLocalCoords() && !this->viewMatrix().cheapEqualTo(that->vi
ewMatrix())) { | 217 if (this->usesLocalCoords() && !this->viewMatrix().cheapEqualTo(that->vi
ewMatrix())) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 205 fGeoData.push_back_n(that->geoData()->count(), that->geoData()->begin())
; | 231 fGeoData.push_back_n(that->geoData()->count(), that->geoData()->begin())
; |
| 206 this->joinBounds(that->bounds()); | 232 this->joinBounds(that->bounds()); |
| 207 return true; | 233 return true; |
| 208 } | 234 } |
| 209 | 235 |
| 210 void generateAAFillRectGeometry(void* vertices, | 236 void generateAAFillRectGeometry(void* vertices, |
| 211 size_t offset, | 237 size_t offset, |
| 212 size_t vertexStride, | 238 size_t vertexStride, |
| 213 GrColor color, | 239 GrColor color, |
| 214 const SkMatrix& viewMatrix, | 240 const SkMatrix& viewMatrix, |
| 241 const SkMatrix& localMatrix, |
| 215 const SkRect& rect, | 242 const SkRect& rect, |
| 216 const SkRect& devRect, | 243 const SkRect& devRect, |
| 244 const SkTArray<const GrCoordTransform*, true
>& coordTransforms, |
| 217 bool tweakAlphaForCoverage) const { | 245 bool tweakAlphaForCoverage) const { |
| 218 intptr_t verts = reinterpret_cast<intptr_t>(vertices) + offset; | 246 intptr_t verts = reinterpret_cast<intptr_t>(vertices) + offset; |
| 219 | 247 |
| 220 SkPoint* fan0Pos = reinterpret_cast<SkPoint*>(verts); | 248 SkPoint* fan0Pos = reinterpret_cast<SkPoint*>(verts); |
| 221 SkPoint* fan1Pos = reinterpret_cast<SkPoint*>(verts + 4 * vertexStride); | 249 SkPoint* fan1Pos = reinterpret_cast<SkPoint*>(verts + 4 * vertexStride); |
| 222 | 250 |
| 223 SkScalar inset = SkMinScalar(devRect.width(), SK_Scalar1); | 251 SkScalar inset = SkMinScalar(devRect.width(), SK_Scalar1); |
| 224 inset = SK_ScalarHalf * SkMinScalar(inset, devRect.height()); | 252 inset = SK_ScalarHalf * SkMinScalar(inset, devRect.height()); |
| 225 | 253 |
| 226 if (viewMatrix.rectStaysRect()) { | 254 if (viewMatrix.rectStaysRect()) { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 257 // BR | 285 // BR |
| 258 *((SkPoint*)((intptr_t)fan1Pos + 2 * vertexStride)) = | 286 *((SkPoint*)((intptr_t)fan1Pos + 2 * vertexStride)) = |
| 259 *((SkPoint*)((intptr_t)fan0Pos + 2 * vertexStride)) - vec[0] - v
ec[1]; | 287 *((SkPoint*)((intptr_t)fan0Pos + 2 * vertexStride)) - vec[0] - v
ec[1]; |
| 260 *((SkPoint*)((intptr_t)fan0Pos + 2 * vertexStride)) += vec[0] + vec[
1]; | 288 *((SkPoint*)((intptr_t)fan0Pos + 2 * vertexStride)) += vec[0] + vec[
1]; |
| 261 // TR | 289 // TR |
| 262 *((SkPoint*)((intptr_t)fan1Pos + 3 * vertexStride)) = | 290 *((SkPoint*)((intptr_t)fan1Pos + 3 * vertexStride)) = |
| 263 *((SkPoint*)((intptr_t)fan0Pos + 3 * vertexStride)) - vec[0] + v
ec[1]; | 291 *((SkPoint*)((intptr_t)fan0Pos + 3 * vertexStride)) - vec[0] + v
ec[1]; |
| 264 *((SkPoint*)((intptr_t)fan0Pos + 3 * vertexStride)) += vec[0] - vec[
1]; | 292 *((SkPoint*)((intptr_t)fan0Pos + 3 * vertexStride)) += vec[0] - vec[
1]; |
| 265 } | 293 } |
| 266 | 294 |
| 295 if (fTransformLocalCoords) { |
| 296 SkASSERT(coordTransforms.count() == 1); |
| 297 SkMatrix localCoordMatrix = |
| 298 GrGLPrimitiveProcessor::GetTransformMatrix(localMatrix, |
| 299 *coordTransforms[
0]); |
| 300 SkPoint* fan0Loc = reinterpret_cast<SkPoint*>(verts + vertexStride -
sizeof(SkPoint)); |
| 301 localCoordMatrix.mapPointsWithStride(fan0Loc, fan0Pos, vertexStride,
8); |
| 302 } |
| 303 |
| 267 // Make verts point to vertex color and then set all the color and cover
age vertex attrs | 304 // Make verts point to vertex color and then set all the color and cover
age vertex attrs |
| 268 // values. | 305 // values. |
| 269 verts += sizeof(SkPoint); | 306 verts += sizeof(SkPoint); |
| 270 for (int i = 0; i < 4; ++i) { | 307 for (int i = 0; i < 4; ++i) { |
| 271 if (tweakAlphaForCoverage) { | 308 if (tweakAlphaForCoverage) { |
| 272 *reinterpret_cast<GrColor*>(verts + i * vertexStride) = 0; | 309 *reinterpret_cast<GrColor*>(verts + i * vertexStride) = 0; |
| 273 } else { | 310 } else { |
| 274 *reinterpret_cast<GrColor*>(verts + i * vertexStride) = color; | 311 *reinterpret_cast<GrColor*>(verts + i * vertexStride) = color; |
| 275 *reinterpret_cast<float*>(verts + i * vertexStride + sizeof(GrCo
lor)) = 0; | 312 *reinterpret_cast<float*>(verts + i * vertexStride + sizeof(GrCo
lor)) = 0; |
| 276 } | 313 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 301 } | 338 } |
| 302 | 339 |
| 303 struct BatchTracker { | 340 struct BatchTracker { |
| 304 GrColor fColor; | 341 GrColor fColor; |
| 305 bool fUsesLocalCoords; | 342 bool fUsesLocalCoords; |
| 306 bool fColorIgnored; | 343 bool fColorIgnored; |
| 307 bool fCoverageIgnored; | 344 bool fCoverageIgnored; |
| 308 bool fCanTweakAlphaForCoverage; | 345 bool fCanTweakAlphaForCoverage; |
| 309 }; | 346 }; |
| 310 | 347 |
| 348 bool fTransformLocalCoords; |
| 311 BatchTracker fBatch; | 349 BatchTracker fBatch; |
| 312 SkSTArray<1, Geometry, true> fGeoData; | 350 SkSTArray<1, Geometry, true> fGeoData; |
| 313 }; | 351 }; |
| 314 | 352 |
| 315 namespace { | 353 namespace { |
| 316 // Should the coverage be multiplied into the color attrib or use a separate att
rib. | 354 // Should the coverage be multiplied into the color attrib or use a separate att
rib. |
| 317 enum CoverageAttribType { | 355 enum CoverageAttribType { |
| 318 kUseColor_CoverageAttribType, | 356 kUseColor_CoverageAttribType, |
| 319 kUseCoverage_CoverageAttribType, | 357 kUseCoverage_CoverageAttribType, |
| 320 }; | 358 }; |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 devOutsideAssist.outset(0, ry); | 433 devOutsideAssist.outset(0, ry); |
| 396 } | 434 } |
| 397 | 435 |
| 398 GeometryStrokeAARect(target, pipelineBuilder, color, viewMatrix, devOutside, | 436 GeometryStrokeAARect(target, pipelineBuilder, color, viewMatrix, devOutside, |
| 399 devOutsideAssist, devInside, miterStroke); | 437 devOutsideAssist, devInside, miterStroke); |
| 400 } | 438 } |
| 401 | 439 |
| 402 GR_DECLARE_STATIC_UNIQUE_KEY(gMiterIndexBufferKey); | 440 GR_DECLARE_STATIC_UNIQUE_KEY(gMiterIndexBufferKey); |
| 403 GR_DECLARE_STATIC_UNIQUE_KEY(gBevelIndexBufferKey); | 441 GR_DECLARE_STATIC_UNIQUE_KEY(gBevelIndexBufferKey); |
| 404 | 442 |
| 443 static const GrGeometryProcessor* create_stroke_rect_gp(bool tweakAlphaForCovera
ge, |
| 444 const SkMatrix& viewMatr
ix, |
| 445 bool usesLocalCoords, |
| 446 bool coverageIgnored) { |
| 447 using namespace GrDefaultGeoProcFactory; |
| 448 |
| 449 Color color(Color::kAttribute_Type); |
| 450 Coverage::Type coverageType; |
| 451 // TODO remove coverage if coverage is ignored |
| 452 /*if (coverageIgnored) { |
| 453 coverageType = Coverage::kNone_Type; |
| 454 } else*/ if (tweakAlphaForCoverage) { |
| 455 coverageType = Coverage::kSolid_Type; |
| 456 } else { |
| 457 coverageType = Coverage::kAttribute_Type; |
| 458 } |
| 459 Coverage coverage(coverageType); |
| 460 LocalCoords localCoords(usesLocalCoords ? LocalCoords::kUsePosition_Type : |
| 461 LocalCoords::kUnused_Type); |
| 462 return CreateForDeviceSpace(color, coverage, localCoords, viewMatrix); |
| 463 } |
| 464 |
| 465 |
| 405 class AAStrokeRectBatch : public GrBatch { | 466 class AAStrokeRectBatch : public GrBatch { |
| 406 public: | 467 public: |
| 407 // TODO support AA rotated stroke rects by copying around view matrices | 468 // TODO support AA rotated stroke rects by copying around view matrices |
| 408 struct Geometry { | 469 struct Geometry { |
| 409 GrColor fColor; | 470 GrColor fColor; |
| 410 SkRect fDevOutside; | 471 SkRect fDevOutside; |
| 411 SkRect fDevOutsideAssist; | 472 SkRect fDevOutsideAssist; |
| 412 SkRect fDevInside; | 473 SkRect fDevInside; |
| 413 bool fMiterStroke; | 474 bool fMiterStroke; |
| 414 }; | 475 }; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 440 fBatch.fColor = fGeoData[0].fColor; | 501 fBatch.fColor = fGeoData[0].fColor; |
| 441 fBatch.fUsesLocalCoords = init.readsLocalCoords(); | 502 fBatch.fUsesLocalCoords = init.readsLocalCoords(); |
| 442 fBatch.fCoverageIgnored = !init.readsCoverage(); | 503 fBatch.fCoverageIgnored = !init.readsCoverage(); |
| 443 fBatch.fMiterStroke = fGeoData[0].fMiterStroke; | 504 fBatch.fMiterStroke = fGeoData[0].fMiterStroke; |
| 444 fBatch.fCanTweakAlphaForCoverage = init.canTweakAlphaForCoverage(); | 505 fBatch.fCanTweakAlphaForCoverage = init.canTweakAlphaForCoverage(); |
| 445 } | 506 } |
| 446 | 507 |
| 447 void generateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeline
) override { | 508 void generateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeline
) override { |
| 448 bool canTweakAlphaForCoverage = this->canTweakAlphaForCoverage(); | 509 bool canTweakAlphaForCoverage = this->canTweakAlphaForCoverage(); |
| 449 | 510 |
| 450 SkAutoTUnref<const GrGeometryProcessor> gp(create_fill_rect_gp(canTweakA
lphaForCoverage, | 511 SkAutoTUnref<const GrGeometryProcessor> gp(create_stroke_rect_gp(canTwea
kAlphaForCoverage, |
| 451 this->vie
wMatrix(), | 512 this->v
iewMatrix(), |
| 452 this->use
sLocalCoords(), | 513 this->u
sesLocalCoords(), |
| 453 this->cov
erageIgnored())); | 514 this->c
overageIgnored())); |
| 454 if (!gp) { | 515 if (!gp) { |
| 455 SkDebugf("Couldn't create GrGeometryProcessor\n"); | 516 SkDebugf("Couldn't create GrGeometryProcessor\n"); |
| 456 return; | 517 return; |
| 457 } | 518 } |
| 458 | 519 |
| 459 batchTarget->initDraw(gp, pipeline); | 520 batchTarget->initDraw(gp, pipeline); |
| 460 | 521 |
| 461 size_t vertexStride = gp->getVertexStride(); | 522 size_t vertexStride = gp->getVertexStride(); |
| 462 | 523 |
| 463 SkASSERT(canTweakAlphaForCoverage ? | 524 SkASSERT(canTweakAlphaForCoverage ? |
| (...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 848 geo.fColor = GrRandomColor(random); | 909 geo.fColor = GrRandomColor(random); |
| 849 geo.fDevOutside = outside; | 910 geo.fDevOutside = outside; |
| 850 geo.fDevOutsideAssist = outsideAssist; | 911 geo.fDevOutsideAssist = outsideAssist; |
| 851 geo.fDevInside = inside; | 912 geo.fDevInside = inside; |
| 852 geo.fMiterStroke = miterStroke; | 913 geo.fMiterStroke = miterStroke; |
| 853 | 914 |
| 854 return AAStrokeRectBatch::Create(geo, GrTest::TestMatrix(random)); | 915 return AAStrokeRectBatch::Create(geo, GrTest::TestMatrix(random)); |
| 855 } | 916 } |
| 856 | 917 |
| 857 #endif | 918 #endif |
| OLD | NEW |