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 /* | 8 /* |
9 * Code for the "gm" (Golden Master) rendering comparison tool. | 9 * Code for the "gm" (Golden Master) rendering comparison tool. |
10 * | 10 * |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 return make_filename(path, shortName, configName, renderModeDescript
or, | 258 return make_filename(path, shortName, configName, renderModeDescript
or, |
259 kPNG_FileExtension); | 259 kPNG_FileExtension); |
260 } | 260 } |
261 } | 261 } |
262 | 262 |
263 /* since PNG insists on unpremultiplying our alpha, we take no | 263 /* since PNG insists on unpremultiplying our alpha, we take no |
264 precision chances and force all pixels to be 100% opaque, | 264 precision chances and force all pixels to be 100% opaque, |
265 otherwise on compare we may not get a perfect match. | 265 otherwise on compare we may not get a perfect match. |
266 */ | 266 */ |
267 static void force_all_opaque(const SkBitmap& bitmap) { | 267 static void force_all_opaque(const SkBitmap& bitmap) { |
268 SkBitmap::Config config = bitmap.config(); | 268 SkColorType colorType = bitmap.colorType(); |
269 switch (config) { | 269 switch (colorType) { |
270 case SkBitmap::kARGB_8888_Config: | 270 case kPMColor_SkColorType: |
271 force_all_opaque_8888(bitmap); | 271 force_all_opaque_8888(bitmap); |
272 break; | 272 break; |
273 case SkBitmap::kRGB_565_Config: | 273 case kRGB_565_SkColorType: |
274 // nothing to do here; 565 bitmaps are inherently opaque | 274 // nothing to do here; 565 bitmaps are inherently opaque |
275 break; | 275 break; |
276 default: | 276 default: |
277 gm_fprintf(stderr, "unsupported bitmap config %d\n", config); | 277 gm_fprintf(stderr, "unsupported bitmap colorType %d\n", colorType); |
278 DEBUGFAIL_SEE_STDERR; | 278 DEBUGFAIL_SEE_STDERR; |
279 } | 279 } |
280 } | 280 } |
281 | 281 |
282 static void force_all_opaque_8888(const SkBitmap& bitmap) { | 282 static void force_all_opaque_8888(const SkBitmap& bitmap) { |
283 SkAutoLockPixels lock(bitmap); | 283 SkAutoLockPixels lock(bitmap); |
284 for (int y = 0; y < bitmap.height(); y++) { | 284 for (int y = 0; y < bitmap.height(); y++) { |
285 for (int x = 0; x < bitmap.width(); x++) { | 285 for (int x = 0; x < bitmap.width(); x++) { |
286 *bitmap.getAddr32(x, y) |= (SK_A32_MASK << SK_A32_SHIFT); | 286 *bitmap.getAddr32(x, y) |= (SK_A32_MASK << SK_A32_SHIFT); |
287 } | 287 } |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
583 surface.reset(SkSurface::NewRenderTargetDirect(gpuTarget->asRenderTa
rget())); | 583 surface.reset(SkSurface::NewRenderTargetDirect(gpuTarget->asRenderTa
rget())); |
584 if (deferred) { | 584 if (deferred) { |
585 canvas.reset(SkDeferredCanvas::Create(surface)); | 585 canvas.reset(SkDeferredCanvas::Create(surface)); |
586 } else { | 586 } else { |
587 canvas.reset(SkRef(surface->getCanvas())); | 587 canvas.reset(SkRef(surface->getCanvas())); |
588 } | 588 } |
589 invokeGM(gm, canvas, false, deferred); | 589 invokeGM(gm, canvas, false, deferred); |
590 // the device is as large as the current rendertarget, so | 590 // the device is as large as the current rendertarget, so |
591 // we explicitly only readback the amount we expect (in | 591 // we explicitly only readback the amount we expect (in |
592 // size) overwrite our previous allocation | 592 // size) overwrite our previous allocation |
593 bitmap->setConfig(SkBitmap::kARGB_8888_Config, size.fWidth, | 593 bitmap->setConfig(SkImageInfo::MakeN32Premul(size.fWidth, size.fHeig
ht)); |
594 size.fHeight); | |
595 canvas->readPixels(bitmap, 0, 0); | 594 canvas->readPixels(bitmap, 0, 0); |
596 } | 595 } |
597 #endif | 596 #endif |
598 complete_bitmap(bitmap); | 597 complete_bitmap(bitmap); |
599 return kEmpty_ErrorCombination; | 598 return kEmpty_ErrorCombination; |
600 } | 599 } |
601 | 600 |
602 static void generate_image_from_picture(GM* gm, const ConfigData& gRec, | 601 static void generate_image_from_picture(GM* gm, const ConfigData& gRec, |
603 SkPicture* pict, SkBitmap* bitmap, | 602 SkPicture* pict, SkBitmap* bitmap, |
604 SkScalar scale = SK_Scalar1, | 603 SkScalar scale = SK_Scalar1, |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
734 const int expectedHeight = expectedBitmap.height(); | 733 const int expectedHeight = expectedBitmap.height(); |
735 const int width = actualBitmap.width(); | 734 const int width = actualBitmap.width(); |
736 const int height = actualBitmap.height(); | 735 const int height = actualBitmap.height(); |
737 if ((expectedWidth != width) || (expectedHeight != height)) { | 736 if ((expectedWidth != width) || (expectedHeight != height)) { |
738 gm_fprintf(stderr, "---- %s: dimension mismatch --" | 737 gm_fprintf(stderr, "---- %s: dimension mismatch --" |
739 " expected [%d %d], actual [%d %d]\n", | 738 " expected [%d %d], actual [%d %d]\n", |
740 testName, expectedWidth, expectedHeight, width, height); | 739 testName, expectedWidth, expectedHeight, width, height); |
741 return; | 740 return; |
742 } | 741 } |
743 | 742 |
744 if ((SkBitmap::kARGB_8888_Config != expectedBitmap.config()) || | 743 if ((kPMColor_SkColorType != expectedBitmap.colorType()) || |
745 (SkBitmap::kARGB_8888_Config != actualBitmap.config())) { | 744 (kPMColor_SkColorType != actualBitmap.colorType())) { |
746 gm_fprintf(stderr, "---- %s: not computing max per-channel" | 745 gm_fprintf(stderr, "---- %s: not computing max per-channel" |
747 " pixel mismatch because non-8888\n", testName); | 746 " pixel mismatch because non-8888\n", testName); |
748 return; | 747 return; |
749 } | 748 } |
750 | 749 |
751 SkAutoLockPixels alp0(expectedBitmap); | 750 SkAutoLockPixels alp0(expectedBitmap); |
752 SkAutoLockPixels alp1(actualBitmap); | 751 SkAutoLockPixels alp1(actualBitmap); |
753 int errR = 0; | 752 int errR = 0; |
754 int errG = 0; | 753 int errG = 0; |
755 int errB = 0; | 754 int errB = 0; |
(...skipping 1663 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2419 if (FLAGS_forceBWtext) { | 2418 if (FLAGS_forceBWtext) { |
2420 canvas->setDrawFilter(SkNEW(BWTextDrawFilter))->unref(); | 2419 canvas->setDrawFilter(SkNEW(BWTextDrawFilter))->unref(); |
2421 } | 2420 } |
2422 } | 2421 } |
2423 | 2422 |
2424 #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL) | 2423 #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL) |
2425 int main(int argc, char * const argv[]) { | 2424 int main(int argc, char * const argv[]) { |
2426 return tool_main(argc, (char**) argv); | 2425 return tool_main(argc, (char**) argv); |
2427 } | 2426 } |
2428 #endif | 2427 #endif |
OLD | NEW |