2 * Copyright (C) 2015 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef DRM_HWCOMPOSER_SEPERATE_RECTS_H_
18 #define DRM_HWCOMPOSER_SEPERATE_RECTS_H_
23 namespace seperate_rects {
25 template <typename TFloat>
29 TFloat left, top, right, bottom;
32 TFloat x1, y1, x2, y2;
42 Rect(TFloat xx1, TFloat yy1, TFloat xx2, TFloat yy2)
43 : x1(xx1), y1(yy1), x2(xx2), y2(yy2) {
47 Rect(const Rect<T> &rhs) {
48 for (int i = 0; i < 4; i++)
49 bounds[i] = rhs.bounds[i];
53 Rect<TFloat> &operator=(const Rect<T> &rhs) {
54 for (int i = 0; i < 4; i++)
55 bounds[i] = rhs.bounds[i];
59 bool operator==(const Rect &rhs) const {
60 for (int i = 0; i < 4; i++) {
61 if (bounds[i] != rhs.bounds[i])
69 template <typename TUInt>
77 IdSet(TId id) : bitset(0) {
82 bitset |= ((TUInt)1) << id;
85 void subtract(TId id) {
86 bitset &= ~(((TUInt)1) << id);
89 bool isEmpty() const {
93 TUInt getBits() const {
97 bool operator==(const IdSet<TId> &rhs) const {
98 return bitset == rhs.bitset;
101 bool operator<(const IdSet<TId> &rhs) const {
102 return bitset < rhs.bitset;
105 IdSet<TId> operator|(const IdSet<TId> &rhs) const {
107 ret.bitset = bitset | rhs.bitset;
111 IdSet<TId> operator|(TId id) const {
118 static const int max_elements = sizeof(TId) * 8;
124 template <typename TId, typename TNum>
129 RectSet(const IdSet<TId> &i, const Rect<TNum> &r) : id_set(i), rect(r) {
132 bool operator==(const RectSet<TId, TNum> &rhs) const {
133 return id_set == rhs.id_set && rect == rhs.rect;
137 // Seperates up to a maximum of 64 input rectangles into mutually non-
138 // overlapping rectangles that cover the exact same area and outputs those non-
139 // overlapping rectangles. Each output rectangle also includes the set of input
140 // rectangle indices that overlap the output rectangle encoded in a bitset. For
141 // example, an output rectangle that overlaps input rectangles in[0], in[1], and
142 // in[4], the bitset would be (ommitting leading zeroes) 10011.
143 void seperate_frects_64(const std::vector<Rect<float> > &in,
144 std::vector<RectSet<uint64_t, float> > *out);
146 } // namespace seperate_rects