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