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

Side by Side Diff: src/gpu/batches/GrNonAAFillRectBatch.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
« no previous file with comments | « src/gpu/batches/GrNinePatch.cpp ('k') | src/gpu/batches/GrNonAAStrokeRectBatch.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "GrNonAAFillRectBatch.h" 8 #include "GrNonAAFillRectBatch.h"
9 9
10 #include "GrBatchFlushState.h" 10 #include "GrBatchFlushState.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 }; 44 };
45 45
46 /** We always use per-vertex colors so that rects can be batched across color ch anges. Sometimes 46 /** We always use per-vertex colors so that rects can be batched across color ch anges. Sometimes
47 we have explicit local coords and sometimes not. We *could* always provide explicit local 47 we have explicit local coords and sometimes not. We *could* always provide explicit local
48 coords and just duplicate the positions when the caller hasn't provided a lo cal coord rect, 48 coords and just duplicate the positions when the caller hasn't provided a lo cal coord rect,
49 but we haven't seen a use case which frequently switches between local rect and no local 49 but we haven't seen a use case which frequently switches between local rect and no local
50 rect draws. 50 rect draws.
51 51
52 The vertex attrib order is always pos, color, [local coords]. 52 The vertex attrib order is always pos, color, [local coords].
53 */ 53 */
54 static const GrGeometryProcessor* create_gp(const SkMatrix& viewMatrix, 54 static sk_sp<GrGeometryProcessor> make_gp(const SkMatrix& viewMatrix,
55 bool readsCoverage, 55 bool readsCoverage,
56 bool hasExplicitLocalCoords, 56 bool hasExplicitLocalCoords,
57 const SkMatrix* localMatrix) { 57 const SkMatrix* localMatrix) {
58 using namespace GrDefaultGeoProcFactory; 58 using namespace GrDefaultGeoProcFactory;
59 Color color(Color::kAttribute_Type); 59 Color color(Color::kAttribute_Type);
60 Coverage coverage(readsCoverage ? Coverage::kSolid_Type : Coverage::kNone_Ty pe); 60 Coverage coverage(readsCoverage ? Coverage::kSolid_Type : Coverage::kNone_Ty pe);
61 61
62 // If we have perspective on the viewMatrix then we won't map on the CPU, no r will we map 62 // If we have perspective on the viewMatrix then we won't map on the CPU, no r will we map
63 // the local rect on the cpu (in case the localMatrix also has perspective). 63 // the local rect on the cpu (in case the localMatrix also has perspective).
64 // Otherwise, if we have a local rect, then we apply the localMatrix directl y to the localRect 64 // Otherwise, if we have a local rect, then we apply the localMatrix directl y to the localRect
65 // to generate vertex local coords 65 // to generate vertex local coords
66 if (viewMatrix.hasPerspective()) { 66 if (viewMatrix.hasPerspective()) {
67 LocalCoords localCoords(hasExplicitLocalCoords ? LocalCoords::kHasExplic it_Type : 67 LocalCoords localCoords(hasExplicitLocalCoords ? LocalCoords::kHasExplic it_Type :
68 LocalCoords::kUsePositi on_Type, 68 LocalCoords::kUsePositi on_Type,
69 localMatrix); 69 localMatrix);
70 return GrDefaultGeoProcFactory::Create(color, coverage, localCoords, vie wMatrix); 70 return GrDefaultGeoProcFactory::Make(color, coverage, localCoords, viewM atrix);
71 } else if (hasExplicitLocalCoords) { 71 } else if (hasExplicitLocalCoords) {
72 LocalCoords localCoords(LocalCoords::kHasExplicit_Type); 72 LocalCoords localCoords(LocalCoords::kHasExplicit_Type);
73 return GrDefaultGeoProcFactory::Create(color, coverage, localCoords, SkM atrix::I()); 73 return GrDefaultGeoProcFactory::Make(color, coverage, localCoords, SkMat rix::I());
74 } else { 74 } else {
75 LocalCoords localCoords(LocalCoords::kUsePosition_Type, localMatrix); 75 LocalCoords localCoords(LocalCoords::kUsePosition_Type, localMatrix);
76 return GrDefaultGeoProcFactory::CreateForDeviceSpace(color, coverage, lo calCoords, 76 return GrDefaultGeoProcFactory::MakeForDeviceSpace(color, coverage, loca lCoords,
77 viewMatrix); 77 viewMatrix);
78 } 78 }
79 } 79 }
80 80
81 static void tesselate(intptr_t vertices, 81 static void tesselate(intptr_t vertices,
82 size_t vertexStride, 82 size_t vertexStride,
83 GrColor color, 83 GrColor color,
84 const SkMatrix& viewMatrix, 84 const SkMatrix& viewMatrix,
85 const SkRect& rect, 85 const SkRect& rect,
86 const GrQuad* localQuad) { 86 const GrQuad* localQuad) {
87 SkPoint* positions = reinterpret_cast<SkPoint*>(vertices); 87 SkPoint* positions = reinterpret_cast<SkPoint*>(vertices);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 geo.fColor, 131 geo.fColor,
132 geo.fRect.fLeft, geo.fRect.fTop, geo.fRect.fRight, geo.fRect .fBottom); 132 geo.fRect.fLeft, geo.fRect.fTop, geo.fRect.fRight, geo.fRect .fBottom);
133 return str; 133 return str;
134 } 134 }
135 135
136 static bool CanCombine(const Geometry& mine, const Geometry& theirs, 136 static bool CanCombine(const Geometry& mine, const Geometry& theirs,
137 const GrXPOverridesForBatch& overrides) { 137 const GrXPOverridesForBatch& overrides) {
138 return true; 138 return true;
139 } 139 }
140 140
141 static const GrGeometryProcessor* CreateGP(const Geometry& geo, 141 static sk_sp<GrGeometryProcessor> MakeGP(const Geometry& geo,
142 const GrXPOverridesForBatch& over rides) { 142 const GrXPOverridesForBatch& overri des) {
143 const GrGeometryProcessor* gp = create_gp(geo.fViewMatrix, overrides.rea dsCoverage(), true, 143 sk_sp<GrGeometryProcessor> gp = make_gp(geo.fViewMatrix, overrides.reads Coverage(), true,
144 nullptr); 144 nullptr);
145 145
146 SkASSERT(gp->getVertexStride() == 146 SkASSERT(gp->getVertexStride() ==
147 sizeof(GrDefaultGeoProcFactory::PositionColorLocalCoordAttr)); 147 sizeof(GrDefaultGeoProcFactory::PositionColorLocalCoordAttr));
148 return gp; 148 return gp;
149 } 149 }
150 150
151 static void Tesselate(intptr_t vertices, size_t vertexStride, const Geometry & geo, 151 static void Tesselate(intptr_t vertices, size_t vertexStride, const Geometry & geo,
152 const GrXPOverridesForBatch& overrides) { 152 const GrXPOverridesForBatch& overrides) {
153 tesselate(vertices, vertexStride, geo.fColor, geo.fViewMatrix, geo.fRect , &geo.fLocalQuad); 153 tesselate(vertices, vertexStride, geo.fColor, geo.fViewMatrix, geo.fRect , &geo.fLocalQuad);
154 } 154 }
(...skipping 24 matching lines...) Expand all
179 } 179 }
180 180
181 static bool CanCombine(const Geometry& mine, const Geometry& theirs, 181 static bool CanCombine(const Geometry& mine, const Geometry& theirs,
182 const GrXPOverridesForBatch& overrides) { 182 const GrXPOverridesForBatch& overrides) {
183 // We could batch across perspective vm changes if we really wanted to 183 // We could batch across perspective vm changes if we really wanted to
184 return mine.fViewMatrix.cheapEqualTo(theirs.fViewMatrix) && 184 return mine.fViewMatrix.cheapEqualTo(theirs.fViewMatrix) &&
185 mine.fHasLocalRect == theirs.fHasLocalRect && 185 mine.fHasLocalRect == theirs.fHasLocalRect &&
186 (!mine.fHasLocalMatrix || mine.fLocalMatrix.cheapEqualTo(theirs.f LocalMatrix)); 186 (!mine.fHasLocalMatrix || mine.fLocalMatrix.cheapEqualTo(theirs.f LocalMatrix));
187 } 187 }
188 188
189 static const GrGeometryProcessor* CreateGP(const Geometry& geo, 189 static sk_sp<GrGeometryProcessor> MakeGP(const Geometry& geo,
190 const GrXPOverridesForBatch& over rides) { 190 const GrXPOverridesForBatch& overri des) {
191 const GrGeometryProcessor* gp = create_gp(geo.fViewMatrix, overrides.rea dsCoverage(), 191 sk_sp<GrGeometryProcessor> gp = make_gp(geo.fViewMatrix, overrides.reads Coverage(),
192 geo.fHasLocalRect, 192 geo.fHasLocalRect,
193 geo.fHasLocalMatrix ? &geo.fLo calMatrix : 193 geo.fHasLocalMatrix ? &geo.fLoca lMatrix
194 nullptr) ; 194 : nullptr);
195 195
196 SkASSERT(geo.fHasLocalRect ? 196 SkASSERT(geo.fHasLocalRect ?
197 gp->getVertexStride() == sizeof(GrDefaultGeoProcFactory::PositionCo lorLocalCoordAttr) : 197 gp->getVertexStride() == sizeof(GrDefaultGeoProcFactory::PositionCo lorLocalCoordAttr) :
198 gp->getVertexStride() == sizeof(GrDefaultGeoProcFactory::PositionCo lorAttr)); 198 gp->getVertexStride() == sizeof(GrDefaultGeoProcFactory::PositionCo lorAttr));
199 return gp; 199 return gp;
200 } 200 }
201 201
202 static void Tesselate(intptr_t vertices, size_t vertexStride, const Geometry & geo, 202 static void Tesselate(intptr_t vertices, size_t vertexStride, const Geometry & geo,
203 const GrXPOverridesForBatch& overrides) { 203 const GrXPOverridesForBatch& overrides) {
204 if (geo.fHasLocalRect) { 204 if (geo.fHasLocalRect) {
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 SkMatrix localMatrix = GrTest::TestMatrix(random); 329 SkMatrix localMatrix = GrTest::TestMatrix(random);
330 330
331 bool hasLocalRect = random->nextBool(); 331 bool hasLocalRect = random->nextBool();
332 bool hasLocalMatrix = random->nextBool(); 332 bool hasLocalMatrix = random->nextBool();
333 return GrNonAAFillRectBatch::Create(color, viewMatrix, rect, 333 return GrNonAAFillRectBatch::Create(color, viewMatrix, rect,
334 hasLocalRect ? &localRect : nullptr, 334 hasLocalRect ? &localRect : nullptr,
335 hasLocalMatrix ? &localMatrix : nullptr) ; 335 hasLocalMatrix ? &localMatrix : nullptr) ;
336 } 336 }
337 337
338 #endif 338 #endif
OLDNEW
« no previous file with comments | « src/gpu/batches/GrNinePatch.cpp ('k') | src/gpu/batches/GrNonAAStrokeRectBatch.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698