| OLD | NEW |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-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 "base/base_paths.h" | 9 #include "base/base_paths.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 DumpAllBackForwardLists(&bfDump); | 234 DumpAllBackForwardLists(&bfDump); |
| 235 printf("%s", WideToUTF8(bfDump).c_str()); | 235 printf("%s", WideToUTF8(bfDump).c_str()); |
| 236 } | 236 } |
| 237 } | 237 } |
| 238 | 238 |
| 239 if (params->dump_pixels && !should_dump_as_text) { | 239 if (params->dump_pixels && !should_dump_as_text) { |
| 240 // Image output: we write the image data to the file given on the | 240 // Image output: we write the image data to the file given on the |
| 241 // command line (for the dump pixels argument), and the MD5 sum to | 241 // command line (for the dump pixels argument), and the MD5 sum to |
| 242 // stdout. | 242 // stdout. |
| 243 dumped_anything = true; | 243 dumped_anything = true; |
| 244 std::string md5sum = DumpImage(shell->webView(), params->pixel_file_name, | 244 WebViewHost* view_host = shell->webViewHost(); |
| 245 params->pixel_hash); | 245 view_host->webview()->layout(); |
| 246 view_host->Paint(); |
| 247 std::string md5sum = DumpImage(view_host->canvas(), |
| 248 params->pixel_file_name, params->pixel_hash); |
| 246 printf("#MD5:%s\n", md5sum.c_str()); | 249 printf("#MD5:%s\n", md5sum.c_str()); |
| 247 } | 250 } |
| 248 if (dumped_anything) | 251 if (dumped_anything) |
| 249 printf("#EOF\n"); | 252 printf("#EOF\n"); |
| 250 fflush(stdout); | 253 fflush(stdout); |
| 251 } | 254 } |
| 252 } | 255 } |
| 253 | 256 |
| 254 // static | 257 // static |
| 255 std::string TestShell::DumpImage(WebView* view, | 258 std::string TestShell::DumpImage(skia::PlatformCanvas* canvas, |
| 256 const std::wstring& file_name, const std::string& pixel_hash) { | 259 const std::wstring& file_name, const std::string& pixel_hash) { |
| 257 view->layout(); | |
| 258 const WebSize& size = view->size(); | |
| 259 | |
| 260 skia::PlatformCanvas canvas; | |
| 261 if (!canvas.initialize(size.width, size.height, true)) | |
| 262 return std::string(); | |
| 263 view->paint(webkit_glue::ToWebCanvas(&canvas), | |
| 264 WebRect(0, 0, size.width, size.height)); | |
| 265 | |
| 266 skia::BitmapPlatformDevice& device = | 260 skia::BitmapPlatformDevice& device = |
| 267 static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice()); | 261 static_cast<skia::BitmapPlatformDevice&>(canvas->getTopPlatformDevice()); |
| 268 const SkBitmap& src_bmp = device.accessBitmap(false); | 262 const SkBitmap& src_bmp = device.accessBitmap(false); |
| 269 | 263 |
| 270 // Encode image. | 264 // Encode image. |
| 271 std::vector<unsigned char> png; | 265 std::vector<unsigned char> png; |
| 272 SkAutoLockPixels src_bmp_lock(src_bmp); | 266 SkAutoLockPixels src_bmp_lock(src_bmp); |
| 273 PNGEncoder::ColorFormat color_format = PNGEncoder::FORMAT_BGRA; | 267 PNGEncoder::ColorFormat color_format = PNGEncoder::FORMAT_BGRA; |
| 274 | 268 |
| 275 // Fix the alpha. The expected PNGs on Mac have an alpha channel, so we want | 269 // Fix the alpha. The expected PNGs on Mac have an alpha channel, so we want |
| 276 // to keep it. On Windows, the alpha channel is wrong since text/form control | 270 // to keep it. On Windows, the alpha channel is wrong since text/form control |
| 277 // drawing may have erased it in a few places. So on Windows we force it to | 271 // drawing may have erased it in a few places. So on Windows we force it to |
| (...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 675 | 669 |
| 676 void CloseIdleConnections() { | 670 void CloseIdleConnections() { |
| 677 // Used in benchmarking, Ignored for test_shell. | 671 // Used in benchmarking, Ignored for test_shell. |
| 678 } | 672 } |
| 679 | 673 |
| 680 void SetCacheMode(bool enabled) { | 674 void SetCacheMode(bool enabled) { |
| 681 // Used in benchmarking, Ignored for test_shell. | 675 // Used in benchmarking, Ignored for test_shell. |
| 682 } | 676 } |
| 683 | 677 |
| 684 } // namespace webkit_glue | 678 } // namespace webkit_glue |
| OLD | NEW |