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

Unified Diff: gm/gradients_no_texture.cpp

Issue 243133005: gradient_many gm to test banding and precision (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 6 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gm/gradients_no_texture.cpp
diff --git a/gm/gradients_no_texture.cpp b/gm/gradients_no_texture.cpp
index 05481288fc422581cf98dc07a6d42e33c1793a70..cea1e8b382f76c854ff8014f0d1fd131ddfe9cf6 100644
--- a/gm/gradients_no_texture.cpp
+++ b/gm/gradients_no_texture.cpp
@@ -127,4 +127,131 @@ private:
///////////////////////////////////////////////////////////////////////////////
+struct ColorPos {
+ SkColor* fColors;
+ SkScalar* fPos;
+ int fCount;
+
+ ColorPos() : fColors(NULL), fPos(NULL), fCount(0) {}
+ ~ColorPos() {
+ SkDELETE(fColors);
+ SkDELETE(fPos);
+ }
+
+ void construct(const SkColor colors[], const SkScalar pos[], int count) {
+ fColors = SkNEW_ARRAY(SkColor, count);
+ memcpy(fColors, colors, count * sizeof(SkColor));
+ if (pos) {
+ fPos = SkNEW_ARRAY(SkScalar, count);
+ memcpy(fPos, pos, count * sizeof(SkScalar));
+ fPos[0] = 0;
+ fPos[count - 1] = 1;
+ }
+ fCount = count;
+ }
+};
+
+static void make0(ColorPos* rec) {
+#if 0
+ From http://jsfiddle.net/3fe2a/
+
+background-image: -webkit-linear-gradient(left, #22d1cd 1%, #22d1cd 0.9510157507590116%, #df4b37 2.9510157507590113%, #df4b37 23.695886056604927%, #22d1cd 25.695886056604927%, #22d1cd 25.39321881940624%, #e6de36 27.39321881940624%, #e6de36 31.849399922570655%, #3267ff 33.849399922570655%, #3267ff 44.57735802921938%, #9d47d1 46.57735802921938%, #9d47d1 53.27185850805876%, #3267ff 55.27185850805876%, #3267ff 61.95718972227316%, #5cdd9d 63.95718972227316%, #5cdd9d 69.89166004442%, #3267ff 71.89166004442%, #3267ff 74.45795382765857%, #9d47d1 76.45795382765857%, #9d47d1 82.78364610713776%, #3267ff 84.78364610713776%, #3267ff 94.52743647737229%, #e3d082 96.52743647737229%, #e3d082 96.03934633331295%);
+height: 30px;
+#endif
+
+ const SkColor colors[] = {
+ 0xFF22d1cd, 0xFF22d1cd, 0xFFdf4b37, 0xFFdf4b37, 0xFF22d1cd, 0xFF22d1cd, 0xFFe6de36, 0xFFe6de36,
+ 0xFF3267ff, 0xFF3267ff, 0xFF9d47d1, 0xFF9d47d1, 0xFF3267ff, 0xFF3267ff, 0xFF5cdd9d, 0xFF5cdd9d,
+ 0xFF3267ff, 0xFF3267ff, 0xFF9d47d1, 0xFF9d47d1, 0xFF3267ff, 0xFF3267ff, 0xFFe3d082, 0xFFe3d082
+ };
+ const double percent[] = {
+ 1, 0.9510157507590116, 2.9510157507590113, 23.695886056604927,
+ 25.695886056604927, 25.39321881940624, 27.39321881940624, 31.849399922570655,
+ 33.849399922570655, 44.57735802921938, 46.57735802921938, 53.27185850805876,
+ 55.27185850805876, 61.95718972227316, 63.95718972227316, 69.89166004442,
+ 71.89166004442, 74.45795382765857, 76.45795382765857, 82.78364610713776,
+ 84.78364610713776, 94.52743647737229, 96.52743647737229, 96.03934633331295,
+ };
+ const int N = SK_ARRAY_COUNT(percent);
+ SkScalar pos[N];
+ for (int i = 0; i < N; ++i) {
+ pos[i] = SkDoubleToScalar(percent[i] / 100);
+ }
+ rec->construct(colors, pos, N);
+}
+
+static void make1(ColorPos* rec) {
+ const SkColor colors[] = {
+ SK_ColorBLACK, SK_ColorWHITE, SK_ColorBLACK, SK_ColorWHITE,
+ SK_ColorBLACK, SK_ColorWHITE, SK_ColorBLACK, SK_ColorWHITE,
+ SK_ColorBLACK,
+ };
+ rec->construct(colors, NULL, SK_ARRAY_COUNT(colors));
+}
+
+static void make2(ColorPos* rec) {
+ const SkColor colors[] = {
+ SK_ColorBLACK, SK_ColorWHITE, SK_ColorBLACK, SK_ColorWHITE,
+ SK_ColorBLACK, SK_ColorWHITE, SK_ColorBLACK, SK_ColorWHITE,
+ SK_ColorBLACK,
+ };
+ const int N = SK_ARRAY_COUNT(colors);
+ SkScalar pos[N];
+ for (int i = 0; i < N; ++i) {
+ pos[i] = SK_Scalar1 * i / (N - 1);
+ }
+ rec->construct(colors, pos, N);
+}
+
+class GradientsManyColorsGM : public GM {
+ enum {
+ W = 800,
+ };
+ SkAutoTUnref<SkShader> fShader;
+
+ typedef void (*Proc)(ColorPos*);
+public:
+ GradientsManyColorsGM() {}
+
+protected:
+ SkString onShortName() SK_OVERRIDE { return SkString("gradients_many"); }
+ virtual SkISize onISize() SK_OVERRIDE { return SkISize::Make(850, 100); }
+
+ virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
+ const Proc procs[] = {
+ make0, make1, make2,
+ };
+ const SkPoint pts[] = {
+ { 0, 0 },
+ { SkIntToScalar(W), 0 },
+ };
+ const SkRect r = SkRect::MakeWH(SkIntToScalar(W), 30);
+
+ SkPaint paint;
+
+ canvas->translate(20, 20);
+
+ for (int i = 0; i <= 8; ++i) {
+ SkScalar x = r.width() * i / 8;
+ canvas->drawLine(x, 0, x, 10000, paint);
+ }
+
+ for (size_t i = 0; i < SK_ARRAY_COUNT(procs); ++i) {
+ ColorPos rec;
+ procs[i](&rec);
+ SkShader* s = SkGradientShader::CreateLinear(pts, rec.fColors, rec.fPos, rec.fCount,
+ SkShader::kClamp_TileMode);
+ paint.setShader(s)->unref();
+ canvas->drawRect(r, paint);
+ canvas->translate(0, r.height() + 20);
+ }
+ }
+
+private:
+ typedef GM INHERITED;
+};
+
+///////////////////////////////////////////////////////////////////////////////
+
DEF_GM( return SkNEW(GradientsNoTextureGM));
+DEF_GM( return SkNEW(GradientsManyColorsGM));
« 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