OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
3 * | 3 * |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 * | 7 * |
8 */ | 8 */ |
9 | 9 |
10 #include "SkExample.h" | 10 #include "SkExample.h" |
11 | 11 |
12 #include "SkApplication.h" | 12 #include "SkApplication.h" |
13 #include "SkDraw.h" | 13 #include "SkDraw.h" |
14 #include "SkGradientShader.h" | 14 #include "SkGradientShader.h" |
15 #include "SkGraphics.h" | 15 #include "SkGraphics.h" |
16 #include "SkUnitMappers.h" | |
17 | 16 |
18 class HelloSkia : public SkExample { | 17 class HelloSkia : public SkExample { |
19 public: | 18 public: |
20 HelloSkia(SkExampleWindow* window) : SkExample(window) { | 19 HelloSkia(SkExampleWindow* window) : SkExample(window) { |
21 fName = "HelloSkia"; | 20 fName = "HelloSkia"; |
22 fBGColor = SK_ColorWHITE; | 21 fBGColor = SK_ColorWHITE; |
23 fRotationAngle = SkIntToScalar(0); | 22 fRotationAngle = SkIntToScalar(0); |
24 | 23 |
25 fWindow->setupBackend(SkExampleWindow::kGPU_DeviceType); | 24 fWindow->setupBackend(SkExampleWindow::kGPU_DeviceType); |
26 // Another option is software rendering: | 25 // Another option is software rendering: |
(...skipping 16 matching lines...) Expand all Loading... |
43 canvas->drawRect(rect, paint); | 42 canvas->drawRect(rect, paint); |
44 | 43 |
45 // Set up a linear gradient and draw a circle | 44 // Set up a linear gradient and draw a circle |
46 { | 45 { |
47 SkPoint linearPoints[] = { | 46 SkPoint linearPoints[] = { |
48 {SkIntToScalar(0), SkIntToScalar(0)}, | 47 {SkIntToScalar(0), SkIntToScalar(0)}, |
49 {SkIntToScalar(300), SkIntToScalar(300)} | 48 {SkIntToScalar(300), SkIntToScalar(300)} |
50 }; | 49 }; |
51 SkColor linearColors[] = {SK_ColorGREEN, SK_ColorBLACK}; | 50 SkColor linearColors[] = {SK_ColorGREEN, SK_ColorBLACK}; |
52 | 51 |
53 SkUnitMapper* linearMapper = new SkDiscreteMapper(100); | |
54 SkAutoUnref lm_deleter(linearMapper); | |
55 | |
56 SkShader* shader = SkGradientShader::CreateLinear( | 52 SkShader* shader = SkGradientShader::CreateLinear( |
57 linearPoints, linearColors, NULL, 2, | 53 linearPoints, linearColors, NULL, 2, |
58 SkShader::kMirror_TileMode, linearMapper); | 54 SkShader::kMirror_TileMode); |
59 SkAutoUnref shader_deleter(shader); | 55 SkAutoUnref shader_deleter(shader); |
60 | 56 |
61 paint.setShader(shader); | 57 paint.setShader(shader); |
62 paint.setFlags(SkPaint::kAntiAlias_Flag); | 58 paint.setFlags(SkPaint::kAntiAlias_Flag); |
63 | 59 |
64 canvas->drawCircle(SkIntToScalar(200), SkIntToScalar(200), | 60 canvas->drawCircle(SkIntToScalar(200), SkIntToScalar(200), |
65 SkIntToScalar(64), paint); | 61 SkIntToScalar(64), paint); |
66 | 62 |
67 // Detach shader | 63 // Detach shader |
68 paint.setShader(NULL); | 64 paint.setShader(NULL); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 SkScalar fRotationAngle; | 97 SkScalar fRotationAngle; |
102 SkColor fBGColor; | 98 SkColor fBGColor; |
103 }; | 99 }; |
104 | 100 |
105 static SkExample* MyFactory(SkExampleWindow* window) { | 101 static SkExample* MyFactory(SkExampleWindow* window) { |
106 return new HelloSkia(window); | 102 return new HelloSkia(window); |
107 } | 103 } |
108 | 104 |
109 // Register this class as a Skia Example. | 105 // Register this class as a Skia Example. |
110 SkExample::Registry registry(MyFactory); | 106 SkExample::Registry registry(MyFactory); |
OLD | NEW |