mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
Add support for begin frame scheduling and direct rendering when GPU compositing is disabled (issue #1368).
- Always set the browser process VSync rate (frame rate) to CefSettings.windowless_frame_rate. - When the `enable-begin-frame-scheduling` command-line flag is specified the VSync rate for all processes will be synchronized to CefSettings.windowless_frame_rate. This flag cannot be used in combination with windowed rendering. - When the `disable-gpu` and `disable-gpu-compositing` command-line flags are specified the CefRenderHandler::OnPaint method will be called directly from the compositor instead of requiring an additional copy for each frame. - CefRenderHandler::OnPopupSize now passes view coordinates instead of (potentially scaled) pixel coordinates. - Add OSR unit tests for 2x (HiDPI) pixel scaling. - Improve CefRenderHandler documentation. git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@1960 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
123
libcef/browser/software_output_device_osr.cc
Normal file
123
libcef/browser/software_output_device_osr.cc
Normal file
@ -0,0 +1,123 @@
|
||||
// Copyright (c) 2014 The Chromium Embedded Framework Authors.
|
||||
// Portions copyright (c) 2014 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "libcef/browser/software_output_device_osr.h"
|
||||
|
||||
#include "libcef/browser/browser_host_impl.h"
|
||||
#include "libcef/browser/render_widget_host_view_osr.h"
|
||||
#include "libcef/browser/thread_util.h"
|
||||
|
||||
#include "third_party/skia/include/core/SkDevice.h"
|
||||
#include "ui/compositor/compositor.h"
|
||||
#include "ui/gfx/skia_util.h"
|
||||
|
||||
CefSoftwareOutputDeviceOSR::CefSoftwareOutputDeviceOSR(
|
||||
ui::Compositor* compositor,
|
||||
bool transparent,
|
||||
const OnPaintCallback& callback)
|
||||
: transparent_(transparent),
|
||||
callback_(callback),
|
||||
active_(false) {
|
||||
CEF_REQUIRE_UIT();
|
||||
DCHECK(!callback_.is_null());
|
||||
}
|
||||
|
||||
CefSoftwareOutputDeviceOSR::~CefSoftwareOutputDeviceOSR() {
|
||||
CEF_REQUIRE_UIT();
|
||||
}
|
||||
|
||||
void CefSoftwareOutputDeviceOSR::Resize(const gfx::Size& viewport_pixel_size,
|
||||
float scale_factor) {
|
||||
CEF_REQUIRE_UIT();
|
||||
|
||||
scale_factor_ = scale_factor;
|
||||
|
||||
if (viewport_pixel_size_ == viewport_pixel_size)
|
||||
return;
|
||||
|
||||
viewport_pixel_size_ = viewport_pixel_size;
|
||||
|
||||
canvas_.reset(NULL);
|
||||
bitmap_.reset(new SkBitmap);
|
||||
bitmap_->allocN32Pixels(viewport_pixel_size.width(),
|
||||
viewport_pixel_size.height(),
|
||||
!transparent_);
|
||||
if (bitmap_->drawsNothing()) {
|
||||
NOTREACHED();
|
||||
bitmap_.reset(NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
if (transparent_)
|
||||
bitmap_->eraseARGB(0, 0, 0, 0);
|
||||
|
||||
canvas_.reset(new SkCanvas(*bitmap_.get()));
|
||||
}
|
||||
|
||||
SkCanvas* CefSoftwareOutputDeviceOSR::BeginPaint(const gfx::Rect& damage_rect) {
|
||||
CEF_REQUIRE_UIT();
|
||||
DCHECK(canvas_.get());
|
||||
DCHECK(bitmap_.get());
|
||||
|
||||
damage_rect_ = damage_rect;
|
||||
|
||||
return canvas_.get();
|
||||
}
|
||||
|
||||
void CefSoftwareOutputDeviceOSR::EndPaint(cc::SoftwareFrameData* frame_data) {
|
||||
CEF_REQUIRE_UIT();
|
||||
DCHECK(canvas_.get());
|
||||
DCHECK(bitmap_.get());
|
||||
DCHECK(frame_data);
|
||||
|
||||
if (!bitmap_.get())
|
||||
return;
|
||||
|
||||
cc::SoftwareOutputDevice::EndPaint(frame_data);
|
||||
|
||||
if (active_)
|
||||
OnPaint(damage_rect_);
|
||||
}
|
||||
|
||||
void CefSoftwareOutputDeviceOSR::CopyToPixels(const gfx::Rect& rect,
|
||||
void* pixels) {
|
||||
CEF_REQUIRE_UIT();
|
||||
DCHECK(canvas_.get());
|
||||
SkImageInfo info = SkImageInfo::MakeN32Premul(rect.width(), rect.height());
|
||||
canvas_->readPixels(info, pixels, info.minRowBytes(), rect.x(), rect.y());
|
||||
}
|
||||
|
||||
void CefSoftwareOutputDeviceOSR::SetActive(bool active) {
|
||||
if (active == active_)
|
||||
return;
|
||||
active_ = active;
|
||||
|
||||
// Call OnPaint immediately if deactivated while a damage rect is pending.
|
||||
if (!active_ && !pending_damage_rect_.IsEmpty())
|
||||
OnPaint(pending_damage_rect_);
|
||||
}
|
||||
|
||||
void CefSoftwareOutputDeviceOSR::Invalidate(const gfx::Rect& damage_rect) {
|
||||
if (pending_damage_rect_.IsEmpty())
|
||||
pending_damage_rect_ = damage_rect;
|
||||
else
|
||||
pending_damage_rect_.Union(damage_rect);
|
||||
}
|
||||
|
||||
void CefSoftwareOutputDeviceOSR::OnPaint(const gfx::Rect& damage_rect) {
|
||||
gfx::Rect rect = damage_rect;
|
||||
if (!pending_damage_rect_.IsEmpty()) {
|
||||
rect.Union(pending_damage_rect_);
|
||||
pending_damage_rect_.SetRect(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
rect.Intersect(gfx::Rect(viewport_pixel_size_));
|
||||
if (rect.IsEmpty())
|
||||
return;
|
||||
|
||||
SkAutoLockPixels bitmap_pixels_lock(*bitmap_.get());
|
||||
callback_.Run(rect, bitmap_->width(), bitmap_->height(),
|
||||
bitmap_->getPixels());
|
||||
}
|
Reference in New Issue
Block a user