Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(314)

Side by Side Diff: src/gpu/GrAARectRenderer.cpp

Issue 715903002: Push creation of default GP to the caller (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "gl/builders/GrGLProgramBuilder.h" 12 #include "GrTBackendProcessorFactory.h"
13 #include "SkColorPriv.h"
11 #include "gl/GrGLProcessor.h" 14 #include "gl/GrGLProcessor.h"
12 #include "gl/GrGLGeometryProcessor.h" 15 #include "gl/GrGLGeometryProcessor.h"
13 #include "GrTBackendProcessorFactory.h" 16 #include "gl/builders/GrGLProgramBuilder.h"
14 #include "SkColorPriv.h"
15 #include "GrGeometryProcessor.h"
16 17
17 /////////////////////////////////////////////////////////////////////////////// 18 ///////////////////////////////////////////////////////////////////////////////
18 19
19 namespace { 20 namespace {
20 extern const GrVertexAttrib gAARectAttribs[] = {
21 {kVec2f_GrVertexAttribType, 0, kPosition_Gr VertexAttribBinding},
22 {kVec4ub_GrVertexAttribType, sizeof(SkPoint), kColor_GrVer texAttribBinding},
23 {kFloat_GrVertexAttribType, sizeof(SkPoint) + sizeof(SkColor), kCoverage_Gr VertexAttribBinding},
24 };
25
26 // Should the coverage be multiplied into the color attrib or use a separate att rib. 21 // Should the coverage be multiplied into the color attrib or use a separate att rib.
27 enum CoverageAttribType { 22 enum CoverageAttribType {
28 kUseColor_CoverageAttribType, 23 kUseColor_CoverageAttribType,
29 kUseCoverage_CoverageAttribType, 24 kUseCoverage_CoverageAttribType,
30 }; 25 };
31 } 26 }
32 27
33 static CoverageAttribType set_rect_attribs(GrDrawState* drawState) { 28 static CoverageAttribType set_rect_attribs(GrDrawState* drawState) {
34 if (drawState->canTweakAlphaForCoverage()) { 29 if (drawState->canTweakAlphaForCoverage()) {
35 drawState->setVertexAttribs<gAARectAttribs>(2, sizeof(SkPoint) + sizeof( SkColor)); 30 drawState->setGeometryProcessor(
31 GrDefaultGeoProcFactory::CreateAndSetAttribs(
32 drawState,
33 GrDefaultGeoProcFactory::kColor_GPType))->unref();
36 return kUseColor_CoverageAttribType; 34 return kUseColor_CoverageAttribType;
37 } else { 35 } else {
38 drawState->setVertexAttribs<gAARectAttribs>(3, sizeof(SkPoint) + sizeof( SkColor) + 36 drawState->setGeometryProcessor(
39 sizeof(float)); 37 GrDefaultGeoProcFactory::CreateAndSetAttribs(
38 drawState,
39 GrDefaultGeoProcFactory::kColor_GPType |
40 GrDefaultGeoProcFactory::kCoverage_GPType))->unref();
40 return kUseCoverage_CoverageAttribType; 41 return kUseCoverage_CoverageAttribType;
41 } 42 }
42 } 43 }
43 44
44 static void set_inset_fan(SkPoint* pts, size_t stride, 45 static void set_inset_fan(SkPoint* pts, size_t stride,
45 const SkRect& r, SkScalar dx, SkScalar dy) { 46 const SkRect& r, SkScalar dx, SkScalar dy) {
46 pts->setRectFan(r.fLeft + dx, r.fTop + dy, 47 pts->setRectFan(r.fLeft + dx, r.fTop + dy,
47 r.fRight - dx, r.fBottom - dy, stride); 48 r.fRight - dx, r.fBottom - dy, stride);
48 } 49 }
49 50
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 } 173 }
173 return fAABevelStrokeRectIndexBuffer; 174 return fAABevelStrokeRectIndexBuffer;
174 } 175 }
175 } 176 }
176 177
177 void GrAARectRenderer::geometryFillAARect(GrDrawTarget* target, 178 void GrAARectRenderer::geometryFillAARect(GrDrawTarget* target,
178 const SkRect& rect, 179 const SkRect& rect,
179 const SkMatrix& combinedMatrix, 180 const SkMatrix& combinedMatrix,
180 const SkRect& devRect) { 181 const SkRect& devRect) {
181 GrDrawState* drawState = target->drawState(); 182 GrDrawState* drawState = target->drawState();
183 GrDrawState::AutoRestoreEffects are(drawState);
182 184
183 GrColor color = drawState->getColor(); 185 GrColor color = drawState->getColor();
184 186
185 CoverageAttribType covAttribType = set_rect_attribs(drawState); 187 CoverageAttribType covAttribType = set_rect_attribs(drawState);
186 if (kUseCoverage_CoverageAttribType == covAttribType && GrColorIsOpaque(colo r)) { 188 if (kUseCoverage_CoverageAttribType == covAttribType && GrColorIsOpaque(colo r)) {
187 drawState->setHint(GrDrawState::kVertexColorsAreOpaque_Hint, true); 189 drawState->setHint(GrDrawState::kVertexColorsAreOpaque_Hint, true);
188 } 190 }
189 191
190 GrDrawTarget::AutoReleaseGeometry geo(target, 8, 0); 192 GrDrawTarget::AutoReleaseGeometry geo(target, 8, 0);
191 if (!geo.succeeded()) { 193 if (!geo.succeeded()) {
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 371
370 this->geometryStrokeAARect(target, devOutside, devOutsideAssist, devInside, miterStroke); 372 this->geometryStrokeAARect(target, devOutside, devOutsideAssist, devInside, miterStroke);
371 } 373 }
372 374
373 void GrAARectRenderer::geometryStrokeAARect(GrDrawTarget* target, 375 void GrAARectRenderer::geometryStrokeAARect(GrDrawTarget* target,
374 const SkRect& devOutside, 376 const SkRect& devOutside,
375 const SkRect& devOutsideAssist, 377 const SkRect& devOutsideAssist,
376 const SkRect& devInside, 378 const SkRect& devInside,
377 bool miterStroke) { 379 bool miterStroke) {
378 GrDrawState* drawState = target->drawState(); 380 GrDrawState* drawState = target->drawState();
381 GrDrawState::AutoRestoreEffects are(drawState);
379 382
380 CoverageAttribType covAttribType = set_rect_attribs(drawState); 383 CoverageAttribType covAttribType = set_rect_attribs(drawState);
381 384
382 GrColor color = drawState->getColor(); 385 GrColor color = drawState->getColor();
383 if (kUseCoverage_CoverageAttribType == covAttribType && GrColorIsOpaque(colo r)) { 386 if (kUseCoverage_CoverageAttribType == covAttribType && GrColorIsOpaque(colo r)) {
384 drawState->setHint(GrDrawState::kVertexColorsAreOpaque_Hint, true); 387 drawState->setHint(GrDrawState::kVertexColorsAreOpaque_Hint, true);
385 } 388 }
386 389
387 int innerVertexNum = 4; 390 int innerVertexNum = 4;
388 int outerVertexNum = miterStroke ? 4 : 8; 391 int outerVertexNum = miterStroke ? 4 : 8;
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 // can't call mapRect for devInside since it calls sort 514 // can't call mapRect for devInside since it calls sort
512 combinedMatrix.mapPoints((SkPoint*)&devInside, (const SkPoint*)&rects[1], 2) ; 515 combinedMatrix.mapPoints((SkPoint*)&devInside, (const SkPoint*)&rects[1], 2) ;
513 516
514 if (devInside.isEmpty()) { 517 if (devInside.isEmpty()) {
515 this->fillAARect(target, devOutside, SkMatrix::I(), devOutside); 518 this->fillAARect(target, devOutside, SkMatrix::I(), devOutside);
516 return; 519 return;
517 } 520 }
518 521
519 this->geometryStrokeAARect(target, devOutside, devOutsideAssist, devInside, true); 522 this->geometryStrokeAARect(target, devOutside, devOutsideAssist, devInside, true);
520 } 523 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698