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

Side by Side Diff: gm/gradients.cpp

Issue 1464693002: Tiny linear gradient GM (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: bump isize Created 5 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 | « 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 574 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 585
586 private: 586 private:
587 SkAutoTUnref<SkShader> fShader[100]; 587 SkAutoTUnref<SkShader> fShader[100];
588 bool fDither; 588 bool fDither;
589 589
590 typedef GM INHERITED; 590 typedef GM INHERITED;
591 }; 591 };
592 DEF_GM( return new LinearGradientGM(true); ) 592 DEF_GM( return new LinearGradientGM(true); )
593 DEF_GM( return new LinearGradientGM(false); ) 593 DEF_GM( return new LinearGradientGM(false); )
594 594
595 class LinearGradientTinyGM : public GM {
596 protected:
597 SkString onShortName() override {
598 return SkString("linear_gradient_tiny");
599 }
600
601 SkISize onISize() override {
602 return SkISize::Make(600, 500);
603 }
604
605 void onDraw(SkCanvas* canvas) override {
606 const SkScalar kRectSize = 100;
607 const unsigned kStopCount = 3;
608 const SkColor colors[kStopCount] = { SK_ColorGREEN, SK_ColorRED, SK_Colo rGREEN };
609 const struct {
610 SkPoint pts[2];
611 SkScalar pos[kStopCount];
612 } configs[] = {
613 { { SkPoint::Make(0, 0), SkPoint::Make(10, 0) }, { 0, 0.999999f, 1 }},
614 { { SkPoint::Make(0, 0), SkPoint::Make(10, 0) }, { 0, 0.000001f, 1 }},
615 { { SkPoint::Make(0, 0), SkPoint::Make(10, 0) }, { 0, 0.999999999f, 1 }},
616 { { SkPoint::Make(0, 0), SkPoint::Make(10, 0) }, { 0, 0.000000001f, 1 }},
617 { { SkPoint::Make(0, 0), SkPoint::Make(0, 10) }, { 0, 0.999999f, 1 }},
618 { { SkPoint::Make(0, 0), SkPoint::Make(0, 10) }, { 0, 0.000001f, 1 }},
619 { { SkPoint::Make(0, 0), SkPoint::Make(0, 10) }, { 0, 0.999999999f, 1 }},
620 { { SkPoint::Make(0, 0), SkPoint::Make(0, 10) }, { 0, 0.000000001f, 1 }},
621
622 { { SkPoint::Make(0, 0), SkPoint::Make(0.00001f, 0) } , { 0, 0.5f, 1 }},
623 { { SkPoint::Make(9.99999f, 0), SkPoint::Make(10, 0) }, { 0, 0.5f, 1 }},
624 { { SkPoint::Make(0, 0), SkPoint::Make(0, 0.00001f) }, { 0, 0.5f, 1 }},
625 { { SkPoint::Make(0, 9.99999f), SkPoint::Make(0, 10) }, { 0, 0.5f, 1 }},
626 };
627
628 SkPaint paint;
629 for (unsigned i = 0; i < SK_ARRAY_COUNT(configs); ++i) {
630 SkAutoCanvasRestore acr(canvas, true);
631 SkAutoTUnref<SkShader> gradient(
632 SkGradientShader::CreateLinear(configs[i].pts, colors, configs[i ].pos, kStopCount,
633 SkShader::kClamp_TileMode));
634 canvas->translate(kRectSize * ((i % 4) * 1.5f + 0.25f),
635 kRectSize * ((i / 4) * 1.5f + 0.25f));
636
637 paint.setShader(gradient);
638 canvas->drawRect(SkRect::MakeWH(kRectSize, kRectSize), paint);
639 }
640 }
641
642 private:
643 typedef GM INHERITED;
644 };
645 DEF_GM( return new LinearGradientTinyGM(); )
646
595 } 647 }
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