1 /*
2 * Copyright 2020 The Android Open Source Project
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 #pragma once
18
19 #include <inttypes.h>
20 #include <iosfwd>
21 #include <iostream>
22
23 #include <math/HashCombine.h>
24
25 namespace android {
26
27 struct BlurRegion {
28 uint32_t blurRadius;
29 float cornerRadiusTL;
30 float cornerRadiusTR;
31 float cornerRadiusBL;
32 float cornerRadiusBR;
33 float alpha;
34 int left;
35 int top;
36 int right;
37 int bottom;
38
39 inline bool operator==(const BlurRegion& other) const {
40 return blurRadius == other.blurRadius && cornerRadiusTL == other.cornerRadiusTL &&
41 cornerRadiusTR == other.cornerRadiusTR && cornerRadiusBL == other.cornerRadiusBL &&
42 cornerRadiusBR == other.cornerRadiusBR && alpha == other.alpha &&
43 left == other.left && top == other.top && right == other.right &&
44 bottom == other.bottom;
45 }
46
47 inline bool operator!=(const BlurRegion& other) const { return !(*this == other); }
48 };
49
PrintTo(const BlurRegion & blurRegion,::std::ostream * os)50 static inline void PrintTo(const BlurRegion& blurRegion, ::std::ostream* os) {
51 *os << "BlurRegion {";
52 *os << "\n .blurRadius = " << blurRegion.blurRadius;
53 *os << "\n .cornerRadiusTL = " << blurRegion.cornerRadiusTL;
54 *os << "\n .cornerRadiusTR = " << blurRegion.cornerRadiusTR;
55 *os << "\n .cornerRadiusBL = " << blurRegion.cornerRadiusBL;
56 *os << "\n .cornerRadiusBR = " << blurRegion.cornerRadiusBR;
57 *os << "\n .alpha = " << blurRegion.alpha;
58 *os << "\n .left = " << blurRegion.left;
59 *os << "\n .top = " << blurRegion.top;
60 *os << "\n .right = " << blurRegion.right;
61 *os << "\n .bottom = " << blurRegion.bottom;
62 *os << "\n}";
63 }
64
65 } // namespace android
66
67 namespace std {
68 template <>
69 struct hash<android::BlurRegion> {
70 size_t operator()(const android::BlurRegion& region) const {
71 return android::hashCombine(region.blurRadius, region.cornerRadiusTL, region.cornerRadiusTR,
72 region.cornerRadiusBL, region.cornerRadiusBR, region.alpha,
73 region.left, region.top, region.right, region.bottom);
74 }
75 };
76 } // namespace std