1 /*
2 * Copyright 2019 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 #include <cinttypes>
18
19 #include <android-base/stringprintf.h>
20 #include <compositionengine/impl/DumpHelpers.h>
21
22 namespace android::compositionengine::impl {
23
24 using android::base::StringAppendF;
25
dumpVal(std::string & out,const char * name,bool value)26 void dumpVal(std::string& out, const char* name, bool value) {
27 StringAppendF(&out, "%s=%s ", name, value ? "true" : "false");
28 }
29
dumpVal(std::string & out,const char * name,const void * value)30 void dumpVal(std::string& out, const char* name, const void* value) {
31 StringAppendF(&out, "%s=%p ", name, value);
32 }
33
dumpVal(std::string & out,const char * name,int value)34 void dumpVal(std::string& out, const char* name, int value) {
35 StringAppendF(&out, "%s=%d ", name, value);
36 }
37
dumpVal(std::string & out,const char * name,float value)38 void dumpVal(std::string& out, const char* name, float value) {
39 StringAppendF(&out, "%s=%f ", name, value);
40 }
41
dumpVal(std::string & out,const char * name,uint32_t value)42 void dumpVal(std::string& out, const char* name, uint32_t value) {
43 StringAppendF(&out, "%s=%u ", name, value);
44 }
45
dumpHex(std::string & out,const char * name,uint64_t value)46 void dumpHex(std::string& out, const char* name, uint64_t value) {
47 StringAppendF(&out, "%s=0x08%" PRIx64 " ", name, value);
48 }
49
dumpVal(std::string & out,const char * name,const char * value)50 void dumpVal(std::string& out, const char* name, const char* value) {
51 StringAppendF(&out, "%s=%s ", name, value);
52 }
53
dumpVal(std::string & out,const char * name,const std::string & value)54 void dumpVal(std::string& out, const char* name, const std::string& value) {
55 dumpVal(out, name, value.c_str());
56 }
57
dumpVal(std::string & out,const char * name,const char * valueName,int value)58 void dumpVal(std::string& out, const char* name, const char* valueName, int value) {
59 StringAppendF(&out, "%s=%s (%d) ", name, valueName, value);
60 }
61
dumpVal(std::string & out,const char * name,const std::string & valueName,int value)62 void dumpVal(std::string& out, const char* name, const std::string& valueName, int value) {
63 dumpVal(out, name, valueName.c_str(), value);
64 }
65
dumpVal(std::string & out,const char * name,const FloatRect & rect)66 void dumpVal(std::string& out, const char* name, const FloatRect& rect) {
67 StringAppendF(&out, "%s=[%f %f %f %f] ", name, rect.left, rect.top, rect.right, rect.bottom);
68 }
69
dumpVal(std::string & out,const char * name,const Rect & rect)70 void dumpVal(std::string& out, const char* name, const Rect& rect) {
71 StringAppendF(&out, "%s=[%d %d %d %d] ", name, rect.left, rect.top, rect.right, rect.bottom);
72 }
73
dumpVal(std::string & out,const char * name,const Region & region)74 void dumpVal(std::string& out, const char* name, const Region& region) {
75 region.dump(out, name, 0);
76 }
77
dumpVal(std::string & out,const char * name,const ui::Transform & transform)78 void dumpVal(std::string& out, const char* name, const ui::Transform& transform) {
79 transform.dump(out, name);
80 }
81
dumpVal(std::string & out,const char * name,const ui::Size & size)82 void dumpVal(std::string& out, const char* name, const ui::Size& size) {
83 StringAppendF(&out, "%s=[%d %d] ", name, size.width, size.height);
84 }
85
dumpVal(std::string & out,const char * name,const mat4 & tr)86 void dumpVal(std::string& out, const char* name, const mat4& tr) {
87 StringAppendF(&out,
88 "%s=["
89 /* clang-format off */
90 "[%0.3f,%0.3f,%0.3f,%0.3f]"
91 "[%0.3f,%0.3f,%0.3f,%0.3f]"
92 "[%0.3f,%0.3f,%0.3f,%0.3f]"
93 "[%0.3f,%0.3f,%0.3f,%0.3f]]",
94 name,
95 tr[0][0], tr[1][0], tr[2][0], tr[3][0],
96 tr[0][1], tr[1][1], tr[2][1], tr[3][1],
97 tr[0][2], tr[1][2], tr[2][2], tr[3][2],
98 tr[0][3], tr[1][3], tr[2][3], tr[3][3]
99 ); /* clang-format on */
100 }
101
102 } // namespace android::compositionengine::impl
103