| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/test_runner/pixel_dump.h" | 5 #include "content/shell/test_runner/pixel_dump.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/threading/thread_task_runner_handle.h" | 13 #include "base/threading/thread_task_runner_handle.h" |
| 14 #include "base/trace_event/trace_event.h" | 14 #include "base/trace_event/trace_event.h" |
| 15 #include "cc/paint/paint_canvas.h" | |
| 16 #include "cc/paint/paint_flags.h" | 15 #include "cc/paint/paint_flags.h" |
| 16 #include "cc/paint/skia_paint_canvas.h" |
| 17 #include "content/shell/test_runner/layout_test_runtime_flags.h" | 17 #include "content/shell/test_runner/layout_test_runtime_flags.h" |
| 18 // FIXME: Including platform_canvas.h here is a layering violation. | 18 // FIXME: Including platform_canvas.h here is a layering violation. |
| 19 #include "skia/ext/platform_canvas.h" | 19 #include "skia/ext/platform_canvas.h" |
| 20 #include "third_party/WebKit/public/platform/Platform.h" | 20 #include "third_party/WebKit/public/platform/Platform.h" |
| 21 #include "third_party/WebKit/public/platform/WebCompositeAndReadbackAsyncCallbac
k.h" | 21 #include "third_party/WebKit/public/platform/WebCompositeAndReadbackAsyncCallbac
k.h" |
| 22 #include "third_party/WebKit/public/platform/WebImage.h" | 22 #include "third_party/WebKit/public/platform/WebImage.h" |
| 23 #include "third_party/WebKit/public/platform/WebMockClipboard.h" | 23 #include "third_party/WebKit/public/platform/WebMockClipboard.h" |
| 24 #include "third_party/WebKit/public/platform/WebPoint.h" | 24 #include "third_party/WebKit/public/platform/WebPoint.h" |
| 25 #include "third_party/WebKit/public/web/WebFrame.h" | 25 #include "third_party/WebKit/public/web/WebFrame.h" |
| 26 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 26 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 | 101 |
| 102 SkBitmap bitmap; | 102 SkBitmap bitmap; |
| 103 if (!bitmap.tryAllocN32Pixels(page_size_in_pixels.width, totalHeight, | 103 if (!bitmap.tryAllocN32Pixels(page_size_in_pixels.width, totalHeight, |
| 104 is_opaque)) { | 104 is_opaque)) { |
| 105 LOG(ERROR) << "Failed to create bitmap width=" << page_size_in_pixels.width | 105 LOG(ERROR) << "Failed to create bitmap width=" << page_size_in_pixels.width |
| 106 << " height=" << totalHeight; | 106 << " height=" << totalHeight; |
| 107 dump_request->callback.Run(SkBitmap()); | 107 dump_request->callback.Run(SkBitmap()); |
| 108 return; | 108 return; |
| 109 } | 109 } |
| 110 | 110 |
| 111 cc::PaintCanvas canvas(bitmap); | 111 cc::SkiaPaintCanvas canvas(bitmap); |
| 112 web_frame->printPagesWithBoundaries(&canvas, page_size_in_pixels); | 112 web_frame->printPagesWithBoundaries(&canvas, page_size_in_pixels); |
| 113 web_frame->printEnd(); | 113 web_frame->printEnd(); |
| 114 | 114 |
| 115 DrawSelectionRect(*dump_request, &canvas); | 115 DrawSelectionRect(*dump_request, &canvas); |
| 116 dump_request->callback.Run(bitmap); | 116 dump_request->callback.Run(bitmap); |
| 117 } | 117 } |
| 118 | 118 |
| 119 CaptureCallback::CaptureCallback( | 119 CaptureCallback::CaptureCallback( |
| 120 const base::Callback<void(const SkBitmap&)>& callback) | 120 const base::Callback<void(const SkBitmap&)>& callback) |
| 121 : callback_(callback), wait_for_popup_(false) {} | 121 : callback_(callback), wait_for_popup_(false) {} |
| (...skipping 13 matching lines...) Expand all Loading... |
| 135 return; | 135 return; |
| 136 } | 136 } |
| 137 SkCanvas canvas(main_bitmap_); | 137 SkCanvas canvas(main_bitmap_); |
| 138 canvas.drawBitmap(bitmap, popup_position_.x(), popup_position_.y()); | 138 canvas.drawBitmap(bitmap, popup_position_.x(), popup_position_.y()); |
| 139 callback_.Run(main_bitmap_); | 139 callback_.Run(main_bitmap_); |
| 140 delete this; | 140 delete this; |
| 141 } | 141 } |
| 142 | 142 |
| 143 void DidCapturePixelsAsync(std::unique_ptr<PixelsDumpRequest> dump_request, | 143 void DidCapturePixelsAsync(std::unique_ptr<PixelsDumpRequest> dump_request, |
| 144 const SkBitmap& bitmap) { | 144 const SkBitmap& bitmap) { |
| 145 cc::PaintCanvas canvas(bitmap); | 145 cc::SkiaPaintCanvas canvas(bitmap); |
| 146 DrawSelectionRect(*dump_request, &canvas); | 146 DrawSelectionRect(*dump_request, &canvas); |
| 147 if (!dump_request->callback.is_null()) | 147 if (!dump_request->callback.is_null()) |
| 148 dump_request->callback.Run(bitmap); | 148 dump_request->callback.Run(bitmap); |
| 149 } | 149 } |
| 150 | 150 |
| 151 } // namespace | 151 } // namespace |
| 152 | 152 |
| 153 void DumpPixelsAsync(blink::WebView* web_view, | 153 void DumpPixelsAsync(blink::WebView* web_view, |
| 154 const LayoutTestRuntimeFlags& layout_test_runtime_flags, | 154 const LayoutTestRuntimeFlags& layout_test_runtime_flags, |
| 155 float device_scale_factor_for_test, | 155 float device_scale_factor_for_test, |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 | 203 |
| 204 blink::WebImage image = static_cast<blink::WebMockClipboard*>( | 204 blink::WebImage image = static_cast<blink::WebMockClipboard*>( |
| 205 blink::Platform::current()->clipboard()) | 205 blink::Platform::current()->clipboard()) |
| 206 ->readRawImage(blink::WebClipboard::Buffer()); | 206 ->readRawImage(blink::WebClipboard::Buffer()); |
| 207 const SkBitmap& bitmap = image.getSkBitmap(); | 207 const SkBitmap& bitmap = image.getSkBitmap(); |
| 208 SkAutoLockPixels autoLock(bitmap); | 208 SkAutoLockPixels autoLock(bitmap); |
| 209 callback.Run(bitmap); | 209 callback.Run(bitmap); |
| 210 } | 210 } |
| 211 | 211 |
| 212 } // namespace test_runner | 212 } // namespace test_runner |
| OLD | NEW |