blob: 8b36acf9350d0c3daa2414f999258eabb69bd91e [file] [log] [blame]
Xiyuan Xia40cd41d2018-12-18 16:22:431// 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 Wennborg8586102b2020-05-05 13:43:297#include "base/check_op.h"
Xiyuan Xia40cd41d2018-12-18 16:22:438#include "base/containers/flat_map.h"
Xiyuan Xia40cd41d2018-12-18 16:22:439#include "base/macros.h"
Xiyuan Xiad7e4d942019-06-12 22:32:5210#include "components/viz/client/frame_eviction_manager.h"
Xiyuan Xia40cd41d2018-12-18 16:22:4311#include "third_party/skia/include/core/SkRegion.h"
12#include "ui/aura/window_tracker.h"
13
14namespace aura {
15
16// Provide updating of occlusion info on aura::Window.
17class DefaultWindowOcclusionChangeBuilder
18 : public WindowOcclusionChangeBuilder {
19 public:
20 DefaultWindowOcclusionChangeBuilder() = default;
Peter Boströmc8c12352021-09-21 23:37:1521
22 DefaultWindowOcclusionChangeBuilder(
23 const DefaultWindowOcclusionChangeBuilder&) = delete;
24 DefaultWindowOcclusionChangeBuilder& operator=(
25 const DefaultWindowOcclusionChangeBuilder&) = delete;
26
Xiyuan Xia40cd41d2018-12-18 16:22:4327 ~DefaultWindowOcclusionChangeBuilder() override {
Xiyuan Xiad7e4d942019-06-12 22:32:5228 // No frame eviction until all occlusion state changes are applied.
29 viz::FrameEvictionManager::ScopedPause scoped_frame_eviction_pause;
30
Xiyuan Xia40cd41d2018-12-18 16:22:4331 while (!windows_.windows().empty()) {
32 Window* window = windows_.Pop();
33 auto it = changes_.find(window);
34 if (it == changes_.end())
35 continue;
Xiyuan Xia40cd41d2018-12-18 16:22:4336 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 Xia40cd41d2018-12-18 16:22:4366};
67
68// static
69std::unique_ptr<WindowOcclusionChangeBuilder>
70WindowOcclusionChangeBuilder::Create() {
71 return std::make_unique<DefaultWindowOcclusionChangeBuilder>();
72}
73
74} // namespace aura