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

Side by Side Diff: gm/gradients.cpp

Issue 1259983009: linear gradient with stops discretized gm (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix sign compare Created 5 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 * Copyright 2011 Google Inc. 2 * Copyright 2011 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 "gm.h" 8 #include "gm.h"
9 #include "SkGradientShader.h" 9 #include "SkGradientShader.h"
10 10
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 paint.setAntiAlias(true); 483 paint.setAntiAlias(true);
484 paint.setShader(fShader); 484 paint.setShader(fShader);
485 canvas->drawRect(SkRect::MakeWH(500, 500), paint); 485 canvas->drawRect(SkRect::MakeWH(500, 500), paint);
486 } 486 }
487 487
488 private: 488 private:
489 typedef GM INHERITED; 489 typedef GM INHERITED;
490 }; 490 };
491 DEF_GM( return new RadialGradient4GM; ) 491 DEF_GM( return new RadialGradient4GM; )
492 492
493 class LinearGradientGM : public GM {
494 SkAutoTUnref<SkShader> fShader[100];
495
496 protected:
497 SkString onShortName() override { return SkString("linear_gradient"); }
498 const SkScalar kWidthBump = 30.f;
499 const SkScalar kHeight = 5.f;
500 const SkScalar kMinWidth = 540.f;
501
502 SkISize onISize() override { return SkISize::Make(500, 500); }
503
504 void onOnceBeforeDraw() override {
505 SkPoint pts[2] = { {0, 0}, {0, 0} };
506 const SkColor colors[] = { SK_ColorWHITE, SK_ColorWHITE, 0xFF008200, 0xF F008200,
507 SK_ColorWHITE, SK_ColorWHITE };
508 const SkScalar unitPos[] = { 0, 50, 70, 500, 540 };
509 SkScalar pos[6];
510 pos[5] = 1;
511 for (int index = 0; index < (int) SK_ARRAY_COUNT(fShader); ++index) {
512 pts[1].fX = 500.f + index * kWidthBump;
513 for (int inner = 0; inner < (int) SK_ARRAY_COUNT(unitPos); ++inner) {
514 pos[inner] = unitPos[inner] / (kMinWidth + index * kWidthBump);
515 }
516 fShader[index].reset(SkGradientShader::CreateLinear(pts, colors, pos ,
517 SK_ARRAY_COUNT(gColors), SkShader::kClamp_TileMode));
518 }
519 }
520
521 void onDraw(SkCanvas* canvas) override {
522 SkPaint paint;
523 paint.setAntiAlias(true);
524 for (int index = 0; index < (int) SK_ARRAY_COUNT(fShader); ++index) {
525 paint.setShader(fShader[index]);
526 canvas->drawRect(SkRect::MakeLTRB(0, index * kHeight, kMinWidth + in dex * kWidthBump,
527 (index + 1) * kHeight), paint);
528 }
529 }
530
531 private:
532 typedef GM INHERITED;
533 };
534 DEF_GM( return new LinearGradientGM; )
535
493 } 536 }
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