OSDN Git Service

Remove fd from our tracking list when Thread is killed.
[android-x86/external-IA-Hardware-Composer.git] / common / utils / disjoint_layers.h
1 /*
2 // Copyright (c) 2016 Intel Corporation
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //      http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 */
16
17 #ifndef COMMON_UTILS_DISJOINT_LAYERS_H_
18 #define COMMON_UTILS_DISJOINT_LAYERS_H_
19
20 #include <stdint.h>
21
22 #include <hwcrect.h>
23
24 #include <vector>
25
26 namespace hwcomposer {
27
28 // Some of the structs are adopted from drm_hwcomposer
29 struct RectIDs {
30  public:
31   typedef uint64_t TId;
32
33   RectIDs() : bitset(0) {
34   }
35
36   explicit RectIDs(TId id) : bitset(0) {
37     add(id);
38   }
39
40   void add(TId id) {
41     bitset |= ((uint64_t)1) << id;
42   }
43
44   void subtract(TId id) {
45     bitset &= ~(((uint64_t)1) << id);
46   }
47
48   bool isEmpty() const {
49     return bitset == 0;
50   }
51
52   uint64_t getBits() const {
53     return bitset;
54   }
55
56   bool operator==(const RectIDs &rhs) const {
57     return bitset == rhs.bitset;
58   }
59
60   bool operator<(const RectIDs &rhs) const {
61     return bitset < rhs.bitset;
62   }
63
64   RectIDs operator|(const RectIDs &rhs) const {
65     RectIDs ret;
66     ret.bitset = bitset | rhs.bitset;
67     return ret;
68   }
69
70   RectIDs operator|(TId id) const {
71     RectIDs ret;
72     ret.bitset = bitset;
73     ret.add(id);
74     return ret;
75   }
76
77   static const int max_elements = sizeof(TId) * 8;
78
79  private:
80   uint64_t bitset;
81 };
82
83 template <typename TNum>
84 struct RectSet {
85   RectIDs id_set;
86   Rect<TNum> rect;
87
88   RectSet(const RectIDs &i, const Rect<TNum> &r) : id_set(i), rect(r) {
89   }
90
91   bool operator==(const RectSet<TNum> &rhs) const {
92     return (id_set == rhs.id_set) && (rect == rhs.rect);
93   }
94 };
95
96 void get_draw_regions(const std::vector<Rect<int>> &in,
97                       std::vector<RectSet<int>> *out);
98 }  // namespace hwcomposer
99
100 #endif  // COMMON_UTILS_DISJOINT_LAYERS_H_