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 "components/test_runner/pixel_dump.h" | 5 #include "components/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 "components/test_runner/layout_test_runtime_flags.h" | 17 #include "components/test_runner/layout_test_runtime_flags.h" |
16 // FIXME: Including platform_canvas.h here is a layering violation. | 18 // FIXME: Including platform_canvas.h here is a layering violation. |
17 #include "skia/ext/platform_canvas.h" | 19 #include "skia/ext/platform_canvas.h" |
18 #include "third_party/WebKit/public/platform/Platform.h" | 20 #include "third_party/WebKit/public/platform/Platform.h" |
19 #include "third_party/WebKit/public/platform/WebCompositeAndReadbackAsyncCallbac k.h" | 21 #include "third_party/WebKit/public/platform/WebCompositeAndReadbackAsyncCallbac k.h" |
20 #include "third_party/WebKit/public/platform/WebImage.h" | 22 #include "third_party/WebKit/public/platform/WebImage.h" |
21 #include "third_party/WebKit/public/platform/WebMockClipboard.h" | 23 #include "third_party/WebKit/public/platform/WebMockClipboard.h" |
22 #include "third_party/WebKit/public/platform/WebPoint.h" | 24 #include "third_party/WebKit/public/platform/WebPoint.h" |
23 #include "third_party/WebKit/public/web/WebFrame.h" | 25 #include "third_party/WebKit/public/web/WebFrame.h" |
24 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 26 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
58 void didCompositeAndReadback(const SkBitmap& bitmap) override; | 60 void didCompositeAndReadback(const SkBitmap& bitmap) override; |
59 | 61 |
60 private: | 62 private: |
61 base::Callback<void(const SkBitmap&)> callback_; | 63 base::Callback<void(const SkBitmap&)> callback_; |
62 SkBitmap main_bitmap_; | 64 SkBitmap main_bitmap_; |
63 bool wait_for_popup_; | 65 bool wait_for_popup_; |
64 gfx::Point popup_position_; | 66 gfx::Point popup_position_; |
65 }; | 67 }; |
66 | 68 |
67 void DrawSelectionRect(const PixelsDumpRequest& dump_request, | 69 void DrawSelectionRect(const PixelsDumpRequest& dump_request, |
68 SkCanvas* canvas) { | 70 cc::PaintCanvas* canvas) { |
69 // See if we need to draw the selection bounds rect. Selection bounds | 71 // See if we need to draw the selection bounds rect. Selection bounds |
70 // rect is the rect enclosing the (possibly transformed) selection. | 72 // rect is the rect enclosing the (possibly transformed) selection. |
71 // The rect should be drawn after everything is laid out and painted. | 73 // The rect should be drawn after everything is laid out and painted. |
72 if (!dump_request.layout_test_runtime_flags.dump_selection_rect()) | 74 if (!dump_request.layout_test_runtime_flags.dump_selection_rect()) |
73 return; | 75 return; |
74 // If there is a selection rect - draw a red 1px border enclosing rect | 76 // If there is a selection rect - draw a red 1px border enclosing rect |
75 blink::WebRect wr = dump_request.web_view->mainFrame()->selectionBoundsRect(); | 77 blink::WebRect wr = dump_request.web_view->mainFrame()->selectionBoundsRect(); |
76 if (wr.isEmpty()) | 78 if (wr.isEmpty()) |
77 return; | 79 return; |
78 // Render a red rectangle bounding selection rect | 80 // Render a red rectangle bounding selection rect |
79 SkPaint paint; | 81 cc::PaintFlags paint; |
80 paint.setColor(0xFFFF0000); // Fully opaque red | 82 paint.setColor(0xFFFF0000); // Fully opaque red |
81 paint.setStyle(SkPaint::kStroke_Style); | 83 paint.setStyle(cc::PaintFlags::kStroke_Style); |
82 paint.setFlags(SkPaint::kAntiAlias_Flag); | 84 paint.setAntiAlias(true); |
83 paint.setStrokeWidth(1.0f); | 85 paint.setStrokeWidth(1.0f); |
84 SkIRect rect; // Bounding rect | 86 SkIRect rect; // Bounding rect |
85 rect.set(wr.x, wr.y, wr.x + wr.width, wr.y + wr.height); | 87 rect.set(wr.x, wr.y, wr.x + wr.width, wr.y + wr.height); |
86 canvas->drawIRect(rect, paint); | 88 canvas->drawIRect(rect, paint); |
87 } | 89 } |
88 | 90 |
89 void CapturePixelsForPrinting(std::unique_ptr<PixelsDumpRequest> dump_request) { | 91 void CapturePixelsForPrinting(std::unique_ptr<PixelsDumpRequest> dump_request) { |
90 dump_request->web_view->updateAllLifecyclePhases(); | 92 dump_request->web_view->updateAllLifecyclePhases(); |
91 | 93 |
92 blink::WebSize page_size_in_pixels = dump_request->web_view->size(); | 94 blink::WebSize page_size_in_pixels = dump_request->web_view->size(); |
93 blink::WebFrame* web_frame = dump_request->web_view->mainFrame(); | 95 blink::WebFrame* web_frame = dump_request->web_view->mainFrame(); |
94 | 96 |
95 int page_count = web_frame->printBegin(page_size_in_pixels); | 97 int page_count = web_frame->printBegin(page_size_in_pixels); |
96 int totalHeight = page_count * (page_size_in_pixels.height + 1) - 1; | 98 int totalHeight = page_count * (page_size_in_pixels.height + 1) - 1; |
97 | 99 |
98 bool is_opaque = false; | 100 bool is_opaque = false; |
99 std::unique_ptr<SkCanvas> canvas = skia::TryCreateBitmapCanvas( | 101 std::unique_ptr<cc::PaintCanvas> canvas = skia::TryCreateBitmapCanvas( |
danakj
2017/01/20 23:34:14
this looks like a type mismatch? also noting that
enne (OOO)
2017/01/24 01:51:28
Yeah, I was trying to avoid changing too much logi
| |
100 page_size_in_pixels.width, totalHeight, is_opaque); | 102 page_size_in_pixels.width, totalHeight, is_opaque); |
101 if (!canvas) { | 103 if (!canvas) { |
102 LOG(ERROR) << "Failed to create canvas width=" | 104 LOG(ERROR) << "Failed to create canvas width=" |
103 << page_size_in_pixels.width << " height=" << totalHeight; | 105 << page_size_in_pixels.width << " height=" << totalHeight; |
104 dump_request->callback.Run(SkBitmap()); | 106 dump_request->callback.Run(SkBitmap()); |
105 return; | 107 return; |
106 } | 108 } |
107 web_frame->printPagesWithBoundaries(canvas.get(), page_size_in_pixels); | 109 web_frame->printPagesWithBoundaries(canvas.get(), page_size_in_pixels); |
108 web_frame->printEnd(); | 110 web_frame->printEnd(); |
109 | 111 |
(...skipping 21 matching lines...) Expand all Loading... | |
131 return; | 133 return; |
132 } | 134 } |
133 SkCanvas canvas(main_bitmap_); | 135 SkCanvas canvas(main_bitmap_); |
134 canvas.drawBitmap(bitmap, popup_position_.x(), popup_position_.y()); | 136 canvas.drawBitmap(bitmap, popup_position_.x(), popup_position_.y()); |
135 callback_.Run(main_bitmap_); | 137 callback_.Run(main_bitmap_); |
136 delete this; | 138 delete this; |
137 } | 139 } |
138 | 140 |
139 void DidCapturePixelsAsync(std::unique_ptr<PixelsDumpRequest> dump_request, | 141 void DidCapturePixelsAsync(std::unique_ptr<PixelsDumpRequest> dump_request, |
140 const SkBitmap& bitmap) { | 142 const SkBitmap& bitmap) { |
141 SkCanvas canvas(bitmap); | 143 cc::PaintCanvas canvas(bitmap); |
142 DrawSelectionRect(*dump_request, &canvas); | 144 DrawSelectionRect(*dump_request, &canvas); |
143 if (!dump_request->callback.is_null()) | 145 if (!dump_request->callback.is_null()) |
144 dump_request->callback.Run(bitmap); | 146 dump_request->callback.Run(bitmap); |
145 } | 147 } |
146 | 148 |
147 } // namespace | 149 } // namespace |
148 | 150 |
149 void DumpPixelsAsync(blink::WebView* web_view, | 151 void DumpPixelsAsync(blink::WebView* web_view, |
150 const LayoutTestRuntimeFlags& layout_test_runtime_flags, | 152 const LayoutTestRuntimeFlags& layout_test_runtime_flags, |
151 float device_scale_factor_for_test, | 153 float device_scale_factor_for_test, |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
199 | 201 |
200 blink::WebImage image = static_cast<blink::WebMockClipboard*>( | 202 blink::WebImage image = static_cast<blink::WebMockClipboard*>( |
201 blink::Platform::current()->clipboard()) | 203 blink::Platform::current()->clipboard()) |
202 ->readRawImage(blink::WebClipboard::Buffer()); | 204 ->readRawImage(blink::WebClipboard::Buffer()); |
203 const SkBitmap& bitmap = image.getSkBitmap(); | 205 const SkBitmap& bitmap = image.getSkBitmap(); |
204 SkAutoLockPixels autoLock(bitmap); | 206 SkAutoLockPixels autoLock(bitmap); |
205 callback.Run(bitmap); | 207 callback.Run(bitmap); |
206 } | 208 } |
207 | 209 |
208 } // namespace test_runner | 210 } // namespace test_runner |
OLD | NEW |