OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
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 #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 "SkGraphics.h" | 11 #include "SkGraphics.h" |
12 #include "SkPath.h" | 12 #include "SkPath.h" |
13 #include "SkRegion.h" | 13 #include "SkRegion.h" |
14 #include "SkShader.h" | 14 #include "SkShader.h" |
15 | 15 |
16 static void make_bitmap(SkBitmap* bitmap) { | 16 static void make_bitmap(SkBitmap* bitmap) { |
17 bitmap->setConfig(SkBitmap::kARGB_8888_Config, 64, 64); | 17 bitmap->allocN32Pixels(64, 64); |
18 bitmap->allocPixels(); | |
19 | 18 |
20 SkCanvas canvas(*bitmap); | 19 SkCanvas canvas(*bitmap); |
21 | 20 |
22 canvas.drawColor(SK_ColorRED); | 21 canvas.drawColor(SK_ColorRED); |
23 SkPaint paint; | 22 SkPaint paint; |
24 paint.setAntiAlias(true); | 23 paint.setAntiAlias(true); |
25 const SkPoint pts[] = { { 0, 0 }, { 64, 64 } }; | 24 const SkPoint pts[] = { { 0, 0 }, { 64, 64 } }; |
26 const SkColor colors[] = { SK_ColorWHITE, SK_ColorBLUE }; | 25 const SkColor colors[] = { SK_ColorWHITE, SK_ColorBLUE }; |
27 paint.setShader(SkGradientShader::CreateLinear(pts, colors, NULL, 2, | 26 paint.setShader(SkGradientShader::CreateLinear(pts, colors, NULL, 2, |
28 SkShader::kClamp_TileMode))->
unref(); | 27 SkShader::kClamp_TileMode))->
unref(); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 static const int gXSize = 3; | 92 static const int gXSize = 3; |
94 static const int gYSize = 3; | 93 static const int gYSize = 3; |
95 | 94 |
96 SkColor textureData[gXSize][gYSize] = { | 95 SkColor textureData[gXSize][gYSize] = { |
97 { SK_ColorRED, SK_ColorWHITE, SK_ColorBLUE }, | 96 { SK_ColorRED, SK_ColorWHITE, SK_ColorBLUE }, |
98 { SK_ColorGREEN, SK_ColorBLACK, SK_ColorCYAN }, | 97 { SK_ColorGREEN, SK_ColorBLACK, SK_ColorCYAN }, |
99 { SK_ColorYELLOW, SK_ColorGRAY, SK_ColorMAGENTA } | 98 { SK_ColorYELLOW, SK_ColorGRAY, SK_ColorMAGENTA } |
100 }; | 99 }; |
101 | 100 |
102 | 101 |
103 bitmap->setConfig(SkBitmap::kARGB_8888_Config, gXSize, gYSize); | 102 bitmap->allocN32Pixels(gXSize, gYSize); |
104 bitmap->allocPixels(); | |
105 | |
106 SkAutoLockPixels lock(*bitmap); | |
107 for (int y = 0; y < gYSize; y++) { | 103 for (int y = 0; y < gYSize; y++) { |
108 for (int x = 0; x < gXSize; x++) { | 104 for (int x = 0; x < gXSize; x++) { |
109 *bitmap->getAddr32(x, y) = textureData[x][y]; | 105 *bitmap->getAddr32(x, y) = textureData[x][y]; |
110 } | 106 } |
111 } | 107 } |
112 } | 108 } |
113 | 109 |
114 // This GM attempts to make visible any issues drawBitmapRectToRect may have | 110 // This GM attempts to make visible any issues drawBitmapRectToRect may have |
115 // with partial source rects. In this case the eight pixels on the border | 111 // with partial source rects. In this case the eight pixels on the border |
116 // should be half the width/height of the central pixel, i.e.: | 112 // should be half the width/height of the central pixel, i.e.: |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 typedef skiagm::GM INHERITED; | 146 typedef skiagm::GM INHERITED; |
151 }; | 147 }; |
152 | 148 |
153 ////////////////////////////////////////////////////////////////////////////// | 149 ////////////////////////////////////////////////////////////////////////////// |
154 static void make_big_bitmap(SkBitmap* bitmap) { | 150 static void make_big_bitmap(SkBitmap* bitmap) { |
155 | 151 |
156 static const int gXSize = 4096; | 152 static const int gXSize = 4096; |
157 static const int gYSize = 4096; | 153 static const int gYSize = 4096; |
158 static const int gBorderWidth = 10; | 154 static const int gBorderWidth = 10; |
159 | 155 |
160 bitmap->setConfig(SkBitmap::kARGB_8888_Config, gXSize, gYSize); | 156 bitmap->allocN32Pixels(gXSize, gYSize); |
161 bitmap->allocPixels(); | |
162 | |
163 SkAutoLockPixels lock(*bitmap); | |
164 for (int y = 0; y < gYSize; ++y) { | 157 for (int y = 0; y < gYSize; ++y) { |
165 for (int x = 0; x < gXSize; ++x) { | 158 for (int x = 0; x < gXSize; ++x) { |
166 if (x <= gBorderWidth || x >= gXSize-gBorderWidth || | 159 if (x <= gBorderWidth || x >= gXSize-gBorderWidth || |
167 y <= gBorderWidth || y >= gYSize-gBorderWidth) { | 160 y <= gBorderWidth || y >= gYSize-gBorderWidth) { |
168 *bitmap->getAddr32(x, y) = 0x88FFFFFF; | 161 *bitmap->getAddr32(x, y) = 0x88FFFFFF; |
169 } else { | 162 } else { |
170 *bitmap->getAddr32(x, y) = 0x88FF0000; | 163 *bitmap->getAddr32(x, y) = 0x88FF0000; |
171 } | 164 } |
172 } | 165 } |
173 } | 166 } |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 | 237 |
245 static skiagm::GMRegistry reg0(MyFactory0); | 238 static skiagm::GMRegistry reg0(MyFactory0); |
246 static skiagm::GMRegistry reg1(MyFactory1); | 239 static skiagm::GMRegistry reg1(MyFactory1); |
247 | 240 |
248 static skiagm::GMRegistry reg2(MyFactory2); | 241 static skiagm::GMRegistry reg2(MyFactory2); |
249 | 242 |
250 #ifndef SK_BUILD_FOR_ANDROID | 243 #ifndef SK_BUILD_FOR_ANDROID |
251 static skiagm::GMRegistry reg3(MyFactory3); | 244 static skiagm::GMRegistry reg3(MyFactory3); |
252 static skiagm::GMRegistry reg4(MyFactory4); | 245 static skiagm::GMRegistry reg4(MyFactory4); |
253 #endif | 246 #endif |
OLD | NEW |