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 | |
| 7 | #include "base/containers/flat_map.h" |
| 8 | #include "base/logging.h" |
| 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; |
| 21 | ~DefaultWindowOcclusionChangeBuilder() override { |
Xiyuan Xia | d7e4d94 | 2019-06-12 22:32:52 | [diff] [blame^] | 22 | // No frame eviction until all occlusion state changes are applied. |
| 23 | viz::FrameEvictionManager::ScopedPause scoped_frame_eviction_pause; |
| 24 | |
Xiyuan Xia | 40cd41d | 2018-12-18 16:22:43 | [diff] [blame] | 25 | while (!windows_.windows().empty()) { |
| 26 | Window* window = windows_.Pop(); |
| 27 | auto it = changes_.find(window); |
| 28 | if (it == changes_.end()) |
| 29 | continue; |
| 30 | |
| 31 | window->SetOcclusionInfo(it->second.occlusion_state, |
| 32 | it->second.occluded_region); |
| 33 | } |
| 34 | changes_.clear(); |
| 35 | } |
| 36 | |
| 37 | private: |
| 38 | struct OcclusionData { |
| 39 | Window::OcclusionState occlusion_state; |
| 40 | SkRegion occluded_region; |
| 41 | }; |
| 42 | |
| 43 | // WindowOcclusionChangeBuilder: |
| 44 | void Add(Window* window, |
| 45 | Window::OcclusionState occlusion_state, |
| 46 | SkRegion occluded_region) override { |
| 47 | // Change back to UNKNOWN is not allowed. |
| 48 | DCHECK_NE(occlusion_state, Window::OcclusionState::UNKNOWN); |
| 49 | |
| 50 | windows_.Add(window); |
| 51 | changes_[window] = {occlusion_state, occluded_region}; |
| 52 | } |
| 53 | |
| 54 | // Tracks live windows that has a change. This is needed in addition to the |
| 55 | // keys in |changes_| because the window tree may change while changes are |
| 56 | // accumulated or being applied. |
| 57 | WindowTracker windows_; |
| 58 | |
| 59 | // Stores the accumulated occlusion changes. |
| 60 | base::flat_map<Window*, OcclusionData> changes_; |
| 61 | |
| 62 | DISALLOW_COPY_AND_ASSIGN(DefaultWindowOcclusionChangeBuilder); |
| 63 | }; |
| 64 | |
| 65 | // static |
| 66 | std::unique_ptr<WindowOcclusionChangeBuilder> |
| 67 | WindowOcclusionChangeBuilder::Create() { |
| 68 | return std::make_unique<DefaultWindowOcclusionChangeBuilder>(); |
| 69 | } |
| 70 | |
| 71 | } // namespace aura |