Merge lp:~azzar1/unity/clear-color-buffer-before-suspending into lp:unity

Proposed by Andrea Azzarone on 2017-09-19
Status: Merged
Approved by: Marco Trevisan (Treviño) on 2017-09-20
Approved revision: 4258
Merged at revision: 4258
Proposed branch: lp:~azzar1/unity/clear-color-buffer-before-suspending
Merge into: lp:unity
Prerequisite: lp:~azzar1/unity/fix-missing-entry-lockscreen
Diff against target: 159 lines (+61/-1)
5 files modified
lockscreen/LockScreenController.cpp (+39/-1)
lockscreen/LockScreenController.h (+7/-0)
lockscreen/SuspendInhibitorManager.cpp (+2/-0)
lockscreen/SuspendInhibitorManager.h (+1/-0)
plugins/unityshell/src/unityshell.cpp (+12/-0)
To merge this branch: bzr merge lp:~azzar1/unity/clear-color-buffer-before-suspending
Reviewer Review Type Date Requested Status
Marco Trevisan (Treviño) 2017-09-19 Approve on 2017-09-20
Review via email: mp+331003@code.launchpad.net

Commit message

Wait until the color buffer is cleared before suspending.

To post a comment you must log in.
4258. By Andrea Azzarone on 2017-09-19

use color alpha 1.0

Marco Trevisan (Treviño) (3v1n0) wrote :

Looks good... Let's get it!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lockscreen/LockScreenController.cpp'
2--- lockscreen/LockScreenController.cpp 2017-09-19 18:10:01 +0000
3+++ lockscreen/LockScreenController.cpp 2017-09-19 18:10:01 +0000
4@@ -76,6 +76,8 @@
5 , blank_window_animator_(IDLE_FADE_DURATION)
6 , test_mode_(test_mode)
7 , prompt_activation_(false)
8+ , is_paint_inhibited_(false)
9+ , buffer_cleared_(true)
10 {
11 auto* uscreen = UScreen::GetDefault();
12 uscreen_connection_ = uscreen->changed.connect([this] (int, std::vector<nux::Geometry> const& monitors) {
13@@ -93,7 +95,13 @@
14 suspend_inhibitor_manager_->connected.connect(sigc::mem_fun(this, &Controller::SyncInhibitor));
15 suspend_inhibitor_manager_->about_to_suspend.connect([this] () {
16 if (Settings::Instance().lock_on_suspend())
17+ {
18+ InhibitPaint();
19 session_manager_->PromptLockScreen();
20+ }
21+ });
22+ suspend_inhibitor_manager_->resumed.connect([this] () {
23+ UninhibitPaint();
24 });
25
26 Settings::Instance().lock_on_suspend.changed.connect(sigc::hide(sigc::mem_fun(this, &Controller::SyncInhibitor)));
27@@ -556,6 +564,36 @@
28 return primary_shield_.IsValid() ? primary_shield_->IsIndicatorOpen() : false;
29 }
30
31+void Controller::InhibitPaint()
32+{
33+ buffer_cleared_ = false;
34+ is_paint_inhibited_ = true;
35+}
36+
37+void Controller::UninhibitPaint()
38+{
39+ if (!is_paint_inhibited_)
40+ return;
41+
42+ buffer_cleared_ = true;
43+ is_paint_inhibited_ = false;
44+ SyncInhibitor();
45+}
46+
47+bool Controller::IsPaintInhibited() const
48+{
49+ return is_paint_inhibited_;
50+}
51+
52+void Controller::MarkBufferHasCleared()
53+{
54+ if (buffer_cleared_)
55+ return;
56+
57+ buffer_cleared_ = true;
58+ SyncInhibitor();
59+}
60+
61 void Controller::SyncInhibitor()
62 {
63 bool locked = IsLocked() && primary_shield_.IsValid() && primary_shield_->GetOpacity() == 1.0f;
64@@ -566,7 +604,7 @@
65
66 if (inhibit)
67 suspend_inhibitor_manager_->Inhibit("Unity needs to lock the screen");
68- else
69+ else if (buffer_cleared_)
70 suspend_inhibitor_manager_->Uninhibit();
71 }
72
73
74=== modified file 'lockscreen/LockScreenController.h'
75--- lockscreen/LockScreenController.h 2017-09-19 18:10:01 +0000
76+++ lockscreen/LockScreenController.h 2017-09-19 18:10:01 +0000
77@@ -56,6 +56,8 @@
78
79 bool IsLocked() const;
80 bool HasOpenMenu() const;
81+ bool IsPaintInhibited() const;
82+ void MarkBufferHasCleared();
83
84 private:
85 friend class TestLockScreenController;
86@@ -82,6 +84,9 @@
87 void OnLockScreenInputEvent(XEvent const&);
88 void OnBlankWindowInputEvent(XEvent const&);
89
90+ void InhibitPaint();
91+ void UninhibitPaint();
92+
93 std::vector<nux::ObjectPtr<BaseShield>> shields_;
94 nux::ObjectWeakPtr<BaseShield> primary_shield_;
95 nux::ObjectWeakPtr<AbstractUserPromptView> prompt_view_;
96@@ -104,6 +109,8 @@
97 bool test_mode_;
98 bool prompt_activation_;
99 BlurType old_blur_type_;
100+ bool is_paint_inhibited_;
101+ bool buffer_cleared_;
102
103 connection::Wrapper uscreen_connection_;
104 connection::Wrapper hidden_window_connection_;
105
106=== modified file 'lockscreen/SuspendInhibitorManager.cpp'
107--- lockscreen/SuspendInhibitorManager.cpp 2016-03-31 09:59:30 +0000
108+++ lockscreen/SuspendInhibitorManager.cpp 2017-09-19 18:10:01 +0000
109@@ -60,6 +60,8 @@
110 lm_proxy_->Connect("PrepareForSleep", [this] (GVariant* variant) {
111 if (glib::Variant(variant).GetBool())
112 parent_->about_to_suspend.emit();
113+ else
114+ parent_->resumed.emit();
115 });
116
117 lm_proxy_->connected.connect(sigc::mem_fun(&parent->connected, &decltype(parent->connected)::emit));
118
119=== modified file 'lockscreen/SuspendInhibitorManager.h'
120--- lockscreen/SuspendInhibitorManager.h 2016-03-31 09:59:30 +0000
121+++ lockscreen/SuspendInhibitorManager.h 2017-09-19 18:10:01 +0000
122@@ -42,6 +42,7 @@
123
124 sigc::signal<void> connected;
125 sigc::signal<void> about_to_suspend;
126+ sigc::signal<void> resumed;
127
128 private:
129 class Impl;
130
131=== modified file 'plugins/unityshell/src/unityshell.cpp'
132--- plugins/unityshell/src/unityshell.cpp 2017-07-17 10:53:40 +0000
133+++ plugins/unityshell/src/unityshell.cpp 2017-09-19 18:10:01 +0000
134@@ -1496,6 +1496,13 @@
135 CompOutput* output,
136 unsigned int mask)
137 {
138+ if (G_UNLIKELY(lockscreen_controller_->IsPaintInhibited()))
139+ {
140+ CHECKGL(glClearColor(0.0f, 0.0f, 0.0f, 1.0f));
141+ CHECKGL(glClear(GL_COLOR_BUFFER_BIT));
142+ return true;
143+ }
144+
145 bool ret;
146
147 /*
148@@ -1692,6 +1699,11 @@
149
150 void UnityScreen::donePaint()
151 {
152+ if (G_UNLIKELY(lockscreen_controller_->IsPaintInhibited()))
153+ {
154+ lockscreen_controller_->MarkBufferHasCleared();
155+ }
156+
157 /*
158 * It's only safe to clear the draw list if drawing actually occurred
159 * (i.e. the shell was not obscured behind a fullscreen window).