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

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

Issue 2523673004: [NOT FOR COMMIT] Fully replace SkCanvas uses.
Patch Set: Support Android build. Created 4 years 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> 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"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 void didCompositeAndReadback(const SkBitmap& bitmap) override; 58 void didCompositeAndReadback(const SkBitmap& bitmap) override;
59 59
60 private: 60 private:
61 base::Callback<void(const SkBitmap&)> callback_; 61 base::Callback<void(const SkBitmap&)> callback_;
62 SkBitmap main_bitmap_; 62 SkBitmap main_bitmap_;
63 bool wait_for_popup_; 63 bool wait_for_popup_;
64 gfx::Point popup_position_; 64 gfx::Point popup_position_;
65 }; 65 };
66 66
67 void DrawSelectionRect(const PixelsDumpRequest& dump_request, 67 void DrawSelectionRect(const PixelsDumpRequest& dump_request,
68 SkCanvas* canvas) { 68 CdlCanvas* canvas) {
69 // See if we need to draw the selection bounds rect. Selection bounds 69 // See if we need to draw the selection bounds rect. Selection bounds
70 // rect is the rect enclosing the (possibly transformed) selection. 70 // rect is the rect enclosing the (possibly transformed) selection.
71 // The rect should be drawn after everything is laid out and painted. 71 // The rect should be drawn after everything is laid out and painted.
72 if (!dump_request.layout_test_runtime_flags.dump_selection_rect()) 72 if (!dump_request.layout_test_runtime_flags.dump_selection_rect())
73 return; 73 return;
74 // If there is a selection rect - draw a red 1px border enclosing rect 74 // If there is a selection rect - draw a red 1px border enclosing rect
75 blink::WebRect wr = dump_request.web_view->mainFrame()->selectionBoundsRect(); 75 blink::WebRect wr = dump_request.web_view->mainFrame()->selectionBoundsRect();
76 if (wr.isEmpty()) 76 if (wr.isEmpty())
77 return; 77 return;
78 // Render a red rectangle bounding selection rect 78 // Render a red rectangle bounding selection rect
79 SkPaint paint; 79 CdlPaint paint;
80 paint.setColor(0xFFFF0000); // Fully opaque red 80 paint.setColor(0xFFFF0000); // Fully opaque red
81 paint.setStyle(SkPaint::kStroke_Style); 81 paint.setStyle(CdlPaint::kStroke_Style);
82 paint.setFlags(SkPaint::kAntiAlias_Flag); 82 paint.setAntiAlias(true);
83 paint.setStrokeWidth(1.0f); 83 paint.setStrokeWidth(1.0f);
84 SkIRect rect; // Bounding rect 84 SkIRect rect; // Bounding rect
85 rect.set(wr.x, wr.y, wr.x + wr.width, wr.y + wr.height); 85 rect.set(wr.x, wr.y, wr.x + wr.width, wr.y + wr.height);
86 canvas->drawIRect(rect, paint); 86 canvas->drawIRect(rect, paint);
87 } 87 }
88 88
89 void CapturePixelsForPrinting(std::unique_ptr<PixelsDumpRequest> dump_request) { 89 void CapturePixelsForPrinting(std::unique_ptr<PixelsDumpRequest> dump_request) {
90 dump_request->web_view->updateAllLifecyclePhases(); 90 dump_request->web_view->updateAllLifecyclePhases();
91 91
92 blink::WebSize page_size_in_pixels = dump_request->web_view->size(); 92 blink::WebSize page_size_in_pixels = dump_request->web_view->size();
93 blink::WebFrame* web_frame = dump_request->web_view->mainFrame(); 93 blink::WebFrame* web_frame = dump_request->web_view->mainFrame();
94 94
95 int page_count = web_frame->printBegin(page_size_in_pixels); 95 int page_count = web_frame->printBegin(page_size_in_pixels);
96 int totalHeight = page_count * (page_size_in_pixels.height + 1) - 1; 96 int totalHeight = page_count * (page_size_in_pixels.height + 1) - 1;
97 97
98 bool is_opaque = false; 98 bool is_opaque = false;
99 std::unique_ptr<SkCanvas> canvas = skia::TryCreateBitmapCanvas( 99 std::unique_ptr<CdlCanvas> canvas = skia::TryCreateBitmapCanvas(
100 page_size_in_pixels.width, totalHeight, is_opaque); 100 page_size_in_pixels.width, totalHeight, is_opaque);
101 if (!canvas) { 101 if (!canvas) {
102 LOG(ERROR) << "Failed to create canvas width=" 102 LOG(ERROR) << "Failed to create canvas width="
103 << page_size_in_pixels.width << " height=" << totalHeight; 103 << page_size_in_pixels.width << " height=" << totalHeight;
104 dump_request->callback.Run(SkBitmap()); 104 dump_request->callback.Run(SkBitmap());
105 return; 105 return;
106 } 106 }
107 web_frame->printPagesWithBoundaries(canvas.get(), page_size_in_pixels); 107 web_frame->printPagesWithBoundaries(canvas.get(), page_size_in_pixels);
108 web_frame->printEnd(); 108 web_frame->printEnd();
109 109
(...skipping 21 matching lines...) Expand all
131 return; 131 return;
132 } 132 }
133 SkCanvas canvas(main_bitmap_); 133 SkCanvas canvas(main_bitmap_);
134 canvas.drawBitmap(bitmap, popup_position_.x(), popup_position_.y()); 134 canvas.drawBitmap(bitmap, popup_position_.x(), popup_position_.y());
135 callback_.Run(main_bitmap_); 135 callback_.Run(main_bitmap_);
136 delete this; 136 delete this;
137 } 137 }
138 138
139 void DidCapturePixelsAsync(std::unique_ptr<PixelsDumpRequest> dump_request, 139 void DidCapturePixelsAsync(std::unique_ptr<PixelsDumpRequest> dump_request,
140 const SkBitmap& bitmap) { 140 const SkBitmap& bitmap) {
141 SkCanvas canvas(bitmap); 141 CdlCanvas canvas(bitmap);
142 DrawSelectionRect(*dump_request, &canvas); 142 DrawSelectionRect(*dump_request, &canvas);
143 if (!dump_request->callback.is_null()) 143 if (!dump_request->callback.is_null())
144 dump_request->callback.Run(bitmap); 144 dump_request->callback.Run(bitmap);
145 } 145 }
146 146
147 } // namespace 147 } // namespace
148 148
149 void DumpPixelsAsync(blink::WebView* web_view, 149 void DumpPixelsAsync(blink::WebView* web_view,
150 const LayoutTestRuntimeFlags& layout_test_runtime_flags, 150 const LayoutTestRuntimeFlags& layout_test_runtime_flags,
151 float device_scale_factor_for_test, 151 float device_scale_factor_for_test,
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 199
200 blink::WebImage image = static_cast<blink::WebMockClipboard*>( 200 blink::WebImage image = static_cast<blink::WebMockClipboard*>(
201 blink::Platform::current()->clipboard()) 201 blink::Platform::current()->clipboard())
202 ->readRawImage(blink::WebClipboard::Buffer()); 202 ->readRawImage(blink::WebClipboard::Buffer());
203 const SkBitmap& bitmap = image.getSkBitmap(); 203 const SkBitmap& bitmap = image.getSkBitmap();
204 SkAutoLockPixels autoLock(bitmap); 204 SkAutoLockPixels autoLock(bitmap);
205 callback.Run(bitmap); 205 callback.Run(bitmap);
206 } 206 }
207 207
208 } // namespace test_runner 208 } // namespace test_runner
OLDNEW
« no previous file with comments | « components/test_runner/mock_web_theme_engine.cc ('k') | content/browser/web_contents/aura/gesture_nav_simple.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698