1 /*
2 * Copyright 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 #define LOG_TAG "DisplayInfo"
18
19 #include <binder/Parcel.h>
20 #include <gui/DisplayInfo.h>
21 #include <private/gui/ParcelUtils.h>
22
23 #include <android-base/stringprintf.h>
24 #include <log/log.h>
25
26 #include <inttypes.h>
27
28 #define INDENT " "
29
30 namespace android::gui {
31
32 // --- DisplayInfo ---
33
readFromParcel(const android::Parcel * parcel)34 status_t DisplayInfo::readFromParcel(const android::Parcel* parcel) {
35 if (parcel == nullptr) {
36 ALOGE("%s: Null parcel", __func__);
37 return BAD_VALUE;
38 }
39
40 int32_t displayIdInt;
41 float dsdx, dtdx, tx, dtdy, dsdy, ty;
42 SAFE_PARCEL(parcel->readInt32, &displayIdInt);
43 SAFE_PARCEL(parcel->readInt32, &logicalWidth);
44 SAFE_PARCEL(parcel->readInt32, &logicalHeight);
45 SAFE_PARCEL(parcel->readFloat, &dsdx);
46 SAFE_PARCEL(parcel->readFloat, &dtdx);
47 SAFE_PARCEL(parcel->readFloat, &tx);
48 SAFE_PARCEL(parcel->readFloat, &dtdy);
49 SAFE_PARCEL(parcel->readFloat, &dsdy);
50 SAFE_PARCEL(parcel->readFloat, &ty);
51
52 displayId = ui::LogicalDisplayId{displayIdInt};
53 transform.set({dsdx, dtdx, tx, dtdy, dsdy, ty, 0, 0, 1});
54
55 return OK;
56 }
57
writeToParcel(android::Parcel * parcel) const58 status_t DisplayInfo::writeToParcel(android::Parcel* parcel) const {
59 if (parcel == nullptr) {
60 ALOGE("%s: Null parcel", __func__);
61 return BAD_VALUE;
62 }
63
64 SAFE_PARCEL(parcel->writeInt32, displayId.val());
65 SAFE_PARCEL(parcel->writeInt32, logicalWidth);
66 SAFE_PARCEL(parcel->writeInt32, logicalHeight);
67 SAFE_PARCEL(parcel->writeFloat, transform.dsdx());
68 SAFE_PARCEL(parcel->writeFloat, transform.dtdx());
69 SAFE_PARCEL(parcel->writeFloat, transform.tx());
70 SAFE_PARCEL(parcel->writeFloat, transform.dtdy());
71 SAFE_PARCEL(parcel->writeFloat, transform.dsdy());
72 SAFE_PARCEL(parcel->writeFloat, transform.ty());
73
74 return OK;
75 }
76
dump(std::string & out,const char * prefix) const77 void DisplayInfo::dump(std::string& out, const char* prefix) const {
78 using android::base::StringAppendF;
79
80 out += prefix;
81 StringAppendF(&out, "DisplayViewport[id=%s]\n", displayId.toString().c_str());
82 out += prefix;
83 StringAppendF(&out, INDENT "Width=%" PRId32 ", Height=%" PRId32 "\n", logicalWidth,
84 logicalHeight);
85 std::string transformPrefix(prefix);
86 transformPrefix.append(INDENT);
87 transform.dump(out, "Transform", transformPrefix.c_str());
88 }
89
90 } // namespace android::gui
91