Skip to content

Commit 080f170

Browse files
committed
Merge pull request nwjs#2924 from jtg-gg/nw12-transparency
nw12 transparency rebase
2 parents f6031d6 + 4e2b83d commit 080f170

File tree

3 files changed

+49
-18
lines changed

3 files changed

+49
-18
lines changed

src/browser/native_window.cc

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "content/nw/src/common/shell_switches.h"
2828
#include "content/nw/src/nw_package.h"
2929
#include "content/nw/src/nw_shell.h"
30+
#include "content/public/common/content_switches.h"
3031
#include "grit/nw_resources.h"
3132
#include "ui/base/resource/resource_bundle.h"
3233
#include "ui/gfx/rect.h"
@@ -41,6 +42,7 @@
4142

4243
namespace content {
4344
extern bool g_support_transparency;
45+
extern bool g_force_cpu_draw;
4446
}
4547

4648
namespace nw {
@@ -78,9 +80,16 @@ NativeWindow::NativeWindow(const base::WeakPtr<content::Shell>& shell,
7880
capture_page_helper_(NULL) {
7981
manifest->GetBoolean(switches::kmFrame, &has_frame_);
8082
content::g_support_transparency = !base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kmDisableTransparency);
81-
if (content::g_support_transparency)
83+
if (content::g_support_transparency) {
84+
content::g_force_cpu_draw = base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kForceCpuDraw);
85+
if (content::g_force_cpu_draw) {
86+
if (!base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableGpu)) {
87+
content::g_force_cpu_draw = false;
88+
LOG(WARNING) << "switch " << switches::kForceCpuDraw << " must be used with switch " << switches::kDisableGpu;
89+
}
90+
}
8291
manifest->GetBoolean(switches::kmTransparent, &transparent_);
83-
92+
}
8493
LoadAppIconFromPackage(manifest);
8594
}
8695

src/browser/native_window_aura.cc

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
#include "content/nw/src/nw_shell.h"
4545
#include "content/public/browser/native_web_keyboard_event.h"
4646
#include "content/public/browser/render_view_host.h"
47-
#include "content/public/browser/render_widget_host_view.h"
47+
#include "content/browser/renderer_host/render_view_host_impl.h"
4848
#include "content/public/browser/web_contents.h"
4949
#include "content/public/common/content_switches.h"
5050
#include "extensions/common/draggable_region.h"
@@ -84,6 +84,7 @@
8484

8585
namespace content {
8686
extern bool g_support_transparency;
87+
extern bool g_force_cpu_draw;
8788
}
8889

8990

@@ -458,15 +459,6 @@ void NativeWindowAura::SetTransparent(bool transparent) {
458459

459460
// this is needed, or transparency will fail if it defined on startup
460461
bool change_window_style = false;
461-
462-
if (!has_frame_) {
463-
const LONG lastStyle = GetWindowLong(hWnd, GWL_STYLE);
464-
const LONG style = WS_CAPTION;
465-
const LONG newStyle = transparent ? lastStyle | style : lastStyle & ~style;
466-
SetWindowLong(hWnd, GWL_STYLE, newStyle);
467-
change_window_style |= lastStyle != newStyle;
468-
}
469-
470462
const LONG lastExStyle = GetWindowLong(hWnd, GWL_EXSTYLE);
471463
const LONG exStyle = WS_EX_COMPOSITED;
472464
const LONG newExStyle = transparent ? lastExStyle | exStyle : lastExStyle & ~exStyle;
@@ -476,6 +468,13 @@ void NativeWindowAura::SetTransparent(bool transparent) {
476468
if (change_window_style) {
477469
window_->FrameTypeChanged();
478470
}
471+
472+
if (content::g_force_cpu_draw && transparent) {
473+
// Quick FIX where window content is not updated
474+
Minimize();
475+
Restore();
476+
}
477+
479478
#elif defined(USE_X11) && !defined(OS_CHROMEOS)
480479

481480
static char cachedRes = -1;
@@ -497,10 +496,9 @@ void NativeWindowAura::SetTransparent(bool transparent) {
497496
toolbar_->SchedulePaint();
498497
}
499498

500-
content::RenderWidgetHostView* rwhv = shell_->web_contents()->GetRenderWidgetHostView();
501-
if (rwhv) {
502-
if (transparent)
503-
rwhv->SetBackgroundColor(SK_ColorTRANSPARENT);
499+
content::RenderViewHostImpl* rvh = static_cast<content::RenderViewHostImpl*>(shell_->web_contents()->GetRenderViewHost());
500+
if (rvh) {
501+
rvh->SetBackgroundOpaque(!transparent);
504502
}
505503

506504
transparent_ = transparent;

src/browser/native_window_mac.mm

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545

4646
namespace content {
4747
extern bool g_support_transparency;
48+
extern bool g_force_cpu_draw;
4849
}
4950

5051
@interface NSWindow (NSPrivateApis)
@@ -397,7 +398,7 @@ - (void)drawRect:(NSRect)dirtyRect {
397398
window_ = shell_window;
398399
opaque_color_ = [window() backgroundColor];
399400
[shell_window setShell:shell];
400-
[[window() contentView] setWantsLayer:YES];
401+
[[window() contentView] setWantsLayer:!content::g_force_cpu_draw];
401402
[window() setDelegate:[[NativeWindowDelegate alloc] initWithShell:shell]];
402403

403404
SetTransparent(transparent_);
@@ -555,6 +556,23 @@ - (void)drawRect:(NSRect)dirtyRect {
555556
return is_fullscreen_;
556557
}
557558

559+
//debug function to iterate all the sublayers
560+
void SetTransparent (CALayer* layer, const bool transparent) {
561+
if (layer == NULL) return;
562+
[layer setBackgroundColor:CGColorGetConstantColor(transparent ? kCGColorClear : kCGColorWhite)];
563+
for (CALayer* l in layer.sublayers) {
564+
SetTransparent(l, transparent);
565+
}
566+
}
567+
568+
//debug function to iterate all the subviews
569+
void SetTransparent (NSView * view, const bool transparent) {
570+
if (view == NULL) return;
571+
SetTransparent(view.layer, transparent);
572+
for (NSView* v in view.subviews)
573+
SetTransparent(v, transparent);
574+
}
575+
558576
void NativeWindowCocoa::SetTransparent(bool transparent) {
559577

560578
if (!content::g_support_transparency) return;
@@ -570,10 +588,16 @@ - (void)drawRect:(NSRect)dirtyRect {
570588
content::RenderViewHostImpl* rvh = static_cast<content::RenderViewHostImpl*>(shell_->web_contents()->GetRenderViewHost());
571589

572590
if (rwhv) {
573-
rvh->SetBackgroundOpaque(!transparent);
574591
[rwhv->background_layer_ setBackgroundColor:CGColorGetConstantColor(transparent ? kCGColorClear : kCGColorWhite)];
575592
}
576593

594+
if (rvh) {
595+
rvh->SetBackgroundOpaque(!transparent);
596+
}
597+
598+
//this is for debugging, iterate all the subviews / sublayers
599+
//nw::SetTransparent((NSView*)[window()contentView], transparent);
600+
577601
transparent_ = transparent;
578602

579603
}

0 commit comments

Comments
 (0)