| OLD | NEW |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #undef LOG | 5 #undef LOG |
| 6 | 6 |
| 7 #include "webkit/tools/test_shell/test_shell.h" | 7 #include "webkit/tools/test_shell/test_shell.h" |
| 8 | 8 |
| 9 #include "app/gfx/codec/png_codec.h" |
| 9 #include "base/base_paths.h" | 10 #include "base/base_paths.h" |
| 10 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 11 #include "base/debug_on_start.h" | 12 #include "base/debug_on_start.h" |
| 12 #include "base/file_path.h" | 13 #include "base/file_path.h" |
| 13 #include "base/file_util.h" | 14 #include "base/file_util.h" |
| 14 #include "base/gfx/png_encoder.h" | |
| 15 #include "base/gfx/size.h" | 15 #include "base/gfx/size.h" |
| 16 #include "base/icu_util.h" | 16 #include "base/icu_util.h" |
| 17 #if defined(OS_MACOSX) | 17 #if defined(OS_MACOSX) |
| 18 #include "base/mac_util.h" | 18 #include "base/mac_util.h" |
| 19 #endif | 19 #endif |
| 20 #include "base/md5.h" | 20 #include "base/md5.h" |
| 21 #include "base/message_loop.h" | 21 #include "base/message_loop.h" |
| 22 #include "base/path_service.h" | 22 #include "base/path_service.h" |
| 23 #include "base/stats_table.h" | 23 #include "base/stats_table.h" |
| 24 #include "base/string_util.h" | 24 #include "base/string_util.h" |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 // static | 258 // static |
| 259 std::string TestShell::DumpImage(skia::PlatformCanvas* canvas, | 259 std::string TestShell::DumpImage(skia::PlatformCanvas* canvas, |
| 260 const std::wstring& file_name, const std::string& pixel_hash) { | 260 const std::wstring& file_name, const std::string& pixel_hash) { |
| 261 skia::BitmapPlatformDevice& device = | 261 skia::BitmapPlatformDevice& device = |
| 262 static_cast<skia::BitmapPlatformDevice&>(canvas->getTopPlatformDevice()); | 262 static_cast<skia::BitmapPlatformDevice&>(canvas->getTopPlatformDevice()); |
| 263 const SkBitmap& src_bmp = device.accessBitmap(false); | 263 const SkBitmap& src_bmp = device.accessBitmap(false); |
| 264 | 264 |
| 265 // Encode image. | 265 // Encode image. |
| 266 std::vector<unsigned char> png; | 266 std::vector<unsigned char> png; |
| 267 SkAutoLockPixels src_bmp_lock(src_bmp); | 267 SkAutoLockPixels src_bmp_lock(src_bmp); |
| 268 PNGEncoder::ColorFormat color_format = PNGEncoder::FORMAT_BGRA; | 268 gfx::PNGCodec::ColorFormat color_format = gfx::PNGCodec::FORMAT_BGRA; |
| 269 | 269 |
| 270 // Fix the alpha. The expected PNGs on Mac have an alpha channel, so we want | 270 // Fix the alpha. The expected PNGs on Mac have an alpha channel, so we want |
| 271 // to keep it. On Windows, the alpha channel is wrong since text/form control | 271 // to keep it. On Windows, the alpha channel is wrong since text/form control |
| 272 // drawing may have erased it in a few places. So on Windows we force it to | 272 // drawing may have erased it in a few places. So on Windows we force it to |
| 273 // opaque and also don't write the alpha channel for the reference. Linux | 273 // opaque and also don't write the alpha channel for the reference. Linux |
| 274 // doesn't have the wrong alpha like Windows, but we ignore it anyway. | 274 // doesn't have the wrong alpha like Windows, but we ignore it anyway. |
| 275 #if defined(OS_WIN) | 275 #if defined(OS_WIN) |
| 276 bool discard_transparency = true; | 276 bool discard_transparency = true; |
| 277 device.makeOpaque(0, 0, src_bmp.width(), src_bmp.height()); | 277 device.makeOpaque(0, 0, src_bmp.width(), src_bmp.height()); |
| 278 #elif defined(OS_LINUX) | 278 #elif defined(OS_LINUX) |
| (...skipping 11 matching lines...) Expand all Loading... |
| 290 MD5Init(&ctx); | 290 MD5Init(&ctx); |
| 291 MD5Update(&ctx, src_bmp.getPixels(), src_bmp.getSize()); | 291 MD5Update(&ctx, src_bmp.getPixels(), src_bmp.getSize()); |
| 292 | 292 |
| 293 MD5Digest digest; | 293 MD5Digest digest; |
| 294 MD5Final(&digest, &ctx); | 294 MD5Final(&digest, &ctx); |
| 295 std::string md5hash = MD5DigestToBase16(digest); | 295 std::string md5hash = MD5DigestToBase16(digest); |
| 296 | 296 |
| 297 // Only encode and dump the png if the hashes don't match. Encoding the image | 297 // Only encode and dump the png if the hashes don't match. Encoding the image |
| 298 // is really expensive. | 298 // is really expensive. |
| 299 if (md5hash.compare(pixel_hash) != 0) { | 299 if (md5hash.compare(pixel_hash) != 0) { |
| 300 PNGEncoder::Encode( | 300 gfx::PNGCodec::Encode( |
| 301 reinterpret_cast<const unsigned char*>(src_bmp.getPixels()), | 301 reinterpret_cast<const unsigned char*>(src_bmp.getPixels()), |
| 302 color_format, src_bmp.width(), src_bmp.height(), | 302 color_format, src_bmp.width(), src_bmp.height(), |
| 303 static_cast<int>(src_bmp.rowBytes()), discard_transparency, &png); | 303 static_cast<int>(src_bmp.rowBytes()), discard_transparency, &png); |
| 304 | 304 |
| 305 // Write to disk. | 305 // Write to disk. |
| 306 file_util::WriteFile(file_name, reinterpret_cast<const char *>(&png[0]), | 306 file_util::WriteFile(file_name, reinterpret_cast<const char *>(&png[0]), |
| 307 png.size()); | 307 png.size()); |
| 308 } | 308 } |
| 309 | 309 |
| 310 return md5hash; | 310 return md5hash; |
| (...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 685 | 685 |
| 686 void CloseIdleConnections() { | 686 void CloseIdleConnections() { |
| 687 // Used in benchmarking, Ignored for test_shell. | 687 // Used in benchmarking, Ignored for test_shell. |
| 688 } | 688 } |
| 689 | 689 |
| 690 void SetCacheMode(bool enabled) { | 690 void SetCacheMode(bool enabled) { |
| 691 // Used in benchmarking, Ignored for test_shell. | 691 // Used in benchmarking, Ignored for test_shell. |
| 692 } | 692 } |
| 693 | 693 |
| 694 } // namespace webkit_glue | 694 } // namespace webkit_glue |
| OLD | NEW |