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

Side by Side Diff: src/gpu/batches/GrAAStrokeRectBatch.cpp

Issue 2041113004: sk_sp for gpu. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Reserve correctly. Created 4 years, 6 months 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 2015 Google Inc. 2 * Copyright 2015 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 "GrAAStrokeRectBatch.h" 8 #include "GrAAStrokeRectBatch.h"
9 9
10 #include "GrBatchFlushState.h" 10 #include "GrBatchFlushState.h"
11 #include "GrDefaultGeoProcFactory.h" 11 #include "GrDefaultGeoProcFactory.h"
12 #include "GrResourceKey.h" 12 #include "GrResourceKey.h"
13 #include "GrResourceProvider.h" 13 #include "GrResourceProvider.h"
14 14
15 GR_DECLARE_STATIC_UNIQUE_KEY(gMiterIndexBufferKey); 15 GR_DECLARE_STATIC_UNIQUE_KEY(gMiterIndexBufferKey);
16 GR_DECLARE_STATIC_UNIQUE_KEY(gBevelIndexBufferKey); 16 GR_DECLARE_STATIC_UNIQUE_KEY(gBevelIndexBufferKey);
17 17
18 static void set_inset_fan(SkPoint* pts, size_t stride, 18 static void set_inset_fan(SkPoint* pts, size_t stride,
19 const SkRect& r, SkScalar dx, SkScalar dy) { 19 const SkRect& r, SkScalar dx, SkScalar dy) {
20 pts->setRectFan(r.fLeft + dx, r.fTop + dy, 20 pts->setRectFan(r.fLeft + dx, r.fTop + dy,
21 r.fRight - dx, r.fBottom - dy, stride); 21 r.fRight - dx, r.fBottom - dy, stride);
22 } 22 }
23 23
24 static const GrGeometryProcessor* create_stroke_rect_gp(bool tweakAlphaForCovera ge, 24 static sk_sp<GrGeometryProcessor> create_stroke_rect_gp(bool tweakAlphaForCovera ge,
25 const SkMatrix& viewMatr ix, 25 const SkMatrix& viewMatr ix,
26 bool usesLocalCoords, 26 bool usesLocalCoords,
27 bool coverageIgnored) { 27 bool coverageIgnored) {
28 using namespace GrDefaultGeoProcFactory; 28 using namespace GrDefaultGeoProcFactory;
29 29
30 Color color(Color::kAttribute_Type); 30 Color color(Color::kAttribute_Type);
31 Coverage::Type coverageType; 31 Coverage::Type coverageType;
32 // TODO remove coverage if coverage is ignored 32 // TODO remove coverage if coverage is ignored
33 /*if (coverageIgnored) { 33 /*if (coverageIgnored) {
34 coverageType = Coverage::kNone_Type; 34 coverageType = Coverage::kNone_Type;
35 } else*/ if (tweakAlphaForCoverage) { 35 } else*/ if (tweakAlphaForCoverage) {
36 coverageType = Coverage::kSolid_Type; 36 coverageType = Coverage::kSolid_Type;
37 } else { 37 } else {
38 coverageType = Coverage::kAttribute_Type; 38 coverageType = Coverage::kAttribute_Type;
39 } 39 }
40 Coverage coverage(coverageType); 40 Coverage coverage(coverageType);
41 LocalCoords localCoords(usesLocalCoords ? LocalCoords::kUsePosition_Type : 41 LocalCoords localCoords(usesLocalCoords ? LocalCoords::kUsePosition_Type :
42 LocalCoords::kUnused_Type); 42 LocalCoords::kUnused_Type);
43 return CreateForDeviceSpace(color, coverage, localCoords, viewMatrix); 43 return MakeForDeviceSpace(color, coverage, localCoords, viewMatrix);
44 } 44 }
45 45
46 class AAStrokeRectBatch : public GrVertexBatch { 46 class AAStrokeRectBatch : public GrVertexBatch {
47 public: 47 public:
48 DEFINE_BATCH_CLASS_ID 48 DEFINE_BATCH_CLASS_ID
49 49
50 // TODO support AA rotated stroke rects by copying around view matrices 50 // TODO support AA rotated stroke rects by copying around view matrices
51 struct Geometry { 51 struct Geometry {
52 SkRect fDevOutside; 52 SkRect fDevOutside;
53 SkRect fDevOutsideAssist; 53 SkRect fDevOutsideAssist;
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 fBatch.fColorIgnored = !overrides.readsColor(); 176 fBatch.fColorIgnored = !overrides.readsColor();
177 fBatch.fColor = fGeoData[0].fColor; 177 fBatch.fColor = fGeoData[0].fColor;
178 fBatch.fUsesLocalCoords = overrides.readsLocalCoords(); 178 fBatch.fUsesLocalCoords = overrides.readsLocalCoords();
179 fBatch.fCoverageIgnored = !overrides.readsCoverage(); 179 fBatch.fCoverageIgnored = !overrides.readsCoverage();
180 fBatch.fCanTweakAlphaForCoverage = overrides.canTweakAlphaForCoverage(); 180 fBatch.fCanTweakAlphaForCoverage = overrides.canTweakAlphaForCoverage();
181 } 181 }
182 182
183 void AAStrokeRectBatch::onPrepareDraws(Target* target) const { 183 void AAStrokeRectBatch::onPrepareDraws(Target* target) const {
184 bool canTweakAlphaForCoverage = this->canTweakAlphaForCoverage(); 184 bool canTweakAlphaForCoverage = this->canTweakAlphaForCoverage();
185 185
186 SkAutoTUnref<const GrGeometryProcessor> gp(create_stroke_rect_gp(canTweakAlp haForCoverage, 186 sk_sp<GrGeometryProcessor> gp(create_stroke_rect_gp(canTweakAlphaForCoverage ,
187 this->viewM atrix(), 187 this->viewMatrix(),
188 this->usesL ocalCoords(), 188 this->usesLocalCoords(),
189 this->cover ageIgnored())); 189 this->coverageIgnored()) );
190 if (!gp) { 190 if (!gp) {
191 SkDebugf("Couldn't create GrGeometryProcessor\n"); 191 SkDebugf("Couldn't create GrGeometryProcessor\n");
192 return; 192 return;
193 } 193 }
194 194
195 size_t vertexStride = gp->getVertexStride(); 195 size_t vertexStride = gp->getVertexStride();
196 196
197 SkASSERT(canTweakAlphaForCoverage ? 197 SkASSERT(canTweakAlphaForCoverage ?
198 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorAttr) : 198 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorAttr) :
199 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorCovera geAttr)); 199 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorCovera geAttr));
(...skipping 22 matching lines...) Expand all
222 outerVertexNum, 222 outerVertexNum,
223 innerVertexNum, 223 innerVertexNum,
224 args.fColor, 224 args.fColor,
225 args.fDevOutside, 225 args.fDevOutside,
226 args.fDevOutsideAssist, 226 args.fDevOutsideAssist,
227 args.fDevInside, 227 args.fDevInside,
228 fMiterStroke, 228 fMiterStroke,
229 args.fDegenerate, 229 args.fDegenerate,
230 canTweakAlphaForCoverage); 230 canTweakAlphaForCoverage);
231 } 231 }
232 helper.recordDraw(target, gp); 232 helper.recordDraw(target, gp.get());
233 } 233 }
234 234
235 const GrBuffer* AAStrokeRectBatch::GetIndexBuffer(GrResourceProvider* resourcePr ovider, 235 const GrBuffer* AAStrokeRectBatch::GetIndexBuffer(GrResourceProvider* resourcePr ovider,
236 bool miterStroke) { 236 bool miterStroke) {
237 237
238 if (miterStroke) { 238 if (miterStroke) {
239 static const uint16_t gMiterIndices[] = { 239 static const uint16_t gMiterIndices[] = {
240 0 + 0, 1 + 0, 5 + 0, 5 + 0, 4 + 0, 0 + 0, 240 0 + 0, 1 + 0, 5 + 0, 5 + 0, 4 + 0, 0 + 0,
241 1 + 0, 2 + 0, 6 + 0, 6 + 0, 5 + 0, 1 + 0, 241 1 + 0, 2 + 0, 6 + 0, 6 + 0, 5 + 0, 1 + 0,
242 2 + 0, 3 + 0, 7 + 0, 7 + 0, 6 + 0, 2 + 0, 242 2 + 0, 3 + 0, 7 + 0, 7 + 0, 6 + 0, 2 + 0,
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after
653 SkStrokeRec rec(SkStrokeRec::kFill_InitStyle); 653 SkStrokeRec rec(SkStrokeRec::kFill_InitStyle);
654 rec.setStrokeStyle(strokeWidth); 654 rec.setStrokeStyle(strokeWidth);
655 rec.setStrokeParams(SkPaint::kButt_Cap, 655 rec.setStrokeParams(SkPaint::kButt_Cap,
656 miterStroke ? SkPaint::kMiter_Join : SkPaint::kBevel_Joi n, 656 miterStroke ? SkPaint::kMiter_Join : SkPaint::kBevel_Joi n,
657 1.f); 657 1.f);
658 SkMatrix matrix = GrTest::TestMatrixRectStaysRect(random); 658 SkMatrix matrix = GrTest::TestMatrixRectStaysRect(random);
659 return GrAAStrokeRectBatch::Create(color, matrix, rect, rec); 659 return GrAAStrokeRectBatch::Create(color, matrix, rect, rec);
660 } 660 }
661 661
662 #endif 662 #endif
OLDNEW
« no previous file with comments | « src/gpu/batches/GrAALinearizingConvexPathRenderer.cpp ('k') | src/gpu/batches/GrAtlasTextBatch.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698