OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "SkGradientShader.h" | 10 #include "SkGradientShader.h" |
11 #include "SkPath.h" | 11 #include "SkPath.h" |
12 | 12 |
13 static void make_bm(SkBitmap* bm, int width, int height, SkColor colors[2]) { | 13 static void make_bm(SkBitmap* bm, int width, int height, SkColor colors[2]) { |
14 bm->allocN32Pixels(width, height); | 14 bm->allocN32Pixels(width, height); |
15 SkCanvas canvas(*bm); | 15 SkCanvas canvas(*bm); |
16 SkPoint center = {SkIntToScalar(width)/2, SkIntToScalar(height)/2}; | 16 SkPoint center = {SkIntToScalar(width)/2, SkIntToScalar(height)/2}; |
17 SkScalar radius = 40; | 17 SkScalar radius = 40; |
18 SkShader* shader = SkGradientShader::CreateRadial(center, radius, colors, NU
LL, 2, | 18 SkShader* shader = SkGradientShader::CreateRadial(center, radius, colors, nu
llptr, 2, |
19 SkShader::kMirror_TileMode
); | 19 SkShader::kMirror_TileMode
); |
20 SkPaint paint; | 20 SkPaint paint; |
21 paint.setShader(shader)->unref(); | 21 paint.setShader(shader)->unref(); |
22 paint.setXfermodeMode(SkXfermode::kSrc_Mode); | 22 paint.setXfermodeMode(SkXfermode::kSrc_Mode); |
23 canvas.drawPaint(paint); | 23 canvas.drawPaint(paint); |
24 bm->setImmutable(); | 24 bm->setImmutable(); |
25 } | 25 } |
26 | 26 |
27 static void show_bm(SkCanvas* canvas, int width, int height, SkColor colors[2])
{ | 27 static void show_bm(SkCanvas* canvas, int width, int height, SkColor colors[2])
{ |
28 SkBitmap bm; | 28 SkBitmap bm; |
29 make_bm(&bm, width, height, colors); | 29 make_bm(&bm, width, height, colors); |
30 | 30 |
31 SkPaint paint; | 31 SkPaint paint; |
32 SkRect r; | 32 SkRect r; |
33 SkIRect ir; | 33 SkIRect ir; |
34 | 34 |
35 paint.setStyle(SkPaint::kStroke_Style); | 35 paint.setStyle(SkPaint::kStroke_Style); |
36 | 36 |
37 ir.set(0, 0, 128, 128); | 37 ir.set(0, 0, 128, 128); |
38 r.set(ir); | 38 r.set(ir); |
39 | 39 |
40 canvas->save(); | 40 canvas->save(); |
41 canvas->clipRect(r); | 41 canvas->clipRect(r); |
42 canvas->drawBitmap(bm, 0, 0, NULL); | 42 canvas->drawBitmap(bm, 0, 0, nullptr); |
43 canvas->restore(); | 43 canvas->restore(); |
44 canvas->drawRect(r, paint); | 44 canvas->drawRect(r, paint); |
45 | 45 |
46 r.offset(SkIntToScalar(150), 0); | 46 r.offset(SkIntToScalar(150), 0); |
47 // exercises extract bitmap, but not shader | 47 // exercises extract bitmap, but not shader |
48 canvas->drawBitmapRect(bm, ir, r, NULL); | 48 canvas->drawBitmapRect(bm, ir, r, nullptr); |
49 canvas->drawRect(r, paint); | 49 canvas->drawRect(r, paint); |
50 | 50 |
51 r.offset(SkIntToScalar(150), 0); | 51 r.offset(SkIntToScalar(150), 0); |
52 // exercises bitmapshader | 52 // exercises bitmapshader |
53 canvas->drawBitmapRect(bm, r, nullptr); | 53 canvas->drawBitmapRect(bm, r, nullptr); |
54 canvas->drawRect(r, paint); | 54 canvas->drawRect(r, paint); |
55 } | 55 } |
56 | 56 |
57 class VeryLargeBitmapGM : public skiagm::GM { | 57 class VeryLargeBitmapGM : public skiagm::GM { |
58 public: | 58 public: |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 } | 100 } |
101 | 101 |
102 private: | 102 private: |
103 typedef skiagm::GM INHERITED; | 103 typedef skiagm::GM INHERITED; |
104 }; | 104 }; |
105 | 105 |
106 ////////////////////////////////////////////////////////////////////////////// | 106 ////////////////////////////////////////////////////////////////////////////// |
107 | 107 |
108 static skiagm::GM* MyFactory(void*) { return new VeryLargeBitmapGM; } | 108 static skiagm::GM* MyFactory(void*) { return new VeryLargeBitmapGM; } |
109 static skiagm::GMRegistry reg(MyFactory); | 109 static skiagm::GMRegistry reg(MyFactory); |
OLD | NEW |