Pass OnPaint callback in constructor

This can catch the paint events happened before onload event.
This commit is contained in:
Cheng Zhao 2016-08-04 13:03:24 +09:00
parent 32d9382417
commit 530fcc8de1
5 changed files with 21 additions and 29 deletions

View file

@ -314,7 +314,8 @@ WebContents::WebContents(v8::Isolate* isolate,
options.Get("transparent", &transparent);
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.delegate_view = view;
@ -608,16 +609,9 @@ void WebContents::DidChangeThemeColor(SkColor theme_color) {
void WebContents::DocumentLoadedInFrame(
content::RenderFrameHost* render_frame_host) {
if (!render_frame_host->GetParent()) {
if (IsOffScreen()) {
auto* rwhv = web_contents()->GetRenderWidgetHostView();
static_cast<OffScreenRenderWidgetHostView*>(rwhv)->SetPaintCallback(
base::Bind(&WebContents::OnPaint, base::Unretained(this)));
}
if (!render_frame_host->GetParent())
Emit("dom-ready");
}
}
void WebContents::DidFinishLoad(content::RenderFrameHost* render_frame_host,
const GURL& validated_url) {

View file

@ -338,15 +338,17 @@ class AtomBeginFrameTimer : public cc::DelayBasedTimeSourceClient {
OffScreenRenderWidgetHostView::OffScreenRenderWidgetHostView(
bool transparent,
const OnPaintCallback& callback,
content::RenderWidgetHost* host,
NativeWindow* native_window)
: render_widget_host_(content::RenderWidgetHostImpl::From(host)),
native_window_(native_window),
software_output_device_(nullptr),
transparent_(transparent),
callback_(callback),
frame_rate_(60),
frame_rate_threshold_ms_(0),
last_time_(base::Time::Now()),
transparent_(transparent),
scale_factor_(kDefaultScaleFactor),
is_showing_(!render_widget_host_->is_hidden()),
size_(native_window->GetSize()),
@ -783,19 +785,12 @@ void OffScreenRenderWidgetHostView::OnSetNeedsBeginFrames(bool enabled) {
}
}
void OffScreenRenderWidgetHostView::SetPaintCallback(
const OnPaintCallback& callback) {
callback_ = callback;
}
void OffScreenRenderWidgetHostView::OnPaint(
const gfx::Rect& damage_rect,
const gfx::Size& bitmap_size,
const int pixel_size,
int pixel_size,
void* bitmap_pixels) {
TRACE_EVENT0("electron", "OffScreenRenderWidgetHostView::OnPaint");
if (!callback_.is_null())
callback_.Run(damage_rect, bitmap_size, pixel_size, bitmap_pixels);
}

View file

@ -63,6 +63,7 @@ class OffScreenRenderWidgetHostView
public content::DelegatedFrameHostClient {
public:
OffScreenRenderWidgetHostView(bool transparent,
const OnPaintCallback& callback,
content::RenderWidgetHost* render_widget_host,
NativeWindow* native_window);
~OffScreenRenderWidgetHostView() override;
@ -189,10 +190,9 @@ class OffScreenRenderWidgetHostView
void DestroyPlatformWidget();
#endif
void SetPaintCallback(const OnPaintCallback& callback);
void OnPaint(const gfx::Rect& damage_rect,
const gfx::Size& bitmap_size,
const int pixel_size,
int pixel_size,
void* bitmap_pixels);
void SetPainting(bool painting);
@ -214,6 +214,7 @@ class OffScreenRenderWidgetHostView
NativeWindow* native_window_;
OffScreenOutputDevice* software_output_device_;
const bool transparent_;
OnPaintCallback callback_;
int frame_rate_;
@ -221,7 +222,6 @@ class OffScreenRenderWidgetHostView
base::Time last_time_;
const bool transparent_;
float scale_factor_;
bool is_showing_;
gfx::Vector2dF last_scroll_offset_;

View file

@ -6,8 +6,10 @@
namespace atom {
OffScreenWebContentsView::OffScreenWebContentsView(bool transparent)
OffScreenWebContentsView::OffScreenWebContentsView(
bool transparent, const OnPaintCallback& callback)
: transparent_(transparent),
callback_(callback),
web_contents_(nullptr) {
}
@ -66,8 +68,8 @@ content::RenderWidgetHostViewBase*
OffScreenWebContentsView::CreateViewForWidget(
content::RenderWidgetHost* render_widget_host, bool is_guest_view_hack) {
auto relay = NativeWindowRelay::FromWebContents(web_contents_);
view_ = new OffScreenRenderWidgetHostView(transparent_, render_widget_host,
relay->window.get());
view_ = new OffScreenRenderWidgetHostView(
transparent_, callback_, render_widget_host, relay->window.get());
return view_;
}
@ -75,8 +77,8 @@ content::RenderWidgetHostViewBase*
OffScreenWebContentsView::CreateViewForPopupWidget(
content::RenderWidgetHost* render_widget_host) {
auto relay = NativeWindowRelay::FromWebContents(web_contents_);
view_ = new OffScreenRenderWidgetHostView(transparent_, render_widget_host,
relay->window.get());
view_ = new OffScreenRenderWidgetHostView(
transparent_, callback_, render_widget_host, relay->window.get());
return view_;
}

View file

@ -15,12 +15,12 @@ namespace atom {
class OffScreenWebContentsView : public content::WebContentsView,
public content::RenderViewHostDelegateView {
public:
explicit OffScreenWebContentsView(bool transparent);
OffScreenWebContentsView(bool transparent, const OnPaintCallback& callback);
~OffScreenWebContentsView();
void SetWebContents(content::WebContents*);
// content::WebContentsView
// content::WebContentsView:
gfx::NativeView GetNativeView() const override;
gfx::NativeView GetContentNativeView() const override;
gfx::NativeWindow GetTopLevelNativeWindow() const override;
@ -62,6 +62,7 @@ class OffScreenWebContentsView : public content::WebContentsView,
private:
const bool transparent_;
OnPaintCallback callback_;
// Weak refs.
OffScreenRenderWidgetHostView* view_;