| 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 SkASSERT(drawState->getGeometryProcessor()->getVertexStride() == |
| 33 drawState, | 34 sizeof(GrDefaultGeoProcFactory::PositionColorAttr)); |
| 34 GrDefaultGeoProcFactory::kColor_GPType))->unref(); | |
| 35 return kUseColor_CoverageAttribType; | 35 return kUseColor_CoverageAttribType; |
| 36 } else { | 36 } else { |
| 37 drawState->setGeometryProcessor( | 37 flags |= GrDefaultGeoProcFactory::kCoverage_GPType; |
| 38 GrDefaultGeoProcFactory::CreateAndSetAttribs( | 38 drawState->setGeometryProcessor(GrDefaultGeoProcFactory::Create(flags))-
>unref(); |
| 39 drawState, | 39 SkASSERT(drawState->getGeometryProcessor()->getVertexStride() == |
| 40 GrDefaultGeoProcFactory::kColor_GPType | | 40 sizeof(GrDefaultGeoProcFactory::PositionColorCoverageAttr)); |
| 41 GrDefaultGeoProcFactory::kCoverage_GPType))->unref(); | |
| 42 return kUseCoverage_CoverageAttribType; | 41 return kUseCoverage_CoverageAttribType; |
| 43 } | 42 } |
| 44 } | 43 } |
| 45 | 44 |
| 46 static void set_inset_fan(SkPoint* pts, size_t stride, | 45 static void set_inset_fan(SkPoint* pts, size_t stride, |
| 47 const SkRect& r, SkScalar dx, SkScalar dy) { | 46 const SkRect& r, SkScalar dx, SkScalar dy) { |
| 48 pts->setRectFan(r.fLeft + dx, r.fTop + dy, | 47 pts->setRectFan(r.fLeft + dx, r.fTop + dy, |
| 49 r.fRight - dx, r.fBottom - dy, stride); | 48 r.fRight - dx, r.fBottom - dy, stride); |
| 50 } | 49 } |
| 51 | 50 |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 const SkRect& devRect) { | 182 const SkRect& devRect) { |
| 184 GrDrawState::AutoRestoreEffects are(drawState); | 183 GrDrawState::AutoRestoreEffects are(drawState); |
| 185 | 184 |
| 186 GrColor color = drawState->getColor(); | 185 GrColor color = drawState->getColor(); |
| 187 | 186 |
| 188 CoverageAttribType covAttribType = set_rect_attribs(drawState); | 187 CoverageAttribType covAttribType = set_rect_attribs(drawState); |
| 189 if (kUseCoverage_CoverageAttribType == covAttribType && GrColorIsOpaque(colo
r)) { | 188 if (kUseCoverage_CoverageAttribType == covAttribType && GrColorIsOpaque(colo
r)) { |
| 190 drawState->setHint(GrDrawState::kVertexColorsAreOpaque_Hint, true); | 189 drawState->setHint(GrDrawState::kVertexColorsAreOpaque_Hint, true); |
| 191 } | 190 } |
| 192 | 191 |
| 193 GrDrawTarget::AutoReleaseGeometry geo(target, 8, drawState->getVertexStride(
), 0); | 192 size_t vstride = drawState->getGeometryProcessor()->getVertexStride(); |
| 193 GrDrawTarget::AutoReleaseGeometry geo(target, 8, vstride, 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); |
| 204 } | 204 } |
| 205 GrIndexBuffer* indexBuffer = fAAFillRectIndexBuffer; | 205 GrIndexBuffer* indexBuffer = fAAFillRectIndexBuffer; |
| 206 if (NULL == indexBuffer) { | 206 if (NULL == indexBuffer) { |
| 207 SkDebugf("Failed to create index buffer!\n"); | 207 SkDebugf("Failed to create index buffer!\n"); |
| 208 return; | 208 return; |
| 209 } | 209 } |
| 210 | 210 |
| 211 intptr_t verts = reinterpret_cast<intptr_t>(geo.vertices()); | 211 intptr_t verts = reinterpret_cast<intptr_t>(geo.vertices()); |
| 212 size_t vstride = drawState->getVertexStride(); | |
| 213 | 212 |
| 214 SkPoint* fan0Pos = reinterpret_cast<SkPoint*>(verts); | 213 SkPoint* fan0Pos = reinterpret_cast<SkPoint*>(verts); |
| 215 SkPoint* fan1Pos = reinterpret_cast<SkPoint*>(verts + 4 * vstride); | 214 SkPoint* fan1Pos = reinterpret_cast<SkPoint*>(verts + 4 * vstride); |
| 216 | 215 |
| 217 SkScalar inset = SkMinScalar(devRect.width(), SK_Scalar1); | 216 SkScalar inset = SkMinScalar(devRect.width(), SK_Scalar1); |
| 218 inset = SK_ScalarHalf * SkMinScalar(inset, devRect.height()); | 217 inset = SK_ScalarHalf * SkMinScalar(inset, devRect.height()); |
| 219 | 218 |
| 220 if (combinedMatrix.rectStaysRect()) { | 219 if (combinedMatrix.rectStaysRect()) { |
| 221 // Temporarily #if'ed out. We don't want to pass in the devRect but | 220 // 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 | 221 // 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 | 387 |
| 389 GrColor color = drawState->getColor(); | 388 GrColor color = drawState->getColor(); |
| 390 if (kUseCoverage_CoverageAttribType == covAttribType && GrColorIsOpaque(colo
r)) { | 389 if (kUseCoverage_CoverageAttribType == covAttribType && GrColorIsOpaque(colo
r)) { |
| 391 drawState->setHint(GrDrawState::kVertexColorsAreOpaque_Hint, true); | 390 drawState->setHint(GrDrawState::kVertexColorsAreOpaque_Hint, true); |
| 392 } | 391 } |
| 393 | 392 |
| 394 int innerVertexNum = 4; | 393 int innerVertexNum = 4; |
| 395 int outerVertexNum = miterStroke ? 4 : 8; | 394 int outerVertexNum = miterStroke ? 4 : 8; |
| 396 int totalVertexNum = (outerVertexNum + innerVertexNum) * 2; | 395 int totalVertexNum = (outerVertexNum + innerVertexNum) * 2; |
| 397 | 396 |
| 398 GrDrawTarget::AutoReleaseGeometry geo(target, totalVertexNum, drawState->ge
tVertexStride(), 0); | 397 size_t vstride = drawState->getGeometryProcessor()->getVertexStride(); |
| 398 GrDrawTarget::AutoReleaseGeometry geo(target, totalVertexNum, vstride, 0); |
| 399 if (!geo.succeeded()) { | 399 if (!geo.succeeded()) { |
| 400 SkDebugf("Failed to get space for vertices!\n"); | 400 SkDebugf("Failed to get space for vertices!\n"); |
| 401 return; | 401 return; |
| 402 } | 402 } |
| 403 GrIndexBuffer* indexBuffer = this->aaStrokeRectIndexBuffer(miterStroke); | 403 GrIndexBuffer* indexBuffer = this->aaStrokeRectIndexBuffer(miterStroke); |
| 404 if (NULL == indexBuffer) { | 404 if (NULL == indexBuffer) { |
| 405 SkDebugf("Failed to create index buffer!\n"); | 405 SkDebugf("Failed to create index buffer!\n"); |
| 406 return; | 406 return; |
| 407 } | 407 } |
| 408 | 408 |
| 409 intptr_t verts = reinterpret_cast<intptr_t>(geo.vertices()); | 409 intptr_t verts = reinterpret_cast<intptr_t>(geo.vertices()); |
| 410 size_t vstride = drawState->getVertexStride(); | |
| 411 | 410 |
| 412 // We create vertices for four nested rectangles. There are two ramps from 0
to full | 411 // 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
. | 412 // 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. | 413 // The following pointers refer to the four rects, from outermost to innermo
st. |
| 415 SkPoint* fan0Pos = reinterpret_cast<SkPoint*>(verts); | 414 SkPoint* fan0Pos = reinterpret_cast<SkPoint*>(verts); |
| 416 SkPoint* fan1Pos = reinterpret_cast<SkPoint*>(verts + outerVertexNum * vstri
de); | 415 SkPoint* fan1Pos = reinterpret_cast<SkPoint*>(verts + outerVertexNum * vstri
de); |
| 417 SkPoint* fan2Pos = reinterpret_cast<SkPoint*>(verts + 2 * outerVertexNum * v
stride); | 416 SkPoint* fan2Pos = reinterpret_cast<SkPoint*>(verts + 2 * outerVertexNum * v
stride); |
| 418 SkPoint* fan3Pos = reinterpret_cast<SkPoint*>(verts + (2 * outerVertexNum +
innerVertexNum) * vstride); | 417 SkPoint* fan3Pos = reinterpret_cast<SkPoint*>(verts + (2 * outerVertexNum +
innerVertexNum) * vstride); |
| 419 | 418 |
| 420 #ifndef SK_IGNORE_THIN_STROKED_RECT_FIX | 419 #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 | 521 // can't call mapRect for devInside since it calls sort |
| 523 combinedMatrix.mapPoints((SkPoint*)&devInside, (const SkPoint*)&rects[1], 2)
; | 522 combinedMatrix.mapPoints((SkPoint*)&devInside, (const SkPoint*)&rects[1], 2)
; |
| 524 | 523 |
| 525 if (devInside.isEmpty()) { | 524 if (devInside.isEmpty()) { |
| 526 this->fillAARect(target, drawState, devOutside, SkMatrix::I(), devOutsid
e); | 525 this->fillAARect(target, drawState, devOutside, SkMatrix::I(), devOutsid
e); |
| 527 return; | 526 return; |
| 528 } | 527 } |
| 529 | 528 |
| 530 this->geometryStrokeAARect(target, drawState, devOutside, devOutsideAssist,
devInside, true); | 529 this->geometryStrokeAARect(target, drawState, devOutside, devOutsideAssist,
devInside, true); |
| 531 } | 530 } |
| OLD | NEW |