| OLD | NEW |
| 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 "SkCanvas.h" | 9 #include "SkCanvas.h" |
| 10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 | 24 |
| 25 static SkBitmap make_src() { | 25 static SkBitmap make_src() { |
| 26 SkBitmap bm = make_bm(); | 26 SkBitmap bm = make_bm(); |
| 27 SkCanvas canvas(bm); | 27 SkCanvas canvas(bm); |
| 28 SkPaint paint; | 28 SkPaint paint; |
| 29 SkPoint pts[] = { {0, 0}, {SkIntToScalar(WW), SkIntToScalar(HH)} }; | 29 SkPoint pts[] = { {0, 0}, {SkIntToScalar(WW), SkIntToScalar(HH)} }; |
| 30 SkColor colors[] = { | 30 SkColor colors[] = { |
| 31 SK_ColorTRANSPARENT, SK_ColorGREEN, SK_ColorCYAN, | 31 SK_ColorTRANSPARENT, SK_ColorGREEN, SK_ColorCYAN, |
| 32 SK_ColorRED, SK_ColorMAGENTA, SK_ColorWHITE, | 32 SK_ColorRED, SK_ColorMAGENTA, SK_ColorWHITE, |
| 33 }; | 33 }; |
| 34 SkShader* s = SkGradientShader::CreateLinear(pts, colors, NULL, SK_ARRAY_COU
NT(colors), | 34 SkShader* s = SkGradientShader::CreateLinear(pts, colors, nullptr, SK_ARRAY_
COUNT(colors), |
| 35 SkShader::kClamp_TileMode); | 35 SkShader::kClamp_TileMode); |
| 36 paint.setShader(s)->unref(); | 36 paint.setShader(s)->unref(); |
| 37 canvas.drawPaint(paint); | 37 canvas.drawPaint(paint); |
| 38 return bm; | 38 return bm; |
| 39 } | 39 } |
| 40 | 40 |
| 41 static SkBitmap make_dst() { | 41 static SkBitmap make_dst() { |
| 42 SkBitmap bm = make_bm(); | 42 SkBitmap bm = make_bm(); |
| 43 SkCanvas canvas(bm); | 43 SkCanvas canvas(bm); |
| 44 SkPaint paint; | 44 SkPaint paint; |
| 45 SkPoint pts[] = { {0, SkIntToScalar(HH)}, {SkIntToScalar(WW), 0} }; | 45 SkPoint pts[] = { {0, SkIntToScalar(HH)}, {SkIntToScalar(WW), 0} }; |
| 46 SkColor colors[] = { | 46 SkColor colors[] = { |
| 47 SK_ColorBLUE, SK_ColorYELLOW, SK_ColorBLACK, SK_ColorGREEN, | 47 SK_ColorBLUE, SK_ColorYELLOW, SK_ColorBLACK, SK_ColorGREEN, |
| 48 sk_tool_utils::color_to_565(SK_ColorGRAY) | 48 sk_tool_utils::color_to_565(SK_ColorGRAY) |
| 49 }; | 49 }; |
| 50 SkShader* s = SkGradientShader::CreateLinear(pts, colors, NULL, SK_ARRAY_COU
NT(colors), | 50 SkShader* s = SkGradientShader::CreateLinear(pts, colors, nullptr, SK_ARRAY_
COUNT(colors), |
| 51 SkShader::kClamp_TileMode); | 51 SkShader::kClamp_TileMode); |
| 52 paint.setShader(s)->unref(); | 52 paint.setShader(s)->unref(); |
| 53 canvas.drawPaint(paint); | 53 canvas.drawPaint(paint); |
| 54 return bm; | 54 return bm; |
| 55 } | 55 } |
| 56 | 56 |
| 57 static void show_k_text(SkCanvas* canvas, SkScalar x, SkScalar y, const SkScalar
k[]) { | 57 static void show_k_text(SkCanvas* canvas, SkScalar x, SkScalar y, const SkScalar
k[]) { |
| 58 SkPaint paint; | 58 SkPaint paint; |
| 59 paint.setTextSize(SkIntToScalar(24)); | 59 paint.setTextSize(SkIntToScalar(24)); |
| 60 paint.setAntiAlias(true); | 60 paint.setAntiAlias(true); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 one/4, one/2, one/2, 0, | 98 one/4, one/2, one/2, 0, |
| 99 -one/4, one/2, one/2, 0, | 99 -one/4, one/2, one/2, 0, |
| 100 }; | 100 }; |
| 101 | 101 |
| 102 const SkScalar* k = K; | 102 const SkScalar* k = K; |
| 103 const SkScalar* stop = k + SK_ARRAY_COUNT(K); | 103 const SkScalar* stop = k + SK_ARRAY_COUNT(K); |
| 104 SkScalar y = 0; | 104 SkScalar y = 0; |
| 105 SkScalar gap = SkIntToScalar(src.width() + 20); | 105 SkScalar gap = SkIntToScalar(src.width() + 20); |
| 106 while (k < stop) { | 106 while (k < stop) { |
| 107 SkScalar x = 0; | 107 SkScalar x = 0; |
| 108 canvas->drawBitmap(src, x, y, NULL); | 108 canvas->drawBitmap(src, x, y, nullptr); |
| 109 x += gap; | 109 x += gap; |
| 110 canvas->drawBitmap(dst, x, y, NULL); | 110 canvas->drawBitmap(dst, x, y, nullptr); |
| 111 x += gap; | 111 x += gap; |
| 112 SkRect rect = SkRect::MakeXYWH(x, y, SkIntToScalar(WW), SkIntToScala
r(HH)); | 112 SkRect rect = SkRect::MakeXYWH(x, y, SkIntToScalar(WW), SkIntToScala
r(HH)); |
| 113 canvas->saveLayer(&rect, NULL); | 113 canvas->saveLayer(&rect, nullptr); |
| 114 canvas->drawBitmap(dst, x, y, NULL); | 114 canvas->drawBitmap(dst, x, y, nullptr); |
| 115 SkXfermode* xfer = SkArithmeticMode::Create(k[0], k[1], k[2], k[3]); | 115 SkXfermode* xfer = SkArithmeticMode::Create(k[0], k[1], k[2], k[3]); |
| 116 SkPaint paint; | 116 SkPaint paint; |
| 117 paint.setXfermode(xfer)->unref(); | 117 paint.setXfermode(xfer)->unref(); |
| 118 canvas->drawBitmap(src, x, y, &paint); | 118 canvas->drawBitmap(src, x, y, &paint); |
| 119 canvas->restore(); | 119 canvas->restore(); |
| 120 x += gap; | 120 x += gap; |
| 121 show_k_text(canvas, x, y, k); | 121 show_k_text(canvas, x, y, k); |
| 122 k += 4; | 122 k += 4; |
| 123 y += SkIntToScalar(src.height() + 12); | 123 y += SkIntToScalar(src.height() + 12); |
| 124 } | 124 } |
| 125 } | 125 } |
| 126 | 126 |
| 127 private: | 127 private: |
| 128 typedef GM INHERITED; | 128 typedef GM INHERITED; |
| 129 }; | 129 }; |
| 130 | 130 |
| 131 /////////////////////////////////////////////////////////////////////////////// | 131 /////////////////////////////////////////////////////////////////////////////// |
| 132 | 132 |
| 133 static skiagm::GM* MyFactory(void*) { return new ArithmodeGM; } | 133 static skiagm::GM* MyFactory(void*) { return new ArithmodeGM; } |
| 134 static skiagm::GMRegistry reg(MyFactory); | 134 static skiagm::GMRegistry reg(MyFactory); |
| OLD | NEW |