blob: 8411daae366c4580bb5234872654bcad5f393088 [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
7#include "base/containers/flat_map.h"
8#include "base/logging.h"
9#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;
21 ~DefaultWindowOcclusionChangeBuilder() override {
Xiyuan Xiad7e4d942019-06-12 22:32:5222 // No frame eviction until all occlusion state changes are applied.
23 viz::FrameEvictionManager::ScopedPause scoped_frame_eviction_pause;
24
Xiyuan Xia40cd41d2018-12-18 16:22:4325 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
66std::unique_ptr<WindowOcclusionChangeBuilder>
67WindowOcclusionChangeBuilder::Create() {
68 return std::make_unique<DefaultWindowOcclusionChangeBuilder>();
69}
70
71} // namespace aura