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" |
| 10 #include "GrGeometryProcessor.h" |
9 #include "GrGpu.h" | 11 #include "GrGpu.h" |
10 #include "GrInvariantOutput.h" | 12 #include "GrInvariantOutput.h" |
11 #include "gl/builders/GrGLProgramBuilder.h" | 13 #include "GrTBackendProcessorFactory.h" |
| 14 #include "SkColorPriv.h" |
12 #include "gl/GrGLProcessor.h" | 15 #include "gl/GrGLProcessor.h" |
13 #include "gl/GrGLGeometryProcessor.h" | 16 #include "gl/GrGLGeometryProcessor.h" |
14 #include "GrTBackendProcessorFactory.h" | 17 #include "gl/builders/GrGLProgramBuilder.h" |
15 #include "SkColorPriv.h" | |
16 #include "GrGeometryProcessor.h" | |
17 | 18 |
18 /////////////////////////////////////////////////////////////////////////////// | 19 /////////////////////////////////////////////////////////////////////////////// |
19 | 20 |
20 namespace { | 21 namespace { |
21 extern const GrVertexAttrib gAARectAttribs[] = { | |
22 {kVec2f_GrVertexAttribType, 0, kPosition_Gr
VertexAttribBinding}, | |
23 {kVec4ub_GrVertexAttribType, sizeof(SkPoint), kColor_GrVer
texAttribBinding}, | |
24 {kFloat_GrVertexAttribType, sizeof(SkPoint) + sizeof(SkColor), kCoverage_Gr
VertexAttribBinding}, | |
25 }; | |
26 | |
27 // 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. |
28 enum CoverageAttribType { | 23 enum CoverageAttribType { |
29 kUseColor_CoverageAttribType, | 24 kUseColor_CoverageAttribType, |
30 kUseCoverage_CoverageAttribType, | 25 kUseCoverage_CoverageAttribType, |
31 }; | 26 }; |
32 } | 27 } |
33 | 28 |
34 static CoverageAttribType set_rect_attribs(GrDrawState* drawState) { | 29 static CoverageAttribType set_rect_attribs(GrDrawState* drawState) { |
35 if (drawState->canTweakAlphaForCoverage()) { | 30 if (drawState->canTweakAlphaForCoverage()) { |
36 drawState->setVertexAttribs<gAARectAttribs>(2, sizeof(SkPoint) + sizeof(
SkColor)); | 31 drawState->setGeometryProcessor( |
| 32 GrDefaultGeoProcFactory::CreateAndSetAttribs( |
| 33 drawState, |
| 34 GrDefaultGeoProcFactory::kColor_GPType))->unref(); |
37 return kUseColor_CoverageAttribType; | 35 return kUseColor_CoverageAttribType; |
38 } else { | 36 } else { |
39 drawState->setVertexAttribs<gAARectAttribs>(3, sizeof(SkPoint) + sizeof(
SkColor) + | 37 drawState->setGeometryProcessor( |
40 sizeof(float)); | 38 GrDefaultGeoProcFactory::CreateAndSetAttribs( |
| 39 drawState, |
| 40 GrDefaultGeoProcFactory::kColor_GPType | |
| 41 GrDefaultGeoProcFactory::kCoverage_GPType))->unref(); |
41 return kUseCoverage_CoverageAttribType; | 42 return kUseCoverage_CoverageAttribType; |
42 } | 43 } |
43 } | 44 } |
44 | 45 |
45 static void set_inset_fan(SkPoint* pts, size_t stride, | 46 static void set_inset_fan(SkPoint* pts, size_t stride, |
46 const SkRect& r, SkScalar dx, SkScalar dy) { | 47 const SkRect& r, SkScalar dx, SkScalar dy) { |
47 pts->setRectFan(r.fLeft + dx, r.fTop + dy, | 48 pts->setRectFan(r.fLeft + dx, r.fTop + dy, |
48 r.fRight - dx, r.fBottom - dy, stride); | 49 r.fRight - dx, r.fBottom - dy, stride); |
49 } | 50 } |
50 | 51 |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 } | 174 } |
174 return fAABevelStrokeRectIndexBuffer; | 175 return fAABevelStrokeRectIndexBuffer; |
175 } | 176 } |
176 } | 177 } |
177 | 178 |
178 void GrAARectRenderer::geometryFillAARect(GrDrawTarget* target, | 179 void GrAARectRenderer::geometryFillAARect(GrDrawTarget* target, |
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* drawState = target->drawState(); |
| 184 GrDrawState::AutoRestoreEffects are(drawState); |
183 | 185 |
184 GrColor color = drawState->getColor(); | 186 GrColor color = drawState->getColor(); |
185 | 187 |
186 CoverageAttribType covAttribType = set_rect_attribs(drawState); | 188 CoverageAttribType covAttribType = set_rect_attribs(drawState); |
187 if (kUseCoverage_CoverageAttribType == covAttribType && GrColorIsOpaque(colo
r)) { | 189 if (kUseCoverage_CoverageAttribType == covAttribType && GrColorIsOpaque(colo
r)) { |
188 drawState->setHint(GrDrawState::kVertexColorsAreOpaque_Hint, true); | 190 drawState->setHint(GrDrawState::kVertexColorsAreOpaque_Hint, true); |
189 } | 191 } |
190 | 192 |
191 GrDrawTarget::AutoReleaseGeometry geo(target, 8, 0); | 193 GrDrawTarget::AutoReleaseGeometry geo(target, 8, 0); |
192 if (!geo.succeeded()) { | 194 if (!geo.succeeded()) { |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 | 372 |
371 this->geometryStrokeAARect(target, devOutside, devOutsideAssist, devInside,
miterStroke); | 373 this->geometryStrokeAARect(target, devOutside, devOutsideAssist, devInside,
miterStroke); |
372 } | 374 } |
373 | 375 |
374 void GrAARectRenderer::geometryStrokeAARect(GrDrawTarget* target, | 376 void GrAARectRenderer::geometryStrokeAARect(GrDrawTarget* target, |
375 const SkRect& devOutside, | 377 const SkRect& devOutside, |
376 const SkRect& devOutsideAssist, | 378 const SkRect& devOutsideAssist, |
377 const SkRect& devInside, | 379 const SkRect& devInside, |
378 bool miterStroke) { | 380 bool miterStroke) { |
379 GrDrawState* drawState = target->drawState(); | 381 GrDrawState* drawState = target->drawState(); |
| 382 GrDrawState::AutoRestoreEffects are(drawState); |
380 | 383 |
381 CoverageAttribType covAttribType = set_rect_attribs(drawState); | 384 CoverageAttribType covAttribType = set_rect_attribs(drawState); |
382 | 385 |
383 GrColor color = drawState->getColor(); | 386 GrColor color = drawState->getColor(); |
384 if (kUseCoverage_CoverageAttribType == covAttribType && GrColorIsOpaque(colo
r)) { | 387 if (kUseCoverage_CoverageAttribType == covAttribType && GrColorIsOpaque(colo
r)) { |
385 drawState->setHint(GrDrawState::kVertexColorsAreOpaque_Hint, true); | 388 drawState->setHint(GrDrawState::kVertexColorsAreOpaque_Hint, true); |
386 } | 389 } |
387 | 390 |
388 int innerVertexNum = 4; | 391 int innerVertexNum = 4; |
389 int outerVertexNum = miterStroke ? 4 : 8; | 392 int outerVertexNum = miterStroke ? 4 : 8; |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
512 // can't call mapRect for devInside since it calls sort | 515 // can't call mapRect for devInside since it calls sort |
513 combinedMatrix.mapPoints((SkPoint*)&devInside, (const SkPoint*)&rects[1], 2)
; | 516 combinedMatrix.mapPoints((SkPoint*)&devInside, (const SkPoint*)&rects[1], 2)
; |
514 | 517 |
515 if (devInside.isEmpty()) { | 518 if (devInside.isEmpty()) { |
516 this->fillAARect(target, devOutside, SkMatrix::I(), devOutside); | 519 this->fillAARect(target, devOutside, SkMatrix::I(), devOutside); |
517 return; | 520 return; |
518 } | 521 } |
519 | 522 |
520 this->geometryStrokeAARect(target, devOutside, devOutsideAssist, devInside,
true); | 523 this->geometryStrokeAARect(target, devOutside, devOutsideAssist, devInside,
true); |
521 } | 524 } |
OLD | NEW |