Pass OnPaint callback in constructor
This can catch the paint events happened before onload event.
This commit is contained in:
parent
32d9382417
commit
530fcc8de1
5 changed files with 21 additions and 29 deletions
|
@ -314,7 +314,8 @@ WebContents::WebContents(v8::Isolate* isolate,
|
||||||
options.Get("transparent", &transparent);
|
options.Get("transparent", &transparent);
|
||||||
|
|
||||||
content::WebContents::CreateParams params(session->browser_context());
|
content::WebContents::CreateParams params(session->browser_context());
|
||||||
auto* view = new OffScreenWebContentsView(transparent);
|
auto* view = new OffScreenWebContentsView(
|
||||||
|
transparent, base::Bind(&WebContents::OnPaint, base::Unretained(this)));
|
||||||
params.view = view;
|
params.view = view;
|
||||||
params.delegate_view = view;
|
params.delegate_view = view;
|
||||||
|
|
||||||
|
@ -608,16 +609,9 @@ void WebContents::DidChangeThemeColor(SkColor theme_color) {
|
||||||
|
|
||||||
void WebContents::DocumentLoadedInFrame(
|
void WebContents::DocumentLoadedInFrame(
|
||||||
content::RenderFrameHost* render_frame_host) {
|
content::RenderFrameHost* render_frame_host) {
|
||||||
if (!render_frame_host->GetParent()) {
|
if (!render_frame_host->GetParent())
|
||||||
if (IsOffScreen()) {
|
|
||||||
auto* rwhv = web_contents()->GetRenderWidgetHostView();
|
|
||||||
static_cast<OffScreenRenderWidgetHostView*>(rwhv)->SetPaintCallback(
|
|
||||||
base::Bind(&WebContents::OnPaint, base::Unretained(this)));
|
|
||||||
}
|
|
||||||
|
|
||||||
Emit("dom-ready");
|
Emit("dom-ready");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void WebContents::DidFinishLoad(content::RenderFrameHost* render_frame_host,
|
void WebContents::DidFinishLoad(content::RenderFrameHost* render_frame_host,
|
||||||
const GURL& validated_url) {
|
const GURL& validated_url) {
|
||||||
|
|
|
@ -338,15 +338,17 @@ class AtomBeginFrameTimer : public cc::DelayBasedTimeSourceClient {
|
||||||
|
|
||||||
OffScreenRenderWidgetHostView::OffScreenRenderWidgetHostView(
|
OffScreenRenderWidgetHostView::OffScreenRenderWidgetHostView(
|
||||||
bool transparent,
|
bool transparent,
|
||||||
|
const OnPaintCallback& callback,
|
||||||
content::RenderWidgetHost* host,
|
content::RenderWidgetHost* host,
|
||||||
NativeWindow* native_window)
|
NativeWindow* native_window)
|
||||||
: render_widget_host_(content::RenderWidgetHostImpl::From(host)),
|
: render_widget_host_(content::RenderWidgetHostImpl::From(host)),
|
||||||
native_window_(native_window),
|
native_window_(native_window),
|
||||||
software_output_device_(nullptr),
|
software_output_device_(nullptr),
|
||||||
|
transparent_(transparent),
|
||||||
|
callback_(callback),
|
||||||
frame_rate_(60),
|
frame_rate_(60),
|
||||||
frame_rate_threshold_ms_(0),
|
frame_rate_threshold_ms_(0),
|
||||||
last_time_(base::Time::Now()),
|
last_time_(base::Time::Now()),
|
||||||
transparent_(transparent),
|
|
||||||
scale_factor_(kDefaultScaleFactor),
|
scale_factor_(kDefaultScaleFactor),
|
||||||
is_showing_(!render_widget_host_->is_hidden()),
|
is_showing_(!render_widget_host_->is_hidden()),
|
||||||
size_(native_window->GetSize()),
|
size_(native_window->GetSize()),
|
||||||
|
@ -783,19 +785,12 @@ void OffScreenRenderWidgetHostView::OnSetNeedsBeginFrames(bool enabled) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void OffScreenRenderWidgetHostView::SetPaintCallback(
|
|
||||||
const OnPaintCallback& callback) {
|
|
||||||
callback_ = callback;
|
|
||||||
}
|
|
||||||
|
|
||||||
void OffScreenRenderWidgetHostView::OnPaint(
|
void OffScreenRenderWidgetHostView::OnPaint(
|
||||||
const gfx::Rect& damage_rect,
|
const gfx::Rect& damage_rect,
|
||||||
const gfx::Size& bitmap_size,
|
const gfx::Size& bitmap_size,
|
||||||
const int pixel_size,
|
int pixel_size,
|
||||||
void* bitmap_pixels) {
|
void* bitmap_pixels) {
|
||||||
TRACE_EVENT0("electron", "OffScreenRenderWidgetHostView::OnPaint");
|
TRACE_EVENT0("electron", "OffScreenRenderWidgetHostView::OnPaint");
|
||||||
|
|
||||||
if (!callback_.is_null())
|
|
||||||
callback_.Run(damage_rect, bitmap_size, pixel_size, bitmap_pixels);
|
callback_.Run(damage_rect, bitmap_size, pixel_size, bitmap_pixels);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -63,6 +63,7 @@ class OffScreenRenderWidgetHostView
|
||||||
public content::DelegatedFrameHostClient {
|
public content::DelegatedFrameHostClient {
|
||||||
public:
|
public:
|
||||||
OffScreenRenderWidgetHostView(bool transparent,
|
OffScreenRenderWidgetHostView(bool transparent,
|
||||||
|
const OnPaintCallback& callback,
|
||||||
content::RenderWidgetHost* render_widget_host,
|
content::RenderWidgetHost* render_widget_host,
|
||||||
NativeWindow* native_window);
|
NativeWindow* native_window);
|
||||||
~OffScreenRenderWidgetHostView() override;
|
~OffScreenRenderWidgetHostView() override;
|
||||||
|
@ -189,10 +190,9 @@ class OffScreenRenderWidgetHostView
|
||||||
void DestroyPlatformWidget();
|
void DestroyPlatformWidget();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void SetPaintCallback(const OnPaintCallback& callback);
|
|
||||||
void OnPaint(const gfx::Rect& damage_rect,
|
void OnPaint(const gfx::Rect& damage_rect,
|
||||||
const gfx::Size& bitmap_size,
|
const gfx::Size& bitmap_size,
|
||||||
const int pixel_size,
|
int pixel_size,
|
||||||
void* bitmap_pixels);
|
void* bitmap_pixels);
|
||||||
|
|
||||||
void SetPainting(bool painting);
|
void SetPainting(bool painting);
|
||||||
|
@ -214,6 +214,7 @@ class OffScreenRenderWidgetHostView
|
||||||
NativeWindow* native_window_;
|
NativeWindow* native_window_;
|
||||||
OffScreenOutputDevice* software_output_device_;
|
OffScreenOutputDevice* software_output_device_;
|
||||||
|
|
||||||
|
const bool transparent_;
|
||||||
OnPaintCallback callback_;
|
OnPaintCallback callback_;
|
||||||
|
|
||||||
int frame_rate_;
|
int frame_rate_;
|
||||||
|
@ -221,7 +222,6 @@ class OffScreenRenderWidgetHostView
|
||||||
|
|
||||||
base::Time last_time_;
|
base::Time last_time_;
|
||||||
|
|
||||||
const bool transparent_;
|
|
||||||
float scale_factor_;
|
float scale_factor_;
|
||||||
bool is_showing_;
|
bool is_showing_;
|
||||||
gfx::Vector2dF last_scroll_offset_;
|
gfx::Vector2dF last_scroll_offset_;
|
||||||
|
|
|
@ -6,8 +6,10 @@
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
|
||||||
OffScreenWebContentsView::OffScreenWebContentsView(bool transparent)
|
OffScreenWebContentsView::OffScreenWebContentsView(
|
||||||
|
bool transparent, const OnPaintCallback& callback)
|
||||||
: transparent_(transparent),
|
: transparent_(transparent),
|
||||||
|
callback_(callback),
|
||||||
web_contents_(nullptr) {
|
web_contents_(nullptr) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,8 +68,8 @@ content::RenderWidgetHostViewBase*
|
||||||
OffScreenWebContentsView::CreateViewForWidget(
|
OffScreenWebContentsView::CreateViewForWidget(
|
||||||
content::RenderWidgetHost* render_widget_host, bool is_guest_view_hack) {
|
content::RenderWidgetHost* render_widget_host, bool is_guest_view_hack) {
|
||||||
auto relay = NativeWindowRelay::FromWebContents(web_contents_);
|
auto relay = NativeWindowRelay::FromWebContents(web_contents_);
|
||||||
view_ = new OffScreenRenderWidgetHostView(transparent_, render_widget_host,
|
view_ = new OffScreenRenderWidgetHostView(
|
||||||
relay->window.get());
|
transparent_, callback_, render_widget_host, relay->window.get());
|
||||||
return view_;
|
return view_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,8 +77,8 @@ content::RenderWidgetHostViewBase*
|
||||||
OffScreenWebContentsView::CreateViewForPopupWidget(
|
OffScreenWebContentsView::CreateViewForPopupWidget(
|
||||||
content::RenderWidgetHost* render_widget_host) {
|
content::RenderWidgetHost* render_widget_host) {
|
||||||
auto relay = NativeWindowRelay::FromWebContents(web_contents_);
|
auto relay = NativeWindowRelay::FromWebContents(web_contents_);
|
||||||
view_ = new OffScreenRenderWidgetHostView(transparent_, render_widget_host,
|
view_ = new OffScreenRenderWidgetHostView(
|
||||||
relay->window.get());
|
transparent_, callback_, render_widget_host, relay->window.get());
|
||||||
return view_;
|
return view_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,12 +15,12 @@ namespace atom {
|
||||||
class OffScreenWebContentsView : public content::WebContentsView,
|
class OffScreenWebContentsView : public content::WebContentsView,
|
||||||
public content::RenderViewHostDelegateView {
|
public content::RenderViewHostDelegateView {
|
||||||
public:
|
public:
|
||||||
explicit OffScreenWebContentsView(bool transparent);
|
OffScreenWebContentsView(bool transparent, const OnPaintCallback& callback);
|
||||||
~OffScreenWebContentsView();
|
~OffScreenWebContentsView();
|
||||||
|
|
||||||
void SetWebContents(content::WebContents*);
|
void SetWebContents(content::WebContents*);
|
||||||
|
|
||||||
// content::WebContentsView
|
// content::WebContentsView:
|
||||||
gfx::NativeView GetNativeView() const override;
|
gfx::NativeView GetNativeView() const override;
|
||||||
gfx::NativeView GetContentNativeView() const override;
|
gfx::NativeView GetContentNativeView() const override;
|
||||||
gfx::NativeWindow GetTopLevelNativeWindow() const override;
|
gfx::NativeWindow GetTopLevelNativeWindow() const override;
|
||||||
|
@ -62,6 +62,7 @@ class OffScreenWebContentsView : public content::WebContentsView,
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const bool transparent_;
|
const bool transparent_;
|
||||||
|
OnPaintCallback callback_;
|
||||||
|
|
||||||
// Weak refs.
|
// Weak refs.
|
||||||
OffScreenRenderWidgetHostView* view_;
|
OffScreenRenderWidgetHostView* view_;
|
||||||
|
|
Loading…
Reference in a new issue