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

Side by Side Diff: samplecode/SamplePatch.cpp

Issue 446913002: parameterize tesselation params (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase Created 6 years, 4 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 | « no previous file | no next file » | 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 2011 Google Inc. 3 * Copyright 2011 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 #include "SampleCode.h" 8 #include "SampleCode.h"
9 #include "SkView.h" 9 #include "SkView.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 t += dt; 199 t += dt;
200 canvas->drawVertices(SkCanvas::kTriangleStrip_VertexMode, stripCount, 200 canvas->drawVertices(SkCanvas::kTriangleStrip_VertexMode, stripCount,
201 strip, doTextures ? tex : NULL, 201 strip, doTextures ? tex : NULL,
202 doColors ? colors : NULL, NULL, 202 doColors ? colors : NULL, NULL,
203 NULL, 0, paint); 203 NULL, 0, paint);
204 } 204 }
205 } 205 }
206 206
207 static void drawpatches(SkCanvas* canvas, const SkPaint& paint, int nu, int nv, 207 static void drawpatches(SkCanvas* canvas, const SkPaint& paint, int nu, int nv,
208 Patch* patch) { 208 Patch* patch) {
209
210 SkAutoCanvasRestore ar(canvas, true); 209 SkAutoCanvasRestore ar(canvas, true);
211 210
212 patch->draw(canvas, paint, 10, 10, false, false); 211 patch->draw(canvas, paint, nu, nv, false, false);
213 canvas->translate(SkIntToScalar(180), 0); 212 canvas->translate(SkIntToScalar(180), 0);
214 patch->draw(canvas, paint, 10, 10, true, false); 213 patch->draw(canvas, paint, nu, nv, true, false);
215 canvas->translate(SkIntToScalar(180), 0); 214 canvas->translate(SkIntToScalar(180), 0);
216 patch->draw(canvas, paint, 10, 10, false, true); 215 patch->draw(canvas, paint, nu, nv, false, true);
217 canvas->translate(SkIntToScalar(180), 0); 216 canvas->translate(SkIntToScalar(180), 0);
218 patch->draw(canvas, paint, 10, 10, true, true); 217 patch->draw(canvas, paint, nu, nv, true, true);
219 } 218 }
220 219
221 const SkScalar DX = 20; 220 const SkScalar DX = 20;
222 const SkScalar DY = 0; 221 const SkScalar DY = 0;
223 222
224 class PatchView : public SampleView { 223 class PatchView : public SampleView {
225 SkShader* fShader0; 224 SkShader* fShader0;
226 SkShader* fShader1; 225 SkShader* fShader1;
227 SkIPoint fSize0, fSize1; 226 SkIPoint fSize0, fSize1;
228 SkPoint fPts[12]; 227 SkPoint fPts[12];
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 // overrides from SkEventSink 262 // overrides from SkEventSink
264 virtual bool onQuery(SkEvent* evt) { 263 virtual bool onQuery(SkEvent* evt) {
265 if (SampleCode::TitleQ(*evt)) { 264 if (SampleCode::TitleQ(*evt)) {
266 SampleCode::TitleR(evt, "Patch"); 265 SampleCode::TitleR(evt, "Patch");
267 return true; 266 return true;
268 } 267 }
269 return this->INHERITED::onQuery(evt); 268 return this->INHERITED::onQuery(evt);
270 } 269 }
271 270
272 virtual void onDrawContent(SkCanvas* canvas) { 271 virtual void onDrawContent(SkCanvas* canvas) {
272 const int nu = 10;
273 const int nv = 10;
274
273 SkPaint paint; 275 SkPaint paint;
274 paint.setDither(true); 276 paint.setDither(true);
275 paint.setFilterLevel(SkPaint::kLow_FilterLevel); 277 paint.setFilterLevel(SkPaint::kLow_FilterLevel);
276 278
277 canvas->translate(DX, DY); 279 canvas->translate(DX, DY);
278 280
279 Patch patch; 281 Patch patch;
280 282
281 paint.setShader(fShader0); 283 paint.setShader(fShader0);
282 if (fSize0.fX == 0) { 284 if (fSize0.fX == 0) {
283 fSize0.fX = 1; 285 fSize0.fX = 1;
284 } 286 }
285 if (fSize0.fY == 0) { 287 if (fSize0.fY == 0) {
286 fSize0.fY = 1; 288 fSize0.fY = 1;
287 } 289 }
288 patch.setBounds(fSize0.fX, fSize0.fY); 290 patch.setBounds(fSize0.fX, fSize0.fY);
289 291
290 patch.setPatch(fPts); 292 patch.setPatch(fPts);
291 drawpatches(canvas, paint, 10, 10, &patch); 293 drawpatches(canvas, paint, nu, nv, &patch);
292 294
293 paint.setShader(NULL); 295 paint.setShader(NULL);
294 paint.setAntiAlias(true); 296 paint.setAntiAlias(true);
295 paint.setStrokeWidth(SkIntToScalar(5)); 297 paint.setStrokeWidth(SkIntToScalar(5));
296 canvas->drawPoints(SkCanvas::kPoints_PointMode, SK_ARRAY_COUNT(fPts), fP ts, paint); 298 canvas->drawPoints(SkCanvas::kPoints_PointMode, SK_ARRAY_COUNT(fPts), fP ts, paint);
297 299
298 canvas->translate(0, SkIntToScalar(300)); 300 canvas->translate(0, SkIntToScalar(300));
299 301
300 paint.setAntiAlias(false); 302 paint.setAntiAlias(false);
301 paint.setShader(fShader1); 303 paint.setShader(fShader1);
302 { 304 if (true) {
303 SkMatrix m; 305 SkMatrix m;
304 m.setSkew(1, 0); 306 m.setSkew(1, 0);
305 SkShader* s = SkShader::CreateLocalMatrixShader(paint.getShader(), m ); 307 SkShader* s = SkShader::CreateLocalMatrixShader(paint.getShader(), m );
306 paint.setShader(s)->unref(); 308 paint.setShader(s)->unref();
307 } 309 }
308 { 310 if (true) {
309 static int gAngle; 311 static int gAngle;
310 SkMatrix m; 312 SkMatrix m;
311 m.setRotate(SkIntToScalar(gAngle++)); 313 m.setRotate(SkIntToScalar(gAngle++));
312 SkShader* s = SkShader::CreateLocalMatrixShader(paint.getShader(), m ); 314 SkShader* s = SkShader::CreateLocalMatrixShader(paint.getShader(), m );
313 paint.setShader(s)->unref(); 315 paint.setShader(s)->unref();
314 } 316 }
315 patch.setBounds(fSize1.fX, fSize1.fY); 317 patch.setBounds(fSize1.fX, fSize1.fY);
316 drawpatches(canvas, paint, 10, 10, &patch); 318 drawpatches(canvas, paint, nu, nv, &patch);
317 319
318 this->inval(NULL); 320 this->inval(NULL);
319 } 321 }
320 322
321 class PtClick : public Click { 323 class PtClick : public Click {
322 public: 324 public:
323 int fIndex; 325 int fIndex;
324 PtClick(SkView* view, int index) : Click(view), fIndex(index) {} 326 PtClick(SkView* view, int index) : Click(view), fIndex(index) {}
325 }; 327 };
326 328
(...skipping 20 matching lines...) Expand all
347 } 349 }
348 350
349 private: 351 private:
350 typedef SampleView INHERITED; 352 typedef SampleView INHERITED;
351 }; 353 };
352 354
353 ////////////////////////////////////////////////////////////////////////////// 355 //////////////////////////////////////////////////////////////////////////////
354 356
355 static SkView* MyFactory() { return new PatchView; } 357 static SkView* MyFactory() { return new PatchView; }
356 static SkViewRegister reg(MyFactory); 358 static SkViewRegister reg(MyFactory);
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698