зеркало из https://github.com/electron/electron.git
Refactor osr_output_device
This commit is contained in:
Родитель
9d8e510a55
Коммит
ea8ea1543f
|
@ -314,8 +314,9 @@ WebContents::WebContents(v8::Isolate* isolate,
|
|||
options.Get("transparent", &transparent);
|
||||
|
||||
content::WebContents::CreateParams params(session->browser_context());
|
||||
params.view = new OffScreenWebContentsView(transparent);
|
||||
params.delegate_view = params.view;
|
||||
auto* view = new OffScreenWebContentsView(transparent);
|
||||
params.view = view;
|
||||
params.delegate_view = view;
|
||||
|
||||
web_contents = content::WebContents::Create(params);
|
||||
view->SetWebContents(web_contents);
|
||||
|
@ -609,9 +610,9 @@ void WebContents::DocumentLoadedInFrame(
|
|||
content::RenderFrameHost* render_frame_host) {
|
||||
if (!render_frame_host->GetParent()) {
|
||||
if (IsOffScreen()) {
|
||||
const auto* rwhv = web_contents()->GetRenderWidgetHostView();
|
||||
auto* rwhv = web_contents()->GetRenderWidgetHostView();
|
||||
static_cast<OffScreenRenderWidgetHostView*>(rwhv)->SetPaintCallback(
|
||||
base::Bind(&WebContents::OnPaint, base::Unretained(this), isolate));
|
||||
base::Bind(&WebContents::OnPaint, base::Unretained(this)));
|
||||
}
|
||||
|
||||
Emit("dom-ready");
|
||||
|
@ -1347,19 +1348,20 @@ bool WebContents::IsOffScreen() const {
|
|||
return type_ == OFF_SCREEN;
|
||||
}
|
||||
|
||||
void WebContents::OnPaint(v8::Isolate* isolate, const gfx::Rect& dirty_rect,
|
||||
const gfx::Size& bitmap_size, void* bitmap_pixels) {
|
||||
void WebContents::OnPaint(const gfx::Rect& dirty_rect,
|
||||
const gfx::Size& bitmap_size,
|
||||
void* bitmap_pixels) {
|
||||
v8::MaybeLocal<v8::Object> buffer = node::Buffer::New(
|
||||
isolate, reinterpret_cast<char*>(bitmap_pixels), sizeof(bitmap_pixels));
|
||||
isolate(), reinterpret_cast<char*>(bitmap_pixels), sizeof(bitmap_pixels));
|
||||
if (!buffer.IsEmpty())
|
||||
Emit("paint", damage_rect, buffer.ToLocalChecked(), bitmap_size);
|
||||
Emit("paint", dirty_rect, buffer.ToLocalChecked(), bitmap_size);
|
||||
}
|
||||
|
||||
void WebContents::StartPainting() {
|
||||
if (!IsOffScreen())
|
||||
return;
|
||||
|
||||
const auto* osr_rwhv = static_cast<OffScreenRenderWidgetHostView*>(
|
||||
auto* osr_rwhv = static_cast<OffScreenRenderWidgetHostView*>(
|
||||
web_contents()->GetRenderWidgetHostView());
|
||||
if (osr_rwhv) {
|
||||
osr_rwhv->SetPainting(true);
|
||||
|
@ -1371,7 +1373,7 @@ void WebContents::StopPainting() {
|
|||
if (!IsOffScreen())
|
||||
return;
|
||||
|
||||
const auto* osr_rwhv = static_cast<OffScreenRenderWidgetHostView*>(
|
||||
auto* osr_rwhv = static_cast<OffScreenRenderWidgetHostView*>(
|
||||
web_contents()->GetRenderWidgetHostView());
|
||||
if (osr_rwhv) {
|
||||
osr_rwhv->SetPainting(false);
|
||||
|
@ -1392,7 +1394,7 @@ void WebContents::SetFrameRate(int frame_rate) {
|
|||
if (!IsOffScreen())
|
||||
return;
|
||||
|
||||
const auto* osr_rwhv = static_cast<OffScreenRenderWidgetHostView*>(
|
||||
auto* osr_rwhv = static_cast<OffScreenRenderWidgetHostView*>(
|
||||
web_contents()->GetRenderWidgetHostView());
|
||||
if (osr_rwhv)
|
||||
osr_rwhv->SetFrameRate(frame_rate);
|
||||
|
|
|
@ -158,8 +158,9 @@ class WebContents : public mate::TrackableObject<WebContents>,
|
|||
|
||||
// Methods for offscreen rendering
|
||||
bool IsOffScreen() const;
|
||||
void OnPaint(v8::Isolate* isolate, const gfx::Rect& dirty_rect,
|
||||
const gfx::Size& bitmap_size, void* bitmap_pixels);
|
||||
void OnPaint(const gfx::Rect& dirty_rect,
|
||||
const gfx::Size& bitmap_size,
|
||||
void* bitmap_pixels);
|
||||
void StartPainting();
|
||||
void StopPainting();
|
||||
bool IsPainting() const;
|
||||
|
|
|
@ -10,8 +10,8 @@
|
|||
namespace atom {
|
||||
|
||||
OffScreenOutputDevice::OffScreenOutputDevice(bool transparent,
|
||||
const OnPaintCallback& callback):
|
||||
transparent_(transparent),
|
||||
const OnPaintCallback& callback)
|
||||
: transparent_(transparent),
|
||||
callback_(callback),
|
||||
active_(false) {
|
||||
DCHECK(!callback_.is_null());
|
||||
|
@ -27,21 +27,21 @@ void OffScreenOutputDevice::Resize(
|
|||
if (viewport_pixel_size_ == pixel_size) return;
|
||||
viewport_pixel_size_ = pixel_size;
|
||||
|
||||
canvas_.reset(NULL);
|
||||
canvas_.reset();
|
||||
bitmap_.reset(new SkBitmap);
|
||||
bitmap_->allocN32Pixels(viewport_pixel_size_.width(),
|
||||
viewport_pixel_size_.height(),
|
||||
!transparent_);
|
||||
if (bitmap_->drawsNothing()) {
|
||||
NOTREACHED();
|
||||
bitmap_.reset(NULL);
|
||||
bitmap_.reset();
|
||||
return;
|
||||
}
|
||||
|
||||
if (transparent_)
|
||||
bitmap_->eraseARGB(0, 0, 0, 0);
|
||||
|
||||
canvas_.reset(new SkCanvas(*bitmap_.get()));
|
||||
canvas_.reset(new SkCanvas(*bitmap_));
|
||||
}
|
||||
|
||||
SkCanvas* OffScreenOutputDevice::BeginPaint(const gfx::Rect& damage_rect) {
|
||||
|
@ -71,8 +71,7 @@ void OffScreenOutputDevice::SetActive(bool active) {
|
|||
active_ = active;
|
||||
|
||||
if (active_)
|
||||
OnPaint(gfx::Rect(0, 0, viewport_pixel_size_.width(),
|
||||
viewport_pixel_size_.height()));
|
||||
OnPaint(gfx::Rect(viewport_pixel_size_));
|
||||
}
|
||||
|
||||
void OffScreenOutputDevice::OnPaint(const gfx::Rect& damage_rect) {
|
||||
|
@ -86,9 +85,8 @@ void OffScreenOutputDevice::OnPaint(const gfx::Rect& damage_rect) {
|
|||
if (rect.IsEmpty())
|
||||
return;
|
||||
|
||||
SkAutoLockPixels bitmap_pixels_lock(*bitmap_.get());
|
||||
|
||||
callback_.Run(rect, bitmap_->width(), bitmap_->height(),
|
||||
SkAutoLockPixels bitmap_pixels_lock(*bitmap_);
|
||||
callback_.Run(rect, gfx::Size(bitmap_->width(), bitmap_->height()),
|
||||
bitmap_->getPixels());
|
||||
}
|
||||
|
||||
|
|
|
@ -12,26 +12,25 @@
|
|||
|
||||
namespace atom {
|
||||
|
||||
typedef base::Callback<void(const gfx::Rect&, int, int, void*)> OnPaintCallback;
|
||||
typedef base::Callback<void(const gfx::Rect&,
|
||||
const gfx::Size&, void*)> OnPaintCallback;
|
||||
|
||||
class OffScreenOutputDevice : public cc::SoftwareOutputDevice {
|
||||
public:
|
||||
OffScreenOutputDevice(bool transparent, const OnPaintCallback& callback);
|
||||
~OffScreenOutputDevice();
|
||||
|
||||
// cc::SoftwareOutputDevice:
|
||||
void Resize(const gfx::Size& pixel_size, float scale_factor) override;
|
||||
|
||||
SkCanvas* BeginPaint(const gfx::Rect& damage_rect) override;
|
||||
|
||||
void EndPaint() override;
|
||||
|
||||
void SetActive(bool active);
|
||||
|
||||
void OnPaint(const gfx::Rect& damage_rect);
|
||||
|
||||
private:
|
||||
const bool transparent_;
|
||||
const OnPaintCallback callback_;
|
||||
OnPaintCallback callback_;
|
||||
|
||||
bool active_;
|
||||
|
||||
|
|
|
@ -259,9 +259,9 @@ class AtomCopyFrameGenerator {
|
|||
const gfx::Rect& damage_rect,
|
||||
const SkBitmap& bitmap,
|
||||
std::unique_ptr<SkAutoLockPixels> bitmap_pixels_lock) {
|
||||
uint8_t* pixels = reinterpret_cast<uint8_t*>(bitmap.getPixels());
|
||||
|
||||
view_->OnPaint(damage_rect, bitmap.width(), bitmap.height(), pixels);
|
||||
view_->OnPaint(damage_rect,
|
||||
gfx::Size(bitmap.width(), bitmap.height()),
|
||||
bitmap.getPixels());
|
||||
|
||||
if (frame_retry_count_ > 0)
|
||||
frame_retry_count_ = 0;
|
||||
|
@ -845,15 +845,12 @@ bool OffScreenRenderWidgetHostView::IsAutoResizeEnabled() const {
|
|||
|
||||
void OffScreenRenderWidgetHostView::OnPaint(
|
||||
const gfx::Rect& damage_rect,
|
||||
int bitmap_width,
|
||||
int bitmap_height,
|
||||
const gfx::Size& bitmap_size,
|
||||
void* bitmap_pixels) {
|
||||
TRACE_EVENT0("electron", "OffScreenRenderWidgetHostView::OnPaint");
|
||||
|
||||
if (!callback_.is_null()) {
|
||||
callback_.Run(damage_rect, gfx::Size(bitmap_width, bitmap_height),
|
||||
bitmap_pixels);
|
||||
}
|
||||
if (!callback_.is_null())
|
||||
callback_.Run(damage_rect, bitmap_size, bitmap_pixels);
|
||||
}
|
||||
|
||||
void OffScreenRenderWidgetHostView::SetPainting(bool painting) {
|
||||
|
|
|
@ -198,8 +198,7 @@ class OffScreenRenderWidgetHostView:
|
|||
void SetPaintCallback(const OnPaintCallback& callback);
|
||||
|
||||
void OnPaint(const gfx::Rect& damage_rect,
|
||||
int bitmap_width,
|
||||
int bitmap_height,
|
||||
const gfx::Size& bitmap_size,
|
||||
void* bitmap_pixels);
|
||||
|
||||
void SetPainting(bool painting);
|
||||
|
@ -219,7 +218,7 @@ private:
|
|||
|
||||
OffScreenOutputDevice* software_output_device_;
|
||||
|
||||
const OnPaintCallback callback_;
|
||||
OnPaintCallback callback_;
|
||||
|
||||
int frame_rate_;
|
||||
int frame_rate_threshold_ms_;
|
||||
|
|
|
@ -190,7 +190,7 @@ void WebContentsPreferences::AppendExtraCommandLineSwitches(
|
|||
// Use frame scheduling for offscreen renderers.
|
||||
// TODO(zcbenz): Remove this after Chrome 54, on which it becomes default.
|
||||
bool offscreen;
|
||||
if (web_preferences.Get("offscreen", &offscreen) && offscreen)
|
||||
if (web_preferences.GetBoolean("offscreen", &offscreen) && offscreen)
|
||||
command_line->AppendSwitch(cc::switches::kEnableBeginFrameScheduling);
|
||||
}
|
||||
|
||||
|
|
|
@ -1244,9 +1244,9 @@ describe('browser-window module', function () {
|
|||
assert.equal(w.webContents.getFrameRate(), 60)
|
||||
done()
|
||||
})
|
||||
})
|
||||
w.loadURL('file://' + fixtures + '/api/offscreen-rendering.html')
|
||||
})
|
||||
})
|
||||
|
||||
describe('window.webContents.setFrameRate(frameRate)', function () {
|
||||
it('sets custom frame rate', function (done) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче