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

Side by Side Diff: gm/convexpolyeffect.cpp

Issue 732693002: Drawstate on stack (Closed) Base URL: https://skia.googlesource.com/skia.git@real_def_gp
Patch Set: tiny fix 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
« no previous file with comments | « gm/beziereffects.cpp ('k') | gm/rrects.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 /* 2 /*
3 * Copyright 2014 Google Inc. 3 * Copyright 2014 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 // This test only works with the GPU backend. 9 // This test only works with the GPU backend.
10 10
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 const SkPath* path = iter.get(); 114 const SkPath* path = iter.get();
115 SkScalar x = 0; 115 SkScalar x = 0;
116 116
117 for (int et = 0; et < kGrProcessorEdgeTypeCnt; ++et) { 117 for (int et = 0; et < kGrProcessorEdgeTypeCnt; ++et) {
118 GrTestTarget tt; 118 GrTestTarget tt;
119 context->getTestTarget(&tt); 119 context->getTestTarget(&tt);
120 if (NULL == tt.target()) { 120 if (NULL == tt.target()) {
121 SkDEBUGFAIL("Couldn't get Gr test target."); 121 SkDEBUGFAIL("Couldn't get Gr test target.");
122 return; 122 return;
123 } 123 }
124 GrDrawState* drawState = tt.target()->drawState();
125
126 SkMatrix m; 124 SkMatrix m;
127 SkPath p; 125 SkPath p;
128 m.setTranslate(x, y); 126 m.setTranslate(x, y);
129 path->transform(m, &p); 127 path->transform(m, &p);
130 128
131 GrPrimitiveEdgeType edgeType = (GrPrimitiveEdgeType) et; 129 GrPrimitiveEdgeType edgeType = (GrPrimitiveEdgeType) et;
132 SkAutoTUnref<GrFragmentProcessor> fp(GrConvexPolyEffect::Create( edgeType, p)); 130 SkAutoTUnref<GrFragmentProcessor> fp(GrConvexPolyEffect::Create( edgeType, p));
133 if (!fp) { 131 if (!fp) {
134 continue; 132 continue;
135 } 133 }
136 drawState->setGeometryProcessor(GrDefaultGeoProcFactory::Create( false))->unref();
137 drawState->addCoverageProcessor(fp);
138 drawState->setIdentityViewMatrix();
139 drawState->setRenderTarget(rt);
140 drawState->setColor(0xff000000);
141 134
142 GrDrawTarget::AutoReleaseGeometry geo(tt.target(), 4, 0); 135 GrDrawState ds;
136 ds.setGeometryProcessor(GrDefaultGeoProcFactory::Create(false))- >unref();
137 ds.addCoverageProcessor(fp);
138 ds.setIdentityViewMatrix();
139 ds.setRenderTarget(rt);
140 ds.setColor(0xff000000);
141
142 GrDrawTarget::AutoReleaseGeometry geo(tt.target(), 4, ds.getVert exStride(), 0);
143 SkPoint* verts = reinterpret_cast<SkPoint*>(geo.vertices()); 143 SkPoint* verts = reinterpret_cast<SkPoint*>(geo.vertices());
144 144
145 SkRect bounds = p.getBounds(); 145 SkRect bounds = p.getBounds();
146 // Make sure any artifacts around the exterior of path are visib le by using overly 146 // Make sure any artifacts around the exterior of path are visib le by using overly
147 // conservative bounding geometry. 147 // conservative bounding geometry.
148 bounds.outset(5.f, 5.f); 148 bounds.outset(5.f, 5.f);
149 bounds.toQuad(verts); 149 bounds.toQuad(verts);
150 150
151 tt.target()->setIndexSourceToBuffer(context->getQuadIndexBuffer( )); 151 tt.target()->setIndexSourceToBuffer(context->getQuadIndexBuffer( ));
152 tt.target()->drawIndexed(kTriangleFan_GrPrimitiveType, 0, 0, 4, 6); 152 tt.target()->drawIndexed(&ds, kTriangleFan_GrPrimitiveType, 0, 0 , 4, 6);
153 153
154 x += SkScalarCeilToScalar(path->getBounds().width() + 10.f); 154 x += SkScalarCeilToScalar(path->getBounds().width() + 10.f);
155 } 155 }
156 156
157 // Draw AA and non AA paths using normal API for reference. 157 // Draw AA and non AA paths using normal API for reference.
158 canvas->save(); 158 canvas->save();
159 canvas->translate(x, y); 159 canvas->translate(x, y);
160 SkPaint paint; 160 SkPaint paint;
161 canvas->drawPath(*path, paint); 161 canvas->drawPath(*path, paint);
162 canvas->translate(path->getBounds().width() + 10.f, 0); 162 canvas->translate(path->getBounds().width() + 10.f, 0);
(...skipping 18 matching lines...) Expand all
181 return; 181 return;
182 } 182 }
183 SkRect rect = *iter.get(); 183 SkRect rect = *iter.get();
184 rect.offset(x, y); 184 rect.offset(x, y);
185 GrPrimitiveEdgeType edgeType = (GrPrimitiveEdgeType) et; 185 GrPrimitiveEdgeType edgeType = (GrPrimitiveEdgeType) et;
186 SkAutoTUnref<GrFragmentProcessor> fp(GrConvexPolyEffect::Create( edgeType, rect)); 186 SkAutoTUnref<GrFragmentProcessor> fp(GrConvexPolyEffect::Create( edgeType, rect));
187 if (!fp) { 187 if (!fp) {
188 continue; 188 continue;
189 } 189 }
190 190
191 GrDrawState* drawState = tt.target()->drawState(); 191 GrDrawState ds;
192 drawState->setGeometryProcessor(GrDefaultGeoProcFactory::Create( false))->unref(); 192 ds.setGeometryProcessor(GrDefaultGeoProcFactory::Create(false))- >unref();
193 drawState->addCoverageProcessor(fp); 193 ds.addCoverageProcessor(fp);
194 drawState->setIdentityViewMatrix(); 194 ds.setIdentityViewMatrix();
195 drawState->setRenderTarget(rt); 195 ds.setRenderTarget(rt);
196 drawState->setColor(0xff000000); 196 ds.setColor(0xff000000);
197 197
198 GrDrawTarget::AutoReleaseGeometry geo(tt.target(), 4, 0); 198 GrDrawTarget::AutoReleaseGeometry geo(tt.target(), 4, ds.getVert exStride(), 0);
199 SkPoint* verts = reinterpret_cast<SkPoint*>(geo.vertices()); 199 SkPoint* verts = reinterpret_cast<SkPoint*>(geo.vertices());
200 200
201 SkRect bounds = rect; 201 SkRect bounds = rect;
202 bounds.outset(5.f, 5.f); 202 bounds.outset(5.f, 5.f);
203 bounds.toQuad(verts); 203 bounds.toQuad(verts);
204 204
205 tt.target()->setIndexSourceToBuffer(context->getQuadIndexBuffer( )); 205 tt.target()->setIndexSourceToBuffer(context->getQuadIndexBuffer( ));
206 tt.target()->drawIndexed(kTriangleFan_GrPrimitiveType, 0, 0, 4, 6); 206 tt.target()->drawIndexed(&ds, kTriangleFan_GrPrimitiveType, 0, 0 , 4, 6);
207 207
208 x += SkScalarCeilToScalar(rect.width() + 10.f); 208 x += SkScalarCeilToScalar(rect.width() + 10.f);
209 } 209 }
210 210
211 // Draw rect without and with AA using normal API for reference 211 // Draw rect without and with AA using normal API for reference
212 canvas->save(); 212 canvas->save();
213 canvas->translate(x, y); 213 canvas->translate(x, y);
214 SkPaint paint; 214 SkPaint paint;
215 canvas->drawRect(*iter.get(), paint); 215 canvas->drawRect(*iter.get(), paint);
216 x += SkScalarCeilToScalar(iter.get()->width() + 10.f); 216 x += SkScalarCeilToScalar(iter.get()->width() + 10.f);
217 paint.setAntiAlias(true); 217 paint.setAntiAlias(true);
218 canvas->drawRect(*iter.get(), paint); 218 canvas->drawRect(*iter.get(), paint);
219 canvas->restore(); 219 canvas->restore();
220 220
221 y += SkScalarCeilToScalar(iter.get()->height() + 20.f); 221 y += SkScalarCeilToScalar(iter.get()->height() + 20.f);
222 } 222 }
223 } 223 }
224 224
225 private: 225 private:
226 SkTLList<SkPath> fPaths; 226 SkTLList<SkPath> fPaths;
227 SkTLList<SkRect> fRects; 227 SkTLList<SkRect> fRects;
228 228
229 typedef GM INHERITED; 229 typedef GM INHERITED;
230 }; 230 };
231 231
232 DEF_GM( return SkNEW(ConvexPolyEffect); ) 232 DEF_GM( return SkNEW(ConvexPolyEffect); )
233 } 233 }
234 234
235 #endif 235 #endif
OLDNEW
« no previous file with comments | « gm/beziereffects.cpp ('k') | gm/rrects.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698