Xiyuan Xia | 40cd41d | 2018-12-18 16:22:43 | [diff] [blame] | 1 | // Copyright 2018 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "ui/aura/window_occlusion_change_builder.h" |
| 6 | |
Hans Wennborg | 8586102b | 2020-05-05 13:43:29 | [diff] [blame] | 7 | #include "base/check_op.h" |
Xiyuan Xia | 40cd41d | 2018-12-18 16:22:43 | [diff] [blame] | 8 | #include "base/containers/flat_map.h" |
Xiyuan Xia | 40cd41d | 2018-12-18 16:22:43 | [diff] [blame] | 9 | #include "base/macros.h" |
Xiyuan Xia | d7e4d94 | 2019-06-12 22:32:52 | [diff] [blame] | 10 | #include "components/viz/client/frame_eviction_manager.h" |
Xiyuan Xia | 40cd41d | 2018-12-18 16:22:43 | [diff] [blame] | 11 | #include "third_party/skia/include/core/SkRegion.h" |
| 12 | #include "ui/aura/window_tracker.h" |
| 13 | |
| 14 | namespace aura { |
| 15 | |
| 16 | // Provide updating of occlusion info on aura::Window. |
| 17 | class DefaultWindowOcclusionChangeBuilder |
| 18 | : public WindowOcclusionChangeBuilder { |
| 19 | public: |
| 20 | DefaultWindowOcclusionChangeBuilder() = default; |
Peter Boström | c8c1235 | 2021-09-21 23:37:15 | [diff] [blame^] | 21 | |
| 22 | DefaultWindowOcclusionChangeBuilder( |
| 23 | const DefaultWindowOcclusionChangeBuilder&) = delete; |
| 24 | DefaultWindowOcclusionChangeBuilder& operator=( |
| 25 | const DefaultWindowOcclusionChangeBuilder&) = delete; |
| 26 | |
Xiyuan Xia | 40cd41d | 2018-12-18 16:22:43 | [diff] [blame] | 27 | ~DefaultWindowOcclusionChangeBuilder() override { |
Xiyuan Xia | d7e4d94 | 2019-06-12 22:32:52 | [diff] [blame] | 28 | // No frame eviction until all occlusion state changes are applied. |
| 29 | viz::FrameEvictionManager::ScopedPause scoped_frame_eviction_pause; |
| 30 | |
Xiyuan Xia | 40cd41d | 2018-12-18 16:22:43 | [diff] [blame] | 31 | while (!windows_.windows().empty()) { |
| 32 | Window* window = windows_.Pop(); |
| 33 | auto it = changes_.find(window); |
| 34 | if (it == changes_.end()) |
| 35 | continue; |
Xiyuan Xia | 40cd41d | 2018-12-18 16:22:43 | [diff] [blame] | 36 | window->SetOcclusionInfo(it->second.occlusion_state, |
| 37 | it->second.occluded_region); |
| 38 | } |
| 39 | changes_.clear(); |
| 40 | } |
| 41 | |
| 42 | private: |
| 43 | struct OcclusionData { |
| 44 | Window::OcclusionState occlusion_state; |
| 45 | SkRegion occluded_region; |
| 46 | }; |
| 47 | |
| 48 | // WindowOcclusionChangeBuilder: |
| 49 | void Add(Window* window, |
| 50 | Window::OcclusionState occlusion_state, |
| 51 | SkRegion occluded_region) override { |
| 52 | // Change back to UNKNOWN is not allowed. |
| 53 | DCHECK_NE(occlusion_state, Window::OcclusionState::UNKNOWN); |
| 54 | |
| 55 | windows_.Add(window); |
| 56 | changes_[window] = {occlusion_state, occluded_region}; |
| 57 | } |
| 58 | |
| 59 | // Tracks live windows that has a change. This is needed in addition to the |
| 60 | // keys in |changes_| because the window tree may change while changes are |
| 61 | // accumulated or being applied. |
| 62 | WindowTracker windows_; |
| 63 | |
| 64 | // Stores the accumulated occlusion changes. |
| 65 | base::flat_map<Window*, OcclusionData> changes_; |
Xiyuan Xia | 40cd41d | 2018-12-18 16:22:43 | [diff] [blame] | 66 | }; |
| 67 | |
| 68 | // static |
| 69 | std::unique_ptr<WindowOcclusionChangeBuilder> |
| 70 | WindowOcclusionChangeBuilder::Create() { |
| 71 | return std::make_unique<DefaultWindowOcclusionChangeBuilder>(); |
| 72 | } |
| 73 | |
| 74 | } // namespace aura |