| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "content/shell/webkit_test_runner.h" | 5 #include "content/shell/webkit_test_runner.h" |
| 6 | 6 |
| 7 #include "base/md5.h" | 7 #include "base/md5.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 | 106 |
| 107 if (recursive) { | 107 if (recursive) { |
| 108 for (WebFrame* child = frame->firstChild(); child; | 108 for (WebFrame* child = frame->firstChild(); child; |
| 109 child = child->nextSibling()) { | 109 child = child->nextSibling()) { |
| 110 result.append(DumpFrameScrollPosition(child, recursive)); | 110 result.append(DumpFrameScrollPosition(child, recursive)); |
| 111 } | 111 } |
| 112 } | 112 } |
| 113 return result; | 113 return result; |
| 114 } | 114 } |
| 115 | 115 |
| 116 bool PaintViewIntoCanvas(WebView* view, skia::PlatformCanvas& canvas) { | 116 SkCanvas* PaintViewIntoCanvas(WebView* view) { |
| 117 view->layout(); | 117 view->layout(); |
| 118 const WebSize& size = view->size(); | 118 const WebSize& size = view->size(); |
| 119 | 119 |
| 120 if (!canvas.initialize(size.width, size.height, true)) | 120 SkCanvas* canvas = skia::CreatePlatformCanvas(size.width, size.height, true, |
| 121 return false; | 121 0, skia::RETURN_NULL_ON_FAILURE); |
| 122 | 122 if (canvas) { |
| 123 view->paint(webkit_glue::ToWebCanvas(&canvas), | 123 view->paint(webkit_glue::ToWebCanvas(canvas), |
| 124 WebRect(0, 0, size.width, size.height)); | 124 WebRect(0, 0, size.width, size.height)); |
| 125 return true; | 125 } |
| 126 return canvas; |
| 126 } | 127 } |
| 127 | 128 |
| 128 #if !defined(OS_MACOSX) | 129 #if !defined(OS_MACOSX) |
| 129 void MakeBitmapOpaque(SkBitmap* bitmap) { | 130 void MakeBitmapOpaque(SkBitmap* bitmap) { |
| 130 SkAutoLockPixels lock(*bitmap); | 131 SkAutoLockPixels lock(*bitmap); |
| 131 DCHECK(bitmap->config() == SkBitmap::kARGB_8888_Config); | 132 DCHECK(bitmap->config() == SkBitmap::kARGB_8888_Config); |
| 132 for (int y = 0; y < bitmap->height(); ++y) { | 133 for (int y = 0; y < bitmap->height(); ++y) { |
| 133 uint32_t* row = bitmap->getAddr32(0, y); | 134 uint32_t* row = bitmap->getAddr32(0, y); |
| 134 for (int x = 0; x < bitmap->width(); ++x) | 135 for (int x = 0; x < bitmap->width(); ++x) |
| 135 row[x] |= 0xFF000000; // Set alpha bits to 1. | 136 row[x] |= 0xFF000000; // Set alpha bits to 1. |
| 136 } | 137 } |
| 137 } | 138 } |
| 138 #endif | 139 #endif |
| 139 | 140 |
| 140 void CaptureSnapshot(WebView* view, SkBitmap* snapshot) { | 141 void CaptureSnapshot(WebView* view, SkBitmap* snapshot) { |
| 141 skia::PlatformCanvas canvas; | 142 SkCanvas* canvas = PaintViewIntoCanvas(view); |
| 142 if (!PaintViewIntoCanvas(view, canvas)) | 143 if (!canvas) |
| 143 return; | 144 return; |
| 144 | 145 |
| 145 SkDevice* device = skia::GetTopDevice(canvas); | 146 SkDevice* device = skia::GetTopDevice(*canvas); |
| 146 | 147 |
| 147 const SkBitmap& bitmap = device->accessBitmap(false); | 148 const SkBitmap& bitmap = device->accessBitmap(false); |
| 148 bitmap.copyTo(snapshot, SkBitmap::kARGB_8888_Config); | 149 bitmap.copyTo(snapshot, SkBitmap::kARGB_8888_Config); |
| 149 | 150 |
| 150 #if !defined(OS_MACOSX) | 151 #if !defined(OS_MACOSX) |
| 151 // Only the expected PNGs for Mac have a valid alpha channel. | 152 // Only the expected PNGs for Mac have a valid alpha channel. |
| 152 MakeBitmapOpaque(snapshot); | 153 MakeBitmapOpaque(snapshot); |
| 153 #endif | 154 #endif |
| 154 | 155 |
| 155 } | 156 } |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 const FilePath& current_working_directory) { | 339 const FilePath& current_working_directory) { |
| 339 current_working_directory_ = current_working_directory; | 340 current_working_directory_ = current_working_directory; |
| 340 } | 341 } |
| 341 | 342 |
| 342 void WebKitTestRunner::OnSetIsMainWindow() { | 343 void WebKitTestRunner::OnSetIsMainWindow() { |
| 343 is_main_window_ = true; | 344 is_main_window_ = true; |
| 344 ShellRenderProcessObserver::GetInstance()->SetMainWindow(render_view(), this); | 345 ShellRenderProcessObserver::GetInstance()->SetMainWindow(render_view(), this); |
| 345 } | 346 } |
| 346 | 347 |
| 347 } // namespace content | 348 } // namespace content |
| OLD | NEW |