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 "GrDefaultGeoProcFactory.h" | 9 #include "GrDefaultGeoProcFactory.h" |
10 #include "GrGeometryProcessor.h" | 10 #include "GrGeometryProcessor.h" |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 fGpu->createInstancedIndexBuffer(gBevelStrokeAARectIdx, | 170 fGpu->createInstancedIndexBuffer(gBevelStrokeAARectIdx, |
171 kIndicesPerBevelStrokeRect, | 171 kIndicesPerBevelStrokeRect, |
172 kNumBevelStrokeRectsInIndex
Buffer, | 172 kNumBevelStrokeRectsInIndex
Buffer, |
173 kVertsPerBevelStrokeRect); | 173 kVertsPerBevelStrokeRect); |
174 } | 174 } |
175 return fAABevelStrokeRectIndexBuffer; | 175 return fAABevelStrokeRectIndexBuffer; |
176 } | 176 } |
177 } | 177 } |
178 | 178 |
179 void GrAARectRenderer::geometryFillAARect(GrDrawTarget* target, | 179 void GrAARectRenderer::geometryFillAARect(GrDrawTarget* target, |
| 180 GrDrawState* drawState, |
180 const SkRect& rect, | 181 const SkRect& rect, |
181 const SkMatrix& combinedMatrix, | 182 const SkMatrix& combinedMatrix, |
182 const SkRect& devRect) { | 183 const SkRect& devRect) { |
183 GrDrawState* drawState = target->drawState(); | |
184 GrDrawState::AutoRestoreEffects are(drawState); | 184 GrDrawState::AutoRestoreEffects are(drawState); |
185 | 185 |
186 GrColor color = drawState->getColor(); | 186 GrColor color = drawState->getColor(); |
187 | 187 |
188 CoverageAttribType covAttribType = set_rect_attribs(drawState); | 188 CoverageAttribType covAttribType = set_rect_attribs(drawState); |
189 if (kUseCoverage_CoverageAttribType == covAttribType && GrColorIsOpaque(colo
r)) { | 189 if (kUseCoverage_CoverageAttribType == covAttribType && GrColorIsOpaque(colo
r)) { |
190 drawState->setHint(GrDrawState::kVertexColorsAreOpaque_Hint, true); | 190 drawState->setHint(GrDrawState::kVertexColorsAreOpaque_Hint, true); |
191 } | 191 } |
192 | 192 |
193 GrDrawTarget::AutoReleaseGeometry geo(target, 8, 0); | 193 GrDrawTarget::AutoReleaseGeometry geo(target, 8, drawState->getVertexStride(
), 0); |
194 if (!geo.succeeded()) { | 194 if (!geo.succeeded()) { |
195 SkDebugf("Failed to get space for vertices!\n"); | 195 SkDebugf("Failed to get space for vertices!\n"); |
196 return; | 196 return; |
197 } | 197 } |
198 | 198 |
199 if (NULL == fAAFillRectIndexBuffer) { | 199 if (NULL == fAAFillRectIndexBuffer) { |
200 fAAFillRectIndexBuffer = fGpu->createInstancedIndexBuffer(gFillAARectIdx
, | 200 fAAFillRectIndexBuffer = fGpu->createInstancedIndexBuffer(gFillAARectIdx
, |
201 kIndicesPerAAF
illRect, | 201 kIndicesPerAAF
illRect, |
202 kNumAAFillRect
sInIndexBuffer, | 202 kNumAAFillRect
sInIndexBuffer, |
203 kVertsPerAAFil
lRect); | 203 kVertsPerAAFil
lRect); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 for (int i = 0; i < 4; ++i) { | 293 for (int i = 0; i < 4; ++i) { |
294 if (kUseCoverage_CoverageAttribType == covAttribType) { | 294 if (kUseCoverage_CoverageAttribType == covAttribType) { |
295 *reinterpret_cast<GrColor*>(verts + i * vstride) = color; | 295 *reinterpret_cast<GrColor*>(verts + i * vstride) = color; |
296 *reinterpret_cast<float*>(verts + i * vstride + sizeof(GrColor)) = i
nnerCoverage; | 296 *reinterpret_cast<float*>(verts + i * vstride + sizeof(GrColor)) = i
nnerCoverage; |
297 } else { | 297 } else { |
298 *reinterpret_cast<GrColor*>(verts + i * vstride) = scaledColor; | 298 *reinterpret_cast<GrColor*>(verts + i * vstride) = scaledColor; |
299 } | 299 } |
300 } | 300 } |
301 | 301 |
302 target->setIndexSourceToBuffer(indexBuffer); | 302 target->setIndexSourceToBuffer(indexBuffer); |
303 target->drawIndexedInstances(kTriangles_GrPrimitiveType, 1, | 303 target->drawIndexedInstances(drawState, |
| 304 kTriangles_GrPrimitiveType, |
| 305 1, |
304 kVertsPerAAFillRect, | 306 kVertsPerAAFillRect, |
305 kIndicesPerAAFillRect); | 307 kIndicesPerAAFillRect); |
306 target->resetIndexSource(); | 308 target->resetIndexSource(); |
307 } | 309 } |
308 | 310 |
309 void GrAARectRenderer::strokeAARect(GrDrawTarget* target, | 311 void GrAARectRenderer::strokeAARect(GrDrawTarget* target, |
| 312 GrDrawState* drawState, |
310 const SkRect& rect, | 313 const SkRect& rect, |
311 const SkMatrix& combinedMatrix, | 314 const SkMatrix& combinedMatrix, |
312 const SkRect& devRect, | 315 const SkRect& devRect, |
313 const SkStrokeRec& stroke) { | 316 const SkStrokeRec& stroke) { |
314 SkVector devStrokeSize; | 317 SkVector devStrokeSize; |
315 SkScalar width = stroke.getWidth(); | 318 SkScalar width = stroke.getWidth(); |
316 if (width > 0) { | 319 if (width > 0) { |
317 devStrokeSize.set(width, width); | 320 devStrokeSize.set(width, width); |
318 combinedMatrix.mapVectors(&devStrokeSize, 1); | 321 combinedMatrix.mapVectors(&devStrokeSize, 1); |
319 devStrokeSize.setAbs(devStrokeSize); | 322 devStrokeSize.setAbs(devStrokeSize); |
(...skipping 26 matching lines...) Expand all Loading... |
346 | 349 |
347 bool miterStroke = true; | 350 bool miterStroke = true; |
348 // For hairlines, make bevel and round joins appear the same as mitered ones
. | 351 // For hairlines, make bevel and round joins appear the same as mitered ones
. |
349 // small miter limit means right angles show bevel... | 352 // small miter limit means right angles show bevel... |
350 if ((width > 0) && (stroke.getJoin() != SkPaint::kMiter_Join || | 353 if ((width > 0) && (stroke.getJoin() != SkPaint::kMiter_Join || |
351 stroke.getMiter() < SK_ScalarSqrt2)) { | 354 stroke.getMiter() < SK_ScalarSqrt2)) { |
352 miterStroke = false; | 355 miterStroke = false; |
353 } | 356 } |
354 | 357 |
355 if (spare <= 0 && miterStroke) { | 358 if (spare <= 0 && miterStroke) { |
356 this->fillAARect(target, devOutside, SkMatrix::I(), devOutside); | 359 this->fillAARect(target, drawState, devOutside, SkMatrix::I(), devOutsid
e); |
357 return; | 360 return; |
358 } | 361 } |
359 | 362 |
360 SkRect devInside(devRect); | 363 SkRect devInside(devRect); |
361 devInside.inset(rx, ry); | 364 devInside.inset(rx, ry); |
362 | 365 |
363 SkRect devOutsideAssist(devRect); | 366 SkRect devOutsideAssist(devRect); |
364 | 367 |
365 // For bevel-stroke, use 2 SkRect instances(devOutside and devOutsideAssist) | 368 // For bevel-stroke, use 2 SkRect instances(devOutside and devOutsideAssist) |
366 // to draw the outer of the rect. Because there are 8 vertices on the outer | 369 // to draw the outer of the rect. Because there are 8 vertices on the outer |
367 // edge, while vertex number of inner edge is 4, the same as miter-stroke. | 370 // edge, while vertex number of inner edge is 4, the same as miter-stroke. |
368 if (!miterStroke) { | 371 if (!miterStroke) { |
369 devOutside.inset(0, ry); | 372 devOutside.inset(0, ry); |
370 devOutsideAssist.outset(0, ry); | 373 devOutsideAssist.outset(0, ry); |
371 } | 374 } |
372 | 375 |
373 this->geometryStrokeAARect(target, devOutside, devOutsideAssist, devInside,
miterStroke); | 376 this->geometryStrokeAARect(target, drawState, devOutside, devOutsideAssist,
devInside, |
| 377 miterStroke); |
374 } | 378 } |
375 | 379 |
376 void GrAARectRenderer::geometryStrokeAARect(GrDrawTarget* target, | 380 void GrAARectRenderer::geometryStrokeAARect(GrDrawTarget* target, |
| 381 GrDrawState* drawState, |
377 const SkRect& devOutside, | 382 const SkRect& devOutside, |
378 const SkRect& devOutsideAssist, | 383 const SkRect& devOutsideAssist, |
379 const SkRect& devInside, | 384 const SkRect& devInside, |
380 bool miterStroke) { | 385 bool miterStroke) { |
381 GrDrawState* drawState = target->drawState(); | |
382 GrDrawState::AutoRestoreEffects are(drawState); | 386 GrDrawState::AutoRestoreEffects are(drawState); |
383 | |
384 CoverageAttribType covAttribType = set_rect_attribs(drawState); | 387 CoverageAttribType covAttribType = set_rect_attribs(drawState); |
385 | 388 |
386 GrColor color = drawState->getColor(); | 389 GrColor color = drawState->getColor(); |
387 if (kUseCoverage_CoverageAttribType == covAttribType && GrColorIsOpaque(colo
r)) { | 390 if (kUseCoverage_CoverageAttribType == covAttribType && GrColorIsOpaque(colo
r)) { |
388 drawState->setHint(GrDrawState::kVertexColorsAreOpaque_Hint, true); | 391 drawState->setHint(GrDrawState::kVertexColorsAreOpaque_Hint, true); |
389 } | 392 } |
390 | 393 |
391 int innerVertexNum = 4; | 394 int innerVertexNum = 4; |
392 int outerVertexNum = miterStroke ? 4 : 8; | 395 int outerVertexNum = miterStroke ? 4 : 8; |
393 int totalVertexNum = (outerVertexNum + innerVertexNum) * 2; | 396 int totalVertexNum = (outerVertexNum + innerVertexNum) * 2; |
394 | 397 |
395 GrDrawTarget::AutoReleaseGeometry geo(target, totalVertexNum, 0); | 398 GrDrawTarget::AutoReleaseGeometry geo(target, totalVertexNum, drawState->ge
tVertexStride(), 0); |
396 if (!geo.succeeded()) { | 399 if (!geo.succeeded()) { |
397 SkDebugf("Failed to get space for vertices!\n"); | 400 SkDebugf("Failed to get space for vertices!\n"); |
398 return; | 401 return; |
399 } | 402 } |
400 GrIndexBuffer* indexBuffer = this->aaStrokeRectIndexBuffer(miterStroke); | 403 GrIndexBuffer* indexBuffer = this->aaStrokeRectIndexBuffer(miterStroke); |
401 if (NULL == indexBuffer) { | 404 if (NULL == indexBuffer) { |
402 SkDebugf("Failed to create index buffer!\n"); | 405 SkDebugf("Failed to create index buffer!\n"); |
403 return; | 406 return; |
404 } | 407 } |
405 | 408 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 for (int i = 0; i < innerVertexNum; ++i) { | 495 for (int i = 0; i < innerVertexNum; ++i) { |
493 if (kUseCoverage_CoverageAttribType == covAttribType) { | 496 if (kUseCoverage_CoverageAttribType == covAttribType) { |
494 *reinterpret_cast<GrColor*>(verts + i * vstride) = color; | 497 *reinterpret_cast<GrColor*>(verts + i * vstride) = color; |
495 *reinterpret_cast<GrColor*>(verts + i * vstride + sizeof(GrColor)) =
0; | 498 *reinterpret_cast<GrColor*>(verts + i * vstride + sizeof(GrColor)) =
0; |
496 } else { | 499 } else { |
497 *reinterpret_cast<GrColor*>(verts + i * vstride) = 0; | 500 *reinterpret_cast<GrColor*>(verts + i * vstride) = 0; |
498 } | 501 } |
499 } | 502 } |
500 | 503 |
501 target->setIndexSourceToBuffer(indexBuffer); | 504 target->setIndexSourceToBuffer(indexBuffer); |
502 target->drawIndexedInstances(kTriangles_GrPrimitiveType, 1, | 505 target->drawIndexedInstances(drawState, |
503 totalVertexNum, aa_stroke_rect_index_count(mite
rStroke)); | 506 kTriangles_GrPrimitiveType, |
| 507 1, |
| 508 totalVertexNum, |
| 509 aa_stroke_rect_index_count(miterStroke)); |
504 target->resetIndexSource(); | 510 target->resetIndexSource(); |
505 } | 511 } |
506 | 512 |
507 void GrAARectRenderer::fillAANestedRects(GrDrawTarget* target, | 513 void GrAARectRenderer::fillAANestedRects(GrDrawTarget* target, |
| 514 GrDrawState* drawState, |
508 const SkRect rects[2], | 515 const SkRect rects[2], |
509 const SkMatrix& combinedMatrix) { | 516 const SkMatrix& combinedMatrix) { |
510 SkASSERT(combinedMatrix.rectStaysRect()); | 517 SkASSERT(combinedMatrix.rectStaysRect()); |
511 SkASSERT(!rects[1].isEmpty()); | 518 SkASSERT(!rects[1].isEmpty()); |
512 | 519 |
513 SkRect devOutside, devOutsideAssist, devInside; | 520 SkRect devOutside, devOutsideAssist, devInside; |
514 combinedMatrix.mapRect(&devOutside, rects[0]); | 521 combinedMatrix.mapRect(&devOutside, rects[0]); |
515 // can't call mapRect for devInside since it calls sort | 522 // can't call mapRect for devInside since it calls sort |
516 combinedMatrix.mapPoints((SkPoint*)&devInside, (const SkPoint*)&rects[1], 2)
; | 523 combinedMatrix.mapPoints((SkPoint*)&devInside, (const SkPoint*)&rects[1], 2)
; |
517 | 524 |
518 if (devInside.isEmpty()) { | 525 if (devInside.isEmpty()) { |
519 this->fillAARect(target, devOutside, SkMatrix::I(), devOutside); | 526 this->fillAARect(target, drawState, devOutside, SkMatrix::I(), devOutsid
e); |
520 return; | 527 return; |
521 } | 528 } |
522 | 529 |
523 this->geometryStrokeAARect(target, devOutside, devOutsideAssist, devInside,
true); | 530 this->geometryStrokeAARect(target, drawState, devOutside, devOutsideAssist,
devInside, true); |
524 } | 531 } |
OLD | NEW |