| 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" |
| 11 #include "GrGpu.h" | 11 #include "GrGpu.h" |
| 12 #include "GrInvariantOutput.h" | 12 #include "GrInvariantOutput.h" |
| 13 #include "GrTBackendProcessorFactory.h" | 13 #include "GrTBackendProcessorFactory.h" |
| 14 #include "SkColorPriv.h" | 14 #include "SkColorPriv.h" |
| 15 #include "gl/GrGLProcessor.h" | 15 #include "gl/GrGLProcessor.h" |
| 16 #include "gl/GrGLGeometryProcessor.h" | 16 #include "gl/GrGLGeometryProcessor.h" |
| 17 #include "gl/builders/GrGLProgramBuilder.h" | 17 #include "gl/builders/GrGLProgramBuilder.h" |
| 18 | 18 |
| 19 /////////////////////////////////////////////////////////////////////////////// | 19 /////////////////////////////////////////////////////////////////////////////// |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 // Should the coverage be multiplied into the color attrib or use a separate att
rib. | 22 // Should the coverage be multiplied into the color attrib or use a separate att
rib. |
| 23 enum CoverageAttribType { | 23 enum CoverageAttribType { |
| 24 kUseColor_CoverageAttribType, | 24 kUseColor_CoverageAttribType, |
| 25 kUseCoverage_CoverageAttribType, | 25 kUseCoverage_CoverageAttribType, |
| 26 }; | 26 }; |
| 27 } | 27 } |
| 28 | 28 |
| 29 static CoverageAttribType set_rect_attribs(GrDrawState* drawState) { | 29 static CoverageAttribType set_rect_attribs(GrDrawState* drawState) { |
| 30 uint32_t flags = GrDefaultGeoProcFactory::kColor_GPType; |
| 30 if (drawState->canTweakAlphaForCoverage()) { | 31 if (drawState->canTweakAlphaForCoverage()) { |
| 31 drawState->setGeometryProcessor( | 32 drawState->setGeometryProcessor(GrDefaultGeoProcFactory::Create(flags))-
>unref(); |
| 32 GrDefaultGeoProcFactory::CreateAndSetAttribs( | |
| 33 drawState, | |
| 34 GrDefaultGeoProcFactory::kColor_GPType))->unref(); | |
| 35 return kUseColor_CoverageAttribType; | 33 return kUseColor_CoverageAttribType; |
| 36 } else { | 34 } else { |
| 37 drawState->setGeometryProcessor( | 35 flags |= GrDefaultGeoProcFactory::kCoverage_GPType; |
| 38 GrDefaultGeoProcFactory::CreateAndSetAttribs( | 36 drawState->setGeometryProcessor(GrDefaultGeoProcFactory::Create(flags))-
>unref(); |
| 39 drawState, | |
| 40 GrDefaultGeoProcFactory::kColor_GPType | | |
| 41 GrDefaultGeoProcFactory::kCoverage_GPType))->unref(); | |
| 42 return kUseCoverage_CoverageAttribType; | 37 return kUseCoverage_CoverageAttribType; |
| 43 } | 38 } |
| 44 } | 39 } |
| 45 | 40 |
| 46 static void set_inset_fan(SkPoint* pts, size_t stride, | 41 static void set_inset_fan(SkPoint* pts, size_t stride, |
| 47 const SkRect& r, SkScalar dx, SkScalar dy) { | 42 const SkRect& r, SkScalar dx, SkScalar dy) { |
| 48 pts->setRectFan(r.fLeft + dx, r.fTop + dy, | 43 pts->setRectFan(r.fLeft + dx, r.fTop + dy, |
| 49 r.fRight - dx, r.fBottom - dy, stride); | 44 r.fRight - dx, r.fBottom - dy, stride); |
| 50 } | 45 } |
| 51 | 46 |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 const SkRect& devRect) { | 178 const SkRect& devRect) { |
| 184 GrDrawState::AutoRestoreEffects are(drawState); | 179 GrDrawState::AutoRestoreEffects are(drawState); |
| 185 | 180 |
| 186 GrColor color = drawState->getColor(); | 181 GrColor color = drawState->getColor(); |
| 187 | 182 |
| 188 CoverageAttribType covAttribType = set_rect_attribs(drawState); | 183 CoverageAttribType covAttribType = set_rect_attribs(drawState); |
| 189 if (kUseCoverage_CoverageAttribType == covAttribType && GrColorIsOpaque(colo
r)) { | 184 if (kUseCoverage_CoverageAttribType == covAttribType && GrColorIsOpaque(colo
r)) { |
| 190 drawState->setHint(GrDrawState::kVertexColorsAreOpaque_Hint, true); | 185 drawState->setHint(GrDrawState::kVertexColorsAreOpaque_Hint, true); |
| 191 } | 186 } |
| 192 | 187 |
| 193 GrDrawTarget::AutoReleaseGeometry geo(target, 8, drawState->getVertexStride(
), 0); | 188 size_t vstride = drawState->getGeometryProcessor()->getVertexStride(); |
| 189 GrDrawTarget::AutoReleaseGeometry geo(target, 8, vstride, 0); |
| 194 if (!geo.succeeded()) { | 190 if (!geo.succeeded()) { |
| 195 SkDebugf("Failed to get space for vertices!\n"); | 191 SkDebugf("Failed to get space for vertices!\n"); |
| 196 return; | 192 return; |
| 197 } | 193 } |
| 198 | 194 |
| 199 if (NULL == fAAFillRectIndexBuffer) { | 195 if (NULL == fAAFillRectIndexBuffer) { |
| 200 fAAFillRectIndexBuffer = fGpu->createInstancedIndexBuffer(gFillAARectIdx
, | 196 fAAFillRectIndexBuffer = fGpu->createInstancedIndexBuffer(gFillAARectIdx
, |
| 201 kIndicesPerAAF
illRect, | 197 kIndicesPerAAF
illRect, |
| 202 kNumAAFillRect
sInIndexBuffer, | 198 kNumAAFillRect
sInIndexBuffer, |
| 203 kVertsPerAAFil
lRect); | 199 kVertsPerAAFil
lRect); |
| 204 } | 200 } |
| 205 GrIndexBuffer* indexBuffer = fAAFillRectIndexBuffer; | 201 GrIndexBuffer* indexBuffer = fAAFillRectIndexBuffer; |
| 206 if (NULL == indexBuffer) { | 202 if (NULL == indexBuffer) { |
| 207 SkDebugf("Failed to create index buffer!\n"); | 203 SkDebugf("Failed to create index buffer!\n"); |
| 208 return; | 204 return; |
| 209 } | 205 } |
| 210 | 206 |
| 211 intptr_t verts = reinterpret_cast<intptr_t>(geo.vertices()); | 207 intptr_t verts = reinterpret_cast<intptr_t>(geo.vertices()); |
| 212 size_t vstride = drawState->getVertexStride(); | |
| 213 | 208 |
| 214 SkPoint* fan0Pos = reinterpret_cast<SkPoint*>(verts); | 209 SkPoint* fan0Pos = reinterpret_cast<SkPoint*>(verts); |
| 215 SkPoint* fan1Pos = reinterpret_cast<SkPoint*>(verts + 4 * vstride); | 210 SkPoint* fan1Pos = reinterpret_cast<SkPoint*>(verts + 4 * vstride); |
| 216 | 211 |
| 217 SkScalar inset = SkMinScalar(devRect.width(), SK_Scalar1); | 212 SkScalar inset = SkMinScalar(devRect.width(), SK_Scalar1); |
| 218 inset = SK_ScalarHalf * SkMinScalar(inset, devRect.height()); | 213 inset = SK_ScalarHalf * SkMinScalar(inset, devRect.height()); |
| 219 | 214 |
| 220 if (combinedMatrix.rectStaysRect()) { | 215 if (combinedMatrix.rectStaysRect()) { |
| 221 // Temporarily #if'ed out. We don't want to pass in the devRect but | 216 // Temporarily #if'ed out. We don't want to pass in the devRect but |
| 222 // right now it is computed in GrContext::apply_aa_to_rect and we don't | 217 // right now it is computed in GrContext::apply_aa_to_rect and we don't |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 | 383 |
| 389 GrColor color = drawState->getColor(); | 384 GrColor color = drawState->getColor(); |
| 390 if (kUseCoverage_CoverageAttribType == covAttribType && GrColorIsOpaque(colo
r)) { | 385 if (kUseCoverage_CoverageAttribType == covAttribType && GrColorIsOpaque(colo
r)) { |
| 391 drawState->setHint(GrDrawState::kVertexColorsAreOpaque_Hint, true); | 386 drawState->setHint(GrDrawState::kVertexColorsAreOpaque_Hint, true); |
| 392 } | 387 } |
| 393 | 388 |
| 394 int innerVertexNum = 4; | 389 int innerVertexNum = 4; |
| 395 int outerVertexNum = miterStroke ? 4 : 8; | 390 int outerVertexNum = miterStroke ? 4 : 8; |
| 396 int totalVertexNum = (outerVertexNum + innerVertexNum) * 2; | 391 int totalVertexNum = (outerVertexNum + innerVertexNum) * 2; |
| 397 | 392 |
| 398 GrDrawTarget::AutoReleaseGeometry geo(target, totalVertexNum, drawState->ge
tVertexStride(), 0); | 393 size_t vstride = drawState->getGeometryProcessor()->getVertexStride(); |
| 394 GrDrawTarget::AutoReleaseGeometry geo(target, totalVertexNum, vstride, 0); |
| 399 if (!geo.succeeded()) { | 395 if (!geo.succeeded()) { |
| 400 SkDebugf("Failed to get space for vertices!\n"); | 396 SkDebugf("Failed to get space for vertices!\n"); |
| 401 return; | 397 return; |
| 402 } | 398 } |
| 403 GrIndexBuffer* indexBuffer = this->aaStrokeRectIndexBuffer(miterStroke); | 399 GrIndexBuffer* indexBuffer = this->aaStrokeRectIndexBuffer(miterStroke); |
| 404 if (NULL == indexBuffer) { | 400 if (NULL == indexBuffer) { |
| 405 SkDebugf("Failed to create index buffer!\n"); | 401 SkDebugf("Failed to create index buffer!\n"); |
| 406 return; | 402 return; |
| 407 } | 403 } |
| 408 | 404 |
| 409 intptr_t verts = reinterpret_cast<intptr_t>(geo.vertices()); | 405 intptr_t verts = reinterpret_cast<intptr_t>(geo.vertices()); |
| 410 size_t vstride = drawState->getVertexStride(); | |
| 411 | 406 |
| 412 // We create vertices for four nested rectangles. There are two ramps from 0
to full | 407 // We create vertices for four nested rectangles. There are two ramps from 0
to full |
| 413 // coverage, one on the exterior of the stroke and the other on the interior
. | 408 // coverage, one on the exterior of the stroke and the other on the interior
. |
| 414 // The following pointers refer to the four rects, from outermost to innermo
st. | 409 // The following pointers refer to the four rects, from outermost to innermo
st. |
| 415 SkPoint* fan0Pos = reinterpret_cast<SkPoint*>(verts); | 410 SkPoint* fan0Pos = reinterpret_cast<SkPoint*>(verts); |
| 416 SkPoint* fan1Pos = reinterpret_cast<SkPoint*>(verts + outerVertexNum * vstri
de); | 411 SkPoint* fan1Pos = reinterpret_cast<SkPoint*>(verts + outerVertexNum * vstri
de); |
| 417 SkPoint* fan2Pos = reinterpret_cast<SkPoint*>(verts + 2 * outerVertexNum * v
stride); | 412 SkPoint* fan2Pos = reinterpret_cast<SkPoint*>(verts + 2 * outerVertexNum * v
stride); |
| 418 SkPoint* fan3Pos = reinterpret_cast<SkPoint*>(verts + (2 * outerVertexNum +
innerVertexNum) * vstride); | 413 SkPoint* fan3Pos = reinterpret_cast<SkPoint*>(verts + (2 * outerVertexNum +
innerVertexNum) * vstride); |
| 419 | 414 |
| 420 #ifndef SK_IGNORE_THIN_STROKED_RECT_FIX | 415 #ifndef SK_IGNORE_THIN_STROKED_RECT_FIX |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 // can't call mapRect for devInside since it calls sort | 517 // can't call mapRect for devInside since it calls sort |
| 523 combinedMatrix.mapPoints((SkPoint*)&devInside, (const SkPoint*)&rects[1], 2)
; | 518 combinedMatrix.mapPoints((SkPoint*)&devInside, (const SkPoint*)&rects[1], 2)
; |
| 524 | 519 |
| 525 if (devInside.isEmpty()) { | 520 if (devInside.isEmpty()) { |
| 526 this->fillAARect(target, drawState, devOutside, SkMatrix::I(), devOutsid
e); | 521 this->fillAARect(target, drawState, devOutside, SkMatrix::I(), devOutsid
e); |
| 527 return; | 522 return; |
| 528 } | 523 } |
| 529 | 524 |
| 530 this->geometryStrokeAARect(target, drawState, devOutside, devOutsideAssist,
devInside, true); | 525 this->geometryStrokeAARect(target, drawState, devOutside, devOutsideAssist,
devInside, true); |
| 531 } | 526 } |
| OLD | NEW |