| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef UI_DISPLAY_DISPLAY_LIST_H_ | 5 #ifndef UI_DISPLAY_DISPLAY_LIST_H_ |
| 6 #define UI_DISPLAY_DISPLAY_LIST_H_ | 6 #define UI_DISPLAY_DISPLAY_LIST_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> |
| 10 #include <vector> | 11 #include <vector> |
| 11 | 12 |
| 12 #include "base/observer_list.h" | 13 #include "base/observer_list.h" |
| 13 #include "ui/display/display.h" | 14 #include "ui/display/display.h" |
| 14 #include "ui/display/display_export.h" | 15 #include "ui/display/display_export.h" |
| 15 | 16 |
| 16 namespace display { | 17 namespace display { |
| 17 | 18 |
| 18 class Display; | 19 class Display; |
| 20 class DisplayList; |
| 19 class DisplayObserver; | 21 class DisplayObserver; |
| 20 | 22 |
| 23 // See description in DisplayLock::SuspendObserverUpdates. |
| 24 class DISPLAY_EXPORT DisplayListObserverLock { |
| 25 public: |
| 26 ~DisplayListObserverLock(); |
| 27 |
| 28 private: |
| 29 friend class DisplayList; |
| 30 |
| 31 explicit DisplayListObserverLock(DisplayList* display_list); |
| 32 |
| 33 DisplayList* display_list_; |
| 34 |
| 35 DISALLOW_COPY_AND_ASSIGN(DisplayListObserverLock); |
| 36 }; |
| 37 |
| 21 // Maintains an ordered list of display::Displays as well as operations to add, | 38 // Maintains an ordered list of display::Displays as well as operations to add, |
| 22 // remove and update said list. Additionally maintains display::DisplayObservers | 39 // remove and update said list. Additionally maintains display::DisplayObservers |
| 23 // and updates them as appropriate. | 40 // and updates them as appropriate. |
| 24 class DISPLAY_EXPORT DisplayList { | 41 class DISPLAY_EXPORT DisplayList { |
| 25 public: | 42 public: |
| 26 using Displays = std::vector<display::Display>; | 43 using Displays = std::vector<display::Display>; |
| 27 | 44 |
| 28 enum class Type { | 45 enum class Type { |
| 29 PRIMARY, | 46 PRIMARY, |
| 30 NOT_PRIMARY, | 47 NOT_PRIMARY, |
| 31 }; | 48 }; |
| 32 | 49 |
| 33 DisplayList(); | 50 DisplayList(); |
| 34 ~DisplayList(); | 51 ~DisplayList(); |
| 35 | 52 |
| 36 void AddObserver(display::DisplayObserver* observer); | 53 void AddObserver(display::DisplayObserver* observer); |
| 37 void RemoveObserver(display::DisplayObserver* observer); | 54 void RemoveObserver(display::DisplayObserver* observer); |
| 38 | 55 |
| 39 const Displays& displays() const { return displays_; } | 56 const Displays& displays() const { return displays_; } |
| 40 | 57 |
| 41 Displays::const_iterator FindDisplayById(int64_t id) const; | 58 Displays::const_iterator FindDisplayById(int64_t id) const; |
| 42 Displays::iterator FindDisplayById(int64_t id); | 59 Displays::iterator FindDisplayById(int64_t id); |
| 43 | 60 |
| 44 Displays::const_iterator GetPrimaryDisplayIterator() const; | 61 Displays::const_iterator GetPrimaryDisplayIterator() const; |
| 45 | 62 |
| 63 // Internally increments a counter that while non-zero results in observers |
| 64 // not being called for any changes to the displays. It is assumed once |
| 65 // callers release the last lock they call the observers appropriately. |
| 66 std::unique_ptr<DisplayListObserverLock> SuspendObserverUpdates(); |
| 67 |
| 46 // Updates the cached id based on display.id() as well as whether the Display | 68 // Updates the cached id based on display.id() as well as whether the Display |
| 47 // is the primary display. | 69 // is the primary display. |
| 48 void UpdateDisplay(const display::Display& display, Type type); | 70 void UpdateDisplay(const display::Display& display, Type type); |
| 49 | 71 |
| 50 // Adds a new Display. | 72 // Adds a new Display. |
| 51 void AddDisplay(const display::Display& display, Type type); | 73 void AddDisplay(const display::Display& display, Type type); |
| 52 | 74 |
| 53 // Removes the Display with the specified id. | 75 // Removes the Display with the specified id. |
| 54 void RemoveDisplay(int64_t id); | 76 void RemoveDisplay(int64_t id); |
| 55 | 77 |
| 78 base::ObserverList<display::DisplayObserver>* observers() { |
| 79 return &observers_; |
| 80 } |
| 81 |
| 56 private: | 82 private: |
| 83 friend class DisplayListObserverLock; |
| 84 |
| 85 bool should_notify_observers() const { |
| 86 return observer_suspend_lock_count_ == 0; |
| 87 } |
| 88 void IncrementObserverSuspendLockCount(); |
| 89 void DecrementObserverSuspendLockCount(); |
| 90 |
| 57 std::vector<display::Display> displays_; | 91 std::vector<display::Display> displays_; |
| 58 int primary_display_index_ = -1; | 92 int primary_display_index_ = -1; |
| 59 base::ObserverList<display::DisplayObserver> observers_; | 93 base::ObserverList<display::DisplayObserver> observers_; |
| 60 | 94 |
| 95 int observer_suspend_lock_count_ = 0; |
| 96 |
| 61 DISALLOW_COPY_AND_ASSIGN(DisplayList); | 97 DISALLOW_COPY_AND_ASSIGN(DisplayList); |
| 62 }; | 98 }; |
| 63 | 99 |
| 64 } // namespace display | 100 } // namespace display |
| 65 | 101 |
| 66 #endif // UI_DISPLAY_DISPLAY_LIST_H_ | 102 #endif // UI_DISPLAY_DISPLAY_LIST_H_ |
| OLD | NEW |