Commit 75453eca authored by Mason Freed's avatar Mason Freed Committed by Commit Bot

[CI] Implement selection rects for display compositor pixel dumps

This patch implements selection rects on the renderer side for display
compositor pixel dumps (when using OOPIF).

Bug: 875963, 876064
Change-Id: Ie1bc94d94dd290fce13198c63ce3ae8f3fd4b6bd
Reviewed-on: https://chromium-review.googlesource.com/1185915Reviewed-by: default avatarChris Harrelson <chrishtr@chromium.org>
Reviewed-by: default avatarJochen Eisinger <jochen@chromium.org>
Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Reviewed-by: default avatarvmpstr <vmpstr@chromium.org>
Commit-Queue: Mason Freed <masonfreed@chromium.org>
Cr-Commit-Position: refs/heads/master@{#586291}
parent 327e1f37
......@@ -54,6 +54,19 @@ source_set("layout_test_switches") {
]
}
source_set("layout_test_utils") {
testonly = true
sources = [
"common/layout_test/layout_test_utils.cc",
"common/layout_test/layout_test_utils.h",
]
deps = [
"//cc/paint:paint",
"//skia",
"//third_party/blink/public:blink_headers",
]
}
static_library("content_shell_lib") {
testonly = true
sources = [
......@@ -238,6 +251,7 @@ static_library("content_shell_lib") {
deps = [
":content_shell_packaged_services_manifest_overlay",
":layout_test_switches",
":layout_test_utils",
":mojo_bindings",
":resources",
"//base",
......
......@@ -67,6 +67,7 @@
#include "content/shell/browser/shell_network_delegate.h"
#include "content/shell/common/layout_test/layout_test_messages.h"
#include "content/shell/common/layout_test/layout_test_switches.h"
#include "content/shell/common/layout_test/layout_test_utils.h"
#include "content/shell/common/shell_messages.h"
#include "content/shell/renderer/layout_test/blink_test_helpers.h"
#include "content/shell/test_runner/test_common.h"
......@@ -571,7 +572,6 @@ void BlinkTestController::OnInitiateCaptureDump(bool capture_navigation_history,
DCHECK(base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableDisplayCompositorPixelDump));
waiting_for_pixel_results_ = true;
auto* rwhv = main_window_->web_contents()->GetRenderWidgetHostView();
// If we're running in threaded mode, then the frames will be produced via a
// scheduler elsewhere, all we need to do is to ensure that the surface is
......@@ -584,7 +584,7 @@ void BlinkTestController::OnInitiateCaptureDump(bool capture_navigation_history,
CompositeAllFrames();
}
// Enqueue a copy output request.
// Enqueue an image copy output request.
rwhv->CopyFromSurface(
gfx::Rect(), gfx::Size(),
base::BindOnce(&BlinkTestController::OnPixelDumpCaptured,
......@@ -945,16 +945,7 @@ void BlinkTestController::OnCaptureDumpCompleted(
void BlinkTestController::OnPixelDumpCaptured(const SkBitmap& snapshot) {
DCHECK(!snapshot.drawsNothing());
// The snapshot arrives from the GPU process via shared memory. Because MSan
// can't track initializedness across processes, we must assure it that the
// pixels are in fact initialized.
MSAN_UNPOISON(snapshot.getPixels(), snapshot.computeByteSize());
base::MD5Digest digest;
base::MD5Sum(snapshot.getPixels(), snapshot.computeByteSize(), &digest);
actual_pixel_hash_ = base::MD5DigestToBase16(digest);
pixel_dump_ = snapshot;
waiting_for_pixel_results_ = false;
ReportResults();
}
......@@ -962,7 +953,6 @@ void BlinkTestController::OnPixelDumpCaptured(const SkBitmap& snapshot) {
void BlinkTestController::ReportResults() {
if (waiting_for_pixel_results_ || waiting_for_main_frame_dump_)
return;
if (main_frame_dump_->audio)
OnAudioDump(*main_frame_dump_->audio);
if (main_frame_dump_->layout)
......@@ -970,6 +960,20 @@ void BlinkTestController::ReportResults() {
// If we have local pixels, report that. Otherwise report whatever the pixel
// dump received from the renderer contains.
if (pixel_dump_) {
// See if we need to draw the selection bounds rect on top of the snapshot.
if (!main_frame_dump_->selection_rect.IsEmpty()) {
content::layout_test_utils::DrawSelectionRect(
*pixel_dump_, main_frame_dump_->selection_rect);
}
// The snapshot arrives from the GPU process via shared memory. Because MSan
// can't track initializedness across processes, we must assure it that the
// pixels are in fact initialized.
MSAN_UNPOISON(pixel_dump_->getPixels(), pixel_dump_->computeByteSize());
base::MD5Digest digest;
base::MD5Sum(pixel_dump_->getPixels(), pixel_dump_->computeByteSize(),
&digest);
actual_pixel_hash_ = base::MD5DigestToBase16(digest);
OnImageDump(actual_pixel_hash_, *pixel_dump_);
} else if (!main_frame_dump_->actual_pixel_hash.empty()) {
OnImageDump(main_frame_dump_->actual_pixel_hash, main_frame_dump_->pixels);
......
......@@ -22,7 +22,7 @@ struct ShellTestConfiguration {
// True if pixel tests are enabled.
bool enable_pixel_dumping = true;
// True if tests can open external URLs
// True if tests can open external URLs.
bool allow_external_pages;
// The expected MD5 hash of the pixel results.
......@@ -43,6 +43,9 @@ struct LayoutTestDump {
// Image dump.
skia.mojom.Bitmap? pixels;
string actual_pixel_hash;
// Selection rect dump.
gfx.mojom.Rect selection_rect;
};
interface LayoutTestControl {
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/shell/common/layout_test/layout_test_utils.h"
#include "cc/paint/skia_paint_canvas.h"
#include "third_party/blink/public/platform/web_rect.h"
namespace content {
namespace layout_test_utils {
// Utility function to draw a selection rect into a bitmap.
void DrawSelectionRect(const SkBitmap& bitmap, const blink::WebRect& wr) {
// Render a red rectangle bounding selection rect
cc::SkiaPaintCanvas canvas(bitmap);
cc::PaintFlags flags;
flags.setColor(0xFFFF0000); // Fully opaque red
flags.setStyle(cc::PaintFlags::kStroke_Style);
flags.setAntiAlias(true);
flags.setStrokeWidth(1.0f);
SkIRect rect; // Bounding rect
rect.set(wr.x, wr.y, wr.x + wr.width, wr.y + wr.height);
canvas.drawIRect(rect, flags);
}
} // namespace layout_test_utils
} // namespace content
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Helpful layout_test utility functions, built in both content_shell and
// test_runner.
#ifndef CONTENT_SHELL_COMMON_LAYOUT_TEST_LAYOUT_TEST_UTILS_H_
#define CONTENT_SHELL_COMMON_LAYOUT_TEST_LAYOUT_TEST_UTILS_H_
class SkBitmap;
namespace blink {
struct WebRect;
}
namespace content {
namespace layout_test_utils {
void DrawSelectionRect(const SkBitmap& bitmap, const blink::WebRect& wr);
} // namespace layout_test_utils
} // namespace content
#endif // CONTENT_SHELL_COMMON_LAYOUT_TEST_LAYOUT_TEST_UTILS_H_
......@@ -447,12 +447,8 @@ void BlinkTestRunner::TestFinished() {
// Now we know that we're in the main frame, we should generate dump results.
// Clean out the lifecycle if needed before capturing the layout tree
// dump and pixels from the compositor.
render_view()
->GetWebView()
->MainFrame()
->ToWebLocalFrame()
->FrameWidget()
->UpdateAllLifecyclePhases();
auto* web_frame = render_view()->GetWebView()->MainFrame()->ToWebLocalFrame();
web_frame->FrameWidget()->UpdateAllLifecyclePhases();
// Initialize a new dump results object which we will populate in the calls
// below.
......@@ -471,6 +467,13 @@ void BlinkTestRunner::TestFinished() {
// dumps.
bool browser_should_capture_pixels = CaptureLocalPixelsDump();
// Add the current selection rect to the dump result, if requested.
if (browser_should_capture_pixels &&
interfaces->TestRunner()->ShouldDumpSelectionRect()) {
dump_result_->selection_rect =
web_frame->GetSelectionBoundsRectForTesting();
}
// Request the browser to send us a callback through which we will return the
// results.
Send(new LayoutTestHostMsg_InitiateCaptureDump(
......@@ -533,6 +536,7 @@ bool BlinkTestRunner::CaptureLocalPixelsDump() {
render_view()->GetWebView()->MainFrame()->ToWebLocalFrame(),
base::BindOnce(&BlinkTestRunner::OnPixelsDumpCompleted,
base::Unretained(this)));
// If the browser should capture pixels, then we shouldn't be waiting for dump
// results.
DCHECK(!browser_should_capture_pixels || !waiting_for_layout_dump_results_);
......
......@@ -106,6 +106,7 @@ component("test_runner") {
"//content/public/renderer",
"//content/renderer:for_content_tests",
"//content/shell:layout_test_switches",
"//content/shell:layout_test_utils",
"//content/test:test_runner_support",
"//device/base/synchronization",
"//device/gamepad/public/cpp:shared_with_blink",
......
......@@ -16,6 +16,7 @@
#include "base/trace_event/trace_event.h"
#include "cc/paint/paint_flags.h"
#include "cc/paint/skia_paint_canvas.h"
#include "content/shell/common/layout_test/layout_test_utils.h"
#include "content/shell/test_runner/layout_test_runtime_flags.h"
#include "services/service_manager/public/cpp/connector.h"
// FIXME: Including platform_canvas.h here is a layering violation.
......@@ -60,17 +61,7 @@ void DrawSelectionRect(
const blink::WebRect& wr,
base::OnceCallback<void(const SkBitmap&)> original_callback,
const SkBitmap& bitmap) {
// Render a red rectangle bounding selection rect
cc::SkiaPaintCanvas canvas(bitmap);
cc::PaintFlags flags;
flags.setColor(0xFFFF0000); // Fully opaque red
flags.setStyle(cc::PaintFlags::kStroke_Style);
flags.setAntiAlias(true);
flags.setStrokeWidth(1.0f);
SkIRect rect; // Bounding rect
rect.set(wr.x, wr.y, wr.x + wr.width, wr.y + wr.height);
canvas.drawIRect(rect, flags);
content::layout_test_utils::DrawSelectionRect(bitmap, wr);
std::move(original_callback).Run(bitmap);
}
......
......@@ -1600,6 +1600,10 @@ void TestRunner::SetTestIsRunning(bool running) {
test_is_running_ = running;
}
bool TestRunner::ShouldDumpSelectionRect() const {
return layout_test_runtime_flags_.dump_selection_rect();
}
bool TestRunner::shouldDumpEditingCallbacks() const {
return layout_test_runtime_flags_.dump_editting_callbacks();
}
......
......@@ -87,6 +87,7 @@ class TestRunner : public WebTestRunner {
void GetAudioData(std::vector<unsigned char>* buffer_view) const override;
bool IsRecursiveLayoutDumpRequested() override;
std::string DumpLayout(blink::WebLocalFrame* frame) override;
bool ShouldDumpSelectionRect() const override;
// Returns true if the browser should capture the pixels instead.
bool DumpPixelsAsync(
blink::WebLocalFrame* frame,
......
......@@ -52,6 +52,10 @@ class WebTestRunner {
// (i.e. text mode if testRunner.dumpAsText() was called from javascript).
virtual std::string DumpLayout(blink::WebLocalFrame* frame) = 0;
// Returns true if the selection window should be painted onto captured
// pixels.
virtual bool ShouldDumpSelectionRect() const = 0;
// Snapshots image of |web_view| using the mode requested by the current test
// and calls |callback| with the result. Caller needs to ensure that
// |web_view| stays alive until |callback| is called.
......
......@@ -1211,13 +1211,9 @@ bool WebLocalFrameImpl::HasSelection() const {
return plugin_container->Plugin()->HasSelection();
// frame()->selection()->isNone() never returns true.
return GetFrame()
->Selection()
.ComputeVisibleSelectionInDOMTreeDeprecated()
.Start() != GetFrame()
->Selection()
.ComputeVisibleSelectionInDOMTreeDeprecated()
.End();
const auto& selection =
GetFrame()->Selection().ComputeVisibleSelectionInDOMTreeDeprecated();
return selection.Start() != selection.End();
}
WebRange WebLocalFrameImpl::SelectionRange() const {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment