• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 package com.android.server.wm.traces.common
18 
19 /**
20  * Wrapper for Color3 (frameworks/native/services/surfaceflinger/layerproto/transactions.proto)
21  *
22  * This class is used by flicker and Winscope
23  */
24 open class Color3(val r: Float, val g: Float, val b: Float) {
25     open val isEmpty: Boolean
26         get() = r < 0 || g < 0 || b < 0
27 
28     open val isNotEmpty: Boolean
29         get() = !isEmpty
30 
prettyPrintnull31     open fun prettyPrint(): String {
32         val r = FloatFormatter.format(r)
33         val g = FloatFormatter.format(g)
34         val b = FloatFormatter.format(b)
35         return "r:$r g:$g b:$b"
36     }
37 
toStringnull38     override fun toString(): String = if (isEmpty) "[empty]" else prettyPrint()
39 
40     override fun equals(other: Any?): Boolean {
41         if (this === other) return true
42         if (other !is Color) return false
43 
44         if (r != other.r) return false
45         if (g != other.g) return false
46         if (b != other.b) return false
47 
48         return true
49     }
50 
hashCodenull51     override fun hashCode(): Int {
52         var result = r.hashCode()
53         result = 31 * result + g.hashCode()
54         result = 31 * result + b.hashCode()
55         return result
56     }
57 
58     companion object {
59         val EMPTY: Color3 = Color3(r = -1f, g = -1f, b = -1f)
60     }
61 }
62