adds destructors + more code cleanup

This commit is contained in:
gellert 2016-07-30 00:51:19 +02:00
parent 70656dc991
commit 2190c4dd8d
5 changed files with 95 additions and 203 deletions

View file

@ -17,43 +17,23 @@
#include "base/single_thread_task_runner.h" #include "base/single_thread_task_runner.h"
#include "ui/compositor/layer.h" #include "ui/compositor/layer.h"
#include "ui/compositor/layer_type.h" #include "ui/compositor/layer_type.h"
#include "base/callback_helpers.h"
#include "base/location.h" #include "base/location.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "ui/gfx/native_widget_types.h" #include "ui/gfx/native_widget_types.h"
#include "ui/views/widget/widget.h" #include "ui/views/widget/widget.h"
#include <iostream>
#include <chrono>
#include <thread>
#include "third_party/skia/include/core/SkSurface.h"
#include "third_party/skia/include/core/SkPixmap.h"
#include "cc/output/output_surface_client.h"
#include "cc/output/copy_output_request.h" #include "cc/output/copy_output_request.h"
#include "base/callback_helpers.h"
#include "base/location.h"
#include "base/logging.h"
#include "content/public/browser/browser_thread.h"
#include "cc/scheduler/delay_based_time_source.h" #include "cc/scheduler/delay_based_time_source.h"
#include "content/public/browser/browser_thread.h"
#include <iostream>
const float kDefaultScaleFactor = 1.0; const float kDefaultScaleFactor = 1.0;
// The maximum number of retry counts if frame capture fails.
const int kFrameRetryLimit = 2; const int kFrameRetryLimit = 2;
// When accelerated compositing is enabled and a widget resize is pending,
// we delay further resizes of the UI. The following constant is the maximum
// length of time that we should delay further UI resizes while waiting for a
// resized frame from a renderer.
// const int kResizeLockTimeoutMs = 67; // const int kResizeLockTimeoutMs = 67;
#define CEF_UIT content::BrowserThread::UI
#define CEF_POST_TASK(id, task) \
content::BrowserThread::PostTask(id, FROM_HERE, task)
#define CEF_POST_DELAYED_TASK(id, task, delay_ms) \
content::BrowserThread::PostDelayedTask(id, FROM_HERE, task, \
base::TimeDelta::FromMilliseconds(delay_ms))
namespace atom { namespace atom {
class AtomCopyFrameGenerator { class AtomCopyFrameGenerator {
@ -75,29 +55,25 @@ class AtomCopyFrameGenerator {
if (force_frame && !frame_pending_) if (force_frame && !frame_pending_)
frame_pending_ = true; frame_pending_ = true;
// No frame needs to be generated at this time.
if (!frame_pending_) if (!frame_pending_)
return; return;
// Keep track of |damage_rect| for when the next frame is generated.
if (!damage_rect.IsEmpty()) if (!damage_rect.IsEmpty())
pending_damage_rect_.Union(damage_rect); pending_damage_rect_.Union(damage_rect);
// Don't attempt to generate a frame while one is currently in-progress.
if (frame_in_progress_) { if (frame_in_progress_) {
return; return;
} }
frame_in_progress_ = true; frame_in_progress_ = true;
// Don't exceed the frame rate threshold.
const int64_t frame_rate_delta = const int64_t frame_rate_delta =
(base::TimeTicks::Now() - frame_start_time_).InMilliseconds(); (base::TimeTicks::Now() - frame_start_time_).InMilliseconds();
if (frame_rate_delta < frame_rate_threshold_ms_) { if (frame_rate_delta < frame_rate_threshold_ms_) {
// Generate the frame after the necessary time has passed. content::BrowserThread::PostDelayedTask(content::BrowserThread::UI,
CEF_POST_DELAYED_TASK(CEF_UIT, FROM_HERE,
base::Bind(&AtomCopyFrameGenerator::InternalGenerateCopyFrame, base::Bind(&AtomCopyFrameGenerator::InternalGenerateCopyFrame,
weak_ptr_factory_.GetWeakPtr()), weak_ptr_factory_.GetWeakPtr()), base::TimeDelta::FromMilliseconds(
frame_rate_threshold_ms_ - frame_rate_delta); frame_rate_threshold_ms_ - frame_rate_delta));
return; return;
} }
@ -121,9 +97,6 @@ class AtomCopyFrameGenerator {
const gfx::Rect damage_rect = pending_damage_rect_; const gfx::Rect damage_rect = pending_damage_rect_;
pending_damage_rect_.SetRect(0, 0, 0, 0); pending_damage_rect_.SetRect(0, 0, 0, 0);
// The below code is similar in functionality to
// DelegatedFrameHost::CopyFromCompositingSurface but we reuse the same
// SkBitmap in the GPU codepath and avoid scaling where possible.
std::unique_ptr<cc::CopyOutputRequest> request = std::unique_ptr<cc::CopyOutputRequest> request =
cc::CopyOutputRequest::CreateRequest(base::Bind( cc::CopyOutputRequest::CreateRequest(base::Bind(
&AtomCopyFrameGenerator::CopyFromCompositingSurfaceHasResult, &AtomCopyFrameGenerator::CopyFromCompositingSurfaceHasResult,
@ -139,7 +112,6 @@ class AtomCopyFrameGenerator {
void CopyFromCompositingSurfaceHasResult( void CopyFromCompositingSurfaceHasResult(
const gfx::Rect& damage_rect, const gfx::Rect& damage_rect,
std::unique_ptr<cc::CopyOutputResult> result) { std::unique_ptr<cc::CopyOutputResult> result) {
// std::cout << "has result" << std::endl;
if (result->IsEmpty() || result->size().IsEmpty() || if (result->IsEmpty() || result->size().IsEmpty() ||
!view_->render_widget_host()) { !view_->render_widget_host()) {
OnCopyFrameCaptureFailure(damage_rect); OnCopyFrameCaptureFailure(damage_rect);
@ -172,7 +144,6 @@ class AtomCopyFrameGenerator {
if (!bitmap_ || if (!bitmap_ ||
bitmap_size.width() != result_size.width() || bitmap_size.width() != result_size.width() ||
bitmap_size.height() != result_size.height()) { bitmap_size.height() != result_size.height()) {
// Create a new bitmap if the size has changed.
bitmap_.reset(new SkBitmap); bitmap_.reset(new SkBitmap);
bitmap_->allocN32Pixels(result_size.width(), bitmap_->allocN32Pixels(result_size.width(),
result_size.height(), result_size.height(),
@ -225,7 +196,6 @@ class AtomCopyFrameGenerator {
std::unique_ptr<SkBitmap> bitmap, std::unique_ptr<SkBitmap> bitmap,
std::unique_ptr<SkAutoLockPixels> bitmap_pixels_lock, std::unique_ptr<SkAutoLockPixels> bitmap_pixels_lock,
bool result) { bool result) {
// This method may be called after the view has been deleted.
gpu::SyncToken sync_token; gpu::SyncToken sync_token;
if (result) { if (result) {
display_compositor::GLHelper* gl_helper = display_compositor::GLHelper* gl_helper =
@ -251,7 +221,6 @@ class AtomCopyFrameGenerator {
std::unique_ptr<SkBitmap> bitmap, std::unique_ptr<SkBitmap> bitmap,
std::unique_ptr<SkAutoLockPixels> bitmap_pixels_lock, std::unique_ptr<SkAutoLockPixels> bitmap_pixels_lock,
bool result) { bool result) {
// Restore ownership of the bitmap to the view.
DCHECK(!bitmap_); DCHECK(!bitmap_);
bitmap_ = std::move(bitmap); bitmap_ = std::move(bitmap);
@ -282,7 +251,6 @@ class AtomCopyFrameGenerator {
void OnCopyFrameCaptureFailure( void OnCopyFrameCaptureFailure(
const gfx::Rect& damage_rect) { const gfx::Rect& damage_rect) {
// Retry with the same |damage_rect|.
pending_damage_rect_.Union(damage_rect); pending_damage_rect_.Union(damage_rect);
const bool force_frame = (++frame_retry_count_ <= kFrameRetryLimit); const bool force_frame = (++frame_retry_count_ <= kFrameRetryLimit);
@ -293,12 +261,10 @@ class AtomCopyFrameGenerator {
const gfx::Rect& damage_rect, const gfx::Rect& damage_rect,
const SkBitmap& bitmap, const SkBitmap& bitmap,
std::unique_ptr<SkAutoLockPixels> bitmap_pixels_lock) { std::unique_ptr<SkAutoLockPixels> bitmap_pixels_lock) {
uint8_t* pixels = reinterpret_cast<uint8_t*>(bitmap.getPixels()); uint8_t* pixels = reinterpret_cast<uint8_t*>(bitmap.getPixels());
view_->OnPaint(damage_rect, bitmap.width(), bitmap.height(), pixels); view_->OnPaint(damage_rect, bitmap.width(), bitmap.height(), pixels);
// Reset the frame retry count on successful frame generation.
if (frame_retry_count_ > 0) if (frame_retry_count_ > 0)
frame_retry_count_ = 0; frame_retry_count_ = 0;
@ -309,9 +275,7 @@ class AtomCopyFrameGenerator {
frame_in_progress_ = false; frame_in_progress_ = false;
if (frame_pending_) { if (frame_pending_) {
// Another frame was requested while the current frame was in-progress. content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
// Generate the pending frame now.
CEF_POST_TASK(CEF_UIT,
base::Bind(&AtomCopyFrameGenerator::GenerateCopyFrame, base::Bind(&AtomCopyFrameGenerator::GenerateCopyFrame,
weak_ptr_factory_.GetWeakPtr(), weak_ptr_factory_.GetWeakPtr(),
force_frame, force_frame,
@ -336,8 +300,6 @@ class AtomCopyFrameGenerator {
DISALLOW_COPY_AND_ASSIGN(AtomCopyFrameGenerator); DISALLOW_COPY_AND_ASSIGN(AtomCopyFrameGenerator);
}; };
// Used to control the VSync rate in subprocesses when BeginFrame scheduling is
// enabled.
class AtomBeginFrameTimer : public cc::DelayBasedTimeSourceClient { class AtomBeginFrameTimer : public cc::DelayBasedTimeSourceClient {
public: public:
AtomBeginFrameTimer(int frame_rate_threshold_ms, AtomBeginFrameTimer(int frame_rate_threshold_ms,
@ -345,7 +307,7 @@ class AtomBeginFrameTimer : public cc::DelayBasedTimeSourceClient {
: callback_(callback) { : callback_(callback) {
time_source_ = cc::DelayBasedTimeSource::Create( time_source_ = cc::DelayBasedTimeSource::Create(
base::TimeDelta::FromMilliseconds(frame_rate_threshold_ms), base::TimeDelta::FromMilliseconds(frame_rate_threshold_ms),
content::BrowserThread::GetMessageLoopProxyForThread(CEF_UIT).get()); content::BrowserThread::GetMessageLoopProxyForThread(content::BrowserThread::UI).get());
time_source_->SetClient(this); time_source_->SetClient(this);
} }
@ -364,7 +326,6 @@ class AtomBeginFrameTimer : public cc::DelayBasedTimeSourceClient {
} }
private: private:
// cc::TimerSourceClient implementation.
void OnTimerTick() override { void OnTimerTick() override {
callback_.Run(); callback_.Run();
} }
@ -398,7 +359,6 @@ OffScreenRenderWidgetHostView::OffScreenRenderWidgetHostView(
#endif #endif
#if !defined(OS_MACOSX) #if !defined(OS_MACOSX)
// On OS X the ui::Compositor is created/owned by the platform view.
compositor_widget_ = native_window_->GetAcceleratedWidget(); compositor_widget_ = native_window_->GetAcceleratedWidget();
compositor_.reset( compositor_.reset(
new ui::Compositor(content::GetContextFactory(), new ui::Compositor(content::GetContextFactory(),
@ -411,27 +371,38 @@ OffScreenRenderWidgetHostView::OffScreenRenderWidgetHostView(
ResizeRootLayer(); ResizeRootLayer();
} }
OffScreenRenderWidgetHostView::~OffScreenRenderWidgetHostView() {
if (is_showing_)
delegated_frame_host_->WasHidden();
delegated_frame_host_->ResetCompositor();
DestroyPlatformWidget();
if (copy_frame_generator_.get())
copy_frame_generator_.reset(NULL);
delegated_frame_host_.reset(NULL);
compositor_.reset(NULL);
root_layer_.reset(NULL);
}
void OffScreenRenderWidgetHostView::ResizeRootLayer() { void OffScreenRenderWidgetHostView::ResizeRootLayer() {
SetFrameRate(); SetFrameRate();
// const float orgScaleFactor = scale_factor_; const float orgScaleFactor = scale_factor_;
// SetDeviceScaleFactor(); const bool scaleFactorDidChange = (orgScaleFactor != scale_factor_);
// const bool scaleFactorDidChange = (orgScaleFactor != scale_factor_);
// gfx::Size size = GetViewBounds().size();
// gfx::Size size;
// if (!IsPopupWidget()) if (!scaleFactorDidChange && size == root_layer_->bounds().size())
// size = GetViewBounds().size(); return;
// else
// size = popup_position_.size(); const gfx::Size& size_in_pixels =
// gfx::ConvertSizeToPixel(scale_factor_, size);
// if (!scaleFactorDidChange && size == root_layer_->bounds().size())
// return; root_layer_->SetBounds(gfx::Rect(size));
// compositor_->SetScaleAndSize(scale_factor_, size_in_pixels);
// const gfx::Size& size_in_pixels =
// gfx::ConvertSizeToPixel(scale_factor_, size);
//
// root_layer_->SetBounds(gfx::Rect(size));
// compositor_->SetScaleAndSize(scale_factor_, size_in_pixels);
} }
void OffScreenRenderWidgetHostView::OnBeginFrameTimerTick() { void OffScreenRenderWidgetHostView::OnBeginFrameTimerTick() {
@ -445,7 +416,6 @@ void OffScreenRenderWidgetHostView::SendBeginFrame(base::TimeTicks frame_time,
base::TimeDelta vsync_period) { base::TimeDelta vsync_period) {
base::TimeTicks display_time = frame_time + vsync_period; base::TimeTicks display_time = frame_time + vsync_period;
// TODO(brianderson): Use adaptive draw-time estimation.
base::TimeDelta estimated_browser_composite_time = base::TimeDelta estimated_browser_composite_time =
base::TimeDelta::FromMicroseconds( base::TimeDelta::FromMicroseconds(
(1.0f * base::Time::kMicrosecondsPerSecond) / (3.0f * 60)); (1.0f * base::Time::kMicrosecondsPerSecond) / (3.0f * 60));
@ -458,25 +428,13 @@ void OffScreenRenderWidgetHostView::SendBeginFrame(base::TimeTicks frame_time,
vsync_period, cc::BeginFrameArgs::NORMAL))); vsync_period, cc::BeginFrameArgs::NORMAL)));
} }
void OffScreenRenderWidgetHostView::SetPaintCallback(const OnPaintCallback* callback) { void OffScreenRenderWidgetHostView::SetPaintCallback(
const OnPaintCallback* callback) {
callback_.reset(callback); callback_.reset(callback);
} }
OffScreenRenderWidgetHostView::~OffScreenRenderWidgetHostView() { bool OffScreenRenderWidgetHostView::OnMessageReceived(
// std::cout << "~OffScreenRenderWidgetHostView" << std::endl; const IPC::Message& message) {
if (is_showing_)
delegated_frame_host_->WasHidden();
delegated_frame_host_->ResetCompositor();
delegated_frame_host_.reset(NULL);
compositor_.reset(NULL);
root_layer_.reset(NULL);
}
bool OffScreenRenderWidgetHostView::OnMessageReceived(const IPC::Message& message) {
// std::cout << "OnMessageReceived" << std::endl;
bool handled = true; bool handled = true;
IPC_BEGIN_MESSAGE_MAP(OffScreenRenderWidgetHostView, message) IPC_BEGIN_MESSAGE_MAP(OffScreenRenderWidgetHostView, message)
IPC_MESSAGE_HANDLER(ViewHostMsg_SetNeedsBeginFrames, IPC_MESSAGE_HANDLER(ViewHostMsg_SetNeedsBeginFrames,
@ -490,20 +448,16 @@ bool OffScreenRenderWidgetHostView::OnMessageReceived(const IPC::Message& messag
} }
void OffScreenRenderWidgetHostView::InitAsChild(gfx::NativeView) { void OffScreenRenderWidgetHostView::InitAsChild(gfx::NativeView) {
// std::cout << "InitAsChild" << std::endl;
} }
content::RenderWidgetHost* OffScreenRenderWidgetHostView::GetRenderWidgetHost() const { content::RenderWidgetHost* OffScreenRenderWidgetHostView::GetRenderWidgetHost()
// std::cout << "GetRenderWidgetHost" << std::endl; const {
return render_widget_host_; return render_widget_host_;
} }
void OffScreenRenderWidgetHostView::SetSize(const gfx::Size& size) { void OffScreenRenderWidgetHostView::SetSize(const gfx::Size& size) {
// std::cout << "SetSize" << std::endl;
size_ = size; size_ = size;
// std::cout << size.width() << "x" << size.height() << std::endl;
const gfx::Size& size_in_pixels = const gfx::Size& size_in_pixels =
gfx::ConvertSizeToPixel(scale_factor_, size); gfx::ConvertSizeToPixel(scale_factor_, size);
@ -512,45 +466,37 @@ void OffScreenRenderWidgetHostView::SetSize(const gfx::Size& size) {
} }
void OffScreenRenderWidgetHostView::SetBounds(const gfx::Rect& new_bounds) { void OffScreenRenderWidgetHostView::SetBounds(const gfx::Rect& new_bounds) {
// std::cout << "SetBounds" << std::endl;
} }
gfx::Vector2dF OffScreenRenderWidgetHostView::GetLastScrollOffset() const { gfx::Vector2dF OffScreenRenderWidgetHostView::GetLastScrollOffset() const {
// std::cout << "GetLastScrollOffset" << std::endl;
return last_scroll_offset_; return last_scroll_offset_;
} }
gfx::NativeView OffScreenRenderWidgetHostView::GetNativeView() const { gfx::NativeView OffScreenRenderWidgetHostView::GetNativeView() const {
// std::cout << "GetNativeView" << std::endl;
return gfx::NativeView(); return gfx::NativeView();
} }
gfx::NativeViewAccessible OffScreenRenderWidgetHostView::GetNativeViewAccessible() { gfx::NativeViewAccessible
// std::cout << "GetNativeViewAccessible" << std::endl; OffScreenRenderWidgetHostView::GetNativeViewAccessible() {
return gfx::NativeViewAccessible(); return gfx::NativeViewAccessible();
} }
ui::TextInputClient* OffScreenRenderWidgetHostView::GetTextInputClient() { ui::TextInputClient* OffScreenRenderWidgetHostView::GetTextInputClient() {
// std::cout << "GetTextInputClient" << std::endl;
return nullptr; return nullptr;
} }
void OffScreenRenderWidgetHostView::Focus() { void OffScreenRenderWidgetHostView::Focus() {
// std::cout << "Focus" << std::endl;
} }
bool OffScreenRenderWidgetHostView::HasFocus() const { bool OffScreenRenderWidgetHostView::HasFocus() const {
// std::cout << "HasFocus" << std::endl;
return false; return false;
} }
bool OffScreenRenderWidgetHostView::IsSurfaceAvailableForCopy() const { bool OffScreenRenderWidgetHostView::IsSurfaceAvailableForCopy() const {
// std::cout << "IsSurfaceAvailableForCopy" << std::endl;
return delegated_frame_host_->CanCopyToBitmap(); return delegated_frame_host_->CanCopyToBitmap();
} }
void OffScreenRenderWidgetHostView::Show() { void OffScreenRenderWidgetHostView::Show() {
// std::cout << "Show" << std::endl;
if (is_showing_) if (is_showing_)
return; return;
@ -562,7 +508,6 @@ void OffScreenRenderWidgetHostView::Show() {
} }
void OffScreenRenderWidgetHostView::Hide() { void OffScreenRenderWidgetHostView::Hide() {
// std::cout << "Hide" << std::endl;
if (!is_showing_) if (!is_showing_)
return; return;
@ -574,49 +519,36 @@ void OffScreenRenderWidgetHostView::Hide() {
} }
bool OffScreenRenderWidgetHostView::IsShowing() { bool OffScreenRenderWidgetHostView::IsShowing() {
// std::cout << "IsShowing" << std::endl;
return is_showing_; return is_showing_;
} }
gfx::Rect OffScreenRenderWidgetHostView::GetViewBounds() const { gfx::Rect OffScreenRenderWidgetHostView::GetViewBounds() const {
// std::cout << "GetViewBounds" << std::endl;
// std::cout << size_.width() << "x" << size_.height() << std::endl;
return gfx::Rect(size_); return gfx::Rect(size_);
} }
gfx::Size OffScreenRenderWidgetHostView::GetVisibleViewportSize() const { gfx::Size OffScreenRenderWidgetHostView::GetVisibleViewportSize() const {
// std::cout << "GetVisibleViewportSize" << std::endl;
// std::cout << size_.width() << "x" << size_.height() << std::endl;
return size_; return size_;
} }
void OffScreenRenderWidgetHostView::SetInsets(const gfx::Insets& insets) { void OffScreenRenderWidgetHostView::SetInsets(const gfx::Insets& insets) {
// std::cout << "SetInsets" << std::endl;
} }
bool OffScreenRenderWidgetHostView::LockMouse() { bool OffScreenRenderWidgetHostView::LockMouse() {
// std::cout << "LockMouse" << std::endl;
return false; return false;
} }
void OffScreenRenderWidgetHostView::UnlockMouse() { void OffScreenRenderWidgetHostView::UnlockMouse() {
// std::cout << "UnlockMouse" << std::endl;
} }
bool OffScreenRenderWidgetHostView::GetScreenColorProfile(std::vector<char>*) { bool OffScreenRenderWidgetHostView::GetScreenColorProfile(std::vector<char>*) {
// std::cout << "GetScreenColorProfile" << std::endl;
return false; return false;
} }
void OffScreenRenderWidgetHostView::OnSwapCompositorFrame( void OffScreenRenderWidgetHostView::OnSwapCompositorFrame(
uint32_t output_surface_id, uint32_t output_surface_id,
std::unique_ptr<cc::CompositorFrame> frame) { std::unique_ptr<cc::CompositorFrame> frame) {
// base::Time now = base::Time::Now(); TRACE_EVENT0("electron",
// std::cout << "OnSwapCompositorFrame " << (now - last_time_).InMilliseconds() << " ms" << std::endl; "OffScreenRenderWidgetHostView::OnSwapCompositorFrame");
// last_time_ = now;
TRACE_EVENT0("electron", "OffScreenRenderWidgetHostView::OnSwapCompositorFrame");
// std::cout << output_surface_id << std::endl;
if (frame->metadata.root_scroll_offset != last_scroll_offset_) { if (frame->metadata.root_scroll_offset != last_scroll_offset_) {
last_scroll_offset_ = frame->metadata.root_scroll_offset; last_scroll_offset_ = frame->metadata.root_scroll_offset;
@ -652,59 +584,48 @@ void OffScreenRenderWidgetHostView::OnSwapCompositorFrame(
} }
void OffScreenRenderWidgetHostView::ClearCompositorFrame() { void OffScreenRenderWidgetHostView::ClearCompositorFrame() {
// std::cout << "ClearCompositorFrame" << std::endl;
delegated_frame_host_->ClearDelegatedFrame(); delegated_frame_host_->ClearDelegatedFrame();
} }
void OffScreenRenderWidgetHostView::InitAsPopup( void OffScreenRenderWidgetHostView::InitAsPopup(
content::RenderWidgetHostView *, const gfx::Rect &) { content::RenderWidgetHostView *, const gfx::Rect &) {
// std::cout << "InitAsPopup" << std::endl;
} }
void OffScreenRenderWidgetHostView::InitAsFullscreen(content::RenderWidgetHostView *) { void OffScreenRenderWidgetHostView::InitAsFullscreen(
// std::cout << "InitAsFullscreen" << std::endl; content::RenderWidgetHostView *) {
} }
void OffScreenRenderWidgetHostView::UpdateCursor(const content::WebCursor &) { void OffScreenRenderWidgetHostView::UpdateCursor(const content::WebCursor &) {
// std::cout << "UpdateCursor" << std::endl;
} }
void OffScreenRenderWidgetHostView::SetIsLoading(bool loading) { void OffScreenRenderWidgetHostView::SetIsLoading(bool loading) {
// std::cout << "SetIsLoading" << std::endl;
} }
void OffScreenRenderWidgetHostView::TextInputStateChanged( void OffScreenRenderWidgetHostView::TextInputStateChanged(
const content::TextInputState& params) { const content::TextInputState& params) {
// std::cout << "TextInputStateChanged" << std::endl;
} }
void OffScreenRenderWidgetHostView::ImeCancelComposition() { void OffScreenRenderWidgetHostView::ImeCancelComposition() {
// std::cout << "ImeCancelComposition" << std::endl;
} }
void OffScreenRenderWidgetHostView::RenderProcessGone(base::TerminationStatus,int) { void OffScreenRenderWidgetHostView::RenderProcessGone(base::TerminationStatus,int) {
// std::cout << "RenderProcessGone" << std::endl;
Destroy(); Destroy();
} }
void OffScreenRenderWidgetHostView::Destroy() { void OffScreenRenderWidgetHostView::Destroy() {
// std::cout << "Destroy" << std::endl;
} }
void OffScreenRenderWidgetHostView::SetTooltipText(const base::string16 &) { void OffScreenRenderWidgetHostView::SetTooltipText(const base::string16 &) {
// std::cout << "SetTooltipText" << std::endl;
} }
void OffScreenRenderWidgetHostView::SelectionBoundsChanged( void OffScreenRenderWidgetHostView::SelectionBoundsChanged(
const ViewHostMsg_SelectionBounds_Params &) { const ViewHostMsg_SelectionBounds_Params &) {
// std::cout << "SelectionBoundsChanged" << std::endl;
} }
void OffScreenRenderWidgetHostView::CopyFromCompositingSurface(const gfx::Rect& src_subrect, void OffScreenRenderWidgetHostView::CopyFromCompositingSurface(const gfx::Rect& src_subrect,
const gfx::Size& dst_size, const gfx::Size& dst_size,
const content::ReadbackRequestCallback& callback, const content::ReadbackRequestCallback& callback,
const SkColorType preferred_color_type) { const SkColorType preferred_color_type) {
// std::cout << "CopyFromCompositingSurface" << std::endl;
delegated_frame_host_->CopyFromCompositingSurface( delegated_frame_host_->CopyFromCompositingSurface(
src_subrect, dst_size, callback, preferred_color_type); src_subrect, dst_size, callback, preferred_color_type);
} }
@ -713,35 +634,28 @@ void OffScreenRenderWidgetHostView::CopyFromCompositingSurfaceToVideoFrame(
const gfx::Rect& src_subrect, const gfx::Rect& src_subrect,
const scoped_refptr<media::VideoFrame>& target, const scoped_refptr<media::VideoFrame>& target,
const base::Callback<void (const gfx::Rect&, bool)>& callback) { const base::Callback<void (const gfx::Rect&, bool)>& callback) {
// std::cout << "CopyFromCompositingSurfaceToVideoFrame" << std::endl;
delegated_frame_host_->CopyFromCompositingSurfaceToVideoFrame( delegated_frame_host_->CopyFromCompositingSurfaceToVideoFrame(
src_subrect, target, callback); src_subrect, target, callback);
} }
bool OffScreenRenderWidgetHostView::CanCopyToVideoFrame() const { bool OffScreenRenderWidgetHostView::CanCopyToVideoFrame() const {
// std::cout << "CanCopyToVideoFrame" << std::endl;
return delegated_frame_host_->CanCopyToVideoFrame(); return delegated_frame_host_->CanCopyToVideoFrame();
} }
void OffScreenRenderWidgetHostView::BeginFrameSubscription( void OffScreenRenderWidgetHostView::BeginFrameSubscription(
std::unique_ptr<content::RenderWidgetHostViewFrameSubscriber> subscriber) { std::unique_ptr<content::RenderWidgetHostViewFrameSubscriber> subscriber) {
// std::cout << "BeginFrameSubscription" << std::endl;
delegated_frame_host_->BeginFrameSubscription(std::move(subscriber)); delegated_frame_host_->BeginFrameSubscription(std::move(subscriber));
} }
void OffScreenRenderWidgetHostView::EndFrameSubscription() { void OffScreenRenderWidgetHostView::EndFrameSubscription() {
// std::cout << "EndFrameSubscription" << std::endl;
delegated_frame_host_->EndFrameSubscription(); delegated_frame_host_->EndFrameSubscription();
} }
bool OffScreenRenderWidgetHostView::HasAcceleratedSurface(const gfx::Size &) { bool OffScreenRenderWidgetHostView::HasAcceleratedSurface(const gfx::Size &) {
// std::cout << "HasAcceleratedSurface" << std::endl;
return false; return false;
} }
void OffScreenRenderWidgetHostView::GetScreenInfo(blink::WebScreenInfo* results) { void OffScreenRenderWidgetHostView::GetScreenInfo(blink::WebScreenInfo* results) {
// std::cout << "GetScreenInfo" << std::endl;
// std::cout << size_.width() << "x" << size_.height() << std::endl;
results->rect = gfx::Rect(size_); results->rect = gfx::Rect(size_);
results->availableRect = gfx::Rect(size_); results->availableRect = gfx::Rect(size_);
results->depth = 24; results->depth = 24;
@ -752,86 +666,68 @@ void OffScreenRenderWidgetHostView::GetScreenInfo(blink::WebScreenInfo* results)
} }
bool OffScreenRenderWidgetHostView::GetScreenColorProfile(blink::WebVector<char>*) { bool OffScreenRenderWidgetHostView::GetScreenColorProfile(blink::WebVector<char>*) {
// std::cout << "GetScreenColorProfile" << std::endl;
return false; return false;
} }
gfx::Rect OffScreenRenderWidgetHostView::GetBoundsInRootWindow() { gfx::Rect OffScreenRenderWidgetHostView::GetBoundsInRootWindow() {
// std::cout << "GetBoundsInRootWindow" << std::endl;
// std::cout << size_.width() << "x" << size_.height() << std::endl;
return gfx::Rect(size_); return gfx::Rect(size_);
} }
void OffScreenRenderWidgetHostView::LockCompositingSurface() { void OffScreenRenderWidgetHostView::LockCompositingSurface() {
// std::cout << "LockCompositingSurface" << std::endl;
} }
void OffScreenRenderWidgetHostView::UnlockCompositingSurface() { void OffScreenRenderWidgetHostView::UnlockCompositingSurface() {
// std::cout << "UnlockCompositingSurface" << std::endl;
} }
void OffScreenRenderWidgetHostView::ImeCompositionRangeChanged( void OffScreenRenderWidgetHostView::ImeCompositionRangeChanged(
const gfx::Range &, const std::vector<gfx::Rect>&) { const gfx::Range &, const std::vector<gfx::Rect>&) {
// std::cout << "ImeCompositionRangeChanged" << std::endl;
} }
gfx::Size OffScreenRenderWidgetHostView::GetPhysicalBackingSize() const { gfx::Size OffScreenRenderWidgetHostView::GetPhysicalBackingSize() const {
// std::cout << "GetPhysicalBackingSize" << std::endl;
return size_; return size_;
} }
gfx::Size OffScreenRenderWidgetHostView::GetRequestedRendererSize() const { gfx::Size OffScreenRenderWidgetHostView::GetRequestedRendererSize() const {
// std::cout << "GetRequestedRendererSize" << std::endl;
return size_; return size_;
} }
int OffScreenRenderWidgetHostView::DelegatedFrameHostGetGpuMemoryBufferClientId() const { int OffScreenRenderWidgetHostView::DelegatedFrameHostGetGpuMemoryBufferClientId() const {
// std::cout << "DelegatedFrameHostGetGpuMemoryBufferClientId" << std::endl;
return render_widget_host_->GetProcess()->GetID(); return render_widget_host_->GetProcess()->GetID();
} }
ui::Layer* OffScreenRenderWidgetHostView::DelegatedFrameHostGetLayer() const { ui::Layer* OffScreenRenderWidgetHostView::DelegatedFrameHostGetLayer() const {
// std::cout << "DelegatedFrameHostGetLayer" << std::endl;
return const_cast<ui::Layer*>(root_layer_.get()); return const_cast<ui::Layer*>(root_layer_.get());
} }
bool OffScreenRenderWidgetHostView::DelegatedFrameHostIsVisible() const { bool OffScreenRenderWidgetHostView::DelegatedFrameHostIsVisible() const {
// std::cout << "DelegatedFrameHostIsVisible" << std::endl;
// std::cout << !render_widget_host_->is_hidden() << std::endl;
return !render_widget_host_->is_hidden(); return !render_widget_host_->is_hidden();
} }
SkColor OffScreenRenderWidgetHostView::DelegatedFrameHostGetGutterColor(SkColor color) const { SkColor OffScreenRenderWidgetHostView::DelegatedFrameHostGetGutterColor(
// std::cout << "DelegatedFrameHostGetGutterColor" << std::endl; SkColor color) const {
return color; return color;
} }
gfx::Size OffScreenRenderWidgetHostView::DelegatedFrameHostDesiredSizeInDIP() const { gfx::Size OffScreenRenderWidgetHostView::DelegatedFrameHostDesiredSizeInDIP()
// std::cout << "DelegatedFrameHostDesiredSizeInDIP" << std::endl; const {
// std::cout << size_.width() << "x" << size_.height() << std::endl;
return size_; return size_;
} }
bool OffScreenRenderWidgetHostView::DelegatedFrameCanCreateResizeLock() const { bool OffScreenRenderWidgetHostView::DelegatedFrameCanCreateResizeLock() const {
// std::cout << "DelegatedFrameCanCreateResizeLock" << std::endl;
return false; return false;
} }
std::unique_ptr<content::ResizeLock> std::unique_ptr<content::ResizeLock>
OffScreenRenderWidgetHostView::DelegatedFrameHostCreateResizeLock(bool) { OffScreenRenderWidgetHostView::DelegatedFrameHostCreateResizeLock(bool) {
// std::cout << "DelegatedFrameHostCreateResizeLock" << std::endl;
return nullptr; return nullptr;
} }
void OffScreenRenderWidgetHostView::DelegatedFrameHostResizeLockWasReleased() { void OffScreenRenderWidgetHostView::DelegatedFrameHostResizeLockWasReleased() {
// std::cout << "DelegatedFrameHostResizeLockWasReleased" << std::endl;
return render_widget_host_->WasResized(); return render_widget_host_->WasResized();
} }
void OffScreenRenderWidgetHostView::DelegatedFrameHostSendCompositorSwapAck( void OffScreenRenderWidgetHostView::DelegatedFrameHostSendCompositorSwapAck(
int output_surface_id, const cc::CompositorFrameAck& ack) { int output_surface_id, const cc::CompositorFrameAck& ack) {
// std::cout << "DelegatedFrameHostSendCompositorSwapAck" << std::endl;
// std::cout << output_surface_id << std::endl;
render_widget_host_->Send(new ViewMsg_SwapCompositorFrameAck( render_widget_host_->Send(new ViewMsg_SwapCompositorFrameAck(
render_widget_host_->GetRoutingID(), render_widget_host_->GetRoutingID(),
output_surface_id, ack)); output_surface_id, ack));
@ -839,21 +735,17 @@ void OffScreenRenderWidgetHostView::DelegatedFrameHostSendCompositorSwapAck(
void OffScreenRenderWidgetHostView::DelegatedFrameHostSendReclaimCompositorResources( void OffScreenRenderWidgetHostView::DelegatedFrameHostSendReclaimCompositorResources(
int output_surface_id, const cc::CompositorFrameAck& ack) { int output_surface_id, const cc::CompositorFrameAck& ack) {
// std::cout << "DelegatedFrameHostSendReclaimCompositorResources" << std::endl;
// std::cout << output_surface_id << std::endl;
render_widget_host_->Send(new ViewMsg_ReclaimCompositorResources( render_widget_host_->Send(new ViewMsg_ReclaimCompositorResources(
render_widget_host_->GetRoutingID(), render_widget_host_->GetRoutingID(),
output_surface_id, ack)); output_surface_id, ack));
} }
void OffScreenRenderWidgetHostView::DelegatedFrameHostOnLostCompositorResources() { void OffScreenRenderWidgetHostView::DelegatedFrameHostOnLostCompositorResources() {
// std::cout << "DelegatedFrameHostOnLostCompositorResources" << std::endl;
render_widget_host_->ScheduleComposite(); render_widget_host_->ScheduleComposite();
} }
void OffScreenRenderWidgetHostView::DelegatedFrameHostUpdateVSyncParameters( void OffScreenRenderWidgetHostView::DelegatedFrameHostUpdateVSyncParameters(
const base::TimeTicks& timebase, const base::TimeDelta& interval) { const base::TimeTicks& timebase, const base::TimeDelta& interval) {
// std::cout << "DelegatedFrameHostUpdateVSyncParameters" << std::endl;
render_widget_host_->UpdateVSyncParameters(timebase, interval); render_widget_host_->UpdateVSyncParameters(timebase, interval);
} }
@ -877,18 +769,15 @@ void OffScreenRenderWidgetHostView::OnSetNeedsBeginFrames(bool enabled) {
if (software_output_device_) { if (software_output_device_) {
software_output_device_->SetActive(enabled); software_output_device_->SetActive(enabled);
} }
// std::cout << "OnSetNeedsBeginFrames" << enabled << std::endl;
} }
void OffScreenRenderWidgetHostView::SetFrameRate() { void OffScreenRenderWidgetHostView::SetFrameRate() {
// Only set the frame rate one time. if (frame_rate_threshold_ms_ != 0)
// if (frame_rate_threshold_ms_ != 0) return;
// return;
const int frame_rate = 60; const int frame_rate = 60;
frame_rate_threshold_ms_ = 1000 / frame_rate; frame_rate_threshold_ms_ = 1000 / frame_rate;
// Configure the VSync interval for the browser process.
compositor_->vsync_manager()->SetAuthoritativeVSyncInterval( compositor_->vsync_manager()->SetAuthoritativeVSyncInterval(
base::TimeDelta::FromMilliseconds(frame_rate_threshold_ms_)); base::TimeDelta::FromMilliseconds(frame_rate_threshold_ms_));

View file

@ -15,18 +15,15 @@
#include "content/browser/renderer_host/render_widget_host_impl.h" #include "content/browser/renderer_host/render_widget_host_impl.h"
#include "cc/output/compositor_frame.h" #include "cc/output/compositor_frame.h"
#include "ui/gfx/geometry/point.h" #include "ui/gfx/geometry/point.h"
#include "base/process/kill.h"
#include "base/threading/thread.h" #include "base/threading/thread.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "ui/compositor/compositor.h" #include "ui/compositor/compositor.h"
#include "ui/compositor/layer_delegate.h" #include "ui/compositor/layer_delegate.h"
#include "ui/compositor/layer_owner.h" #include "ui/compositor/layer_owner.h"
#include "ui/base/ime/text_input_client.h" #include "ui/base/ime/text_input_client.h"
#include "base/process/kill.h"
#include "cc/output/software_output_device.h" #include "atom/browser/osr_output_device.h"
#include "cc/output/output_surface.h"
#include "cc/output/output_surface_client.h"
#include "cc/scheduler/begin_frame_source.h"
#if defined(OS_WIN) #if defined(OS_WIN)
#include <windows.h> #include <windows.h>
@ -38,8 +35,6 @@
#include "ui/accelerated_widget_mac/accelerated_widget_mac.h" #include "ui/accelerated_widget_mac/accelerated_widget_mac.h"
#endif #endif
#include "atom/browser/osr_output_device.h"
#if defined(OS_MACOSX) #if defined(OS_MACOSX)
#ifdef __OBJC__ #ifdef __OBJC__
@class CALayer; @class CALayer;
@ -57,8 +52,8 @@ namespace atom {
class AtomCopyFrameGenerator; class AtomCopyFrameGenerator;
class AtomBeginFrameTimer; class AtomBeginFrameTimer;
class OffScreenRenderWidgetHostView class OffScreenRenderWidgetHostView:
: public content::RenderWidgetHostViewBase, public content::RenderWidgetHostViewBase,
#if defined(OS_MACOSX) #if defined(OS_MACOSX)
public ui::AcceleratedWidgetMacNSView, public ui::AcceleratedWidgetMacNSView,
#endif #endif
@ -69,6 +64,7 @@ public:
~OffScreenRenderWidgetHostView(); ~OffScreenRenderWidgetHostView();
void CreatePlatformWidget(); void CreatePlatformWidget();
void DestroyPlatformWidget();
// content::RenderWidgetHostView // content::RenderWidgetHostView
bool OnMessageReceived(const IPC::Message&) override; bool OnMessageReceived(const IPC::Message&) override;

View file

@ -102,18 +102,20 @@ void atom::OffScreenRenderWidgetHostView::CreatePlatformWidget() {
browser_compositor_->Unsuspend(); browser_compositor_->Unsuspend();
} }
// void atom::OffScreenRenderWidgetHostView::PlatformDestroyCompositorWidget() { void atom::OffScreenRenderWidgetHostView::DestroyPlatformWidget() {
// DCHECK(window_); DCHECK(window_);
//
// browser_compositor_->Destroy(); ui::Compositor* compositor = compositor_.release();
// ALLOW_UNUSED_LOCAL(compositor);
// [window_ close];
// window_ = nil; [window_ close];
// [background_layer_ release]; window_ = nil;
// background_layer_ = nil; [background_layer_ release];
// background_layer_ = nil;
// browser_compositor_.reset();
// browser_compositor_->accelerated_widget_mac()->ResetNSView();
// delete accelerated_widget_helper_; browser_compositor_->compositor()->SetVisible(false);
// accelerated_widget_helper_ = nullptr; browser_compositor_->compositor()->SetScaleAndSize(1.0, gfx::Size(0, 0));
// } browser_compositor_->compositor()->SetRootLayer(NULL);
content::BrowserCompositorMac::Recycle(std::move(browser_compositor_));
}

View file

@ -38,4 +38,9 @@ void OffScreenRenderWidgetHostView::CreatePlatformWidget() {
compositor_widget_ = window_->hwnd(); compositor_widget_ = window_->hwnd();
} }
void OffScreenRenderWidgetHostView::DestroyPlatformWidget() {
window_.reset(NULL);
compositor_widget_ = gfx::kNullAcceleratedWidget;
}
} // namespace atom } // namespace atom

View file

@ -54,7 +54,7 @@ public:
void CloseTabAfterEventTracking() override; void CloseTabAfterEventTracking() override;
#endif #endif
// RenderViewHostDelegateView methods. // content::RenderViewHostDelegateView
void StartDragging( void StartDragging(
const content::DropData& drop_data, const content::DropData& drop_data,
blink::WebDragOperationsMask allowed_ops, blink::WebDragOperationsMask allowed_ops,