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/layout_test_controller.h" | 5 #include "content/shell/layout_test_controller.h" |
6 | 6 |
7 #include "base/md5.h" | 7 #include "base/md5.h" |
| 8 #include "base/memory/scoped_ptr.h" |
8 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
9 #include "content/public/renderer/render_view.h" | 10 #include "content/public/renderer/render_view.h" |
10 #include "content/shell/shell_messages.h" | 11 #include "content/shell/shell_messages.h" |
11 #include "skia/ext/platform_canvas.h" | 12 #include "skia/ext/platform_canvas.h" |
12 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCString.h
" | 13 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCString.h
" |
13 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h" | 14 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h" |
14 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h" | 15 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h" |
15 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" | 16 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" |
16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" | 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 Send(new ShellViewHostMsg_TextDump(routing_id(), dump)); | 182 Send(new ShellViewHostMsg_TextDump(routing_id(), dump)); |
182 } | 183 } |
183 | 184 |
184 void LayoutTestController::OnCaptureImageDump( | 185 void LayoutTestController::OnCaptureImageDump( |
185 const std::string& expected_pixel_hash) { | 186 const std::string& expected_pixel_hash) { |
186 SkBitmap snapshot; | 187 SkBitmap snapshot; |
187 CaptureSnapshot(render_view()->GetWebView(), &snapshot); | 188 CaptureSnapshot(render_view()->GetWebView(), &snapshot); |
188 | 189 |
189 SkAutoLockPixels snapshot_lock(snapshot); | 190 SkAutoLockPixels snapshot_lock(snapshot); |
190 base::MD5Digest digest; | 191 base::MD5Digest digest; |
| 192 #if defined(OS_ANDROID) |
| 193 // On Android, pixel layout is RGBA, however, other Chrome platforms use BGRA. |
| 194 const uint8_t* raw_pixels = |
| 195 reinterpret_cast<const uint8_t*>(snapshot.getPixels()); |
| 196 size_t snapshot_size = snapshot.getSize(); |
| 197 scoped_array<uint8_t> reordered_pixels(new uint8_t[snapshot_size]); |
| 198 for (size_t i = 0; i < snapshot_size; i += 4) { |
| 199 reordered_pixels[i] = raw_pixels[i + 2]; |
| 200 reordered_pixels[i + 1] = raw_pixels[i + 1]; |
| 201 reordered_pixels[i + 2] = raw_pixels[i]; |
| 202 reordered_pixels[i + 3] = raw_pixels[i + 3]; |
| 203 } |
| 204 base::MD5Sum(reordered_pixels.get(), snapshot_size, &digest); |
| 205 #else |
191 base::MD5Sum(snapshot.getPixels(), snapshot.getSize(), &digest); | 206 base::MD5Sum(snapshot.getPixels(), snapshot.getSize(), &digest); |
| 207 #endif |
192 std::string actual_pixel_hash = base::MD5DigestToBase16(digest); | 208 std::string actual_pixel_hash = base::MD5DigestToBase16(digest); |
193 | 209 |
194 if (actual_pixel_hash == expected_pixel_hash) { | 210 if (actual_pixel_hash == expected_pixel_hash) { |
195 SkBitmap empty_image; | 211 SkBitmap empty_image; |
196 Send(new ShellViewHostMsg_ImageDump( | 212 Send(new ShellViewHostMsg_ImageDump( |
197 routing_id(), actual_pixel_hash, empty_image)); | 213 routing_id(), actual_pixel_hash, empty_image)); |
| 214 return; |
198 } | 215 } |
199 Send(new ShellViewHostMsg_ImageDump( | 216 Send(new ShellViewHostMsg_ImageDump( |
200 routing_id(), actual_pixel_hash, snapshot)); | 217 routing_id(), actual_pixel_hash, snapshot)); |
201 } | 218 } |
202 | 219 |
203 } // namespace content | 220 } // namespace content |
OLD | NEW |