electron/shell/browser/osr/osr_render_widget_host_view.cc
electron-roller[bot] c3b4cd987c
chore: bump chromium to 127.0.6521.0 (main) (#42118)
* chore: bump chromium in DEPS to 126.0.6470.0

* 5492605: Migrate TODOs referencing old crbug IDs to the new issue tracker IDs | https://chromium-review.googlesource.com/c/chromium/src/+/5492605

* 5513277: Move subresource-filter-ruleset to GCS | https://chromium-review.googlesource.com/c/chromium/src/+/5513277

* 5512656: Remove CustomizeChromeSupportsChromeRefresh2023 | https://chromium-review.googlesource.com/c/chromium/src/+/5512656

* 5516009: Accept mouse events in inactive window for Top Chrome WebUIs | https://chromium-review.googlesource.com/c/chromium/src/+/5516009

* 5376861: Change references to RWHVB in RWHIER and RenderWidgetTargeter to RWHVI. | https://chromium-review.googlesource.com/c/chromium/src/+/5376861

* 5490530: Use partition_alloc PA_BUILDFLAG(...) outside PA. #cleanup | https://chromium-review.googlesource.com/c/chromium/src/+/5490530

* 5296870: network: Allow trusted loaders to learn the sent request cookies. | https://chromium-review.googlesource.com/c/chromium/src/+/5296870

* 5453438: Delegate delegated ink trails to RWHI from RWHIER. | https://chromium-review.googlesource.com/c/chromium/src/+/5453438

* chore: update patches

* chore: bump chromium in DEPS to 126.0.6472.0

* chore: bump chromium in DEPS to 126.0.6474.0

* chore: update patches

* chore: bump chromium in DEPS to 126.0.6476.0

* chore: bump chromium in DEPS to 126.0.6478.0

* chore: bump chromium in DEPS to 126.0.6478.3

* chore: bump chromium in DEPS to 126.0.6478.8

* update patches

* only disable enterprise_cloud_content_analysis

* 5403888: [api] support v8::Data in v8::TracedReference and v8::EmbedderGraph

https://chromium-review.googlesource.com/c/v8/v8/+/5403888

* chore: bump chromium in DEPS to 127.0.6484.0

* chore: bump chromium in DEPS to 127.0.6485.0

* 5539004: Use NOTREACHED_IN_MIGRATION() in remaining chrome/ | https://chromium-review.googlesource.com/c/chromium/src/+/5539004

* src: cast to v8::Value before using v8::EmbedderGraph::V8Node | https://github.com/nodejs/node/pull/52638/files

* chore: update patches

* chore: update v8 patches

* chore: bump chromium in DEPS to 127.0.6486.0

* chore: bump chromium in DEPS to 127.0.6488.0

* chore: bump chromium in DEPS to 127.0.6490.0

* chore: bump chromium in DEPS to 127.0.6492.0

* chore: update patches

For some reason, `feat_expose_raw_response_headers_from_urlloader.patch` got messed up in an earlier commit.

* chore: update patches

printing.patch was updated due to https://chromium-review.googlesource.com/c/chromium/src/+/5535938

* 5527572: Move Connectors prefs files to components/enterprise/connectors/

https://chromium-review.googlesource.com/c/chromium/src/+/5527572

* chore: bump chromium in DEPS to 127.0.6494.0

* chore: bump chromium in DEPS to 127.0.6495.0

* chore: bump chromium in DEPS to 127.0.6496.0

* 5465511: [api] Mark v8::ObjectTemplate::SetAccessor(..) for deprecation
https://chromium-review.googlesource.com/c/v8/v8/+/5465511

* chore: revert v8 deprecation

See patch message for more details.

https://chromium-review.googlesource.com/c/v8/v8/+/5526611

* chore: update patches

* 5538771: Remove srcdoc else-if block in CalculateOrigin()
https://chromium-review.googlesource.com/c/chromium/src/+/5538771

* 5522321: [devtools] Support saving base64 encoded files via host bindings
https://chromium-review.googlesource.com/c/chromium/src/+/5522321

* 5376861: Change references to RWHVB in RWHIER and RenderWidgetTargeter to RWHVI.
https://chromium-review.googlesource.com/c/chromium/src/+/5376861

* 5530163: [media] Use VideoFrame::Plane typed enum instead of nameless enum
https://chromium-review.googlesource.com/c/chromium/src/+/5530163

* 5463431: iwa: Only create IsolatedWebAppURLLoaderFactory for subresources in IWAs
https://chromium-review.googlesource.com/c/chromium/src/+/5463431

* fixup! 5465511: [api] Mark v8::ObjectTemplate::SetAccessor(..) for deprecation https://chromium-review.googlesource.com/c/v8/v8/+/5465511

* 5512176: Remove OnEnvironmentEstimationComplete()
https://chromium-review.googlesource.com/c/chromium/src/+/5512176

* 5528282: Move Web Speech API .mojom files to //media/mojo/mojom
https://chromium-review.googlesource.com/c/chromium/src/+/5528282

* 5513740: Reland "[Extensions] Restructure extensions::ProcessMap"
https://chromium-review.googlesource.com/c/chromium/src/+/5513740

* 5483406: [PEPC] Make PEPC permission subscription take into account device status
https://chromium-review.googlesource.com/c/chromium/src/+/5483406

* 5526034: [DoH] Remove kDnsOverHttps feature flag
https://chromium-review.googlesource.com/c/chromium/src/+/5526034

The title is a bit misleading. They removed handling for the feature flag and generally intend to remove it but haven't yet.

I only changed our code to address the flag that was removed. A quick search on GitHub for `DnsOverHttpsFallback` yielded a few results, but they were all C++ chromium code or patches, 0 app code or discussion results. Since I couldn't find any evidence of this flag being used in developer applications, I've chosen to exclude this change from the breaking changes docs.

* chore: revert v8 removal

https://chromium-review.googlesource.com/c/v8/v8/+/5497515

See patch message for more details.

* chore: cherry-pick Node.js patch for V8 API removal fix

Node.js PR: https://github.com/nodejs/node/pull/52996
V8 API Removal CL: https://chromium-review.googlesource.com/c/v8/v8/+/5539888

See the patch description for more details.

* 5492183: Extensions: CodeHealth: Give enums some class
https://chromium-review.googlesource.com/c/chromium/src/+/5492183

* fixup! 5528282: Move Web Speech API .mojom files to //media/mojo/mojom https://chromium-review.googlesource.com/c/chromium/src/+/5528282

* 5514687: Reland "Add a secret handshake to the base::Feature constructor"
https://chromium-review.googlesource.com/c/chromium/src/+/5514687

* fixup! 5530163: [media] Use VideoFrame::Plane typed enum instead of nameless enum https://chromium-review.googlesource.com/c/chromium/src/+/5530163

* 5466238: PDF Viewer: add metrics to record if PDF is opened with a11y
https://chromium-review.googlesource.com/c/chromium/src/+/5466238

* 5502081: Migrate OnDisplayRemoved to OnDisplaysRemoved
https://chromium-review.googlesource.com/c/chromium/src/+/5502081

* 5539888: [api] Remove several APIs deprecated in version 12.6
https://chromium-review.googlesource.com/c/v8/v8/+/5539888

This commit essentially only removes the `only_terminate_in_safe_scope` isolate creation parameter. This undoes some work that was originally done in #35766.

* 5498236: Make browser_tests force full async initialization for OSCrypt Async
https://chromium-review.googlesource.com/c/chromium/src/+/5498236

* fixup! 5528282: Move Web Speech API .mojom files to //media/mojo/mojom https://chromium-review.googlesource.com/c/chromium/src/+/5528282

* 5545807: Migrate most remaining NOTREACHED()
https://chromium-review.googlesource.com/c/chromium/src/+/5545807

I took a systematic approach to modifying all of our uses of `NOTREACHED` that were causing errors:
* If there was a `return` or `break` (etc.) immediately after `NOTREACHED`, I removed the control flow instruction and left the `NOTREACHED` unmodified
* All other instances were migrated to `NOTREACHED_IN_MIGRATION`

We should revisit pretty much all usage of `NOTREACHED` as an upgrade follow-up item.

* fixup! 5526034: [DoH] Remove kDnsOverHttps feature flag https://chromium-review.googlesource.com/c/chromium/src/+/5526034

Turns out the feature flags were removed in the `.cc` file, but not the
`.h` feature list file. This means that the feature flags are pretty
much officially gone. (The leftover symbols in the header are likely an
oversight from what I can gather.)

We may potentially decide to put this in the breaking changes doc if we
decide this feature flag is important enough to highlight.

* chore: bump chromium in DEPS to 127.0.6498.3

* chore: bump chromium in DEPS to 127.0.6500.0

* chore: bump chromium in DEPS to 127.0.6502.0

* chore: bump chromium in DEPS to 127.0.6504.0

* chore: bump chromium in DEPS to 127.0.6505.0

* chore: bump chromium in DEPS to 127.0.6508.0

* build: use Sha256Sum in script/sysroots.json

Xref: https://chromium-review.googlesource.com/c/chromium/src/+/5506275

* chore: update chore_add_electron_deps_to_gitignores.patch

Xref: no manual changes; patch applied with fuzz 2

* chore: update feat_allow_code_cache_in_custom_schemes.patch

Xref: no manual changes; patch applied with fuzz 1

* chore: e patches all

* fixup! build: use Sha256Sum in script/sysroots.json

`sync` succeeds now

* chore: replace absl::optional with std::optional

Xref: https://chromium-review.googlesource.com/c/chromium/src/+/5253843

* chore: update CalculatePreferredSize() to new upstream semantics

Xref: https://chromium-review.googlesource.com/c/chromium/src/+/5459174
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/5541220
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/5514708
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/5504212
Xref: https://chromium-review.googlesource.com/516542

* chore: replace absl::optional with std::optional

Xref: https://chromium-review.googlesource.com/c/chromium/src/+/5296147

* chore: add kPip to enumeration as a no-op

https://chromium-review.googlesource.com/c/chromium/src/+/5546257

* [Autofill] Remove RenderFrame::ElementBoundsInWindow()

Xref: https://chromium-review.googlesource.com/c/chromium/src/+/5553982

* chore: fix feat_add_streaming-protocol_registry_to_multibuffer_data_source.patch

need new header to pick up definition of BLINK_PLATFORM_EXPORT macro

Xref: https://chromium-review.googlesource.com/c/chromium/src/+/5463143

* chore: bump chromium in DEPS to 127.0.6510.0

* chore: update patches

* chore: fix include path for native_web_keyboard_event.h

Xref: https://chromium-review.googlesource.com/c/chromium/src/+/5541976

* chore: add currently-unused should_include_device_status arg to GetPermissionStatusForCurrentDocument()

Xref: https://chromium-review.googlesource.com/c/chromium/src/+/5545382

* chore: bump chromium in DEPS to 127.0.6512.0

* chore: update mas_avoid_private_macos_api_usage.patch.patch

No manual changes; patch applied with fuzz 1

* chore: update feat_add_streaming-protocol_registry_to_multibuffer_data_source.patch

No manual changes; patch applied with fuzz 1

* chore: update webview_fullscreen.patch

No manual changes; patch applied with fuzz 1

* chore=: remove cherry-pick-22db6918bac9.patch

already present upstream

* chore: remove nonexistent patchfiles from .patches

* chore: remove cherry-pick-3e037e195e50.patch

no longer needed; merged upstream

* Update namespace for files moved to //components/input

Xref: https://chromium-review.googlesource.com/c/chromium/src/+/5563251

* Require client for InitParams to always specify an ownership mode.

Xref: https://chromium-review.googlesource.com/c/chromium/src/+/5532482

Xref: https://chromium-review.googlesource.com/c/chromium/src/+/5578714

* chore: e patches all

* fixup! Update namespace for files moved to //components/input

* chore: remove profile_keyed_service_factory, profile_selections from chromium_src

already being linked in via chrome browser for printing

* chore: bump chromium in DEPS to 127.0.6515.0

* chore: bump chromium in DEPS to 127.0.6516.0

* chore: update render_widget_host_view_base.patch

Xref: https://chromium-review.googlesource.com/c/chromium/src/+/5547803

patch applied manually due to simple upstream shear

* chore: update feat_allow_code_cache_in_custom_schemes.patch

No manual changes; patch applied with fuzz 1

* chore: e patches all

* Pull RWHIER and RWT to //content/common/input.

Xref: https://chromium-review.googlesource.com/c/chromium/src/+/5397681

* chore: bump chromium in DEPS to 127.0.6517.0

* chore: update patches

* fixup: Update namespace for files moved to //components/input

* Remove 0-arg (default) constructor for views::Widget::InitParams.

https://chromium-review.googlesource.com/c/chromium/src/+/5578714

* fixup: only disable enterprise_cloud_content_analysis

The original commit a5480accc2, was due to this CL 5527572: Move Connectors prefs files to components/enterprise/connectors/ | https://chromium-review.googlesource.com/c/chromium/src/+/5527572

* chore: bump chromium in DEPS to 127.0.6519.0

* chore: update patches

* src: do not use deprecated V8 API

https://github.com/nodejs/node/pull/53084

* src: remove dependency on wrapper-descriptor-based cpp heap

https://github.com/nodejs/node/pull/53086

* 5344413: [DevTools] Add `getHostConfig` UI binding for sending status of `base::Features` to DevTools

https://chromium-review.googlesource.com/c/chromium/src/+/5344413

* 5585788: Extensions: ManifestHandler: Separate Registry like ExtensionRegistry

https://chromium-review.googlesource.com/c/chromium/src/+/5585788

* chore: update filenames.libcxx.gni

* 5506857: Reland "Migrate clang-format to gcs first class deps"

https://chromium-review.googlesource.com/c/chromium/src/+/5506857

* fixup: 5539888: [api] Remove several APIs deprecated in version 12.6

* fixup:  5506857: Reland Migrate clang-format to gcs first class deps

* chore: bump chromium in DEPS to 127.0.6521.0

* chore: update patches

* spec: update navigator.keyboard should lock the keyboard

* Block or allow all MIDI using the existing SysEx permission

Refs https://chromium-review.googlesource.com/c/chromium/src/+/5154368
Refs https://chromium-review.googlesource.com/c/chromium/src/+/5499157

* spec: update test/parallel/test-v8-stats

* views: remove CalculatePreferredSize()

Refs https://chromium-review.googlesource.com/c/chromium/src/+/5504212

* chore: update patches after rebase

* 5560288: Re-enable ChromeOS XNNPack on Intel only

https://chromium-review.googlesource.com/c/chromium/src/+/5560288

* chore: add nan patches for v8 changes

Refs
5539888: [api] Remove several APIs deprecated in version 12.6 | https://chromium-review.googlesource.com/c/v8/v8/+/5539888
and
5539852: [heap][api] Remove deprecated v8::Isolate::IdleNotificationDeadline | https://chromium-review.googlesource.com/c/v8/v8/+/5539852

* 5573603: Modularize //chrome/browser/themes

https://chromium-review.googlesource.com/c/chromium/src/+/5573603

* 5539888: [api] Remove several APIs deprecated in version 12.6

https://chromium-review.googlesource.com/c/v8/v8/+/5539888

* chore: update patches

* test: fixup navigator.keyboard.lock on Windows

* chore: remove unneeded profile target

---------

Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com>
Co-authored-by: Keeley Hammond <khammond@slack-corp.com>
Co-authored-by: VerteDinde <vertedinde@electronjs.org>
Co-authored-by: Jeremy Rose <nornagon@nornagon.net>
Co-authored-by: clavin <clavin@electronjs.org>
Co-authored-by: Charles Kerr <charles@charleskerr.com>
Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com>
Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org>
Co-authored-by: deepak1556 <hop2deep@gmail.com>
2024-06-07 17:18:35 -04:00

1077 lines
34 KiB
C++

// Copyright (c) 2016 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "shell/browser/osr/osr_render_widget_host_view.h"
#include <algorithm>
#include <memory>
#include <optional>
#include <utility>
#include <vector>
#include "base/functional/callback_helpers.h"
#include "base/location.h"
#include "base/memory/ptr_util.h"
#include "base/memory/raw_ptr.h"
#include "base/task/single_thread_task_runner.h"
#include "base/time/time.h"
#include "components/viz/common/features.h"
#include "components/viz/common/frame_sinks/begin_frame_args.h"
#include "components/viz/common/frame_sinks/copy_output_request.h"
#include "components/viz/common/frame_sinks/delay_based_time_source.h"
#include "components/viz/common/quads/compositor_render_pass.h"
#include "content/browser/renderer_host/render_widget_host_delegate.h" // nogncheck
#include "content/browser/renderer_host/render_widget_host_owner_delegate.h" // nogncheck
#include "content/common/input/cursor_manager.h"
#include "content/common/input/synthetic_gesture.h" // nogncheck
#include "content/common/input/synthetic_gesture_target.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/context_factory.h"
#include "content/public/browser/gpu_data_manager.h"
#include "content/public/browser/render_process_host.h"
#include "gpu/command_buffer/client/gl_helper.h"
#include "media/base/video_frame.h"
#include "third_party/blink/public/common/input/web_input_event.h"
#include "third_party/skia/include/core/SkCanvas.h"
#include "ui/compositor/compositor.h"
#include "ui/compositor/layer.h"
#include "ui/compositor/layer_type.h"
#include "ui/display/screen.h"
#include "ui/events/base_event_utils.h"
#include "ui/events/event_constants.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/geometry/dip_util.h"
#include "ui/gfx/geometry/size_conversions.h"
#include "ui/gfx/image/image_skia.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/gfx/skbitmap_operations.h"
#include "ui/latency/latency_info.h"
namespace electron {
namespace {
const float kDefaultScaleFactor = 1.0;
ui::MouseEvent UiMouseEventFromWebMouseEvent(blink::WebMouseEvent event) {
ui::EventType type = ui::EventType::ET_UNKNOWN;
switch (event.GetType()) {
case blink::WebInputEvent::Type::kMouseDown:
type = ui::EventType::ET_MOUSE_PRESSED;
break;
case blink::WebInputEvent::Type::kMouseUp:
type = ui::EventType::ET_MOUSE_RELEASED;
break;
case blink::WebInputEvent::Type::kMouseMove:
type = ui::EventType::ET_MOUSE_MOVED;
break;
case blink::WebInputEvent::Type::kMouseEnter:
type = ui::EventType::ET_MOUSE_ENTERED;
break;
case blink::WebInputEvent::Type::kMouseLeave:
type = ui::EventType::ET_MOUSE_EXITED;
break;
case blink::WebInputEvent::Type::kMouseWheel:
type = ui::EventType::ET_MOUSEWHEEL;
break;
default:
type = ui::EventType::ET_UNKNOWN;
break;
}
int button_flags = 0;
switch (event.button) {
case blink::WebMouseEvent::Button::kBack:
button_flags |= ui::EF_BACK_MOUSE_BUTTON;
break;
case blink::WebMouseEvent::Button::kForward:
button_flags |= ui::EF_FORWARD_MOUSE_BUTTON;
break;
case blink::WebMouseEvent::Button::kLeft:
button_flags |= ui::EF_LEFT_MOUSE_BUTTON;
break;
case blink::WebMouseEvent::Button::kMiddle:
button_flags |= ui::EF_MIDDLE_MOUSE_BUTTON;
break;
case blink::WebMouseEvent::Button::kRight:
button_flags |= ui::EF_RIGHT_MOUSE_BUTTON;
break;
default:
button_flags = 0;
break;
}
ui::MouseEvent ui_event(type,
gfx::Point(std::floor(event.PositionInWidget().x()),
std::floor(event.PositionInWidget().y())),
gfx::Point(std::floor(event.PositionInWidget().x()),
std::floor(event.PositionInWidget().y())),
ui::EventTimeForNow(), button_flags, button_flags);
ui_event.SetClickCount(event.click_count);
return ui_event;
}
ui::MouseWheelEvent UiMouseWheelEventFromWebMouseEvent(
blink::WebMouseWheelEvent event) {
return ui::MouseWheelEvent(UiMouseEventFromWebMouseEvent(event),
std::floor(event.delta_x),
std::floor(event.delta_y));
}
} // namespace
class ElectronDelegatedFrameHostClient
: public content::DelegatedFrameHostClient {
public:
explicit ElectronDelegatedFrameHostClient(OffScreenRenderWidgetHostView* view)
: view_(view) {}
// disable copy
ElectronDelegatedFrameHostClient(const ElectronDelegatedFrameHostClient&) =
delete;
ElectronDelegatedFrameHostClient& operator=(
const ElectronDelegatedFrameHostClient&) = delete;
ui::Layer* DelegatedFrameHostGetLayer() const override {
return view_->root_layer();
}
bool DelegatedFrameHostIsVisible() const override {
return view_->IsShowing();
}
SkColor DelegatedFrameHostGetGutterColor() const override {
if (view_->render_widget_host()->delegate() &&
view_->render_widget_host()->delegate()->IsFullscreen()) {
return SK_ColorWHITE;
}
return *view_->GetBackgroundColor();
}
void OnFrameTokenChanged(uint32_t frame_token,
base::TimeTicks activation_time) override {
view_->render_widget_host()->DidProcessFrame(frame_token, activation_time);
}
float GetDeviceScaleFactor() const override {
return view_->GetDeviceScaleFactor();
}
viz::FrameEvictorClient::EvictIds CollectSurfaceIdsForEviction() override {
viz::FrameEvictorClient::EvictIds ids;
ids.embedded_ids =
view_->render_widget_host()->CollectSurfaceIdsForEviction();
return ids;
}
bool ShouldShowStaleContentOnEviction() override { return false; }
void InvalidateLocalSurfaceIdOnEviction() override {}
private:
const raw_ptr<OffScreenRenderWidgetHostView> view_;
};
OffScreenRenderWidgetHostView::OffScreenRenderWidgetHostView(
bool transparent,
bool painting,
int frame_rate,
const OnPaintCallback& callback,
content::RenderWidgetHost* host,
OffScreenRenderWidgetHostView* parent_host_view,
gfx::Size initial_size)
: content::RenderWidgetHostViewBase(host),
render_widget_host_(content::RenderWidgetHostImpl::From(host)),
parent_host_view_(parent_host_view),
transparent_(transparent),
callback_(callback),
frame_rate_(frame_rate),
size_(initial_size),
painting_(painting),
delegated_frame_host_client_{
std::make_unique<ElectronDelegatedFrameHostClient>(this)},
delegated_frame_host_{std::make_unique<content::DelegatedFrameHost>(
AllocateFrameSinkId(),
delegated_frame_host_client_.get(),
true /* should_register_frame_sink_id */)},
cursor_manager_(std::make_unique<content::CursorManager>(this)),
mouse_wheel_phase_handler_(this),
backing_(std::make_unique<SkBitmap>()) {
DCHECK(render_widget_host_);
DCHECK(!render_widget_host_->GetView());
// Initialize a screen_infos_ struct as needed, to cache the scale factor.
if (screen_infos_.screen_infos.empty()) {
UpdateScreenInfo();
}
screen_infos_.mutable_current().device_scale_factor = kDefaultScaleFactor;
delegated_frame_host_allocator_.GenerateId();
delegated_frame_host_surface_id_ =
delegated_frame_host_allocator_.GetCurrentLocalSurfaceId();
compositor_allocator_.GenerateId();
compositor_surface_id_ = compositor_allocator_.GetCurrentLocalSurfaceId();
root_layer_ = std::make_unique<ui::Layer>(ui::LAYER_SOLID_COLOR);
bool opaque = SkColorGetA(background_color_) == SK_AlphaOPAQUE;
root_layer()->SetFillsBoundsOpaquely(opaque);
root_layer()->SetColor(background_color_);
ui::ContextFactory* context_factory = content::GetContextFactory();
compositor_ = std::make_unique<ui::Compositor>(
context_factory->AllocateFrameSinkId(), context_factory,
base::SingleThreadTaskRunner::GetCurrentDefault(),
false /* enable_pixel_canvas */,
false /* use_external_begin_frame_control */);
compositor_->SetAcceleratedWidget(gfx::kNullAcceleratedWidget);
compositor_->SetDelegate(this);
compositor_->SetRootLayer(root_layer_.get());
ResizeRootLayer(false);
render_widget_host_->SetView(this);
render_widget_host_->render_frame_metadata_provider()->AddObserver(this);
if (content::GpuDataManager::GetInstance()->HardwareAccelerationEnabled()) {
video_consumer_ = std::make_unique<OffScreenVideoConsumer>(
this, base::BindRepeating(&OffScreenRenderWidgetHostView::OnPaint,
weak_ptr_factory_.GetWeakPtr()));
video_consumer_->SetActive(is_painting());
video_consumer_->SetFrameRate(this->frame_rate());
}
}
void OffScreenRenderWidgetHostView::OnLocalSurfaceIdChanged(
const cc::RenderFrameMetadata& metadata) {
if (metadata.local_surface_id) {
bool changed = delegated_frame_host_allocator_.UpdateFromChild(
*metadata.local_surface_id);
if (changed) {
ResizeRootLayer(true);
}
}
}
OffScreenRenderWidgetHostView::~OffScreenRenderWidgetHostView() {
render_widget_host_->render_frame_metadata_provider()->RemoveObserver(this);
// Marking the DelegatedFrameHost as removed from the window hierarchy is
// necessary to remove all connections to its old ui::Compositor.
if (is_showing_)
delegated_frame_host_->WasHidden(
content::DelegatedFrameHost::HiddenCause::kOther);
delegated_frame_host_->DetachFromCompositor();
compositor_.reset();
root_layer_.reset();
}
void OffScreenRenderWidgetHostView::InitAsChild(gfx::NativeView) {
DCHECK(parent_host_view_);
if (parent_host_view_->child_host_view_) {
parent_host_view_->child_host_view_->CancelWidget();
}
parent_host_view_->set_child_host_view(this);
parent_host_view_->Hide();
ResizeRootLayer(false);
SetPainting(parent_host_view_->is_painting());
}
void OffScreenRenderWidgetHostView::SetSize(const gfx::Size& size) {
size_ = size;
SynchronizeVisualProperties();
}
void OffScreenRenderWidgetHostView::SetBounds(const gfx::Rect& new_bounds) {
SetSize(new_bounds.size());
}
gfx::NativeView OffScreenRenderWidgetHostView::GetNativeView() {
return gfx::NativeView();
}
gfx::NativeViewAccessible
OffScreenRenderWidgetHostView::GetNativeViewAccessible() {
return gfx::NativeViewAccessible();
}
ui::TextInputClient* OffScreenRenderWidgetHostView::GetTextInputClient() {
return nullptr;
}
void OffScreenRenderWidgetHostView::Focus() {}
bool OffScreenRenderWidgetHostView::HasFocus() {
return false;
}
bool OffScreenRenderWidgetHostView::IsSurfaceAvailableForCopy() {
return delegated_frame_host()->CanCopyFromCompositingSurface();
}
void OffScreenRenderWidgetHostView::ShowWithVisibility(
content::PageVisibilityState /*page_visibility*/) {
if (is_showing_)
return;
is_showing_ = true;
delegated_frame_host_->AttachToCompositor(compositor_.get());
delegated_frame_host_->WasShown(GetLocalSurfaceId(),
root_layer()->bounds().size(), {});
if (render_widget_host_)
render_widget_host_->WasShown({});
}
void OffScreenRenderWidgetHostView::Hide() {
if (!is_showing_)
return;
if (render_widget_host_)
render_widget_host_->WasHidden();
// TODO(deermichel): correct or kOther?
delegated_frame_host()->WasHidden(
content::DelegatedFrameHost::HiddenCause::kOccluded);
delegated_frame_host()->DetachFromCompositor();
is_showing_ = false;
}
bool OffScreenRenderWidgetHostView::IsShowing() {
return is_showing_;
}
void OffScreenRenderWidgetHostView::EnsureSurfaceSynchronizedForWebTest() {
++latest_capture_sequence_number_;
SynchronizeVisualProperties();
}
gfx::Rect OffScreenRenderWidgetHostView::GetViewBounds() {
if (IsPopupWidget())
return popup_position_;
return gfx::Rect(size_);
}
void OffScreenRenderWidgetHostView::SetBackgroundColor(SkColor color) {
// The renderer will feed its color back to us with the first CompositorFrame.
// We short-cut here to show a sensible color before that happens.
UpdateBackgroundColorFromRenderer(color);
if (render_widget_host_ && render_widget_host_->owner_delegate()) {
render_widget_host_->owner_delegate()->SetBackgroundOpaque(
SkColorGetA(color) == SK_AlphaOPAQUE);
}
}
std::optional<SkColor> OffScreenRenderWidgetHostView::GetBackgroundColor() {
return background_color_;
}
void OffScreenRenderWidgetHostView::UpdateBackgroundColor() {}
gfx::Size OffScreenRenderWidgetHostView::GetVisibleViewportSize() {
return size_;
}
void OffScreenRenderWidgetHostView::SetInsets(const gfx::Insets& insets) {}
blink::mojom::PointerLockResult OffScreenRenderWidgetHostView::LockPointer(
bool request_unadjusted_movement) {
return blink::mojom::PointerLockResult::kUnsupportedOptions;
}
blink::mojom::PointerLockResult
OffScreenRenderWidgetHostView::ChangePointerLock(
bool request_unadjusted_movement) {
return blink::mojom::PointerLockResult::kUnsupportedOptions;
}
void OffScreenRenderWidgetHostView::UnlockPointer() {}
void OffScreenRenderWidgetHostView::TakeFallbackContentFrom(
content::RenderWidgetHostView* view) {
DCHECK(!static_cast<content::RenderWidgetHostViewBase*>(view)
->IsRenderWidgetHostViewChildFrame());
auto* view_osr = static_cast<OffScreenRenderWidgetHostView*>(view);
SetBackgroundColor(view_osr->background_color_);
if (delegated_frame_host() && view_osr->delegated_frame_host()) {
delegated_frame_host()->TakeFallbackContentFrom(
view_osr->delegated_frame_host());
}
}
void OffScreenRenderWidgetHostView::
InvalidateLocalSurfaceIdAndAllocationGroup() {
compositor_allocator_.Invalidate(/*also_invalidate_allocation_group=*/true);
}
void OffScreenRenderWidgetHostView::UpdateFrameSinkIdRegistration() {
RenderWidgetHostViewBase::UpdateFrameSinkIdRegistration();
delegated_frame_host()->SetIsFrameSinkIdOwner(is_frame_sink_id_owner());
}
void OffScreenRenderWidgetHostView::ResetFallbackToFirstNavigationSurface() {
delegated_frame_host()->ResetFallbackToFirstNavigationSurface();
}
void OffScreenRenderWidgetHostView::InitAsPopup(
content::RenderWidgetHostView* parent_host_view,
const gfx::Rect& bounds,
const gfx::Rect& anchor_rect) {
DCHECK_EQ(parent_host_view_, parent_host_view);
DCHECK_EQ(widget_type_, content::WidgetType::kPopup);
if (parent_host_view_->popup_host_view_) {
parent_host_view_->popup_host_view_->CancelWidget();
}
parent_host_view_->set_popup_host_view(this);
parent_callback_ =
base::BindRepeating(&OffScreenRenderWidgetHostView::OnPopupPaint,
parent_host_view_->weak_ptr_factory_.GetWeakPtr());
popup_position_ = bounds;
ResizeRootLayer(true);
SetPainting(parent_host_view_->is_painting());
Show();
}
void OffScreenRenderWidgetHostView::UpdateCursor(const ui::Cursor&) {}
content::CursorManager* OffScreenRenderWidgetHostView::GetCursorManager() {
return cursor_manager_.get();
}
void OffScreenRenderWidgetHostView::SetIsLoading(bool loading) {}
void OffScreenRenderWidgetHostView::TextInputStateChanged(
const ui::mojom::TextInputState& params) {}
void OffScreenRenderWidgetHostView::ImeCancelComposition() {}
void OffScreenRenderWidgetHostView::RenderProcessGone() {
Destroy();
}
void OffScreenRenderWidgetHostView::Destroy() {
if (!is_destroyed_) {
is_destroyed_ = true;
if (parent_host_view_ != nullptr) {
CancelWidget();
} else {
if (popup_host_view_)
popup_host_view_->CancelWidget();
if (child_host_view_)
child_host_view_->CancelWidget();
if (!guest_host_views_.empty()) {
// Guest RWHVs will be destroyed when the associated RWHVGuest is
// destroyed. This parent RWHV may be destroyed first, so disassociate
// the guest RWHVs here without destroying them.
for (auto* guest_host_view : guest_host_views_)
guest_host_view->parent_host_view_ = nullptr;
guest_host_views_.clear();
}
for (auto* proxy_view : proxy_views_)
proxy_view->RemoveObserver();
Hide();
}
}
delete this;
}
void OffScreenRenderWidgetHostView::UpdateTooltipUnderCursor(
const std::u16string&) {}
uint32_t OffScreenRenderWidgetHostView::GetCaptureSequenceNumber() const {
return latest_capture_sequence_number_;
}
void OffScreenRenderWidgetHostView::CopyFromSurface(
const gfx::Rect& src_rect,
const gfx::Size& output_size,
base::OnceCallback<void(const SkBitmap&)> callback) {
delegated_frame_host()->CopyFromCompositingSurface(src_rect, output_size,
std::move(callback));
}
display::ScreenInfo OffScreenRenderWidgetHostView::GetScreenInfo() const {
display::ScreenInfo screen_info;
screen_info.depth = 24;
screen_info.depth_per_component = 8;
screen_info.orientation_angle = 0;
screen_info.device_scale_factor = GetDeviceScaleFactor();
screen_info.orientation_type =
display::mojom::ScreenOrientation::kLandscapePrimary;
screen_info.rect = gfx::Rect(size_);
screen_info.available_rect = gfx::Rect(size_);
return screen_info;
}
void OffScreenRenderWidgetHostView::TransformPointToRootSurface(
gfx::PointF* point) {}
gfx::Rect OffScreenRenderWidgetHostView::GetBoundsInRootWindow() {
return gfx::Rect(size_);
}
std::optional<content::DisplayFeature>
OffScreenRenderWidgetHostView::GetDisplayFeature() {
return std::nullopt;
}
void OffScreenRenderWidgetHostView::SetDisplayFeatureForTesting(
const content::DisplayFeature* display_feature) {}
viz::SurfaceId OffScreenRenderWidgetHostView::GetCurrentSurfaceId() const {
return delegated_frame_host() ? delegated_frame_host()->GetCurrentSurfaceId()
: viz::SurfaceId();
}
std::unique_ptr<content::SyntheticGestureTarget>
OffScreenRenderWidgetHostView::CreateSyntheticGestureTarget() {
NOTIMPLEMENTED();
return nullptr;
}
void OffScreenRenderWidgetHostView::ImeCompositionRangeChanged(
const gfx::Range&,
const std::optional<std::vector<gfx::Rect>>& character_bounds,
const std::optional<std::vector<gfx::Rect>>& line_bounds) {}
gfx::Size OffScreenRenderWidgetHostView::GetCompositorViewportPixelSize() {
return gfx::ScaleToCeiledSize(GetRequestedRendererSize(),
GetDeviceScaleFactor());
}
ui::Compositor* OffScreenRenderWidgetHostView::GetCompositor() {
return compositor_.get();
}
content::RenderWidgetHostViewBase*
OffScreenRenderWidgetHostView::CreateViewForWidget(
content::RenderWidgetHost* render_widget_host,
content::RenderWidgetHost* embedder_render_widget_host,
content::WebContentsView* web_contents_view) {
if (render_widget_host->GetView()) {
return static_cast<content::RenderWidgetHostViewBase*>(
render_widget_host->GetView());
}
OffScreenRenderWidgetHostView* embedder_host_view = nullptr;
if (embedder_render_widget_host) {
embedder_host_view = static_cast<OffScreenRenderWidgetHostView*>(
embedder_render_widget_host->GetView());
}
return new OffScreenRenderWidgetHostView(
transparent_, true, embedder_host_view->frame_rate(), callback_,
render_widget_host, embedder_host_view, size());
}
const viz::FrameSinkId& OffScreenRenderWidgetHostView::GetFrameSinkId() const {
return delegated_frame_host()->frame_sink_id();
}
void OffScreenRenderWidgetHostView::DidNavigate() {
ResizeRootLayer(true);
if (delegated_frame_host_)
delegated_frame_host_->DidNavigate();
}
bool OffScreenRenderWidgetHostView::TransformPointToCoordSpaceForView(
const gfx::PointF& point,
RenderWidgetHostViewInput* target_view,
gfx::PointF* transformed_point) {
if (target_view == this) {
*transformed_point = point;
return true;
}
return false;
}
void OffScreenRenderWidgetHostView::CancelWidget() {
if (render_widget_host_)
render_widget_host_->LostCapture();
Hide();
if (parent_host_view_) {
if (parent_host_view_->popup_host_view_ == this) {
parent_host_view_->set_popup_host_view(nullptr);
} else if (parent_host_view_->child_host_view_ == this) {
parent_host_view_->set_child_host_view(nullptr);
parent_host_view_->Show();
} else {
parent_host_view_->RemoveGuestHostView(this);
}
parent_host_view_ = nullptr;
}
if (render_widget_host_ && !is_destroyed_) {
is_destroyed_ = true;
// Results in a call to Destroy().
render_widget_host_->ShutdownAndDestroyWidget(true);
}
}
void OffScreenRenderWidgetHostView::AddGuestHostView(
OffScreenRenderWidgetHostView* guest_host) {
guest_host_views_.insert(guest_host);
}
void OffScreenRenderWidgetHostView::RemoveGuestHostView(
OffScreenRenderWidgetHostView* guest_host) {
guest_host_views_.erase(guest_host);
}
void OffScreenRenderWidgetHostView::AddViewProxy(OffscreenViewProxy* proxy) {
proxy->SetObserver(this);
proxy_views_.insert(proxy);
}
void OffScreenRenderWidgetHostView::RemoveViewProxy(OffscreenViewProxy* proxy) {
proxy->RemoveObserver();
proxy_views_.erase(proxy);
}
void OffScreenRenderWidgetHostView::ProxyViewDestroyed(
OffscreenViewProxy* proxy) {
proxy_views_.erase(proxy);
Invalidate();
}
bool OffScreenRenderWidgetHostView::IsOffscreen() const {
return true;
}
std::unique_ptr<viz::HostDisplayClient>
OffScreenRenderWidgetHostView::CreateHostDisplayClient(
ui::Compositor* compositor) {
host_display_client_ = new OffScreenHostDisplayClient(
gfx::kNullAcceleratedWidget,
base::BindRepeating(&OffScreenRenderWidgetHostView::OnPaint,
weak_ptr_factory_.GetWeakPtr()));
host_display_client_->SetActive(is_painting());
return base::WrapUnique(host_display_client_.get());
}
bool OffScreenRenderWidgetHostView::InstallTransparency() {
if (transparent_) {
SetBackgroundColor(SkColor());
compositor_->SetBackgroundColor(SK_ColorTRANSPARENT);
return true;
}
return false;
}
#if BUILDFLAG(IS_MAC)
void OffScreenRenderWidgetHostView::SetActive(bool active) {}
void OffScreenRenderWidgetHostView::ShowDefinitionForSelection() {}
void OffScreenRenderWidgetHostView::SpeakSelection() {}
void OffScreenRenderWidgetHostView::SetWindowFrameInScreen(
const gfx::Rect& rect) {}
void OffScreenRenderWidgetHostView::ShowSharePicker(
const std::string& title,
const std::string& text,
const std::string& url,
const std::vector<std::string>& file_paths,
blink::mojom::ShareService::ShareCallback callback) {}
bool OffScreenRenderWidgetHostView::UpdateNSViewAndDisplay() {
return false;
}
uint64_t OffScreenRenderWidgetHostView::GetNSViewId() const {
return 0;
}
#endif
void OffScreenRenderWidgetHostView::OnPaint(const gfx::Rect& damage_rect,
const SkBitmap& bitmap) {
backing_ = std::make_unique<SkBitmap>();
backing_->allocN32Pixels(bitmap.width(), bitmap.height(), !transparent_);
bitmap.readPixels(backing_->pixmap());
if (IsPopupWidget() && parent_callback_) {
parent_callback_.Run(this->popup_position_);
} else {
CompositeFrame(damage_rect);
}
}
gfx::Size OffScreenRenderWidgetHostView::SizeInPixels() {
float sf = GetDeviceScaleFactor();
return gfx::ToFlooredSize(
gfx::ConvertSizeToPixels(GetViewBounds().size(), sf));
}
void OffScreenRenderWidgetHostView::CompositeFrame(
const gfx::Rect& damage_rect) {
HoldResize();
gfx::Size size_in_pixels = SizeInPixels();
SkBitmap frame;
// Optimize for the case when there is no popup
if (proxy_views_.empty() && !popup_host_view_) {
frame = GetBacking();
} else {
float sf = GetDeviceScaleFactor();
frame.allocN32Pixels(size_in_pixels.width(), size_in_pixels.height(),
false);
if (!GetBacking().drawsNothing()) {
SkCanvas canvas(frame);
canvas.writePixels(GetBacking(), 0, 0);
if (popup_host_view_ && !popup_host_view_->GetBacking().drawsNothing()) {
gfx::Rect rect = popup_host_view_->popup_position_;
gfx::Point origin_in_pixels =
gfx::ToFlooredPoint(gfx::ConvertPointToPixels(rect.origin(), sf));
canvas.writePixels(popup_host_view_->GetBacking(), origin_in_pixels.x(),
origin_in_pixels.y());
}
for (auto* proxy_view : proxy_views_) {
gfx::Rect rect = proxy_view->bounds();
gfx::Point origin_in_pixels =
gfx::ToFlooredPoint(gfx::ConvertPointToPixels(rect.origin(), sf));
canvas.writePixels(*proxy_view->bitmap(), origin_in_pixels.x(),
origin_in_pixels.y());
}
}
}
callback_.Run(gfx::IntersectRects(gfx::Rect(size_in_pixels), damage_rect),
frame);
ReleaseResize();
}
void OffScreenRenderWidgetHostView::OnPopupPaint(const gfx::Rect& damage_rect) {
InvalidateBounds(gfx::ToEnclosingRect(
gfx::ConvertRectToPixels(damage_rect, GetDeviceScaleFactor())));
}
void OffScreenRenderWidgetHostView::OnProxyViewPaint(
const gfx::Rect& damage_rect) {
InvalidateBounds(gfx::ToEnclosingRect(
gfx::ConvertRectToPixels(damage_rect, GetDeviceScaleFactor())));
}
void OffScreenRenderWidgetHostView::HoldResize() {
if (!hold_resize_)
hold_resize_ = true;
}
void OffScreenRenderWidgetHostView::ReleaseResize() {
if (!hold_resize_)
return;
hold_resize_ = false;
if (pending_resize_) {
pending_resize_ = false;
content::GetUIThreadTaskRunner({})->PostTask(
FROM_HERE,
base::BindOnce(
&OffScreenRenderWidgetHostView::SynchronizeVisualProperties,
weak_ptr_factory_.GetWeakPtr()));
}
}
void OffScreenRenderWidgetHostView::SynchronizeVisualProperties() {
if (hold_resize_) {
if (!pending_resize_)
pending_resize_ = true;
return;
}
ResizeRootLayer(true);
}
void OffScreenRenderWidgetHostView::SendMouseEvent(
const blink::WebMouseEvent& event) {
for (auto* proxy_view : proxy_views_) {
gfx::Rect bounds = proxy_view->bounds();
if (bounds.Contains(event.PositionInWidget().x(),
event.PositionInWidget().y())) {
blink::WebMouseEvent proxy_event(event);
proxy_event.SetPositionInWidget(
proxy_event.PositionInWidget().x() - bounds.x(),
proxy_event.PositionInWidget().y() - bounds.y());
ui::MouseEvent ui_event = UiMouseEventFromWebMouseEvent(proxy_event);
proxy_view->OnEvent(&ui_event);
return;
}
}
if (!IsPopupWidget()) {
if (popup_host_view_ &&
popup_host_view_->popup_position_.Contains(
event.PositionInWidget().x(), event.PositionInWidget().y())) {
blink::WebMouseEvent popup_event(event);
popup_event.SetPositionInWidget(
popup_event.PositionInWidget().x() -
popup_host_view_->popup_position_.x(),
popup_event.PositionInWidget().y() -
popup_host_view_->popup_position_.y());
popup_host_view_->ProcessMouseEvent(popup_event, ui::LatencyInfo());
return;
}
}
if (!render_widget_host_)
return;
render_widget_host_->ForwardMouseEvent(event);
}
void OffScreenRenderWidgetHostView::SendMouseWheelEvent(
const blink::WebMouseWheelEvent& event) {
for (auto* proxy_view : proxy_views_) {
gfx::Rect bounds = proxy_view->bounds();
if (bounds.Contains(event.PositionInWidget().x(),
event.PositionInWidget().y())) {
blink::WebMouseWheelEvent proxy_event(event);
proxy_event.SetPositionInWidget(
proxy_event.PositionInWidget().x() - bounds.x(),
proxy_event.PositionInWidget().y() - bounds.y());
ui::MouseWheelEvent ui_event =
UiMouseWheelEventFromWebMouseEvent(proxy_event);
proxy_view->OnEvent(&ui_event);
return;
}
}
blink::WebMouseWheelEvent mouse_wheel_event(event);
bool should_route_event =
render_widget_host_->delegate() &&
render_widget_host_->delegate()->GetInputEventRouter();
mouse_wheel_phase_handler_.SendWheelEndForTouchpadScrollingIfNeeded(
should_route_event);
mouse_wheel_phase_handler_.AddPhaseIfNeededAndScheduleEndEvent(
mouse_wheel_event, false);
if (!IsPopupWidget()) {
if (popup_host_view_) {
if (popup_host_view_->popup_position_.Contains(
mouse_wheel_event.PositionInWidget().x(),
mouse_wheel_event.PositionInWidget().y())) {
blink::WebMouseWheelEvent popup_mouse_wheel_event(mouse_wheel_event);
popup_mouse_wheel_event.SetPositionInWidget(
mouse_wheel_event.PositionInWidget().x() -
popup_host_view_->popup_position_.x(),
mouse_wheel_event.PositionInWidget().y() -
popup_host_view_->popup_position_.y());
popup_mouse_wheel_event.SetPositionInScreen(
popup_mouse_wheel_event.PositionInWidget().x(),
popup_mouse_wheel_event.PositionInWidget().y());
popup_host_view_->SendMouseWheelEvent(popup_mouse_wheel_event);
return;
} else {
// Scrolling outside of the popup widget so destroy it.
// Execute asynchronously to avoid deleting the widget from inside some
// other callback.
content::GetUIThreadTaskRunner({})->PostTask(
FROM_HERE,
base::BindOnce(&OffScreenRenderWidgetHostView::CancelWidget,
popup_host_view_->weak_ptr_factory_.GetWeakPtr()));
}
} else if (!guest_host_views_.empty()) {
for (auto* guest_host_view : guest_host_views_) {
if (!guest_host_view->render_widget_host_ ||
!guest_host_view->render_widget_host_->GetView()) {
continue;
}
const gfx::Rect& guest_bounds =
guest_host_view->render_widget_host_->GetView()->GetViewBounds();
if (guest_bounds.Contains(mouse_wheel_event.PositionInWidget().x(),
mouse_wheel_event.PositionInWidget().y())) {
blink::WebMouseWheelEvent guest_mouse_wheel_event(mouse_wheel_event);
guest_mouse_wheel_event.SetPositionInWidget(
mouse_wheel_event.PositionInWidget().x() - guest_bounds.x(),
mouse_wheel_event.PositionInWidget().y() - guest_bounds.y());
guest_mouse_wheel_event.SetPositionInScreen(
guest_mouse_wheel_event.PositionInWidget().x(),
guest_mouse_wheel_event.PositionInWidget().y());
guest_host_view->SendMouseWheelEvent(guest_mouse_wheel_event);
return;
}
}
}
}
if (!render_widget_host_)
return;
render_widget_host_->ForwardWheelEvent(event);
}
void OffScreenRenderWidgetHostView::SetPainting(bool painting) {
painting_ = painting;
if (popup_host_view_) {
popup_host_view_->SetPainting(painting);
}
for (auto* guest_host_view : guest_host_views_)
guest_host_view->SetPainting(painting);
if (video_consumer_) {
video_consumer_->SetActive(is_painting());
} else if (host_display_client_) {
host_display_client_->SetActive(is_painting());
}
}
void OffScreenRenderWidgetHostView::SetFrameRate(int frame_rate) {
if (parent_host_view_) {
if (parent_host_view_->frame_rate() == this->frame_rate())
return;
frame_rate_ = parent_host_view_->frame_rate();
} else {
if (frame_rate <= 0)
frame_rate = 1;
if (frame_rate > 240)
frame_rate = 240;
frame_rate_ = frame_rate;
}
SetupFrameRate(true);
if (video_consumer_) {
video_consumer_->SetFrameRate(this->frame_rate());
}
for (auto* guest_host_view : guest_host_views_)
guest_host_view->SetFrameRate(frame_rate);
}
const viz::LocalSurfaceId& OffScreenRenderWidgetHostView::GetLocalSurfaceId()
const {
return delegated_frame_host_surface_id_;
}
void OffScreenRenderWidgetHostView::SetupFrameRate(bool force) {
if (!force && frame_rate_threshold_us_ != 0)
return;
frame_rate_threshold_us_ = 1000000 / frame_rate_;
if (compositor_) {
compositor_->SetDisplayVSyncParameters(
base::TimeTicks::Now(), base::Microseconds(frame_rate_threshold_us_));
}
}
void OffScreenRenderWidgetHostView::Invalidate() {
InvalidateBounds(gfx::Rect(GetRequestedRendererSize()));
}
void OffScreenRenderWidgetHostView::InvalidateBounds(const gfx::Rect& bounds) {
CompositeFrame(bounds);
}
void OffScreenRenderWidgetHostView::ResizeRootLayer(bool force) {
SetupFrameRate(false);
display::Display display =
display::Screen::GetScreen()->GetDisplayNearestView(GetNativeView());
const float scaleFactor = display.device_scale_factor();
float sf = GetDeviceScaleFactor();
const bool sf_did_change = scaleFactor != sf;
// Initialize a screen_infos_ struct as needed, to cache the scale factor.
if (screen_infos_.screen_infos.empty()) {
UpdateScreenInfo();
}
screen_infos_.mutable_current().device_scale_factor = scaleFactor;
gfx::Size size = GetViewBounds().size();
if (!force && !sf_did_change && size == root_layer()->bounds().size())
return;
root_layer()->SetBounds(gfx::Rect(size));
const gfx::Size& size_in_pixels =
gfx::ToFlooredSize(gfx::ConvertSizeToPixels(size, sf));
if (compositor_) {
compositor_allocator_.GenerateId();
compositor_surface_id_ = compositor_allocator_.GetCurrentLocalSurfaceId();
compositor_->SetScaleAndSize(sf, size_in_pixels, compositor_surface_id_);
}
delegated_frame_host_allocator_.GenerateId();
delegated_frame_host_surface_id_ =
delegated_frame_host_allocator_.GetCurrentLocalSurfaceId();
delegated_frame_host()->EmbedSurface(
delegated_frame_host_surface_id_, size,
cc::DeadlinePolicy::UseDefaultDeadline());
// Note that |render_widget_host_| will retrieve resize parameters from the
// DelegatedFrameHost, so it must have SynchronizeVisualProperties called
// after.
if (render_widget_host_) {
render_widget_host_->SynchronizeVisualProperties();
}
}
viz::FrameSinkId OffScreenRenderWidgetHostView::AllocateFrameSinkId() {
return viz::FrameSinkId(
base::checked_cast<uint32_t>(render_widget_host_->GetProcess()->GetID()),
base::checked_cast<uint32_t>(render_widget_host_->GetRoutingID()));
}
void OffScreenRenderWidgetHostView::UpdateBackgroundColorFromRenderer(
SkColor color) {
if (color == background_color_)
return;
background_color_ = color;
bool opaque = SkColorGetA(color) == SK_AlphaOPAQUE;
root_layer()->SetFillsBoundsOpaquely(opaque);
root_layer()->SetColor(color);
}
void OffScreenRenderWidgetHostView::NotifyHostAndDelegateOnWasShown(
blink::mojom::RecordContentToVisibleTimeRequestPtr) {
NOTREACHED();
}
void OffScreenRenderWidgetHostView::
RequestSuccessfulPresentationTimeFromHostOrDelegate(
blink::mojom::RecordContentToVisibleTimeRequestPtr) {
NOTREACHED();
}
void OffScreenRenderWidgetHostView::
CancelSuccessfulPresentationTimeRequestForHostAndDelegate() {
NOTREACHED();
}
} // namespace electron