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

Proposed by Andrea Azzarone
Status: Merged
Approved by: Marco Trevisan (Treviño)
Approved revision: no longer in the source branch.
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) Approve
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.
Revision history for this message
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
=== modified file 'lockscreen/LockScreenController.cpp'
--- lockscreen/LockScreenController.cpp 2017-09-19 18:10:01 +0000
+++ lockscreen/LockScreenController.cpp 2017-09-19 18:10:01 +0000
@@ -76,6 +76,8 @@
76 , blank_window_animator_(IDLE_FADE_DURATION)76 , blank_window_animator_(IDLE_FADE_DURATION)
77 , test_mode_(test_mode)77 , test_mode_(test_mode)
78 , prompt_activation_(false)78 , prompt_activation_(false)
79 , is_paint_inhibited_(false)
80 , buffer_cleared_(true)
79{81{
80 auto* uscreen = UScreen::GetDefault();82 auto* uscreen = UScreen::GetDefault();
81 uscreen_connection_ = uscreen->changed.connect([this] (int, std::vector<nux::Geometry> const& monitors) {83 uscreen_connection_ = uscreen->changed.connect([this] (int, std::vector<nux::Geometry> const& monitors) {
@@ -93,7 +95,13 @@
93 suspend_inhibitor_manager_->connected.connect(sigc::mem_fun(this, &Controller::SyncInhibitor));95 suspend_inhibitor_manager_->connected.connect(sigc::mem_fun(this, &Controller::SyncInhibitor));
94 suspend_inhibitor_manager_->about_to_suspend.connect([this] () {96 suspend_inhibitor_manager_->about_to_suspend.connect([this] () {
95 if (Settings::Instance().lock_on_suspend())97 if (Settings::Instance().lock_on_suspend())
98 {
99 InhibitPaint();
96 session_manager_->PromptLockScreen();100 session_manager_->PromptLockScreen();
101 }
102 });
103 suspend_inhibitor_manager_->resumed.connect([this] () {
104 UninhibitPaint();
97 });105 });
98106
99 Settings::Instance().lock_on_suspend.changed.connect(sigc::hide(sigc::mem_fun(this, &Controller::SyncInhibitor)));107 Settings::Instance().lock_on_suspend.changed.connect(sigc::hide(sigc::mem_fun(this, &Controller::SyncInhibitor)));
@@ -556,6 +564,36 @@
556 return primary_shield_.IsValid() ? primary_shield_->IsIndicatorOpen() : false;564 return primary_shield_.IsValid() ? primary_shield_->IsIndicatorOpen() : false;
557}565}
558566
567void Controller::InhibitPaint()
568{
569 buffer_cleared_ = false;
570 is_paint_inhibited_ = true;
571}
572
573void Controller::UninhibitPaint()
574{
575 if (!is_paint_inhibited_)
576 return;
577
578 buffer_cleared_ = true;
579 is_paint_inhibited_ = false;
580 SyncInhibitor();
581}
582
583bool Controller::IsPaintInhibited() const
584{
585 return is_paint_inhibited_;
586}
587
588void Controller::MarkBufferHasCleared()
589{
590 if (buffer_cleared_)
591 return;
592
593 buffer_cleared_ = true;
594 SyncInhibitor();
595}
596
559void Controller::SyncInhibitor()597void Controller::SyncInhibitor()
560{598{
561 bool locked = IsLocked() && primary_shield_.IsValid() && primary_shield_->GetOpacity() == 1.0f;599 bool locked = IsLocked() && primary_shield_.IsValid() && primary_shield_->GetOpacity() == 1.0f;
@@ -566,7 +604,7 @@
566604
567 if (inhibit)605 if (inhibit)
568 suspend_inhibitor_manager_->Inhibit("Unity needs to lock the screen");606 suspend_inhibitor_manager_->Inhibit("Unity needs to lock the screen");
569 else607 else if (buffer_cleared_)
570 suspend_inhibitor_manager_->Uninhibit();608 suspend_inhibitor_manager_->Uninhibit();
571}609}
572610
573611
=== modified file 'lockscreen/LockScreenController.h'
--- lockscreen/LockScreenController.h 2017-09-19 18:10:01 +0000
+++ lockscreen/LockScreenController.h 2017-09-19 18:10:01 +0000
@@ -56,6 +56,8 @@
5656
57 bool IsLocked() const;57 bool IsLocked() const;
58 bool HasOpenMenu() const;58 bool HasOpenMenu() const;
59 bool IsPaintInhibited() const;
60 void MarkBufferHasCleared();
5961
60private:62private:
61 friend class TestLockScreenController;63 friend class TestLockScreenController;
@@ -82,6 +84,9 @@
82 void OnLockScreenInputEvent(XEvent const&);84 void OnLockScreenInputEvent(XEvent const&);
83 void OnBlankWindowInputEvent(XEvent const&);85 void OnBlankWindowInputEvent(XEvent const&);
8486
87 void InhibitPaint();
88 void UninhibitPaint();
89
85 std::vector<nux::ObjectPtr<BaseShield>> shields_;90 std::vector<nux::ObjectPtr<BaseShield>> shields_;
86 nux::ObjectWeakPtr<BaseShield> primary_shield_;91 nux::ObjectWeakPtr<BaseShield> primary_shield_;
87 nux::ObjectWeakPtr<AbstractUserPromptView> prompt_view_;92 nux::ObjectWeakPtr<AbstractUserPromptView> prompt_view_;
@@ -104,6 +109,8 @@
104 bool test_mode_;109 bool test_mode_;
105 bool prompt_activation_;110 bool prompt_activation_;
106 BlurType old_blur_type_;111 BlurType old_blur_type_;
112 bool is_paint_inhibited_;
113 bool buffer_cleared_;
107114
108 connection::Wrapper uscreen_connection_;115 connection::Wrapper uscreen_connection_;
109 connection::Wrapper hidden_window_connection_;116 connection::Wrapper hidden_window_connection_;
110117
=== modified file 'lockscreen/SuspendInhibitorManager.cpp'
--- lockscreen/SuspendInhibitorManager.cpp 2016-03-31 09:59:30 +0000
+++ lockscreen/SuspendInhibitorManager.cpp 2017-09-19 18:10:01 +0000
@@ -60,6 +60,8 @@
60 lm_proxy_->Connect("PrepareForSleep", [this] (GVariant* variant) {60 lm_proxy_->Connect("PrepareForSleep", [this] (GVariant* variant) {
61 if (glib::Variant(variant).GetBool())61 if (glib::Variant(variant).GetBool())
62 parent_->about_to_suspend.emit();62 parent_->about_to_suspend.emit();
63 else
64 parent_->resumed.emit();
63 });65 });
6466
65 lm_proxy_->connected.connect(sigc::mem_fun(&parent->connected, &decltype(parent->connected)::emit));67 lm_proxy_->connected.connect(sigc::mem_fun(&parent->connected, &decltype(parent->connected)::emit));
6668
=== modified file 'lockscreen/SuspendInhibitorManager.h'
--- lockscreen/SuspendInhibitorManager.h 2016-03-31 09:59:30 +0000
+++ lockscreen/SuspendInhibitorManager.h 2017-09-19 18:10:01 +0000
@@ -42,6 +42,7 @@
4242
43 sigc::signal<void> connected;43 sigc::signal<void> connected;
44 sigc::signal<void> about_to_suspend;44 sigc::signal<void> about_to_suspend;
45 sigc::signal<void> resumed;
4546
46private:47private:
47 class Impl;48 class Impl;
4849
=== modified file 'plugins/unityshell/src/unityshell.cpp'
--- plugins/unityshell/src/unityshell.cpp 2017-07-17 10:53:40 +0000
+++ plugins/unityshell/src/unityshell.cpp 2017-09-19 18:10:01 +0000
@@ -1496,6 +1496,13 @@
1496 CompOutput* output,1496 CompOutput* output,
1497 unsigned int mask)1497 unsigned int mask)
1498{1498{
1499 if (G_UNLIKELY(lockscreen_controller_->IsPaintInhibited()))
1500 {
1501 CHECKGL(glClearColor(0.0f, 0.0f, 0.0f, 1.0f));
1502 CHECKGL(glClear(GL_COLOR_BUFFER_BIT));
1503 return true;
1504 }
1505
1499 bool ret;1506 bool ret;
15001507
1501 /*1508 /*
@@ -1692,6 +1699,11 @@
16921699
1693void UnityScreen::donePaint()1700void UnityScreen::donePaint()
1694{1701{
1702 if (G_UNLIKELY(lockscreen_controller_->IsPaintInhibited()))
1703 {
1704 lockscreen_controller_->MarkBufferHasCleared();
1705 }
1706
1695 /*1707 /*
1696 * It's only safe to clear the draw list if drawing actually occurred1708 * It's only safe to clear the draw list if drawing actually occurred
1697 * (i.e. the shell was not obscured behind a fullscreen window).1709 * (i.e. the shell was not obscured behind a fullscreen window).