adds transparency
This commit is contained in:
parent
36918250ec
commit
56f5749675
7 changed files with 53 additions and 12 deletions
|
@ -314,9 +314,12 @@ WebContents::WebContents(v8::Isolate* isolate,
|
|||
params.guest_delegate = guest_delegate_.get();
|
||||
web_contents = content::WebContents::Create(params);
|
||||
} else if (IsOffScreen()) {
|
||||
bool transparent = false;
|
||||
options.Get("transparent", &transparent);
|
||||
|
||||
content::WebContents::CreateParams params(session->browser_context());
|
||||
|
||||
auto view = new OffScreenWebContentsView();
|
||||
auto view = new OffScreenWebContentsView(transparent);
|
||||
params.view = view;
|
||||
params.delegate_view = view;
|
||||
|
||||
|
|
|
@ -79,6 +79,10 @@ Window::Window(v8::Isolate* isolate, const mate::Dictionary& options) {
|
|||
if (options.Get(options::kBackgroundColor, &value))
|
||||
web_preferences.Set(options::kBackgroundColor, value);
|
||||
|
||||
v8::Local<v8::Value> transparent;
|
||||
if (options.Get("transparent", &transparent))
|
||||
web_preferences.Set("transparent", transparent);
|
||||
|
||||
// Creates the WebContents used by BrowserWindow.
|
||||
auto web_contents = WebContents::Create(isolate, web_preferences);
|
||||
web_contents_.Reset(isolate, web_contents.ToV8());
|
||||
|
|
|
@ -336,13 +336,15 @@ class AtomBeginFrameTimer : public cc::DelayBasedTimeSourceClient {
|
|||
};
|
||||
|
||||
OffScreenRenderWidgetHostView::OffScreenRenderWidgetHostView(
|
||||
content::RenderWidgetHost* host, NativeWindow* native_window):
|
||||
const bool transparent, content::RenderWidgetHost* host,
|
||||
NativeWindow* native_window):
|
||||
render_widget_host_(content::RenderWidgetHostImpl::From(host)),
|
||||
native_window_(native_window),
|
||||
software_output_device_(NULL),
|
||||
callback_(nullptr),
|
||||
frame_rate_(60),
|
||||
frame_rate_threshold_ms_(0),
|
||||
transparent_(transparent),
|
||||
scale_factor_(kDefaultScaleFactor),
|
||||
is_showing_(!render_widget_host_->is_hidden()),
|
||||
size_(native_window->GetSize()),
|
||||
|
@ -530,6 +532,17 @@ gfx::Rect OffScreenRenderWidgetHostView::GetViewBounds() const {
|
|||
return gfx::Rect(size_);
|
||||
}
|
||||
|
||||
void OffScreenRenderWidgetHostView::SetBackgroundColor(SkColor color) {
|
||||
if (transparent_)
|
||||
color = SkColorSetARGB(SK_AlphaTRANSPARENT, 0, 0, 0);
|
||||
|
||||
content::RenderWidgetHostViewBase::SetBackgroundColor(color);
|
||||
|
||||
const bool opaque = !transparent_ && GetBackgroundOpaque();
|
||||
if (render_widget_host_)
|
||||
render_widget_host_->SetBackgroundOpaque(opaque);
|
||||
}
|
||||
|
||||
gfx::Size OffScreenRenderWidgetHostView::GetVisibleViewportSize() const {
|
||||
return size_;
|
||||
}
|
||||
|
@ -765,6 +778,15 @@ void OffScreenRenderWidgetHostView::DelegatedFrameHostUpdateVSyncParameters(
|
|||
render_widget_host_->UpdateVSyncParameters(timebase, interval);
|
||||
}
|
||||
|
||||
bool OffScreenRenderWidgetHostView::InstallTransparency() {
|
||||
if (transparent_) {
|
||||
SetBackgroundColor(SkColor());
|
||||
compositor_->SetHostHasTransparentBackground(true);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
std::unique_ptr<cc::SoftwareOutputDevice>
|
||||
OffScreenRenderWidgetHostView::CreateSoftwareOutputDevice(
|
||||
ui::Compositor* compositor) {
|
||||
|
@ -772,7 +794,7 @@ std::unique_ptr<cc::SoftwareOutputDevice>
|
|||
DCHECK(!copy_frame_generator_);
|
||||
DCHECK(!software_output_device_);
|
||||
|
||||
software_output_device_ = new OffScreenOutputDevice(true,
|
||||
software_output_device_ = new OffScreenOutputDevice(transparent_,
|
||||
base::Bind(&OffScreenRenderWidgetHostView::OnPaint,
|
||||
weak_ptr_factory_.GetWeakPtr()));
|
||||
return base::WrapUnique(software_output_device_);
|
||||
|
|
|
@ -63,7 +63,8 @@ class OffScreenRenderWidgetHostView:
|
|||
public ui::CompositorDelegate,
|
||||
public content::DelegatedFrameHostClient {
|
||||
public:
|
||||
OffScreenRenderWidgetHostView(content::RenderWidgetHost*, NativeWindow*);
|
||||
OffScreenRenderWidgetHostView(const bool transparent,
|
||||
content::RenderWidgetHost*, NativeWindow*);
|
||||
~OffScreenRenderWidgetHostView();
|
||||
|
||||
// content::RenderWidgetHostView
|
||||
|
@ -85,6 +86,7 @@ class OffScreenRenderWidgetHostView:
|
|||
gfx::Rect GetViewBounds(void) const override;
|
||||
gfx::Size GetVisibleViewportSize() const override;
|
||||
void SetInsets(const gfx::Insets&) override;
|
||||
void SetBackgroundColor(SkColor color) override;
|
||||
bool LockMouse(void) override;
|
||||
void UnlockMouse(void) override;
|
||||
bool GetScreenColorProfile(std::vector<char>*) override;
|
||||
|
@ -165,6 +167,8 @@ class OffScreenRenderWidgetHostView:
|
|||
const base::TimeTicks &, const base::TimeDelta &) override;
|
||||
void SetBeginFrameSource(cc::BeginFrameSource* source) override;
|
||||
|
||||
bool InstallTransparency();
|
||||
|
||||
bool IsAutoResizeEnabled() const;
|
||||
|
||||
std::unique_ptr<cc::SoftwareOutputDevice> CreateSoftwareOutputDevice(
|
||||
|
@ -221,6 +225,7 @@ private:
|
|||
|
||||
base::Time last_time_;
|
||||
|
||||
const bool transparent_;
|
||||
float scale_factor_;
|
||||
bool is_showing_;
|
||||
gfx::Vector2dF last_scroll_offset_;
|
||||
|
|
|
@ -9,7 +9,8 @@
|
|||
#include "base/strings/utf_string_conversions.h"
|
||||
#include "ui/accelerated_widget_mac/accelerated_widget_mac.h"
|
||||
|
||||
ui::AcceleratedWidgetMac* atom::OffScreenRenderWidgetHostView::GetAcceleratedWidgetMac()
|
||||
ui::AcceleratedWidgetMac*
|
||||
atom::OffScreenRenderWidgetHostView::GetAcceleratedWidgetMac()
|
||||
const {
|
||||
if (browser_compositor_)
|
||||
return browser_compositor_->accelerated_widget_mac();
|
||||
|
|
|
@ -3,12 +3,12 @@
|
|||
// found in the LICENSE file.
|
||||
|
||||
#include "atom/browser/osr_web_contents_view.h"
|
||||
#include "atom/browser/osr_render_widget_host_view.h"
|
||||
|
||||
namespace atom {
|
||||
|
||||
OffScreenWebContentsView::OffScreenWebContentsView():
|
||||
web_contents_(nullptr) {
|
||||
OffScreenWebContentsView::OffScreenWebContentsView(bool transparent):
|
||||
transparent_(transparent),
|
||||
web_contents_(nullptr) {
|
||||
}
|
||||
|
||||
OffScreenWebContentsView::~OffScreenWebContentsView() {
|
||||
|
@ -66,7 +66,7 @@ content::RenderWidgetHostViewBase*
|
|||
OffScreenWebContentsView::CreateViewForWidget(
|
||||
content::RenderWidgetHost* render_widget_host, bool is_guest_view_hack) {
|
||||
auto relay = NativeWindowRelay::FromWebContents(web_contents_);
|
||||
view_ = new OffScreenRenderWidgetHostView(render_widget_host,
|
||||
view_ = new OffScreenRenderWidgetHostView(transparent_, render_widget_host,
|
||||
relay->window.get());
|
||||
return view_;
|
||||
}
|
||||
|
@ -75,7 +75,7 @@ content::RenderWidgetHostViewBase*
|
|||
OffScreenWebContentsView::CreateViewForPopupWidget(
|
||||
content::RenderWidgetHost* render_widget_host) {
|
||||
auto relay = NativeWindowRelay::FromWebContents(web_contents_);
|
||||
view_ = new OffScreenRenderWidgetHostView(render_widget_host,
|
||||
view_ = new OffScreenRenderWidgetHostView(transparent_, render_widget_host,
|
||||
relay->window.get());
|
||||
return view_;
|
||||
}
|
||||
|
@ -85,6 +85,8 @@ void OffScreenWebContentsView::SetPageTitle(const base::string16& title) {
|
|||
|
||||
void OffScreenWebContentsView::RenderViewCreated(
|
||||
content::RenderViewHost* host) {
|
||||
if (view_)
|
||||
view_->InstallTransparency();
|
||||
}
|
||||
|
||||
void OffScreenWebContentsView::RenderViewSwappedIn(
|
||||
|
|
|
@ -9,12 +9,14 @@
|
|||
#include "content/browser/web_contents/web_contents_view.h"
|
||||
#include "content/public/browser/web_contents.h"
|
||||
|
||||
#include "atom/browser/osr_render_widget_host_view.h"
|
||||
|
||||
namespace atom {
|
||||
|
||||
class OffScreenWebContentsView : public content::WebContentsView,
|
||||
public content::RenderViewHostDelegateView {
|
||||
public:
|
||||
OffScreenWebContentsView();
|
||||
OffScreenWebContentsView(bool transparent);
|
||||
~OffScreenWebContentsView();
|
||||
|
||||
void SetWebContents(content::WebContents*);
|
||||
|
@ -60,7 +62,9 @@ class OffScreenWebContentsView : public content::WebContentsView,
|
|||
void UpdateDragCursor(blink::WebDragOperation operation) override;
|
||||
|
||||
private:
|
||||
content::RenderWidgetHostViewBase* view_;
|
||||
const bool transparent_;
|
||||
|
||||
OffScreenRenderWidgetHostView* view_;
|
||||
content::WebContents* web_contents_;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue