2016-07-30 19:35:14 +00:00
|
|
|
// Copyright (c) 2016 GitHub, Inc.
|
2016-07-05 19:33:22 +00:00
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2016-08-03 02:01:35 +00:00
|
|
|
#include "atom/browser/osr/osr_render_widget_host_view.h"
|
2016-07-29 12:50:27 +00:00
|
|
|
|
2017-05-21 17:55:19 +00:00
|
|
|
#include <algorithm>
|
2017-06-29 23:50:55 +00:00
|
|
|
#include <memory>
|
|
|
|
#include <utility>
|
2016-07-31 10:19:56 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2016-08-03 04:46:34 +00:00
|
|
|
#include "base/callback_helpers.h"
|
|
|
|
#include "base/location.h"
|
|
|
|
#include "base/memory/ptr_util.h"
|
|
|
|
#include "base/single_thread_task_runner.h"
|
|
|
|
#include "base/time/time.h"
|
2018-05-15 01:59:22 +00:00
|
|
|
#include "components/viz/common/features.h"
|
2017-12-18 10:07:27 +00:00
|
|
|
#include "components/viz/common/frame_sinks/copy_output_request.h"
|
2017-12-04 21:34:15 +00:00
|
|
|
#include "components/viz/common/frame_sinks/delay_based_time_source.h"
|
2017-10-19 19:04:21 +00:00
|
|
|
#include "components/viz/common/gl_helper.h"
|
2017-12-18 10:09:51 +00:00
|
|
|
#include "components/viz/common/quads/render_pass.h"
|
2017-06-16 21:38:35 +00:00
|
|
|
#include "content/browser/renderer_host/compositor_resize_lock.h"
|
2016-07-05 19:33:22 +00:00
|
|
|
#include "content/browser/renderer_host/render_widget_host_delegate.h"
|
2016-08-26 22:30:02 +00:00
|
|
|
#include "content/browser/renderer_host/render_widget_host_impl.h"
|
2016-07-05 19:33:22 +00:00
|
|
|
#include "content/common/view_messages.h"
|
2016-08-03 04:46:34 +00:00
|
|
|
#include "content/public/browser/browser_thread.h"
|
2016-07-05 19:33:22 +00:00
|
|
|
#include "content/public/browser/context_factory.h"
|
2018-05-15 01:59:22 +00:00
|
|
|
#include "content/public/browser/render_process_host.h"
|
2017-04-05 08:31:22 +00:00
|
|
|
#include "media/base/video_frame.h"
|
2017-05-21 17:55:19 +00:00
|
|
|
#include "third_party/WebKit/public/platform/WebInputEvent.h"
|
2017-01-26 07:10:28 +00:00
|
|
|
#include "ui/compositor/compositor.h"
|
2016-07-05 19:33:22 +00:00
|
|
|
#include "ui/compositor/layer.h"
|
|
|
|
#include "ui/compositor/layer_type.h"
|
2017-05-21 17:55:19 +00:00
|
|
|
#include "ui/events/base_event_utils.h"
|
|
|
|
#include "ui/events/event_constants.h"
|
2016-08-03 04:46:34 +00:00
|
|
|
#include "ui/gfx/geometry/dip_util.h"
|
2016-07-05 19:33:22 +00:00
|
|
|
#include "ui/gfx/native_widget_types.h"
|
2017-03-05 15:18:57 +00:00
|
|
|
#include "ui/gfx/skbitmap_operations.h"
|
2017-06-16 21:41:39 +00:00
|
|
|
#include "ui/latency/latency_info.h"
|
2016-07-29 22:51:19 +00:00
|
|
|
|
2016-08-03 05:09:38 +00:00
|
|
|
namespace atom {
|
|
|
|
|
|
|
|
namespace {
|
2016-07-18 14:16:23 +00:00
|
|
|
|
2016-08-03 05:09:38 +00:00
|
|
|
const float kDefaultScaleFactor = 1.0;
|
2016-07-18 14:16:23 +00:00
|
|
|
const int kFrameRetryLimit = 2;
|
|
|
|
|
2017-05-21 17:55:19 +00:00
|
|
|
ui::MouseEvent UiMouseEventFromWebMouseEvent(blink::WebMouseEvent event) {
|
|
|
|
ui::EventType type = ui::EventType::ET_UNKNOWN;
|
2017-06-16 20:42:33 +00:00
|
|
|
switch (event.GetType()) {
|
|
|
|
case blink::WebInputEvent::kMouseDown:
|
2017-05-21 17:55:19 +00:00
|
|
|
type = ui::EventType::ET_MOUSE_PRESSED;
|
|
|
|
break;
|
2017-06-16 20:42:33 +00:00
|
|
|
case blink::WebInputEvent::kMouseUp:
|
2017-05-21 17:55:19 +00:00
|
|
|
type = ui::EventType::ET_MOUSE_RELEASED;
|
|
|
|
break;
|
2017-06-16 20:42:33 +00:00
|
|
|
case blink::WebInputEvent::kMouseMove:
|
2017-05-21 17:55:19 +00:00
|
|
|
type = ui::EventType::ET_MOUSE_MOVED;
|
|
|
|
break;
|
2017-06-16 20:42:33 +00:00
|
|
|
case blink::WebInputEvent::kMouseEnter:
|
2017-05-21 17:55:19 +00:00
|
|
|
type = ui::EventType::ET_MOUSE_ENTERED;
|
|
|
|
break;
|
2017-06-16 20:42:33 +00:00
|
|
|
case blink::WebInputEvent::kMouseLeave:
|
2017-05-21 17:55:19 +00:00
|
|
|
type = ui::EventType::ET_MOUSE_EXITED;
|
|
|
|
break;
|
2017-06-16 20:42:33 +00:00
|
|
|
case blink::WebInputEvent::kMouseWheel:
|
2017-05-21 17:55:19 +00:00
|
|
|
type = ui::EventType::ET_MOUSEWHEEL;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
type = ui::EventType::ET_UNKNOWN;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
int button_flags = 0;
|
|
|
|
switch (event.button) {
|
2017-06-16 20:42:33 +00:00
|
|
|
case blink::WebMouseEvent::Button::kBack:
|
2017-05-21 17:55:19 +00:00
|
|
|
button_flags |= ui::EventFlags::EF_BACK_MOUSE_BUTTON;
|
|
|
|
break;
|
2017-06-16 20:42:33 +00:00
|
|
|
case blink::WebMouseEvent::Button::kForward:
|
2017-05-21 17:55:19 +00:00
|
|
|
button_flags |= ui::EventFlags::EF_FORWARD_MOUSE_BUTTON;
|
|
|
|
break;
|
2017-06-16 20:42:33 +00:00
|
|
|
case blink::WebMouseEvent::Button::kLeft:
|
2017-05-21 17:55:19 +00:00
|
|
|
button_flags |= ui::EventFlags::EF_LEFT_MOUSE_BUTTON;
|
|
|
|
break;
|
2017-06-16 20:42:33 +00:00
|
|
|
case blink::WebMouseEvent::Button::kMiddle:
|
2017-05-21 17:55:19 +00:00
|
|
|
button_flags |= ui::EventFlags::EF_MIDDLE_MOUSE_BUTTON;
|
|
|
|
break;
|
2017-06-16 20:42:33 +00:00
|
|
|
case blink::WebMouseEvent::Button::kRight:
|
2017-05-21 17:55:19 +00:00
|
|
|
button_flags |= ui::EventFlags::EF_RIGHT_MOUSE_BUTTON;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
button_flags = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ui::MouseEvent ui_event(type,
|
2017-06-29 23:50:55 +00:00
|
|
|
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);
|
2017-06-16 20:42:33 +00:00
|
|
|
ui_event.SetClickCount(event.click_count);
|
2017-05-21 17:55:19 +00:00
|
|
|
|
|
|
|
return ui_event;
|
|
|
|
}
|
|
|
|
|
|
|
|
ui::MouseWheelEvent UiMouseWheelEventFromWebMouseEvent(
|
|
|
|
blink::WebMouseWheelEvent event) {
|
|
|
|
return ui::MouseWheelEvent(UiMouseEventFromWebMouseEvent(event),
|
2018-04-18 01:55:30 +00:00
|
|
|
std::floor(event.delta_x),
|
|
|
|
std::floor(event.delta_y));
|
2017-05-21 17:55:19 +00:00
|
|
|
}
|
|
|
|
|
2016-08-03 05:09:38 +00:00
|
|
|
} // namespace
|
2016-07-05 19:33:22 +00:00
|
|
|
|
2016-07-27 18:31:03 +00:00
|
|
|
class AtomCopyFrameGenerator {
|
2016-07-18 14:16:23 +00:00
|
|
|
public:
|
2017-04-12 14:15:58 +00:00
|
|
|
AtomCopyFrameGenerator(OffScreenRenderWidgetHostView* view,
|
|
|
|
int frame_rate_threshold_us)
|
2018-04-18 01:55:30 +00:00
|
|
|
: view_(view),
|
|
|
|
frame_duration_(
|
|
|
|
base::TimeDelta::FromMicroseconds(frame_rate_threshold_us)),
|
|
|
|
weak_ptr_factory_(this) {
|
2016-07-25 13:55:00 +00:00
|
|
|
last_time_ = base::Time::Now();
|
2016-07-18 14:16:23 +00:00
|
|
|
}
|
|
|
|
|
2017-04-12 14:15:58 +00:00
|
|
|
void GenerateCopyFrame(const gfx::Rect& damage_rect) {
|
2018-01-25 13:43:31 +00:00
|
|
|
if (!view_->render_widget_host() || !view_->IsPainting())
|
2016-07-18 14:16:23 +00:00
|
|
|
return;
|
|
|
|
|
2018-03-13 07:06:50 +00:00
|
|
|
auto request = std::make_unique<viz::CopyOutputRequest>(
|
2018-04-18 01:55:30 +00:00
|
|
|
viz::CopyOutputRequest::ResultFormat::RGBA_BITMAP,
|
|
|
|
base::BindOnce(
|
|
|
|
&AtomCopyFrameGenerator::CopyFromCompositingSurfaceHasResult,
|
|
|
|
weak_ptr_factory_.GetWeakPtr(), damage_rect));
|
2016-07-18 14:16:23 +00:00
|
|
|
|
2018-05-15 01:59:22 +00:00
|
|
|
request->set_area(gfx::Rect(view_->GetCompositorViewportPixelSize()));
|
2016-09-07 08:33:09 +00:00
|
|
|
view_->GetRootLayer()->RequestCopyOfOutput(std::move(request));
|
2016-07-18 14:16:23 +00:00
|
|
|
}
|
2017-04-12 18:54:03 +00:00
|
|
|
|
2017-04-12 14:15:58 +00:00
|
|
|
void set_frame_rate_threshold_us(int frame_rate_threshold_us) {
|
2018-04-18 01:55:30 +00:00
|
|
|
frame_duration_ =
|
|
|
|
base::TimeDelta::FromMicroseconds(frame_rate_threshold_us);
|
2017-04-12 14:15:58 +00:00
|
|
|
}
|
2016-07-18 14:16:23 +00:00
|
|
|
|
2017-04-12 18:54:03 +00:00
|
|
|
private:
|
2016-07-18 14:16:23 +00:00
|
|
|
void CopyFromCompositingSurfaceHasResult(
|
|
|
|
const gfx::Rect& damage_rect,
|
2017-12-04 21:30:54 +00:00
|
|
|
std::unique_ptr<viz::CopyOutputResult> result) {
|
2016-07-18 14:16:23 +00:00
|
|
|
if (result->IsEmpty() || result->size().IsEmpty() ||
|
|
|
|
!view_->render_widget_host()) {
|
|
|
|
OnCopyFrameCaptureFailure(damage_rect);
|
|
|
|
return;
|
|
|
|
}
|
2017-04-12 18:54:03 +00:00
|
|
|
|
2018-03-13 07:06:50 +00:00
|
|
|
DCHECK(!result->IsEmpty());
|
|
|
|
auto source = std::make_unique<SkBitmap>(result->AsSkBitmap());
|
|
|
|
DCHECK(source->readyToDraw());
|
2016-07-18 14:16:23 +00:00
|
|
|
if (source) {
|
2017-04-12 14:15:58 +00:00
|
|
|
base::AutoLock autolock(lock_);
|
|
|
|
std::shared_ptr<SkBitmap> bitmap(source.release());
|
2017-04-12 18:54:03 +00:00
|
|
|
|
2017-04-12 14:15:58 +00:00
|
|
|
base::TimeTicks now = base::TimeTicks::Now();
|
|
|
|
base::TimeDelta next_frame_in = next_frame_time_ - now;
|
|
|
|
if (next_frame_in > frame_duration_ / 4) {
|
|
|
|
next_frame_time_ += frame_duration_;
|
2018-04-18 01:55:30 +00:00
|
|
|
content::BrowserThread::PostDelayedTask(
|
|
|
|
content::BrowserThread::UI, FROM_HERE,
|
2018-04-20 10:55:05 +00:00
|
|
|
base::BindOnce(&AtomCopyFrameGenerator::OnCopyFrameCaptureSuccess,
|
|
|
|
weak_ptr_factory_.GetWeakPtr(), damage_rect, bitmap),
|
2018-04-18 01:55:30 +00:00
|
|
|
next_frame_in);
|
2017-04-12 14:15:58 +00:00
|
|
|
} else {
|
|
|
|
next_frame_time_ = now + frame_duration_;
|
|
|
|
OnCopyFrameCaptureSuccess(damage_rect, bitmap);
|
|
|
|
}
|
2017-04-12 18:54:03 +00:00
|
|
|
|
2017-04-12 14:15:58 +00:00
|
|
|
frame_retry_count_ = 0;
|
2016-07-18 14:16:23 +00:00
|
|
|
} else {
|
|
|
|
OnCopyFrameCaptureFailure(damage_rect);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-12 14:15:58 +00:00
|
|
|
void OnCopyFrameCaptureFailure(const gfx::Rect& damage_rect) {
|
2016-07-18 14:16:23 +00:00
|
|
|
const bool force_frame = (++frame_retry_count_ <= kFrameRetryLimit);
|
2017-04-12 14:15:58 +00:00
|
|
|
if (force_frame) {
|
|
|
|
// Retry with the same |damage_rect|.
|
2018-04-18 01:55:30 +00:00
|
|
|
content::BrowserThread::PostTask(
|
|
|
|
content::BrowserThread::UI, FROM_HERE,
|
2018-04-20 10:55:05 +00:00
|
|
|
base::BindOnce(&AtomCopyFrameGenerator::GenerateCopyFrame,
|
|
|
|
weak_ptr_factory_.GetWeakPtr(), damage_rect));
|
2016-07-18 14:16:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
void OnCopyFrameCaptureSuccess(const gfx::Rect& damage_rect,
|
|
|
|
const std::shared_ptr<SkBitmap>& bitmap) {
|
2017-04-12 14:15:58 +00:00
|
|
|
base::AutoLock lock(onPaintLock_);
|
|
|
|
view_->OnPaint(damage_rect, *bitmap);
|
|
|
|
}
|
2017-04-12 18:54:03 +00:00
|
|
|
|
2017-04-12 14:15:58 +00:00
|
|
|
base::Lock lock_;
|
|
|
|
base::Lock onPaintLock_;
|
2016-07-29 12:50:27 +00:00
|
|
|
OffScreenRenderWidgetHostView* view_;
|
2016-07-18 14:16:23 +00:00
|
|
|
|
2016-07-25 13:55:00 +00:00
|
|
|
base::Time last_time_;
|
|
|
|
|
2018-05-21 22:18:38 +00:00
|
|
|
int frame_retry_count_ = 0;
|
|
|
|
base::TimeTicks next_frame_time_ = base::TimeTicks::Now();
|
2017-04-12 14:15:58 +00:00
|
|
|
base::TimeDelta frame_duration_;
|
2016-07-18 14:16:23 +00:00
|
|
|
|
2016-07-27 18:31:03 +00:00
|
|
|
base::WeakPtrFactory<AtomCopyFrameGenerator> weak_ptr_factory_;
|
2016-07-18 14:16:23 +00:00
|
|
|
|
2016-07-27 18:31:03 +00:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(AtomCopyFrameGenerator);
|
2016-07-18 14:16:23 +00:00
|
|
|
};
|
|
|
|
|
2017-12-04 21:34:15 +00:00
|
|
|
class AtomBeginFrameTimer : public viz::DelayBasedTimeSourceClient {
|
2016-07-18 14:16:23 +00:00
|
|
|
public:
|
2017-04-12 14:15:58 +00:00
|
|
|
AtomBeginFrameTimer(int frame_rate_threshold_us,
|
2016-08-03 03:29:55 +00:00
|
|
|
const base::Closure& callback)
|
2016-07-18 14:16:23 +00:00
|
|
|
: callback_(callback) {
|
2017-12-04 21:34:15 +00:00
|
|
|
time_source_.reset(new viz::DelayBasedTimeSource(
|
2016-11-30 07:30:03 +00:00
|
|
|
content::BrowserThread::GetTaskRunnerForThread(
|
2018-04-18 01:55:30 +00:00
|
|
|
content::BrowserThread::UI)
|
|
|
|
.get()));
|
2017-04-12 14:15:58 +00:00
|
|
|
time_source_->SetTimebaseAndInterval(
|
2018-04-18 01:55:30 +00:00
|
|
|
base::TimeTicks(),
|
|
|
|
base::TimeDelta::FromMicroseconds(frame_rate_threshold_us));
|
2016-07-18 14:16:23 +00:00
|
|
|
time_source_->SetClient(this);
|
|
|
|
}
|
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
void SetActive(bool active) { time_source_->SetActive(active); }
|
2016-07-18 14:16:23 +00:00
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
bool IsActive() const { return time_source_->Active(); }
|
2016-07-18 14:16:23 +00:00
|
|
|
|
2017-04-12 14:15:58 +00:00
|
|
|
void SetFrameRateThresholdUs(int frame_rate_threshold_us) {
|
2016-07-18 14:16:23 +00:00
|
|
|
time_source_->SetTimebaseAndInterval(
|
|
|
|
base::TimeTicks::Now(),
|
2017-04-12 14:15:58 +00:00
|
|
|
base::TimeDelta::FromMicroseconds(frame_rate_threshold_us));
|
2016-07-18 14:16:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2018-04-18 01:55:30 +00:00
|
|
|
void OnTimerTick() override { callback_.Run(); }
|
2016-07-18 14:16:23 +00:00
|
|
|
|
|
|
|
const base::Closure callback_;
|
2017-12-04 21:34:15 +00:00
|
|
|
std::unique_ptr<viz::DelayBasedTimeSource> time_source_;
|
2016-07-18 14:16:23 +00:00
|
|
|
|
2016-07-27 18:31:03 +00:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(AtomBeginFrameTimer);
|
2016-07-18 14:16:23 +00:00
|
|
|
};
|
|
|
|
|
2016-07-29 12:50:27 +00:00
|
|
|
OffScreenRenderWidgetHostView::OffScreenRenderWidgetHostView(
|
2016-08-03 04:46:34 +00:00
|
|
|
bool transparent,
|
2018-01-25 13:46:30 +00:00
|
|
|
bool painting,
|
|
|
|
int frame_rate,
|
2016-08-04 04:03:24 +00:00
|
|
|
const OnPaintCallback& callback,
|
2016-08-03 04:46:34 +00:00
|
|
|
content::RenderWidgetHost* host,
|
2017-03-04 02:09:16 +00:00
|
|
|
OffScreenRenderWidgetHostView* parent_host_view,
|
2016-08-03 04:46:34 +00:00
|
|
|
NativeWindow* native_window)
|
|
|
|
: render_widget_host_(content::RenderWidgetHostImpl::From(host)),
|
2017-03-04 02:09:16 +00:00
|
|
|
parent_host_view_(parent_host_view),
|
2016-08-03 04:46:34 +00:00
|
|
|
native_window_(native_window),
|
2016-08-04 04:03:24 +00:00
|
|
|
transparent_(transparent),
|
|
|
|
callback_(callback),
|
2018-01-25 13:46:30 +00:00
|
|
|
frame_rate_(frame_rate),
|
2016-08-03 04:46:34 +00:00
|
|
|
scale_factor_(kDefaultScaleFactor),
|
2017-03-14 11:56:24 +00:00
|
|
|
size_(native_window->GetSize()),
|
2018-01-25 13:46:30 +00:00
|
|
|
painting_(painting),
|
2016-08-03 04:46:34 +00:00
|
|
|
is_showing_(!render_widget_host_->is_hidden()),
|
|
|
|
weak_ptr_factory_(this) {
|
2016-07-13 15:43:00 +00:00
|
|
|
DCHECK(render_widget_host_);
|
2017-05-02 01:57:40 +00:00
|
|
|
bool is_guest_view_hack = parent_host_view_ != nullptr;
|
2017-05-02 18:46:07 +00:00
|
|
|
#if !defined(OS_MACOSX)
|
2018-04-12 12:48:32 +00:00
|
|
|
delegated_frame_host_ = std::make_unique<content::DelegatedFrameHost>(
|
2018-03-17 22:26:41 +00:00
|
|
|
AllocateFrameSinkId(is_guest_view_hack), this,
|
2018-05-15 01:59:22 +00:00
|
|
|
features::IsSurfaceSynchronizationEnabled(),
|
|
|
|
base::FeatureList::IsEnabled(features::kVizDisplayCompositor),
|
|
|
|
true /* should_register_frame_sink_id */);
|
2017-01-26 07:10:28 +00:00
|
|
|
|
2016-09-07 08:33:09 +00:00
|
|
|
root_layer_.reset(new ui::Layer(ui::LAYER_SOLID_COLOR));
|
|
|
|
#endif
|
|
|
|
|
2018-03-17 22:26:41 +00:00
|
|
|
local_surface_id_ = local_surface_id_allocator_.GenerateId();
|
|
|
|
|
2018-05-15 01:59:22 +00:00
|
|
|
// Surface synchronization is not supported with OSR.
|
|
|
|
DCHECK(!features::IsSurfaceSynchronizationEnabled());
|
|
|
|
|
2016-07-27 16:02:54 +00:00
|
|
|
#if defined(OS_MACOSX)
|
2017-04-05 08:31:22 +00:00
|
|
|
CreatePlatformWidget(is_guest_view_hack);
|
2016-08-03 04:46:34 +00:00
|
|
|
#else
|
2017-04-05 08:31:22 +00:00
|
|
|
// On macOS the ui::Compositor is created/owned by the platform view.
|
|
|
|
content::ImageTransportFactory* factory =
|
|
|
|
content::ImageTransportFactory::GetInstance();
|
|
|
|
ui::ContextFactoryPrivate* context_factory_private =
|
|
|
|
factory->GetContextFactoryPrivate();
|
2016-07-18 14:16:23 +00:00
|
|
|
compositor_.reset(
|
2018-04-18 01:55:30 +00:00
|
|
|
new ui::Compositor(context_factory_private->AllocateFrameSinkId(),
|
|
|
|
content::GetContextFactory(), context_factory_private,
|
|
|
|
base::ThreadTaskRunnerHandle::Get(),
|
2018-05-15 01:59:22 +00:00
|
|
|
features::IsSurfaceSynchronizationEnabled(),
|
2018-04-18 01:55:30 +00:00
|
|
|
false /* enable_pixel_canvas */));
|
2018-01-25 13:40:37 +00:00
|
|
|
compositor_->SetAcceleratedWidget(gfx::kNullAcceleratedWidget);
|
2016-07-13 15:43:00 +00:00
|
|
|
compositor_->SetRootLayer(root_layer_.get());
|
2016-09-07 08:33:09 +00:00
|
|
|
#endif
|
2016-09-23 18:27:05 +00:00
|
|
|
GetCompositor()->SetDelegate(this);
|
2016-07-25 13:55:00 +00:00
|
|
|
|
2016-09-16 18:43:07 +00:00
|
|
|
native_window_->AddObserver(this);
|
|
|
|
|
2016-07-25 13:55:00 +00:00
|
|
|
ResizeRootLayer();
|
2017-03-04 02:09:16 +00:00
|
|
|
render_widget_host_->SetView(this);
|
|
|
|
InstallTransparency();
|
2016-07-22 11:55:58 +00:00
|
|
|
}
|
2016-07-18 14:16:23 +00:00
|
|
|
|
2016-07-29 22:51:19 +00:00
|
|
|
OffScreenRenderWidgetHostView::~OffScreenRenderWidgetHostView() {
|
2016-09-19 07:51:03 +00:00
|
|
|
if (native_window_)
|
|
|
|
native_window_->RemoveObserver(this);
|
|
|
|
|
2016-09-07 08:33:09 +00:00
|
|
|
#if defined(OS_MACOSX)
|
|
|
|
if (is_showing_)
|
|
|
|
browser_compositor_->SetRenderWidgetHostIsHidden(true);
|
|
|
|
#else
|
|
|
|
// Marking the DelegatedFrameHost as removed from the window hierarchy is
|
|
|
|
// necessary to remove all connections to its old ui::Compositor.
|
2016-07-29 22:51:19 +00:00
|
|
|
if (is_showing_)
|
|
|
|
delegated_frame_host_->WasHidden();
|
|
|
|
delegated_frame_host_->ResetCompositor();
|
2016-09-07 08:33:09 +00:00
|
|
|
#endif
|
2016-07-29 22:51:19 +00:00
|
|
|
|
2017-03-04 02:09:16 +00:00
|
|
|
if (copy_frame_generator_.get())
|
|
|
|
copy_frame_generator_.reset(NULL);
|
2017-03-05 15:18:57 +00:00
|
|
|
|
2016-08-02 10:56:03 +00:00
|
|
|
#if defined(OS_MACOSX)
|
2016-07-29 22:51:19 +00:00
|
|
|
DestroyPlatformWidget();
|
2017-03-04 02:09:16 +00:00
|
|
|
#else
|
|
|
|
delegated_frame_host_.reset(NULL);
|
|
|
|
compositor_.reset(NULL);
|
|
|
|
root_layer_.reset(NULL);
|
2016-08-02 10:56:03 +00:00
|
|
|
#endif
|
2016-07-18 14:16:23 +00:00
|
|
|
}
|
|
|
|
|
2017-04-05 08:31:22 +00:00
|
|
|
void OffScreenRenderWidgetHostView::OnWindowResize() {
|
|
|
|
// In offscreen mode call RenderWidgetHostView's SetSize explicitly
|
|
|
|
auto size = native_window_->GetSize();
|
|
|
|
SetSize(size);
|
|
|
|
}
|
|
|
|
|
|
|
|
void OffScreenRenderWidgetHostView::OnWindowClosed() {
|
|
|
|
native_window_->RemoveObserver(this);
|
|
|
|
native_window_ = nullptr;
|
|
|
|
}
|
|
|
|
|
2016-07-29 12:50:27 +00:00
|
|
|
void OffScreenRenderWidgetHostView::OnBeginFrameTimerTick() {
|
2016-07-18 14:16:23 +00:00
|
|
|
const base::TimeTicks frame_time = base::TimeTicks::Now();
|
|
|
|
const base::TimeDelta vsync_period =
|
2017-04-12 14:15:58 +00:00
|
|
|
base::TimeDelta::FromMicroseconds(frame_rate_threshold_us_);
|
2016-07-18 14:16:23 +00:00
|
|
|
SendBeginFrame(frame_time, vsync_period);
|
|
|
|
}
|
|
|
|
|
2016-08-03 04:46:34 +00:00
|
|
|
void OffScreenRenderWidgetHostView::SendBeginFrame(
|
2018-04-18 01:55:30 +00:00
|
|
|
base::TimeTicks frame_time,
|
|
|
|
base::TimeDelta vsync_period) {
|
2016-07-18 14:16:23 +00:00
|
|
|
base::TimeTicks display_time = frame_time + vsync_period;
|
|
|
|
|
|
|
|
base::TimeDelta estimated_browser_composite_time =
|
|
|
|
base::TimeDelta::FromMicroseconds(
|
|
|
|
(1.0f * base::Time::kMicrosecondsPerSecond) / (3.0f * 60));
|
|
|
|
|
|
|
|
base::TimeTicks deadline = display_time - estimated_browser_composite_time;
|
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
const viz::BeginFrameArgs& begin_frame_args = viz::BeginFrameArgs::Create(
|
|
|
|
BEGINFRAME_FROM_HERE, begin_frame_source_.source_id(),
|
|
|
|
begin_frame_number_, frame_time, deadline, vsync_period,
|
|
|
|
viz::BeginFrameArgs::NORMAL);
|
2017-04-05 08:31:22 +00:00
|
|
|
DCHECK(begin_frame_args.IsValid());
|
|
|
|
begin_frame_number_++;
|
|
|
|
|
2017-10-19 19:04:21 +00:00
|
|
|
if (renderer_compositor_frame_sink_)
|
|
|
|
renderer_compositor_frame_sink_->OnBeginFrame(begin_frame_args);
|
2016-07-18 14:16:23 +00:00
|
|
|
}
|
|
|
|
|
2016-07-29 12:50:27 +00:00
|
|
|
void OffScreenRenderWidgetHostView::InitAsChild(gfx::NativeView) {
|
2017-03-04 02:09:16 +00:00
|
|
|
DCHECK(parent_host_view_);
|
|
|
|
|
|
|
|
if (parent_host_view_->child_host_view_) {
|
|
|
|
parent_host_view_->child_host_view_->CancelWidget();
|
|
|
|
}
|
2017-03-05 15:18:57 +00:00
|
|
|
|
2017-03-04 02:09:16 +00:00
|
|
|
parent_host_view_->set_child_host_view(this);
|
|
|
|
parent_host_view_->Hide();
|
|
|
|
|
|
|
|
ResizeRootLayer();
|
|
|
|
Show();
|
2016-07-05 19:33:22 +00:00
|
|
|
}
|
|
|
|
|
2016-07-29 12:50:27 +00:00
|
|
|
void OffScreenRenderWidgetHostView::SetSize(const gfx::Size& size) {
|
2016-07-13 15:43:00 +00:00
|
|
|
size_ = size;
|
2017-03-04 02:09:16 +00:00
|
|
|
WasResized();
|
2016-07-05 19:33:22 +00:00
|
|
|
}
|
|
|
|
|
2016-07-29 12:50:27 +00:00
|
|
|
void OffScreenRenderWidgetHostView::SetBounds(const gfx::Rect& new_bounds) {
|
2017-03-04 02:09:16 +00:00
|
|
|
SetSize(new_bounds.size());
|
2016-07-05 19:33:22 +00:00
|
|
|
}
|
|
|
|
|
2016-07-29 12:50:27 +00:00
|
|
|
gfx::Vector2dF OffScreenRenderWidgetHostView::GetLastScrollOffset() const {
|
2016-07-05 19:33:22 +00:00
|
|
|
return last_scroll_offset_;
|
|
|
|
}
|
|
|
|
|
2016-07-29 12:50:27 +00:00
|
|
|
gfx::NativeView OffScreenRenderWidgetHostView::GetNativeView() const {
|
2016-07-27 16:02:54 +00:00
|
|
|
return gfx::NativeView();
|
2016-07-05 19:33:22 +00:00
|
|
|
}
|
|
|
|
|
2016-07-29 22:51:19 +00:00
|
|
|
gfx::NativeViewAccessible
|
2016-08-03 04:46:34 +00:00
|
|
|
OffScreenRenderWidgetHostView::GetNativeViewAccessible() {
|
2016-07-13 15:43:00 +00:00
|
|
|
return gfx::NativeViewAccessible();
|
2016-07-05 19:33:22 +00:00
|
|
|
}
|
|
|
|
|
2016-07-29 12:50:27 +00:00
|
|
|
ui::TextInputClient* OffScreenRenderWidgetHostView::GetTextInputClient() {
|
2016-07-05 19:33:22 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
void OffScreenRenderWidgetHostView::Focus() {}
|
2016-07-05 19:33:22 +00:00
|
|
|
|
2016-07-29 12:50:27 +00:00
|
|
|
bool OffScreenRenderWidgetHostView::HasFocus() const {
|
2016-07-31 23:01:55 +00:00
|
|
|
return false;
|
2016-07-05 19:33:22 +00:00
|
|
|
}
|
|
|
|
|
2016-07-29 12:50:27 +00:00
|
|
|
bool OffScreenRenderWidgetHostView::IsSurfaceAvailableForCopy() const {
|
2017-04-05 08:31:22 +00:00
|
|
|
return GetDelegatedFrameHost()->CanCopyFromCompositingSurface();
|
2016-07-05 19:33:22 +00:00
|
|
|
}
|
|
|
|
|
2016-07-29 12:50:27 +00:00
|
|
|
void OffScreenRenderWidgetHostView::Show() {
|
2016-07-13 15:43:00 +00:00
|
|
|
if (is_showing_)
|
|
|
|
return;
|
2016-07-05 19:33:22 +00:00
|
|
|
|
2016-07-13 15:43:00 +00:00
|
|
|
is_showing_ = true;
|
2016-09-07 08:33:09 +00:00
|
|
|
|
|
|
|
#if defined(OS_MACOSX)
|
|
|
|
browser_compositor_->SetRenderWidgetHostIsHidden(false);
|
|
|
|
#else
|
2016-07-13 15:43:00 +00:00
|
|
|
delegated_frame_host_->SetCompositor(compositor_.get());
|
2018-05-15 01:59:22 +00:00
|
|
|
delegated_frame_host_->WasShown(
|
|
|
|
GetLocalSurfaceId(), GetRootLayer()->bounds().size(), ui::LatencyInfo());
|
2016-09-07 08:33:09 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if (render_widget_host_)
|
|
|
|
render_widget_host_->WasShown(ui::LatencyInfo());
|
2016-07-05 19:33:22 +00:00
|
|
|
}
|
|
|
|
|
2016-07-29 12:50:27 +00:00
|
|
|
void OffScreenRenderWidgetHostView::Hide() {
|
2016-07-13 15:43:00 +00:00
|
|
|
if (!is_showing_)
|
|
|
|
return;
|
|
|
|
|
2016-07-18 14:16:23 +00:00
|
|
|
if (render_widget_host_)
|
|
|
|
render_widget_host_->WasHidden();
|
2016-09-07 08:33:09 +00:00
|
|
|
|
|
|
|
#if defined(OS_MACOSX)
|
|
|
|
browser_compositor_->SetRenderWidgetHostIsHidden(true);
|
|
|
|
#else
|
|
|
|
GetDelegatedFrameHost()->WasHidden();
|
|
|
|
GetDelegatedFrameHost()->ResetCompositor();
|
|
|
|
#endif
|
|
|
|
|
2016-07-13 15:43:00 +00:00
|
|
|
is_showing_ = false;
|
2016-07-05 19:33:22 +00:00
|
|
|
}
|
|
|
|
|
2016-07-29 12:50:27 +00:00
|
|
|
bool OffScreenRenderWidgetHostView::IsShowing() {
|
2016-07-13 15:43:00 +00:00
|
|
|
return is_showing_;
|
2016-07-05 19:33:22 +00:00
|
|
|
}
|
|
|
|
|
2016-07-29 12:50:27 +00:00
|
|
|
gfx::Rect OffScreenRenderWidgetHostView::GetViewBounds() const {
|
2017-03-04 02:09:16 +00:00
|
|
|
if (IsPopupWidget())
|
|
|
|
return popup_position_;
|
|
|
|
|
2016-07-05 19:33:22 +00:00
|
|
|
return gfx::Rect(size_);
|
|
|
|
}
|
|
|
|
|
2016-08-01 11:27:39 +00:00
|
|
|
void OffScreenRenderWidgetHostView::SetBackgroundColor(SkColor color) {
|
2017-07-08 19:25:15 +00:00
|
|
|
// 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);
|
2016-08-01 11:27:39 +00:00
|
|
|
|
2017-07-08 19:25:15 +00:00
|
|
|
if (render_widget_host_) {
|
|
|
|
render_widget_host_->SetBackgroundOpaque(SkColorGetA(color) ==
|
|
|
|
SK_AlphaOPAQUE);
|
|
|
|
}
|
|
|
|
}
|
2016-08-01 11:27:39 +00:00
|
|
|
|
2017-07-08 19:25:15 +00:00
|
|
|
SkColor OffScreenRenderWidgetHostView::background_color() const {
|
|
|
|
return background_color_;
|
2016-08-01 11:27:39 +00:00
|
|
|
}
|
|
|
|
|
2016-07-29 12:50:27 +00:00
|
|
|
gfx::Size OffScreenRenderWidgetHostView::GetVisibleViewportSize() const {
|
2016-07-05 19:33:22 +00:00
|
|
|
return size_;
|
|
|
|
}
|
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
void OffScreenRenderWidgetHostView::SetInsets(const gfx::Insets& insets) {}
|
2016-07-05 19:33:22 +00:00
|
|
|
|
2016-07-29 12:50:27 +00:00
|
|
|
bool OffScreenRenderWidgetHostView::LockMouse() {
|
2016-07-05 19:33:22 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
void OffScreenRenderWidgetHostView::UnlockMouse() {}
|
2016-07-05 19:33:22 +00:00
|
|
|
|
2017-07-08 19:25:15 +00:00
|
|
|
void OffScreenRenderWidgetHostView::DidCreateNewRendererCompositorFrameSink(
|
2017-12-04 21:35:12 +00:00
|
|
|
viz::mojom::CompositorFrameSinkClient* renderer_compositor_frame_sink) {
|
2017-07-08 19:25:15 +00:00
|
|
|
renderer_compositor_frame_sink_ = renderer_compositor_frame_sink;
|
|
|
|
if (GetDelegatedFrameHost()) {
|
|
|
|
GetDelegatedFrameHost()->DidCreateNewRendererCompositorFrameSink(
|
|
|
|
renderer_compositor_frame_sink_);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void OffScreenRenderWidgetHostView::SubmitCompositorFrame(
|
2017-10-19 19:04:21 +00:00
|
|
|
const viz::LocalSurfaceId& local_surface_id,
|
2018-05-15 01:59:22 +00:00
|
|
|
viz::CompositorFrame frame,
|
|
|
|
viz::mojom::HitTestRegionListPtr hit_test_region_list) {
|
2016-07-29 22:51:19 +00:00
|
|
|
TRACE_EVENT0("electron",
|
2018-04-18 01:55:30 +00:00
|
|
|
"OffScreenRenderWidgetHostView::SubmitCompositorFrame");
|
2016-07-13 15:43:00 +00:00
|
|
|
|
2016-09-06 08:24:37 +00:00
|
|
|
if (frame.metadata.root_scroll_offset != last_scroll_offset_) {
|
|
|
|
last_scroll_offset_ = frame.metadata.root_scroll_offset;
|
2016-07-13 15:43:00 +00:00
|
|
|
}
|
|
|
|
|
2017-04-05 08:31:22 +00:00
|
|
|
if (!frame.render_pass_list.empty()) {
|
2016-07-27 17:44:41 +00:00
|
|
|
if (software_output_device_) {
|
2017-03-04 02:09:16 +00:00
|
|
|
if (!begin_frame_timer_.get() || IsPopupWidget()) {
|
2017-11-02 21:50:04 +00:00
|
|
|
software_output_device_->SetActive(painting_, false);
|
2016-07-27 17:44:41 +00:00
|
|
|
}
|
2016-07-22 11:55:58 +00:00
|
|
|
|
2016-09-07 08:33:09 +00:00
|
|
|
// The compositor will draw directly to the SoftwareOutputDevice which
|
|
|
|
// then calls OnPaint.
|
2017-07-08 19:25:15 +00:00
|
|
|
// We would normally call BrowserCompositorMac::SubmitCompositorFrame on
|
2017-04-05 08:31:22 +00:00
|
|
|
// macOS, however it contains compositor resize logic that we don't want.
|
2017-07-08 19:25:15 +00:00
|
|
|
// Consequently we instead call the SubmitCompositorFrame method directly.
|
2018-05-15 01:59:22 +00:00
|
|
|
GetDelegatedFrameHost()->SubmitCompositorFrame(
|
|
|
|
local_surface_id, std::move(frame), std::move(hit_test_region_list));
|
2016-07-27 17:44:41 +00:00
|
|
|
} else {
|
|
|
|
if (!copy_frame_generator_.get()) {
|
|
|
|
copy_frame_generator_.reset(
|
2017-04-12 14:15:58 +00:00
|
|
|
new AtomCopyFrameGenerator(this, frame_rate_threshold_us_));
|
2016-07-27 17:44:41 +00:00
|
|
|
}
|
|
|
|
|
2016-09-07 08:33:09 +00:00
|
|
|
// Determine the damage rectangle for the current frame. This is the same
|
|
|
|
// calculation that SwapDelegatedFrame uses.
|
2017-12-18 10:09:51 +00:00
|
|
|
viz::RenderPass* root_pass = frame.render_pass_list.back().get();
|
2016-07-27 17:44:41 +00:00
|
|
|
gfx::Size frame_size = root_pass->output_rect.size();
|
|
|
|
gfx::Rect damage_rect =
|
|
|
|
gfx::ToEnclosingRect(gfx::RectF(root_pass->damage_rect));
|
|
|
|
damage_rect.Intersect(gfx::Rect(frame_size));
|
|
|
|
|
2017-07-08 19:25:15 +00:00
|
|
|
// We would normally call BrowserCompositorMac::SubmitCompositorFrame on
|
2017-04-05 08:31:22 +00:00
|
|
|
// macOS, however it contains compositor resize logic that we don't want.
|
2017-07-08 19:25:15 +00:00
|
|
|
// Consequently we instead call the SubmitCompositorFrame method directly.
|
2018-05-15 01:59:22 +00:00
|
|
|
GetDelegatedFrameHost()->SubmitCompositorFrame(
|
|
|
|
local_surface_id, std::move(frame), std::move(hit_test_region_list));
|
2016-07-27 17:44:41 +00:00
|
|
|
|
2016-09-07 08:33:09 +00:00
|
|
|
// Request a copy of the last compositor frame which will eventually call
|
|
|
|
// OnPaint asynchronously.
|
2017-04-12 14:15:58 +00:00
|
|
|
copy_frame_generator_->GenerateCopyFrame(damage_rect);
|
2016-07-27 17:44:41 +00:00
|
|
|
}
|
2016-07-18 14:16:23 +00:00
|
|
|
}
|
2016-07-13 15:43:00 +00:00
|
|
|
}
|
|
|
|
|
2016-07-29 12:50:27 +00:00
|
|
|
void OffScreenRenderWidgetHostView::ClearCompositorFrame() {
|
2016-09-07 08:33:09 +00:00
|
|
|
GetDelegatedFrameHost()->ClearDelegatedFrame();
|
2016-07-05 19:33:22 +00:00
|
|
|
}
|
|
|
|
|
2016-07-29 12:50:27 +00:00
|
|
|
void OffScreenRenderWidgetHostView::InitAsPopup(
|
2018-04-18 01:55:30 +00:00
|
|
|
content::RenderWidgetHostView* parent_host_view,
|
|
|
|
const gfx::Rect& pos) {
|
2017-03-04 02:09:16 +00:00
|
|
|
DCHECK_EQ(parent_host_view_, parent_host_view);
|
2017-03-05 15:18:57 +00:00
|
|
|
|
2017-03-04 02:09:16 +00:00
|
|
|
if (parent_host_view_->popup_host_view_) {
|
|
|
|
parent_host_view_->popup_host_view_->CancelWidget();
|
|
|
|
}
|
2017-03-05 15:18:57 +00:00
|
|
|
|
2017-03-04 02:09:16 +00:00
|
|
|
parent_host_view_->set_popup_host_view(this);
|
|
|
|
parent_host_view_->popup_bitmap_.reset(new SkBitmap);
|
2018-04-18 01:55:30 +00:00
|
|
|
parent_callback_ =
|
|
|
|
base::Bind(&OffScreenRenderWidgetHostView::OnPopupPaint,
|
|
|
|
parent_host_view_->weak_ptr_factory_.GetWeakPtr());
|
2017-03-05 15:18:57 +00:00
|
|
|
|
2017-03-04 02:09:16 +00:00
|
|
|
popup_position_ = pos;
|
2017-03-05 15:18:57 +00:00
|
|
|
|
2017-03-04 02:09:16 +00:00
|
|
|
ResizeRootLayer();
|
|
|
|
Show();
|
2016-07-05 19:33:22 +00:00
|
|
|
}
|
|
|
|
|
2016-07-29 22:51:19 +00:00
|
|
|
void OffScreenRenderWidgetHostView::InitAsFullscreen(
|
2018-04-18 01:55:30 +00:00
|
|
|
content::RenderWidgetHostView*) {}
|
2016-07-05 19:33:22 +00:00
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
void OffScreenRenderWidgetHostView::UpdateCursor(const content::WebCursor&) {}
|
2016-07-05 19:33:22 +00:00
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
void OffScreenRenderWidgetHostView::SetIsLoading(bool loading) {}
|
2016-07-05 19:33:22 +00:00
|
|
|
|
2016-07-29 12:50:27 +00:00
|
|
|
void OffScreenRenderWidgetHostView::TextInputStateChanged(
|
2018-04-18 01:55:30 +00:00
|
|
|
const content::TextInputState& params) {}
|
2016-07-05 19:33:22 +00:00
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
void OffScreenRenderWidgetHostView::ImeCancelComposition() {}
|
2016-07-05 19:33:22 +00:00
|
|
|
|
2016-07-31 10:19:56 +00:00
|
|
|
void OffScreenRenderWidgetHostView::RenderProcessGone(base::TerminationStatus,
|
2018-04-18 01:55:30 +00:00
|
|
|
int) {
|
2016-07-05 19:33:22 +00:00
|
|
|
Destroy();
|
|
|
|
}
|
|
|
|
|
2016-07-29 12:50:27 +00:00
|
|
|
void OffScreenRenderWidgetHostView::Destroy() {
|
2017-03-04 02:09:16 +00:00
|
|
|
if (!is_destroyed_) {
|
|
|
|
is_destroyed_ = true;
|
|
|
|
|
|
|
|
if (parent_host_view_ != NULL) {
|
|
|
|
CancelWidget();
|
|
|
|
} else {
|
|
|
|
if (popup_host_view_)
|
|
|
|
popup_host_view_->CancelWidget();
|
|
|
|
popup_bitmap_.reset();
|
|
|
|
if (child_host_view_)
|
|
|
|
child_host_view_->CancelWidget();
|
2017-07-08 19:25:15 +00:00
|
|
|
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.
|
2018-05-04 06:45:12 +00:00
|
|
|
for (auto* guest_host_view : guest_host_views_)
|
2017-07-08 19:25:15 +00:00
|
|
|
guest_host_view->parent_host_view_ = nullptr;
|
|
|
|
guest_host_views_.clear();
|
|
|
|
}
|
2018-05-04 06:45:12 +00:00
|
|
|
for (auto* proxy_view : proxy_views_)
|
2017-05-21 17:55:19 +00:00
|
|
|
proxy_view->RemoveObserver();
|
2017-03-04 02:09:16 +00:00
|
|
|
Hide();
|
|
|
|
}
|
|
|
|
}
|
2017-03-05 15:18:57 +00:00
|
|
|
|
2016-07-30 19:25:49 +00:00
|
|
|
delete this;
|
2016-07-05 19:33:22 +00:00
|
|
|
}
|
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
void OffScreenRenderWidgetHostView::SetTooltipText(const base::string16&) {}
|
2016-07-05 19:33:22 +00:00
|
|
|
|
2016-07-29 12:50:27 +00:00
|
|
|
void OffScreenRenderWidgetHostView::SelectionBoundsChanged(
|
2018-04-18 01:55:30 +00:00
|
|
|
const ViewHostMsg_SelectionBounds_Params&) {}
|
2016-07-05 19:33:22 +00:00
|
|
|
|
2017-04-05 08:31:22 +00:00
|
|
|
void OffScreenRenderWidgetHostView::CopyFromSurface(
|
2018-05-15 01:59:22 +00:00
|
|
|
const gfx::Rect& src_rect,
|
|
|
|
const gfx::Size& output_size,
|
|
|
|
base::OnceCallback<void(const SkBitmap&)> callback) {
|
|
|
|
GetDelegatedFrameHost()->CopyFromCompositingSurface(src_rect, output_size,
|
|
|
|
std::move(callback));
|
2016-07-05 19:33:22 +00:00
|
|
|
}
|
|
|
|
|
2018-05-15 01:59:22 +00:00
|
|
|
void OffScreenRenderWidgetHostView::GetScreenInfo(
|
|
|
|
content::ScreenInfo* screen_info) const {
|
|
|
|
screen_info->depth = 24;
|
|
|
|
screen_info->depth_per_component = 8;
|
|
|
|
screen_info->orientation_angle = 0;
|
|
|
|
screen_info->device_scale_factor = 1.0;
|
|
|
|
screen_info->orientation_type =
|
|
|
|
content::SCREEN_ORIENTATION_VALUES_LANDSCAPE_PRIMARY;
|
|
|
|
screen_info->rect = gfx::Rect(size_);
|
|
|
|
screen_info->available_rect = gfx::Rect(size_);
|
2016-07-05 19:33:22 +00:00
|
|
|
}
|
|
|
|
|
2017-03-04 02:09:16 +00:00
|
|
|
void OffScreenRenderWidgetHostView::InitAsGuest(
|
2017-03-05 15:18:57 +00:00
|
|
|
content::RenderWidgetHostView* parent_host_view,
|
|
|
|
content::RenderWidgetHostViewGuest* guest_view) {
|
2017-03-04 02:09:16 +00:00
|
|
|
parent_host_view_->AddGuestHostView(this);
|
|
|
|
parent_host_view_->RegisterGuestViewFrameSwappedCallback(guest_view);
|
|
|
|
}
|
|
|
|
|
2018-05-15 01:59:22 +00:00
|
|
|
gfx::Vector2d OffScreenRenderWidgetHostView::GetOffsetFromRootSurface() {
|
|
|
|
return gfx::Vector2d();
|
2016-07-05 19:33:22 +00:00
|
|
|
}
|
|
|
|
|
2016-07-29 12:50:27 +00:00
|
|
|
gfx::Rect OffScreenRenderWidgetHostView::GetBoundsInRootWindow() {
|
2016-07-05 19:33:22 +00:00
|
|
|
return gfx::Rect(size_);
|
|
|
|
}
|
|
|
|
|
2018-05-15 01:59:22 +00:00
|
|
|
content::RenderWidgetHostImpl*
|
|
|
|
OffScreenRenderWidgetHostView::GetRenderWidgetHostImpl() const {
|
|
|
|
return render_widget_host_;
|
|
|
|
}
|
|
|
|
|
|
|
|
viz::SurfaceId OffScreenRenderWidgetHostView::GetCurrentSurfaceId() const {
|
|
|
|
return GetDelegatedFrameHost()
|
|
|
|
? GetDelegatedFrameHost()->GetCurrentSurfaceId()
|
|
|
|
: viz::SurfaceId();
|
|
|
|
}
|
|
|
|
|
2016-07-29 12:50:27 +00:00
|
|
|
void OffScreenRenderWidgetHostView::ImeCompositionRangeChanged(
|
2018-04-18 01:55:30 +00:00
|
|
|
const gfx::Range&,
|
|
|
|
const std::vector<gfx::Rect>&) {}
|
2016-07-05 19:33:22 +00:00
|
|
|
|
2018-05-15 01:59:22 +00:00
|
|
|
gfx::Size OffScreenRenderWidgetHostView::GetCompositorViewportPixelSize()
|
|
|
|
const {
|
2018-03-17 22:26:41 +00:00
|
|
|
return gfx::ScaleToCeiledSize(GetRequestedRendererSize(), scale_factor_);
|
2016-07-13 15:43:00 +00:00
|
|
|
}
|
|
|
|
|
2016-07-29 12:50:27 +00:00
|
|
|
gfx::Size OffScreenRenderWidgetHostView::GetRequestedRendererSize() const {
|
2017-03-04 02:09:16 +00:00
|
|
|
return GetDelegatedFrameHost()->GetRequestedRendererSize();
|
2016-07-13 15:43:00 +00:00
|
|
|
}
|
|
|
|
|
2017-03-14 11:56:24 +00:00
|
|
|
content::RenderWidgetHostViewBase*
|
2018-04-18 01:55:30 +00:00
|
|
|
OffScreenRenderWidgetHostView::CreateViewForWidget(
|
2017-03-14 11:56:24 +00:00
|
|
|
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(
|
2018-04-18 01:55:30 +00:00
|
|
|
transparent_, true, embedder_host_view->GetFrameRate(), callback_,
|
|
|
|
render_widget_host, embedder_host_view, native_window_);
|
2017-03-14 11:56:24 +00:00
|
|
|
}
|
|
|
|
|
2016-11-30 07:30:03 +00:00
|
|
|
#if !defined(OS_MACOSX)
|
2016-07-29 12:50:27 +00:00
|
|
|
ui::Layer* OffScreenRenderWidgetHostView::DelegatedFrameHostGetLayer() const {
|
2016-07-13 15:43:00 +00:00
|
|
|
return const_cast<ui::Layer*>(root_layer_.get());
|
2016-07-05 19:33:22 +00:00
|
|
|
}
|
|
|
|
|
2016-07-29 12:50:27 +00:00
|
|
|
bool OffScreenRenderWidgetHostView::DelegatedFrameHostIsVisible() const {
|
2016-07-13 15:43:00 +00:00
|
|
|
return !render_widget_host_->is_hidden();
|
2016-07-05 19:33:22 +00:00
|
|
|
}
|
|
|
|
|
2018-05-15 01:59:22 +00:00
|
|
|
SkColor OffScreenRenderWidgetHostView::DelegatedFrameHostGetGutterColor()
|
|
|
|
const {
|
2017-03-04 02:09:16 +00:00
|
|
|
if (render_widget_host_->delegate() &&
|
|
|
|
render_widget_host_->delegate()->IsFullscreenForCurrentTab()) {
|
2017-04-12 23:30:46 +00:00
|
|
|
return SK_ColorWHITE;
|
2017-03-04 02:09:16 +00:00
|
|
|
}
|
2018-05-15 01:59:22 +00:00
|
|
|
return background_color_;
|
2016-07-05 19:33:22 +00:00
|
|
|
}
|
|
|
|
|
2016-07-29 12:50:27 +00:00
|
|
|
bool OffScreenRenderWidgetHostView::DelegatedFrameCanCreateResizeLock() const {
|
2017-03-04 02:09:16 +00:00
|
|
|
return !render_widget_host_->auto_resize_enabled();
|
2016-07-05 19:33:22 +00:00
|
|
|
}
|
|
|
|
|
2017-07-09 18:53:00 +00:00
|
|
|
std::unique_ptr<content::CompositorResizeLock>
|
|
|
|
OffScreenRenderWidgetHostView::DelegatedFrameHostCreateResizeLock() {
|
|
|
|
HoldResize();
|
|
|
|
const gfx::Size& desired_size = GetRootLayer()->bounds().size();
|
2018-04-12 12:48:32 +00:00
|
|
|
return std::make_unique<content::CompositorResizeLock>(this, desired_size);
|
2016-07-05 19:33:22 +00:00
|
|
|
}
|
|
|
|
|
2018-03-17 22:41:45 +00:00
|
|
|
viz::LocalSurfaceId OffScreenRenderWidgetHostView::GetLocalSurfaceId() const {
|
2018-03-17 22:26:41 +00:00
|
|
|
return local_surface_id_;
|
|
|
|
}
|
|
|
|
|
2018-05-15 01:59:22 +00:00
|
|
|
void OffScreenRenderWidgetHostView::OnFirstSurfaceActivation(
|
|
|
|
const viz::SurfaceInfo& surface_info) {}
|
|
|
|
|
|
|
|
void OffScreenRenderWidgetHostView::OnBeginFrame(base::TimeTicks frame_time) {}
|
|
|
|
|
|
|
|
void OffScreenRenderWidgetHostView::OnFrameTokenChanged(uint32_t frame_token) {
|
|
|
|
render_widget_host_->DidProcessFrame(frame_token);
|
|
|
|
}
|
|
|
|
|
|
|
|
void OffScreenRenderWidgetHostView::DidReceiveFirstFrameAfterNavigation() {
|
|
|
|
render_widget_host_->DidReceiveFirstFrameAfterNavigation();
|
|
|
|
}
|
2016-07-05 19:33:22 +00:00
|
|
|
|
2017-07-09 18:53:00 +00:00
|
|
|
std::unique_ptr<ui::CompositorLock>
|
|
|
|
OffScreenRenderWidgetHostView::GetCompositorLock(
|
|
|
|
ui::CompositorLockClient* client) {
|
|
|
|
return GetCompositor()->GetCompositorLock(client);
|
2016-07-05 19:33:22 +00:00
|
|
|
}
|
|
|
|
|
2017-07-09 18:53:00 +00:00
|
|
|
void OffScreenRenderWidgetHostView::CompositorResizeLockEnded() {
|
|
|
|
ReleaseResize();
|
2016-08-01 11:27:39 +00:00
|
|
|
}
|
|
|
|
|
2018-05-16 19:12:45 +00:00
|
|
|
bool OffScreenRenderWidgetHostView::IsAutoResizeEnabled() const {
|
|
|
|
return render_widget_host_->auto_resize_enabled();
|
|
|
|
}
|
|
|
|
|
2016-11-30 07:30:03 +00:00
|
|
|
#endif // !defined(OS_MACOSX)
|
|
|
|
|
2017-04-05 08:31:22 +00:00
|
|
|
bool OffScreenRenderWidgetHostView::TransformPointToLocalCoordSpace(
|
2018-05-15 01:59:22 +00:00
|
|
|
const gfx::PointF& point,
|
2017-10-19 19:04:21 +00:00
|
|
|
const viz::SurfaceId& original_surface,
|
2018-05-15 01:59:22 +00:00
|
|
|
gfx::PointF* transformed_point) {
|
2017-04-05 08:31:22 +00:00
|
|
|
// Transformations use physical pixels rather than DIP, so conversion
|
|
|
|
// is necessary.
|
2018-05-15 01:59:22 +00:00
|
|
|
gfx::PointF point_in_pixels = gfx::ConvertPointToPixel(scale_factor_, point);
|
2017-04-05 08:31:22 +00:00
|
|
|
if (!GetDelegatedFrameHost()->TransformPointToLocalCoordSpace(
|
|
|
|
point_in_pixels, original_surface, transformed_point)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
*transformed_point =
|
|
|
|
gfx::ConvertPointToDIP(scale_factor_, *transformed_point);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool OffScreenRenderWidgetHostView::TransformPointToCoordSpaceForView(
|
2018-05-15 01:59:22 +00:00
|
|
|
const gfx::PointF& point,
|
2017-04-05 08:31:22 +00:00
|
|
|
RenderWidgetHostViewBase* target_view,
|
2018-05-15 01:59:22 +00:00
|
|
|
gfx::PointF* transformed_point) {
|
2017-04-05 08:31:22 +00:00
|
|
|
if (target_view == this) {
|
|
|
|
*transformed_point = point;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// In TransformPointToLocalCoordSpace() there is a Point-to-Pixel conversion,
|
|
|
|
// but it is not necessary here because the final target view is responsible
|
|
|
|
// for converting before computing the final transform.
|
|
|
|
return GetDelegatedFrameHost()->TransformPointToCoordSpaceForView(
|
|
|
|
point, target_view, transformed_point);
|
|
|
|
}
|
|
|
|
|
2017-03-04 02:09:16 +00:00
|
|
|
void OffScreenRenderWidgetHostView::CancelWidget() {
|
|
|
|
if (render_widget_host_)
|
2017-03-05 15:18:57 +00:00
|
|
|
render_widget_host_->LostCapture();
|
2017-03-04 02:09:16 +00:00
|
|
|
Hide();
|
2017-03-05 15:18:57 +00:00
|
|
|
|
2017-03-04 02:09:16 +00:00
|
|
|
if (parent_host_view_) {
|
|
|
|
if (parent_host_view_->popup_host_view_ == this) {
|
|
|
|
parent_host_view_->set_popup_host_view(NULL);
|
|
|
|
parent_host_view_->popup_bitmap_.reset();
|
|
|
|
} else if (parent_host_view_->child_host_view_ == this) {
|
|
|
|
parent_host_view_->set_child_host_view(NULL);
|
|
|
|
parent_host_view_->Show();
|
|
|
|
} else {
|
|
|
|
parent_host_view_->RemoveGuestHostView(this);
|
|
|
|
}
|
|
|
|
parent_host_view_ = NULL;
|
|
|
|
}
|
2017-03-05 15:18:57 +00:00
|
|
|
|
2017-03-04 02:09:16 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2017-05-21 17:55:19 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2017-03-04 02:09:16 +00:00
|
|
|
void OffScreenRenderWidgetHostView::RegisterGuestViewFrameSwappedCallback(
|
|
|
|
content::RenderWidgetHostViewGuest* guest_host_view) {
|
2018-05-15 01:59:22 +00:00
|
|
|
guest_host_view->RegisterFrameSwappedCallback(base::BindOnce(
|
|
|
|
&OffScreenRenderWidgetHostView::OnGuestViewFrameSwapped,
|
|
|
|
weak_ptr_factory_.GetWeakPtr(), base::Unretained(guest_host_view)));
|
2017-03-04 02:09:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OffScreenRenderWidgetHostView::OnGuestViewFrameSwapped(
|
|
|
|
content::RenderWidgetHostViewGuest* guest_host_view) {
|
|
|
|
InvalidateBounds(
|
2018-04-18 01:55:30 +00:00
|
|
|
gfx::ConvertRectToPixel(scale_factor_, guest_host_view->GetViewBounds()));
|
2017-03-05 15:18:57 +00:00
|
|
|
|
2017-03-04 02:09:16 +00:00
|
|
|
RegisterGuestViewFrameSwappedCallback(guest_host_view);
|
|
|
|
}
|
|
|
|
|
2017-12-18 09:31:54 +00:00
|
|
|
std::unique_ptr<viz::SoftwareOutputDevice>
|
2018-04-18 01:55:30 +00:00
|
|
|
OffScreenRenderWidgetHostView::CreateSoftwareOutputDevice(
|
2016-07-31 10:19:56 +00:00
|
|
|
ui::Compositor* compositor) {
|
2016-09-07 08:33:09 +00:00
|
|
|
DCHECK_EQ(GetCompositor(), compositor);
|
2016-07-27 16:24:58 +00:00
|
|
|
DCHECK(!copy_frame_generator_);
|
|
|
|
DCHECK(!software_output_device_);
|
2016-07-27 17:59:01 +00:00
|
|
|
|
2017-05-12 22:59:25 +00:00
|
|
|
ResizeRootLayer();
|
|
|
|
|
2016-08-04 04:22:19 +00:00
|
|
|
software_output_device_ = new OffScreenOutputDevice(
|
2018-04-18 01:55:30 +00:00
|
|
|
transparent_, base::Bind(&OffScreenRenderWidgetHostView::OnPaint,
|
|
|
|
weak_ptr_factory_.GetWeakPtr()));
|
2016-07-27 16:24:58 +00:00
|
|
|
return base::WrapUnique(software_output_device_);
|
|
|
|
}
|
2016-07-05 19:33:22 +00:00
|
|
|
|
2016-08-03 04:46:34 +00:00
|
|
|
bool OffScreenRenderWidgetHostView::InstallTransparency() {
|
|
|
|
if (transparent_) {
|
|
|
|
SetBackgroundColor(SkColor());
|
2016-09-07 08:33:09 +00:00
|
|
|
#if defined(OS_MACOSX)
|
2018-03-13 06:38:55 +00:00
|
|
|
browser_compositor_->SetBackgroundColor(SK_ColorTRANSPARENT);
|
2016-09-07 08:33:09 +00:00
|
|
|
#else
|
2018-03-13 06:38:55 +00:00
|
|
|
compositor_->SetBackgroundColor(SK_ColorTRANSPARENT);
|
2016-09-07 08:33:09 +00:00
|
|
|
#endif
|
2016-08-03 04:46:34 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-12-20 17:03:42 +00:00
|
|
|
void OffScreenRenderWidgetHostView::SetNeedsBeginFrames(
|
|
|
|
bool needs_begin_frames) {
|
2018-01-25 13:46:30 +00:00
|
|
|
SetupFrameRate(true);
|
2016-12-20 17:03:42 +00:00
|
|
|
|
|
|
|
begin_frame_timer_->SetActive(needs_begin_frames);
|
|
|
|
|
|
|
|
if (software_output_device_) {
|
2017-11-02 21:50:04 +00:00
|
|
|
software_output_device_->SetActive(needs_begin_frames && painting_, false);
|
2016-12-20 17:03:42 +00:00
|
|
|
}
|
2016-07-22 11:55:58 +00:00
|
|
|
}
|
|
|
|
|
2018-05-15 01:59:22 +00:00
|
|
|
void OffScreenRenderWidgetHostView::SetWantsAnimateOnlyBeginFrames() {
|
|
|
|
if (GetDelegatedFrameHost()) {
|
|
|
|
GetDelegatedFrameHost()->SetWantsAnimateOnlyBeginFrames();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
void CopyBitmapTo(const SkBitmap& destination,
|
|
|
|
const SkBitmap& source,
|
|
|
|
const gfx::Rect& pos) {
|
2017-03-04 02:09:16 +00:00
|
|
|
char* src = static_cast<char*>(source.getPixels());
|
|
|
|
char* dest = static_cast<char*>(destination.getPixels());
|
|
|
|
int pixelsize = source.bytesPerPixel();
|
2017-03-05 15:18:57 +00:00
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
int width =
|
|
|
|
pos.x() + pos.width() <= destination.width()
|
|
|
|
? pos.width()
|
|
|
|
: pos.width() - ((pos.x() + pos.width()) - destination.width());
|
|
|
|
int height =
|
|
|
|
pos.y() + pos.height() <= destination.height()
|
|
|
|
? pos.height()
|
|
|
|
: pos.height() - ((pos.y() + pos.height()) - destination.height());
|
2017-05-21 17:55:19 +00:00
|
|
|
|
|
|
|
if (width > 0 && height > 0) {
|
|
|
|
for (int i = 0; i < height; i++) {
|
2017-03-04 02:09:16 +00:00
|
|
|
memcpy(dest + ((pos.y() + i) * destination.width() + pos.x()) * pixelsize,
|
2018-04-18 01:55:30 +00:00
|
|
|
src + (i * source.width()) * pixelsize, width * pixelsize);
|
2017-03-04 02:09:16 +00:00
|
|
|
}
|
|
|
|
}
|
2017-03-05 15:18:57 +00:00
|
|
|
|
2017-03-04 02:09:16 +00:00
|
|
|
destination.notifyPixelsChanged();
|
|
|
|
}
|
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
void OffScreenRenderWidgetHostView::OnPaint(const gfx::Rect& damage_rect,
|
|
|
|
const SkBitmap& bitmap) {
|
2016-07-29 12:50:27 +00:00
|
|
|
TRACE_EVENT0("electron", "OffScreenRenderWidgetHostView::OnPaint");
|
2017-03-05 15:18:57 +00:00
|
|
|
|
2017-03-04 02:09:16 +00:00
|
|
|
HoldResize();
|
2017-03-05 15:19:51 +00:00
|
|
|
|
|
|
|
if (parent_callback_) {
|
2017-03-04 02:09:16 +00:00
|
|
|
parent_callback_.Run(damage_rect, bitmap);
|
2017-05-21 17:55:19 +00:00
|
|
|
} else {
|
2017-03-05 15:19:51 +00:00
|
|
|
gfx::Rect damage(damage_rect);
|
2017-04-12 18:54:03 +00:00
|
|
|
|
2017-05-21 17:55:19 +00:00
|
|
|
std::vector<gfx::Rect> damages;
|
|
|
|
std::vector<const SkBitmap*> bitmaps;
|
|
|
|
std::vector<SkBitmap> originals;
|
|
|
|
|
|
|
|
if (popup_host_view_ && popup_bitmap_.get()) {
|
|
|
|
gfx::Rect pos = popup_host_view_->popup_position_;
|
|
|
|
damage.Union(pos);
|
|
|
|
damages.push_back(pos);
|
|
|
|
bitmaps.push_back(popup_bitmap_.get());
|
2018-04-18 01:55:30 +00:00
|
|
|
originals.push_back(SkBitmapOperations::CreateTiledBitmap(
|
|
|
|
bitmap, pos.x(), pos.y(), pos.width(), pos.height()));
|
2017-05-21 17:55:19 +00:00
|
|
|
}
|
2017-04-12 18:54:03 +00:00
|
|
|
|
2018-05-04 06:45:12 +00:00
|
|
|
for (auto* proxy_view : proxy_views_) {
|
2017-05-21 17:55:19 +00:00
|
|
|
gfx::Rect pos = proxy_view->GetBounds();
|
|
|
|
damage.Union(pos);
|
|
|
|
damages.push_back(pos);
|
|
|
|
bitmaps.push_back(proxy_view->GetBitmap());
|
2018-04-18 01:55:30 +00:00
|
|
|
originals.push_back(SkBitmapOperations::CreateTiledBitmap(
|
|
|
|
bitmap, pos.x(), pos.y(), pos.width(), pos.height()));
|
2017-05-21 17:55:19 +00:00
|
|
|
}
|
|
|
|
|
2017-05-23 09:41:59 +00:00
|
|
|
for (size_t i = 0; i < damages.size(); i++) {
|
2017-05-21 17:55:19 +00:00
|
|
|
CopyBitmapTo(bitmap, *(bitmaps[i]), damages[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
damage.Intersect(GetViewBounds());
|
2018-01-25 13:42:11 +00:00
|
|
|
paint_callback_running_ = true;
|
2017-03-05 15:19:51 +00:00
|
|
|
callback_.Run(damage, bitmap);
|
2018-01-25 13:42:11 +00:00
|
|
|
paint_callback_running_ = false;
|
2017-05-21 17:55:19 +00:00
|
|
|
|
2017-05-23 09:41:59 +00:00
|
|
|
for (size_t i = 0; i < damages.size(); i++) {
|
2017-05-21 17:55:19 +00:00
|
|
|
CopyBitmapTo(bitmap, originals[i], damages[i]);
|
|
|
|
}
|
2017-03-04 02:09:16 +00:00
|
|
|
}
|
2017-03-05 15:18:57 +00:00
|
|
|
|
2017-03-04 02:09:16 +00:00
|
|
|
ReleaseResize();
|
|
|
|
}
|
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
void OffScreenRenderWidgetHostView::OnPopupPaint(const gfx::Rect& damage_rect,
|
|
|
|
const SkBitmap& bitmap) {
|
2017-03-04 02:09:16 +00:00
|
|
|
if (popup_host_view_ && popup_bitmap_.get())
|
2017-10-19 19:04:21 +00:00
|
|
|
popup_bitmap_.reset(new SkBitmap(bitmap));
|
2017-04-08 23:24:09 +00:00
|
|
|
InvalidateBounds(popup_host_view_->popup_position_);
|
2017-03-04 02:09:16 +00:00
|
|
|
}
|
|
|
|
|
2017-05-21 17:55:19 +00:00
|
|
|
void OffScreenRenderWidgetHostView::OnProxyViewPaint(
|
|
|
|
const gfx::Rect& damage_rect) {
|
|
|
|
InvalidateBounds(damage_rect);
|
|
|
|
}
|
|
|
|
|
2017-03-04 02:09:16 +00:00
|
|
|
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;
|
2018-04-18 01:55:30 +00:00
|
|
|
content::BrowserThread::PostTask(
|
|
|
|
content::BrowserThread::UI, FROM_HERE,
|
2018-04-20 10:55:05 +00:00
|
|
|
base::BindOnce(&OffScreenRenderWidgetHostView::WasResized,
|
|
|
|
weak_ptr_factory_.GetWeakPtr()));
|
2017-03-04 02:09:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void OffScreenRenderWidgetHostView::WasResized() {
|
|
|
|
if (hold_resize_) {
|
|
|
|
if (!pending_resize_)
|
|
|
|
pending_resize_ = true;
|
|
|
|
return;
|
|
|
|
}
|
2017-03-05 15:18:57 +00:00
|
|
|
|
2017-03-04 02:09:16 +00:00
|
|
|
ResizeRootLayer();
|
|
|
|
if (render_widget_host_)
|
|
|
|
render_widget_host_->WasResized();
|
2018-05-15 01:59:22 +00:00
|
|
|
GetDelegatedFrameHost()->WasResized(local_surface_id_, size_,
|
|
|
|
cc::DeadlinePolicy::UseDefaultDeadline());
|
2017-03-04 02:09:16 +00:00
|
|
|
}
|
|
|
|
|
2018-05-15 01:59:22 +00:00
|
|
|
void OffScreenRenderWidgetHostView::SendMouseEvent(
|
|
|
|
const blink::WebMouseEvent& event) {
|
2018-05-04 06:45:12 +00:00
|
|
|
for (auto* proxy_view : proxy_views_) {
|
2017-05-21 17:55:19 +00:00
|
|
|
gfx::Rect bounds = proxy_view->GetBounds();
|
2017-06-29 23:50:55 +00:00
|
|
|
if (bounds.Contains(event.PositionInWidget().x,
|
|
|
|
event.PositionInWidget().y)) {
|
2017-05-21 17:55:19 +00:00
|
|
|
blink::WebMouseEvent proxy_event(event);
|
2017-06-16 21:13:28 +00:00
|
|
|
proxy_event.SetPositionInWidget(
|
|
|
|
proxy_event.PositionInWidget().x - bounds.x(),
|
|
|
|
proxy_event.PositionInWidget().y - bounds.y());
|
2017-05-21 17:55:19 +00:00
|
|
|
|
|
|
|
ui::MouseEvent ui_event = UiMouseEventFromWebMouseEvent(proxy_event);
|
|
|
|
proxy_view->OnEvent(&ui_event);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-04 02:09:16 +00:00
|
|
|
if (!IsPopupWidget()) {
|
2018-04-18 01:55:30 +00:00
|
|
|
if (popup_host_view_ &&
|
|
|
|
popup_host_view_->popup_position_.Contains(
|
|
|
|
event.PositionInWidget().x, event.PositionInWidget().y)) {
|
2017-03-04 02:09:16 +00:00
|
|
|
blink::WebMouseEvent popup_event(event);
|
2017-06-16 21:13:28 +00:00
|
|
|
popup_event.SetPositionInWidget(
|
2017-06-29 23:50:55 +00:00
|
|
|
popup_event.PositionInWidget().x -
|
|
|
|
popup_host_view_->popup_position_.x(),
|
|
|
|
popup_event.PositionInWidget().y -
|
|
|
|
popup_host_view_->popup_position_.y());
|
2017-03-04 02:09:16 +00:00
|
|
|
|
2018-05-15 01:59:22 +00:00
|
|
|
popup_host_view_->ProcessMouseEvent(popup_event, ui::LatencyInfo());
|
2017-03-04 02:09:16 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2017-05-21 17:55:19 +00:00
|
|
|
|
2017-03-04 02:09:16 +00:00
|
|
|
if (!render_widget_host_)
|
|
|
|
return;
|
|
|
|
render_widget_host_->ForwardMouseEvent(event);
|
|
|
|
}
|
|
|
|
|
2018-05-15 01:59:22 +00:00
|
|
|
void OffScreenRenderWidgetHostView::SendMouseWheelEvent(
|
|
|
|
const blink::WebMouseWheelEvent& event) {
|
2018-05-04 06:45:12 +00:00
|
|
|
for (auto* proxy_view : proxy_views_) {
|
2017-05-21 17:55:19 +00:00
|
|
|
gfx::Rect bounds = proxy_view->GetBounds();
|
2017-06-29 23:50:55 +00:00
|
|
|
if (bounds.Contains(event.PositionInWidget().x,
|
|
|
|
event.PositionInWidget().y)) {
|
2017-05-21 17:55:19 +00:00
|
|
|
blink::WebMouseWheelEvent proxy_event(event);
|
2017-06-16 21:13:28 +00:00
|
|
|
proxy_event.SetPositionInWidget(
|
|
|
|
proxy_event.PositionInWidget().x - bounds.x(),
|
|
|
|
proxy_event.PositionInWidget().y - bounds.y());
|
2017-05-21 17:55:19 +00:00
|
|
|
|
|
|
|
ui::MouseWheelEvent ui_event =
|
2018-04-18 01:55:30 +00:00
|
|
|
UiMouseWheelEventFromWebMouseEvent(proxy_event);
|
2017-05-21 17:55:19 +00:00
|
|
|
proxy_view->OnEvent(&ui_event);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2017-03-04 02:09:16 +00:00
|
|
|
if (!IsPopupWidget()) {
|
|
|
|
if (popup_host_view_) {
|
2017-06-16 21:13:28 +00:00
|
|
|
if (popup_host_view_->popup_position_.Contains(
|
2018-04-18 01:55:30 +00:00
|
|
|
event.PositionInWidget().x, event.PositionInWidget().y)) {
|
2017-03-04 02:09:16 +00:00
|
|
|
blink::WebMouseWheelEvent popup_event(event);
|
2017-06-16 21:13:28 +00:00
|
|
|
popup_event.SetPositionInWidget(
|
2017-06-29 23:50:55 +00:00
|
|
|
popup_event.PositionInWidget().x -
|
|
|
|
popup_host_view_->popup_position_.x(),
|
|
|
|
popup_event.PositionInWidget().y -
|
|
|
|
popup_host_view_->popup_position_.y());
|
2018-05-15 01:59:22 +00:00
|
|
|
popup_host_view_->ProcessMouseWheelEvent(popup_event,
|
|
|
|
ui::LatencyInfo());
|
2017-03-04 02:09:16 +00:00
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
// Scrolling outside of the popup widget so destroy it.
|
|
|
|
// Execute asynchronously to avoid deleting the widget from inside some
|
|
|
|
// other callback.
|
2018-04-18 01:55:30 +00:00
|
|
|
content::BrowserThread::PostTask(
|
|
|
|
content::BrowserThread::UI, FROM_HERE,
|
2018-04-20 10:55:05 +00:00
|
|
|
base::BindOnce(&OffScreenRenderWidgetHostView::CancelWidget,
|
|
|
|
popup_host_view_->weak_ptr_factory_.GetWeakPtr()));
|
2017-03-04 02:09:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!render_widget_host_)
|
|
|
|
return;
|
|
|
|
render_widget_host_->ForwardWheelEvent(event);
|
2016-07-27 17:44:41 +00:00
|
|
|
}
|
|
|
|
|
2016-07-30 13:40:16 +00:00
|
|
|
void OffScreenRenderWidgetHostView::SetPainting(bool painting) {
|
|
|
|
painting_ = painting;
|
|
|
|
|
2016-07-31 20:05:36 +00:00
|
|
|
if (software_output_device_) {
|
2018-01-25 13:42:11 +00:00
|
|
|
software_output_device_->SetActive(painting_, !paint_callback_running_);
|
2016-07-31 20:05:36 +00:00
|
|
|
}
|
2016-07-30 13:40:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool OffScreenRenderWidgetHostView::IsPainting() const {
|
|
|
|
return painting_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OffScreenRenderWidgetHostView::SetFrameRate(int frame_rate) {
|
2017-03-04 02:09:16 +00:00
|
|
|
if (parent_host_view_) {
|
|
|
|
if (parent_host_view_->GetFrameRate() == GetFrameRate())
|
|
|
|
return;
|
2016-07-30 13:40:16 +00:00
|
|
|
|
2017-03-04 02:09:16 +00:00
|
|
|
frame_rate_ = parent_host_view_->GetFrameRate();
|
|
|
|
} else {
|
|
|
|
if (frame_rate <= 0)
|
|
|
|
frame_rate = 1;
|
2018-01-25 13:44:19 +00:00
|
|
|
if (frame_rate > 240)
|
|
|
|
frame_rate = 240;
|
2017-03-05 15:18:57 +00:00
|
|
|
|
2017-03-04 02:09:16 +00:00
|
|
|
frame_rate_ = frame_rate;
|
|
|
|
}
|
2017-03-05 15:18:57 +00:00
|
|
|
|
2018-01-25 13:46:30 +00:00
|
|
|
SetupFrameRate(true);
|
|
|
|
|
2018-05-04 06:45:12 +00:00
|
|
|
for (auto* guest_host_view : guest_host_views_)
|
2017-03-04 02:09:16 +00:00
|
|
|
guest_host_view->SetFrameRate(frame_rate);
|
2016-07-30 13:40:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int OffScreenRenderWidgetHostView::GetFrameRate() const {
|
|
|
|
return frame_rate_;
|
|
|
|
}
|
|
|
|
|
2016-09-07 08:33:09 +00:00
|
|
|
#if !defined(OS_MACOSX)
|
|
|
|
ui::Compositor* OffScreenRenderWidgetHostView::GetCompositor() const {
|
|
|
|
return compositor_.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
ui::Layer* OffScreenRenderWidgetHostView::GetRootLayer() const {
|
|
|
|
return root_layer_.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
content::DelegatedFrameHost*
|
|
|
|
OffScreenRenderWidgetHostView::GetDelegatedFrameHost() const {
|
|
|
|
return delegated_frame_host_.get();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-08-03 04:46:34 +00:00
|
|
|
void OffScreenRenderWidgetHostView::SetupFrameRate(bool force) {
|
2017-04-12 14:15:58 +00:00
|
|
|
if (!force && frame_rate_threshold_us_ != 0)
|
2016-08-03 04:46:34 +00:00
|
|
|
return;
|
|
|
|
|
2017-04-12 14:15:58 +00:00
|
|
|
frame_rate_threshold_us_ = 1000000 / frame_rate_;
|
2016-08-03 04:46:34 +00:00
|
|
|
|
2018-01-25 13:45:01 +00:00
|
|
|
GetCompositor()->SetAuthoritativeVSyncInterval(
|
2017-04-12 14:15:58 +00:00
|
|
|
base::TimeDelta::FromMicroseconds(frame_rate_threshold_us_));
|
2016-08-03 04:46:34 +00:00
|
|
|
|
2017-04-12 14:15:58 +00:00
|
|
|
if (copy_frame_generator_.get()) {
|
|
|
|
copy_frame_generator_->set_frame_rate_threshold_us(
|
|
|
|
frame_rate_threshold_us_);
|
2016-08-03 04:46:34 +00:00
|
|
|
}
|
|
|
|
|
2017-04-12 14:15:58 +00:00
|
|
|
if (begin_frame_timer_.get()) {
|
|
|
|
begin_frame_timer_->SetFrameRateThresholdUs(frame_rate_threshold_us_);
|
2016-08-03 04:46:34 +00:00
|
|
|
} else {
|
|
|
|
begin_frame_timer_.reset(new AtomBeginFrameTimer(
|
2017-04-12 14:15:58 +00:00
|
|
|
frame_rate_threshold_us_,
|
2016-08-03 04:46:34 +00:00
|
|
|
base::Bind(&OffScreenRenderWidgetHostView::OnBeginFrameTimerTick,
|
|
|
|
weak_ptr_factory_.GetWeakPtr())));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-01 17:25:12 +00:00
|
|
|
void OffScreenRenderWidgetHostView::Invalidate() {
|
2017-03-04 02:09:16 +00:00
|
|
|
InvalidateBounds(GetViewBounds());
|
|
|
|
}
|
2016-09-01 17:25:12 +00:00
|
|
|
|
2017-03-04 02:09:16 +00:00
|
|
|
void OffScreenRenderWidgetHostView::InvalidateBounds(const gfx::Rect& bounds) {
|
2016-09-01 17:25:12 +00:00
|
|
|
if (software_output_device_) {
|
2017-04-12 17:34:52 +00:00
|
|
|
software_output_device_->OnPaint(bounds);
|
2017-03-30 20:22:40 +00:00
|
|
|
} else if (copy_frame_generator_) {
|
2017-04-12 17:34:52 +00:00
|
|
|
copy_frame_generator_->GenerateCopyFrame(bounds);
|
2016-09-01 17:25:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-03 04:46:34 +00:00
|
|
|
void OffScreenRenderWidgetHostView::ResizeRootLayer() {
|
|
|
|
SetupFrameRate(false);
|
|
|
|
|
2017-05-12 22:59:25 +00:00
|
|
|
const float compositorScaleFactor = GetCompositor()->device_scale_factor();
|
|
|
|
const bool scaleFactorDidChange = (compositorScaleFactor != scale_factor_);
|
2016-08-03 04:46:34 +00:00
|
|
|
|
2017-03-04 02:09:16 +00:00
|
|
|
gfx::Size size;
|
|
|
|
if (!IsPopupWidget())
|
|
|
|
size = GetViewBounds().size();
|
|
|
|
else
|
|
|
|
size = popup_position_.size();
|
2016-08-03 04:46:34 +00:00
|
|
|
|
2016-09-07 08:33:09 +00:00
|
|
|
if (!scaleFactorDidChange && size == GetRootLayer()->bounds().size())
|
2016-08-03 04:46:34 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
const gfx::Size& size_in_pixels =
|
|
|
|
gfx::ConvertSizeToPixel(scale_factor_, size);
|
|
|
|
|
2018-03-17 22:26:41 +00:00
|
|
|
local_surface_id_ = local_surface_id_allocator_.GenerateId();
|
|
|
|
|
2016-09-07 08:33:09 +00:00
|
|
|
GetRootLayer()->SetBounds(gfx::Rect(size));
|
2018-05-15 01:59:22 +00:00
|
|
|
GetCompositor()->SetScaleAndSize(scale_factor_, size_in_pixels,
|
|
|
|
local_surface_id_);
|
|
|
|
|
|
|
|
#if defined(OS_MACOSX)
|
|
|
|
bool resized = browser_compositor_->UpdateNSViewAndDisplay();
|
|
|
|
#else
|
|
|
|
bool resized = true;
|
|
|
|
GetDelegatedFrameHost()->WasResized(local_surface_id_, size,
|
|
|
|
cc::DeadlinePolicy::UseDefaultDeadline());
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Note that |render_widget_host_| will retrieve resize parameters from the
|
|
|
|
// DelegatedFrameHost, so it must have WasResized called after.
|
|
|
|
if (resized && render_widget_host_)
|
|
|
|
render_widget_host_->WasResized();
|
2016-08-03 04:46:34 +00:00
|
|
|
}
|
|
|
|
|
2017-10-19 19:04:21 +00:00
|
|
|
viz::FrameSinkId OffScreenRenderWidgetHostView::AllocateFrameSinkId(
|
2017-04-05 08:31:22 +00:00
|
|
|
bool is_guest_view_hack) {
|
|
|
|
// GuestViews have two RenderWidgetHostViews and so we need to make sure
|
|
|
|
// we don't have FrameSinkId collisions.
|
|
|
|
// The FrameSinkId generated here must be unique with FrameSinkId allocated
|
|
|
|
// in ContextFactoryPrivate.
|
|
|
|
content::ImageTransportFactory* factory =
|
|
|
|
content::ImageTransportFactory::GetInstance();
|
|
|
|
return is_guest_view_hack
|
2018-04-18 01:55:30 +00:00
|
|
|
? factory->GetContextFactoryPrivate()->AllocateFrameSinkId()
|
|
|
|
: viz::FrameSinkId(base::checked_cast<uint32_t>(
|
|
|
|
render_widget_host_->GetProcess()->GetID()),
|
|
|
|
base::checked_cast<uint32_t>(
|
|
|
|
render_widget_host_->GetRoutingID()));
|
2016-09-19 07:51:03 +00:00
|
|
|
}
|
|
|
|
|
2017-07-08 19:25:15 +00:00
|
|
|
void OffScreenRenderWidgetHostView::UpdateBackgroundColorFromRenderer(
|
|
|
|
SkColor color) {
|
|
|
|
if (color == background_color())
|
|
|
|
return;
|
|
|
|
background_color_ = color;
|
|
|
|
|
|
|
|
bool opaque = SkColorGetA(color) == SK_AlphaOPAQUE;
|
|
|
|
GetRootLayer()->SetFillsBoundsOpaquely(opaque);
|
|
|
|
GetRootLayer()->SetColor(color);
|
|
|
|
}
|
|
|
|
|
2016-07-05 19:33:22 +00:00
|
|
|
} // namespace atom
|