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

Side by Side Diff: gm/all_bitmap_configs.cpp

Issue 2036493004: Add gm for displaying different variants of 8888. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Sync pdf Created 4 years, 6 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 unified diff | Download patch
« no previous file with comments | « no previous file | src/core/SkBlitter_Sprite.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 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 "sk_tool_utils.h" 8 #include "sk_tool_utils.h"
9 #include "SkSurface.h" 9 #include "SkSurface.h"
10 #include "Resources.h" 10 #include "Resources.h"
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 canvas->translate(0.0f, SkIntToScalar(SCALE)); 184 canvas->translate(0.0f, SkIntToScalar(SCALE));
185 SkBitmap bitmapA8 = make_bitmap(kAlpha_8_SkColorType); 185 SkBitmap bitmapA8 = make_bitmap(kAlpha_8_SkColorType);
186 draw(canvas, p, bitmapA8, kAlpha_8_SkColorType, "Alpha 8"); 186 draw(canvas, p, bitmapA8, kAlpha_8_SkColorType, "Alpha 8");
187 187
188 p.setColor(SK_ColorRED); 188 p.setColor(SK_ColorRED);
189 canvas->translate(0.0f, SkIntToScalar(SCALE)); 189 canvas->translate(0.0f, SkIntToScalar(SCALE));
190 SkBitmap bitmapG8 = make_bitmap(kGray_8_SkColorType); 190 SkBitmap bitmapG8 = make_bitmap(kGray_8_SkColorType);
191 draw(canvas, p, bitmapG8, kGray_8_SkColorType, "Gray 8"); 191 draw(canvas, p, bitmapG8, kGray_8_SkColorType, "Gray 8");
192 } 192 }
193 193
194 // Works on Ganesh, fails on Raster.
195 sk_sp<SkImage> make_not_native32_color_wheel() { 194 sk_sp<SkImage> make_not_native32_color_wheel() {
196 SkBitmap n32bitmap, notN32bitmap; 195 SkBitmap n32bitmap, notN32bitmap;
197 n32bitmap.allocN32Pixels(SCALE, SCALE); 196 n32bitmap.allocN32Pixels(SCALE, SCALE);
198 n32bitmap.eraseColor(SK_ColorTRANSPARENT); 197 n32bitmap.eraseColor(SK_ColorTRANSPARENT);
199 SkCanvas n32canvas(n32bitmap); 198 SkCanvas n32canvas(n32bitmap);
200 color_wheel_native(&n32canvas); 199 color_wheel_native(&n32canvas);
201 n32canvas.flush(); 200 n32canvas.flush();
202 #if SK_PMCOLOR_BYTE_ORDER(B,G,R,A) 201 #if SK_PMCOLOR_BYTE_ORDER(B,G,R,A)
203 const SkColorType ct = kRGBA_8888_SkColorType; 202 const SkColorType ct = kRGBA_8888_SkColorType;
204 #elif SK_PMCOLOR_BYTE_ORDER(R,G,B,A) 203 #elif SK_PMCOLOR_BYTE_ORDER(R,G,B,A)
205 const SkColorType ct = kBGRA_8888_SkColorType; 204 const SkColorType ct = kBGRA_8888_SkColorType;
206 #endif 205 #endif
207 static_assert(ct != kN32_SkColorType, "BRGA!=RGBA"); 206 static_assert(ct != kN32_SkColorType, "BRGA!=RGBA");
208 SkAssertResult(n32bitmap.copyTo(&notN32bitmap, ct)); 207 SkAssertResult(n32bitmap.copyTo(&notN32bitmap, ct));
209 SkASSERT(notN32bitmap.colorType() == ct); 208 SkASSERT(notN32bitmap.colorType() == ct);
210 return SkImage::MakeFromBitmap(notN32bitmap); 209 return SkImage::MakeFromBitmap(notN32bitmap);
211 } 210 }
212 211
213 DEF_SIMPLE_GM(not_native32_bitmap_config, canvas, SCALE, SCALE) { 212 DEF_SIMPLE_GM(not_native32_bitmap_config, canvas, SCALE, SCALE) {
214 sk_sp<SkImage> notN32image(make_not_native32_color_wheel()); 213 sk_sp<SkImage> notN32image(make_not_native32_color_wheel());
215 SkASSERT(notN32image); 214 SkASSERT(notN32image);
216 sk_tool_utils::draw_checkerboard(canvas, SK_ColorLTGRAY, SK_ColorWHITE, 8); 215 sk_tool_utils::draw_checkerboard(canvas, SK_ColorLTGRAY, SK_ColorWHITE, 8);
217 canvas->drawImage(notN32image.get(), 0.0f, 0.0f); 216 canvas->drawImage(notN32image.get(), 0.0f, 0.0f);
218 } 217 }
218
219 static uint32_t make_pixel(int x, int y, SkAlphaType alphaType) {
220 SkASSERT(x >= 0 && x < SCALE);
221 SkASSERT(y >= 0 && y < SCALE);
222
223 SkScalar R = SCALE / 2.0f;
224
225 uint32_t alpha = 0x00;
226
227 if ((x - R) * (x - R) + (y - R) * (y - R) < R * R) {
228 alpha = 0xFF;
229 }
230
231 uint32_t component;
232 switch (alphaType) {
233 case kPremul_SkAlphaType:
234 component = alpha;
235 break;
236 case kUnpremul_SkAlphaType:
237 component = 0xFF;
238 break;
239 default:
240 SkFAIL("Should not get here - invalid alpha type");
241 return 0xFF000000;
242 }
243 return alpha << 24 | component;
244 }
245
246 static void make_color_test_bitmap_variant(
247 SkColorType colorType,
248 SkAlphaType alphaType,
249 SkColorProfileType profile,
250 SkBitmap* bm)
251 {
252 SkASSERT(colorType == kRGBA_8888_SkColorType || colorType == kBGRA_8888_SkCo lorType);
253 SkASSERT(alphaType == kPremul_SkAlphaType || alphaType == kUnpremul_SkAlphaT ype);
254 bm->allocPixels(
255 SkImageInfo::Make(SCALE, SCALE, colorType, alphaType, profile));
256 SkPixmap pm;
257 bm->peekPixels(&pm);
258 for (int y = 0; y < bm->height(); y++) {
259 for (int x = 0; x < bm->width(); x++) {
260 *pm.writable_addr32(x, y) = make_pixel(x, y, alphaType);
261 }
262 }
263 }
264
265 DEF_SIMPLE_GM(all_variants_8888, canvas, 4 * SCALE + 30, 2 * SCALE + 10) {
266 sk_tool_utils::draw_checkerboard(canvas, SK_ColorLTGRAY, SK_ColorWHITE, 8);
267
268 for (auto profile : {kSRGB_SkColorProfileType, kLinear_SkColorProfileType}) {
269 canvas->save();
270 for (auto alphaType : {kPremul_SkAlphaType, kUnpremul_SkAlphaType}) {
271 canvas->save();
272 for (auto colorType : {kRGBA_8888_SkColorType, kBGRA_8888_SkColorTyp e}) {
273 SkBitmap bm;
274 make_color_test_bitmap_variant(colorType, alphaType, profile, &b m);
275 canvas->drawBitmap(bm, 0.0f, 0.0f);
276 canvas->translate(SCALE + 10, 0.0f);
277 }
278 canvas->restore();
279 canvas->translate(0.0f, SCALE + 10);
280 }
281 canvas->restore();
282 canvas->translate(2 * (SCALE + 10), 0.0f);
283 }
284 }
OLDNEW
« no previous file with comments | « no previous file | src/core/SkBlitter_Sprite.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698