Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(172)

Side by Side Diff: components/test_runner/pixel_dump.cc

Issue 1921923002: Convert //components/[o-t]* from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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>
8
7 #include "base/bind.h" 9 #include "base/bind.h"
8 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
9 #include "base/callback.h" 11 #include "base/callback.h"
10 #include "base/logging.h" 12 #include "base/logging.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/thread_task_runner_handle.h" 13 #include "base/thread_task_runner_handle.h"
13 #include "base/trace_event/trace_event.h" 14 #include "base/trace_event/trace_event.h"
14 #include "components/test_runner/layout_test_runtime_flags.h" 15 #include "components/test_runner/layout_test_runtime_flags.h"
15 // FIXME: Including platform_canvas.h here is a layering violation. 16 // FIXME: Including platform_canvas.h here is a layering violation.
16 #include "skia/ext/platform_canvas.h" 17 #include "skia/ext/platform_canvas.h"
17 #include "third_party/WebKit/public/platform/Platform.h" 18 #include "third_party/WebKit/public/platform/Platform.h"
18 #include "third_party/WebKit/public/platform/WebCompositeAndReadbackAsyncCallbac k.h" 19 #include "third_party/WebKit/public/platform/WebCompositeAndReadbackAsyncCallbac k.h"
19 #include "third_party/WebKit/public/platform/WebImage.h" 20 #include "third_party/WebKit/public/platform/WebImage.h"
20 #include "third_party/WebKit/public/platform/WebMockClipboard.h" 21 #include "third_party/WebKit/public/platform/WebMockClipboard.h"
21 #include "third_party/WebKit/public/platform/WebPoint.h" 22 #include "third_party/WebKit/public/platform/WebPoint.h"
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 SkPaint paint; 78 SkPaint paint;
78 paint.setColor(0xFFFF0000); // Fully opaque red 79 paint.setColor(0xFFFF0000); // Fully opaque red
79 paint.setStyle(SkPaint::kStroke_Style); 80 paint.setStyle(SkPaint::kStroke_Style);
80 paint.setFlags(SkPaint::kAntiAlias_Flag); 81 paint.setFlags(SkPaint::kAntiAlias_Flag);
81 paint.setStrokeWidth(1.0f); 82 paint.setStrokeWidth(1.0f);
82 SkIRect rect; // Bounding rect 83 SkIRect rect; // Bounding rect
83 rect.set(wr.x, wr.y, wr.x + wr.width, wr.y + wr.height); 84 rect.set(wr.x, wr.y, wr.x + wr.width, wr.y + wr.height);
84 canvas->drawIRect(rect, paint); 85 canvas->drawIRect(rect, paint);
85 } 86 }
86 87
87 void CapturePixelsForPrinting(scoped_ptr<PixelsDumpRequest> dump_request) { 88 void CapturePixelsForPrinting(std::unique_ptr<PixelsDumpRequest> dump_request) {
88 dump_request->web_view->updateAllLifecyclePhases(); 89 dump_request->web_view->updateAllLifecyclePhases();
89 90
90 blink::WebSize page_size_in_pixels = dump_request->web_view->size(); 91 blink::WebSize page_size_in_pixels = dump_request->web_view->size();
91 blink::WebFrame* web_frame = dump_request->web_view->mainFrame(); 92 blink::WebFrame* web_frame = dump_request->web_view->mainFrame();
92 93
93 int page_count = web_frame->printBegin(page_size_in_pixels); 94 int page_count = web_frame->printBegin(page_size_in_pixels);
94 int totalHeight = page_count * (page_size_in_pixels.height + 1) - 1; 95 int totalHeight = page_count * (page_size_in_pixels.height + 1) - 1;
95 96
96 bool is_opaque = false; 97 bool is_opaque = false;
97 sk_sp<SkCanvas> canvas(skia::TryCreateBitmapCanvas( 98 sk_sp<SkCanvas> canvas(skia::TryCreateBitmapCanvas(
(...skipping 27 matching lines...) Expand all
125 if (main_bitmap_.isNull()) { 126 if (main_bitmap_.isNull()) {
126 bitmap.deepCopyTo(&main_bitmap_); 127 bitmap.deepCopyTo(&main_bitmap_);
127 return; 128 return;
128 } 129 }
129 SkCanvas canvas(main_bitmap_); 130 SkCanvas canvas(main_bitmap_);
130 canvas.drawBitmap(bitmap, popup_position_.x(), popup_position_.y()); 131 canvas.drawBitmap(bitmap, popup_position_.x(), popup_position_.y());
131 callback_.Run(main_bitmap_); 132 callback_.Run(main_bitmap_);
132 delete this; 133 delete this;
133 } 134 }
134 135
135 void DidCapturePixelsAsync(scoped_ptr<PixelsDumpRequest> dump_request, 136 void DidCapturePixelsAsync(std::unique_ptr<PixelsDumpRequest> dump_request,
136 const SkBitmap& bitmap) { 137 const SkBitmap& bitmap) {
137 SkCanvas canvas(bitmap); 138 SkCanvas canvas(bitmap);
138 DrawSelectionRect(*dump_request, &canvas); 139 DrawSelectionRect(*dump_request, &canvas);
139 if (!dump_request->callback.is_null()) 140 if (!dump_request->callback.is_null())
140 dump_request->callback.Run(bitmap); 141 dump_request->callback.Run(bitmap);
141 } 142 }
142 143
143 } // namespace 144 } // namespace
144 145
145 void DumpPixelsAsync(blink::WebView* web_view, 146 void DumpPixelsAsync(blink::WebView* web_view,
146 const LayoutTestRuntimeFlags& layout_test_runtime_flags, 147 const LayoutTestRuntimeFlags& layout_test_runtime_flags,
147 float device_scale_factor_for_test, 148 float device_scale_factor_for_test,
148 const base::Callback<void(const SkBitmap&)>& callback) { 149 const base::Callback<void(const SkBitmap&)>& callback) {
149 TRACE_EVENT0("shell", "WebTestProxyBase::CapturePixelsAsync"); 150 TRACE_EVENT0("shell", "WebTestProxyBase::CapturePixelsAsync");
150 DCHECK(!callback.is_null()); 151 DCHECK(!callback.is_null());
151 DCHECK(!layout_test_runtime_flags.dump_drag_image()); 152 DCHECK(!layout_test_runtime_flags.dump_drag_image());
152 153
153 scoped_ptr<PixelsDumpRequest> pixels_request( 154 std::unique_ptr<PixelsDumpRequest> pixels_request(
154 new PixelsDumpRequest(web_view, layout_test_runtime_flags, callback)); 155 new PixelsDumpRequest(web_view, layout_test_runtime_flags, callback));
155 156
156 if (layout_test_runtime_flags.is_printing()) { 157 if (layout_test_runtime_flags.is_printing()) {
157 base::ThreadTaskRunnerHandle::Get()->PostTask( 158 base::ThreadTaskRunnerHandle::Get()->PostTask(
158 FROM_HERE, base::Bind(&CapturePixelsForPrinting, 159 FROM_HERE, base::Bind(&CapturePixelsForPrinting,
159 base::Passed(std::move(pixels_request)))); 160 base::Passed(std::move(pixels_request))));
160 return; 161 return;
161 } 162 }
162 163
163 CaptureCallback* capture_callback = new CaptureCallback(base::Bind( 164 CaptureCallback* capture_callback = new CaptureCallback(base::Bind(
(...skipping 29 matching lines...) Expand all
193 194
194 blink::WebImage image = static_cast<blink::WebMockClipboard*>( 195 blink::WebImage image = static_cast<blink::WebMockClipboard*>(
195 blink::Platform::current()->clipboard()) 196 blink::Platform::current()->clipboard())
196 ->readRawImage(blink::WebClipboard::Buffer()); 197 ->readRawImage(blink::WebClipboard::Buffer());
197 const SkBitmap& bitmap = image.getSkBitmap(); 198 const SkBitmap& bitmap = image.getSkBitmap();
198 SkAutoLockPixels autoLock(bitmap); 199 SkAutoLockPixels autoLock(bitmap);
199 callback.Run(bitmap); 200 callback.Run(bitmap);
200 } 201 }
201 202
202 } // namespace test_runner 203 } // namespace test_runner
OLDNEW
« no previous file with comments | « components/test_runner/mock_credential_manager_client.h ('k') | components/test_runner/test_interfaces.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698