Commit c5c35e62 authored by Erik Chen's avatar Erik Chen Committed by Commit Bot

Clean up GpuBenchmarking class.

GpuBenchmarking already has as pointer to a RenderFrame. This CL updates the
helper class GpuBenchmarkingContext to use that pointer to fetch the relevant
objects. This CL is mostly a refactor with no intended behavior change. The big
difference is that it used to use a main frame RenderWidget [which may be undead
and nullptr in the future]. Now it fetches the local root render widget.

Bug: 912193
Change-Id: I6c5bde608c955dc0c8f9383ae40e5fcbc884a08a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1838477
Commit-Queue: Erik Chen <erikchen@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Auto-Submit: Erik Chen <erikchen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#703401}
parent b1b11b3b
...@@ -187,40 +187,16 @@ class CallbackAndContext : public base::RefCounted<CallbackAndContext> { ...@@ -187,40 +187,16 @@ class CallbackAndContext : public base::RefCounted<CallbackAndContext> {
DISALLOW_COPY_AND_ASSIGN(CallbackAndContext); DISALLOW_COPY_AND_ASSIGN(CallbackAndContext);
}; };
// This class is a mostly unnecessary helper class. It extracts some commonly
// used objects from RenderFrameImpl.
class GpuBenchmarkingContext { class GpuBenchmarkingContext {
public: public:
GpuBenchmarkingContext() = default; explicit GpuBenchmarkingContext(RenderFrameImpl* frame) {
web_frame_ = frame->GetWebFrame();
bool Init(bool init_compositor) {
web_frame_ = WebLocalFrame::FrameForCurrentContext();
if (!web_frame_)
return false;
web_view_ = web_frame_->View(); web_view_ = web_frame_->View();
if (!web_view_) {
web_frame_ = nullptr;
return false;
}
render_view_impl_ = RenderViewImpl::FromWebView(web_view_); render_view_impl_ = RenderViewImpl::FromWebView(web_view_);
if (!render_view_impl_) { render_widget_ = frame->GetLocalRootRenderWidget();
web_frame_ = nullptr; layer_tree_host_ = render_widget_->layer_tree_host();
web_view_ = nullptr;
return false;
}
if (!init_compositor)
return true;
layer_tree_host_ = render_view_impl_->GetWidget()->layer_tree_host();
if (!layer_tree_host_) {
web_frame_ = nullptr;
web_view_ = nullptr;
render_view_impl_ = nullptr;
return false;
}
return true;
} }
WebLocalFrame* web_frame() const { WebLocalFrame* web_frame() const {
...@@ -235,6 +211,7 @@ class GpuBenchmarkingContext { ...@@ -235,6 +211,7 @@ class GpuBenchmarkingContext {
DCHECK(render_view_impl_ != nullptr); DCHECK(render_view_impl_ != nullptr);
return render_view_impl_; return render_view_impl_;
} }
RenderWidget* render_widget() const { return render_widget_; }
cc::LayerTreeHost* layer_tree_host() const { cc::LayerTreeHost* layer_tree_host() const {
DCHECK(layer_tree_host_ != nullptr); DCHECK(layer_tree_host_ != nullptr);
return layer_tree_host_; return layer_tree_host_;
...@@ -244,6 +221,7 @@ class GpuBenchmarkingContext { ...@@ -244,6 +221,7 @@ class GpuBenchmarkingContext {
WebLocalFrame* web_frame_ = nullptr; WebLocalFrame* web_frame_ = nullptr;
WebView* web_view_ = nullptr; WebView* web_view_ = nullptr;
RenderViewImpl* render_view_impl_ = nullptr; RenderViewImpl* render_view_impl_ = nullptr;
RenderWidget* render_widget_ = nullptr;
cc::LayerTreeHost* layer_tree_host_ = nullptr; cc::LayerTreeHost* layer_tree_host_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(GpuBenchmarkingContext); DISALLOW_COPY_AND_ASSIGN(GpuBenchmarkingContext);
...@@ -287,7 +265,7 @@ bool ThrowIfPointOutOfBounds(GpuBenchmarkingContext* context, ...@@ -287,7 +265,7 @@ bool ThrowIfPointOutOfBounds(GpuBenchmarkingContext* context,
gin::Arguments* args, gin::Arguments* args,
const gfx::Point& point, const gfx::Point& point,
const std::string& message) { const std::string& message) {
gfx::Rect rect = context->render_view_impl()->GetWidget()->ViewRect(); gfx::Rect rect = context->render_widget()->ViewRect();
rect -= rect.OffsetFromOrigin(); rect -= rect.OffsetFromOrigin();
// If the bounds are not available here, as is the case with an OOPIF, // If the bounds are not available here, as is the case with an OOPIF,
...@@ -483,10 +461,9 @@ static void PrintDocument(blink::WebLocalFrame* frame, SkDocument* doc) { ...@@ -483,10 +461,9 @@ static void PrintDocument(blink::WebLocalFrame* frame, SkDocument* doc) {
static void PrintDocumentTofile(v8::Isolate* isolate, static void PrintDocumentTofile(v8::Isolate* isolate,
const std::string& filename, const std::string& filename,
sk_sp<SkDocument> (*make_doc)(SkWStream*)) { sk_sp<SkDocument> (*make_doc)(SkWStream*),
GpuBenchmarkingContext context; RenderFrameImpl* render_frame) {
if (!context.Init(true)) GpuBenchmarkingContext context(render_frame);
return;
base::FilePath path = base::FilePath::FromUTF8Unsafe(filename); base::FilePath path = base::FilePath::FromUTF8Unsafe(filename);
if (!base::PathIsWritable(path.DirName())) { if (!base::PathIsWritable(path.DirName())) {
...@@ -630,18 +607,12 @@ gin::ObjectTemplateBuilder GpuBenchmarking::GetObjectTemplateBuilder( ...@@ -630,18 +607,12 @@ gin::ObjectTemplateBuilder GpuBenchmarking::GetObjectTemplateBuilder(
} }
void GpuBenchmarking::SetNeedsDisplayOnAllLayers() { void GpuBenchmarking::SetNeedsDisplayOnAllLayers() {
GpuBenchmarkingContext context; GpuBenchmarkingContext context(render_frame_);
if (!context.Init(true))
return;
context.layer_tree_host()->SetNeedsDisplayOnAllLayers(); context.layer_tree_host()->SetNeedsDisplayOnAllLayers();
} }
void GpuBenchmarking::SetRasterizeOnlyVisibleContent() { void GpuBenchmarking::SetRasterizeOnlyVisibleContent() {
GpuBenchmarkingContext context; GpuBenchmarkingContext context(render_frame_);
if (!context.Init(true))
return;
cc::LayerTreeDebugState current = context.layer_tree_host()->GetDebugState(); cc::LayerTreeDebugState current = context.layer_tree_host()->GetDebugState();
current.rasterize_only_visible_content = true; current.rasterize_only_visible_content = true;
context.layer_tree_host()->SetDebugState(current); context.layer_tree_host()->SetDebugState(current);
...@@ -654,13 +625,14 @@ sk_sp<SkDocument> make_multipicturedocument(SkWStream* stream) { ...@@ -654,13 +625,14 @@ sk_sp<SkDocument> make_multipicturedocument(SkWStream* stream) {
} // namespace } // namespace
void GpuBenchmarking::PrintPagesToSkPictures(v8::Isolate* isolate, void GpuBenchmarking::PrintPagesToSkPictures(v8::Isolate* isolate,
const std::string& filename) { const std::string& filename) {
PrintDocumentTofile(isolate, filename, &make_multipicturedocument); PrintDocumentTofile(isolate, filename, &make_multipicturedocument,
render_frame_);
} }
void GpuBenchmarking::PrintPagesToXPS(v8::Isolate* isolate, void GpuBenchmarking::PrintPagesToXPS(v8::Isolate* isolate,
const std::string& filename) { const std::string& filename) {
#if defined(OS_WIN) && !defined(NDEBUG) #if defined(OS_WIN) && !defined(NDEBUG)
PrintDocumentTofile(isolate, filename, &MakeXPSDocument); PrintDocumentTofile(isolate, filename, &MakeXPSDocument, render_frame_);
#else #else
std::string msg("PrintPagesToXPS is unsupported."); std::string msg("PrintPagesToXPS is unsupported.");
isolate->ThrowException(v8::Exception::Error( isolate->ThrowException(v8::Exception::Error(
...@@ -672,9 +644,7 @@ void GpuBenchmarking::PrintPagesToXPS(v8::Isolate* isolate, ...@@ -672,9 +644,7 @@ void GpuBenchmarking::PrintPagesToXPS(v8::Isolate* isolate,
void GpuBenchmarking::PrintToSkPicture(v8::Isolate* isolate, void GpuBenchmarking::PrintToSkPicture(v8::Isolate* isolate,
const std::string& dirname) { const std::string& dirname) {
GpuBenchmarkingContext context; GpuBenchmarkingContext context(render_frame_);
if (!context.Init(true))
return;
const cc::Layer* root_layer = context.layer_tree_host()->root_layer(); const cc::Layer* root_layer = context.layer_tree_host()->root_layer();
if (!root_layer) if (!root_layer)
...@@ -707,11 +677,8 @@ bool GpuBenchmarking::GestureSourceTypeSupported(int gesture_source_type) { ...@@ -707,11 +677,8 @@ bool GpuBenchmarking::GestureSourceTypeSupported(int gesture_source_type) {
} }
bool GpuBenchmarking::SmoothScrollBy(gin::Arguments* args) { bool GpuBenchmarking::SmoothScrollBy(gin::Arguments* args) {
GpuBenchmarkingContext context; GpuBenchmarkingContext context(render_frame_);
if (!context.Init(true)) blink::WebRect rect = context.render_widget()->ViewRect();
return false;
blink::WebRect rect = context.render_view_impl()->GetWidget()->ViewRect();
float pixels_to_scroll = 0; float pixels_to_scroll = 0;
v8::Local<v8::Function> callback; v8::Local<v8::Function> callback;
...@@ -751,10 +718,7 @@ bool GpuBenchmarking::SmoothScrollBy(gin::Arguments* args) { ...@@ -751,10 +718,7 @@ bool GpuBenchmarking::SmoothScrollBy(gin::Arguments* args) {
} }
bool GpuBenchmarking::SmoothDrag(gin::Arguments* args) { bool GpuBenchmarking::SmoothDrag(gin::Arguments* args) {
GpuBenchmarkingContext context; GpuBenchmarkingContext context(render_frame_);
if (!context.Init(true))
return false;
float start_x; float start_x;
float start_y; float start_y;
float end_x; float end_x;
...@@ -778,11 +742,8 @@ bool GpuBenchmarking::SmoothDrag(gin::Arguments* args) { ...@@ -778,11 +742,8 @@ bool GpuBenchmarking::SmoothDrag(gin::Arguments* args) {
} }
bool GpuBenchmarking::Swipe(gin::Arguments* args) { bool GpuBenchmarking::Swipe(gin::Arguments* args) {
GpuBenchmarkingContext context; GpuBenchmarkingContext context(render_frame_);
if (!context.Init(true)) blink::WebRect rect = context.render_widget()->ViewRect();
return false;
blink::WebRect rect = context.render_view_impl()->GetWidget()->ViewRect();
std::string direction = "up"; std::string direction = "up";
float pixels_to_scroll = 0; float pixels_to_scroll = 0;
...@@ -819,12 +780,8 @@ bool GpuBenchmarking::Swipe(gin::Arguments* args) { ...@@ -819,12 +780,8 @@ bool GpuBenchmarking::Swipe(gin::Arguments* args) {
} }
bool GpuBenchmarking::ScrollBounce(gin::Arguments* args) { bool GpuBenchmarking::ScrollBounce(gin::Arguments* args) {
GpuBenchmarkingContext context; GpuBenchmarkingContext context(render_frame_);
if (!context.Init(false)) blink::WebRect content_rect = context.render_widget()->ViewRect();
return false;
blink::WebRect content_rect =
context.render_view_impl()->GetWidget()->ViewRect();
std::string direction = "down"; std::string direction = "down";
float distance_length = 0; float distance_length = 0;
...@@ -891,9 +848,7 @@ bool GpuBenchmarking::ScrollBounce(gin::Arguments* args) { ...@@ -891,9 +848,7 @@ bool GpuBenchmarking::ScrollBounce(gin::Arguments* args) {
} }
bool GpuBenchmarking::PinchBy(gin::Arguments* args) { bool GpuBenchmarking::PinchBy(gin::Arguments* args) {
GpuBenchmarkingContext context; GpuBenchmarkingContext context(render_frame_);
if (!context.Init(false))
return false;
float scale_factor; float scale_factor;
float anchor_x; float anchor_x;
...@@ -954,23 +909,17 @@ bool GpuBenchmarking::PinchBy(gin::Arguments* args) { ...@@ -954,23 +909,17 @@ bool GpuBenchmarking::PinchBy(gin::Arguments* args) {
} }
float GpuBenchmarking::PageScaleFactor() { float GpuBenchmarking::PageScaleFactor() {
GpuBenchmarkingContext context; GpuBenchmarkingContext context(render_frame_);
if (!context.Init(false))
return 0.0;
return context.web_view()->PageScaleFactor(); return context.web_view()->PageScaleFactor();
} }
void GpuBenchmarking::SetPageScaleFactor(float scale) { void GpuBenchmarking::SetPageScaleFactor(float scale) {
GpuBenchmarkingContext context; GpuBenchmarkingContext context(render_frame_);
if (!context.Init(false))
return;
context.web_view()->SetPageScaleFactor(scale); context.web_view()->SetPageScaleFactor(scale);
} }
void GpuBenchmarking::SetBrowserControlsShown(bool show) { void GpuBenchmarking::SetBrowserControlsShown(bool show) {
GpuBenchmarkingContext context; GpuBenchmarkingContext context(render_frame_);
if (!context.Init(true))
return;
context.layer_tree_host()->UpdateBrowserControlsState( context.layer_tree_host()->UpdateBrowserControlsState(
cc::BrowserControlsState::kBoth, cc::BrowserControlsState::kBoth,
show ? cc::BrowserControlsState::kShown show ? cc::BrowserControlsState::kShown
...@@ -979,49 +928,39 @@ void GpuBenchmarking::SetBrowserControlsShown(bool show) { ...@@ -979,49 +928,39 @@ void GpuBenchmarking::SetBrowserControlsShown(bool show) {
} }
float GpuBenchmarking::VisualViewportY() { float GpuBenchmarking::VisualViewportY() {
GpuBenchmarkingContext context; GpuBenchmarkingContext context(render_frame_);
if (!context.Init(false))
return 0.0;
float y = context.web_view()->VisualViewportOffset().y; float y = context.web_view()->VisualViewportOffset().y;
blink::WebRect rect(0, y, 0, 0); blink::WebRect rect(0, y, 0, 0);
context.render_view_impl()->GetWidget()->ConvertViewportToWindow(&rect); context.render_widget()->ConvertViewportToWindow(&rect);
return rect.y; return rect.y;
} }
float GpuBenchmarking::VisualViewportX() { float GpuBenchmarking::VisualViewportX() {
GpuBenchmarkingContext context; GpuBenchmarkingContext context(render_frame_);
if (!context.Init(false))
return 0.0;
float x = context.web_view()->VisualViewportOffset().x; float x = context.web_view()->VisualViewportOffset().x;
blink::WebRect rect(x, 0, 0, 0); blink::WebRect rect(x, 0, 0, 0);
context.render_view_impl()->GetWidget()->ConvertViewportToWindow(&rect); context.render_widget()->ConvertViewportToWindow(&rect);
return rect.x; return rect.x;
} }
float GpuBenchmarking::VisualViewportHeight() { float GpuBenchmarking::VisualViewportHeight() {
GpuBenchmarkingContext context; GpuBenchmarkingContext context(render_frame_);
if (!context.Init(false))
return 0.0;
float height = context.web_view()->VisualViewportSize().height; float height = context.web_view()->VisualViewportSize().height;
blink::WebRect rect(0, 0, 0, height); blink::WebRect rect(0, 0, 0, height);
context.render_view_impl()->GetWidget()->ConvertViewportToWindow(&rect); context.render_widget()->ConvertViewportToWindow(&rect);
return rect.height; return rect.height;
} }
float GpuBenchmarking::VisualViewportWidth() { float GpuBenchmarking::VisualViewportWidth() {
GpuBenchmarkingContext context; GpuBenchmarkingContext context(render_frame_);
if (!context.Init(false))
return 0.0;
float width = context.web_view()->VisualViewportSize().width; float width = context.web_view()->VisualViewportSize().width;
blink::WebRect rect(0, 0, width, 0); blink::WebRect rect(0, 0, width, 0);
context.render_view_impl()->GetWidget()->ConvertViewportToWindow(&rect); context.render_widget()->ConvertViewportToWindow(&rect);
return rect.width; return rect.width;
} }
bool GpuBenchmarking::Tap(gin::Arguments* args) { bool GpuBenchmarking::Tap(gin::Arguments* args) {
GpuBenchmarkingContext context; GpuBenchmarkingContext context(render_frame_);
if (!context.Init(false))
return false;
float position_x; float position_x;
float position_y; float position_y;
...@@ -1066,9 +1005,7 @@ bool GpuBenchmarking::Tap(gin::Arguments* args) { ...@@ -1066,9 +1005,7 @@ bool GpuBenchmarking::Tap(gin::Arguments* args) {
} }
bool GpuBenchmarking::PointerActionSequence(gin::Arguments* args) { bool GpuBenchmarking::PointerActionSequence(gin::Arguments* args) {
GpuBenchmarkingContext context; GpuBenchmarkingContext context(render_frame_);
if (!context.Init(false))
return false;
v8::Local<v8::Function> callback; v8::Local<v8::Function> callback;
...@@ -1122,9 +1059,7 @@ void GpuBenchmarking::ClearImageCache() { ...@@ -1122,9 +1059,7 @@ void GpuBenchmarking::ClearImageCache() {
} }
int GpuBenchmarking::RunMicroBenchmark(gin::Arguments* args) { int GpuBenchmarking::RunMicroBenchmark(gin::Arguments* args) {
GpuBenchmarkingContext context; GpuBenchmarkingContext context(render_frame_);
if (!context.Init(true))
return 0;
std::string name; std::string name;
v8::Local<v8::Function> callback; v8::Local<v8::Function> callback;
...@@ -1152,9 +1087,7 @@ int GpuBenchmarking::RunMicroBenchmark(gin::Arguments* args) { ...@@ -1152,9 +1087,7 @@ int GpuBenchmarking::RunMicroBenchmark(gin::Arguments* args) {
bool GpuBenchmarking::SendMessageToMicroBenchmark( bool GpuBenchmarking::SendMessageToMicroBenchmark(
int id, int id,
v8::Local<v8::Object> message) { v8::Local<v8::Object> message) {
GpuBenchmarkingContext context; GpuBenchmarkingContext context(render_frame_);
if (!context.Init(true))
return false;
v8::Local<v8::Context> v8_context = v8::Local<v8::Context> v8_context =
context.web_frame()->MainWorldScriptContext(); context.web_frame()->MainWorldScriptContext();
...@@ -1239,9 +1172,7 @@ void GpuBenchmarking::StopProfiling() { ...@@ -1239,9 +1172,7 @@ void GpuBenchmarking::StopProfiling() {
} }
void GpuBenchmarking::Freeze() { void GpuBenchmarking::Freeze() {
GpuBenchmarkingContext context; GpuBenchmarkingContext context(render_frame_);
if (!context.Init(true))
return;
// TODO(fmeawad): Instead of forcing a visibility change, only allow // TODO(fmeawad): Instead of forcing a visibility change, only allow
// freezing a page if it was already hidden. // freezing a page if it was already hidden.
context.web_view()->SetIsHidden(/*hidden=*/true, context.web_view()->SetIsHidden(/*hidden=*/true,
...@@ -1253,16 +1184,11 @@ bool GpuBenchmarking::AddSwapCompletionEventListener(gin::Arguments* args) { ...@@ -1253,16 +1184,11 @@ bool GpuBenchmarking::AddSwapCompletionEventListener(gin::Arguments* args) {
v8::Local<v8::Function> callback; v8::Local<v8::Function> callback;
if (!GetArg(args, &callback)) if (!GetArg(args, &callback))
return false; return false;
if (!render_frame_) GpuBenchmarkingContext context(render_frame_);
return false;
RenderWidget* render_widget = render_frame_->GetLocalRootRenderWidget();
GpuBenchmarkingContext context;
if (!context.Init(true))
return false;
auto callback_and_context = base::MakeRefCounted<CallbackAndContext>( auto callback_and_context = base::MakeRefCounted<CallbackAndContext>(
args->isolate(), callback, context.web_frame()->MainWorldScriptContext()); args->isolate(), callback, context.web_frame()->MainWorldScriptContext());
render_widget->NotifySwapTime(base::BindOnce( context.render_widget()->NotifySwapTime(base::BindOnce(
&OnSwapCompletedHelper, base::RetainedRef(callback_and_context))); &OnSwapCompletedHelper, base::RetainedRef(callback_and_context)));
return true; return true;
} }
......
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