blob: 23724a727457537e92ff7a168acbda231ae74264 [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"
10#include "third_party/skia/include/core/SkRegion.h"
11#include "ui/aura/window_tracker.h"
12
13namespace aura {
14
15// Provide updating of occlusion info on aura::Window.
16class DefaultWindowOcclusionChangeBuilder
17 : public WindowOcclusionChangeBuilder {
18 public:
19 DefaultWindowOcclusionChangeBuilder() = default;
20 ~DefaultWindowOcclusionChangeBuilder() override {
21 while (!windows_.windows().empty()) {
22 Window* window = windows_.Pop();
23 auto it = changes_.find(window);
24 if (it == changes_.end())
25 continue;
26
27 window->SetOcclusionInfo(it->second.occlusion_state,
28 it->second.occluded_region);
29 }
30 changes_.clear();
31 }
32
33 private:
34 struct OcclusionData {
35 Window::OcclusionState occlusion_state;
36 SkRegion occluded_region;
37 };
38
39 // WindowOcclusionChangeBuilder:
40 void Add(Window* window,
41 Window::OcclusionState occlusion_state,
42 SkRegion occluded_region) override {
43 // Change back to UNKNOWN is not allowed.
44 DCHECK_NE(occlusion_state, Window::OcclusionState::UNKNOWN);
45
46 windows_.Add(window);
47 changes_[window] = {occlusion_state, occluded_region};
48 }
49
50 // Tracks live windows that has a change. This is needed in addition to the
51 // keys in |changes_| because the window tree may change while changes are
52 // accumulated or being applied.
53 WindowTracker windows_;
54
55 // Stores the accumulated occlusion changes.
56 base::flat_map<Window*, OcclusionData> changes_;
57
58 DISALLOW_COPY_AND_ASSIGN(DefaultWindowOcclusionChangeBuilder);
59};
60
61// static
62std::unique_ptr<WindowOcclusionChangeBuilder>
63WindowOcclusionChangeBuilder::Create() {
64 return std::make_unique<DefaultWindowOcclusionChangeBuilder>();
65}
66
67} // namespace aura