blob: 9a39ec28aa3dd428e2720dcaa8eae7fe3ae5dbad [file] [log] [blame]
Chris Craik0519c812015-02-11 13:17:06 -08001/*
2 * Copyright (C) 2015 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#ifndef FLOATCOLOR_H
17#define FLOATCOLOR_H
18
19#include "utils/Macros.h"
sergeyvf42bf3e2016-03-11 13:45:15 -080020#include "utils/MathUtils.h"
Chris Craik0519c812015-02-11 13:17:06 -080021
Chris Craik922d3a72015-02-13 17:47:21 -080022#include <stdint.h>
23
Chris Craik0519c812015-02-11 13:17:06 -080024namespace android {
25namespace uirenderer {
26
27struct FloatColor {
Chris Craik922d3a72015-02-13 17:47:21 -080028 void set(uint32_t color) {
29 a = ((color >> 24) & 0xff) / 255.0f;
30 r = a * ((color >> 16) & 0xff) / 255.0f;
31 g = a * ((color >> 8) & 0xff) / 255.0f;
32 b = a * ((color ) & 0xff) / 255.0f;
33 }
34
Chris Craik2bb8f562015-02-17 16:42:02 -080035 bool isNotBlack() {
36 return a < 1.0f
37 || r > 0.0f
38 || g > 0.0f
39 || b > 0.0f;
40 }
41
sergeyvf42bf3e2016-03-11 13:45:15 -080042 bool operator==(const FloatColor& other) const {
43 return MathUtils::areEqual(r, other.r)
44 && MathUtils::areEqual(g, other.g)
45 && MathUtils::areEqual(b, other.b)
46 && MathUtils::areEqual(a, other.a);
47 }
48
49 bool operator!=(const FloatColor& other) const {
50 return !(*this == other);
51 }
52
Chris Craik0519c812015-02-11 13:17:06 -080053 float r;
54 float g;
55 float b;
56 float a;
57};
58
59REQUIRE_COMPATIBLE_LAYOUT(FloatColor);
60
61} /* namespace uirenderer */
62} /* namespace android */
63
64#endif /* FLOATCOLOR_H */