blob: bd640df81eaf64eb7322a2fe38860ace290241ae [file] [log] [blame]
Prabir Pradhan48f8cb92021-08-26 14:05:36 -07001/*
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
Michael Wrightc9e53042022-10-22 03:18:32 +010023#include <android-base/stringprintf.h>
Prabir Pradhan48f8cb92021-08-26 14:05:36 -070024#include <log/log.h>
25
Michael Wrightc9e53042022-10-22 03:18:32 +010026#include <inttypes.h>
27
28#define INDENT " "
29
Prabir Pradhan48f8cb92021-08-26 14:05:36 -070030namespace android::gui {
31
32// --- DisplayInfo ---
33
34status_t DisplayInfo::readFromParcel(const android::Parcel* parcel) {
35 if (parcel == nullptr) {
36 ALOGE("%s: Null parcel", __func__);
37 return BAD_VALUE;
38 }
39
40 float dsdx, dtdx, tx, dtdy, dsdy, ty;
41 SAFE_PARCEL(parcel->readInt32, &displayId);
42 SAFE_PARCEL(parcel->readInt32, &logicalWidth);
43 SAFE_PARCEL(parcel->readInt32, &logicalHeight);
44 SAFE_PARCEL(parcel->readFloat, &dsdx);
45 SAFE_PARCEL(parcel->readFloat, &dtdx);
46 SAFE_PARCEL(parcel->readFloat, &tx);
47 SAFE_PARCEL(parcel->readFloat, &dtdy);
48 SAFE_PARCEL(parcel->readFloat, &dsdy);
49 SAFE_PARCEL(parcel->readFloat, &ty);
50
51 transform.set({dsdx, dtdx, tx, dtdy, dsdy, ty, 0, 0, 1});
52
53 return OK;
54}
55
56status_t DisplayInfo::writeToParcel(android::Parcel* parcel) const {
57 if (parcel == nullptr) {
58 ALOGE("%s: Null parcel", __func__);
59 return BAD_VALUE;
60 }
61
62 SAFE_PARCEL(parcel->writeInt32, displayId);
63 SAFE_PARCEL(parcel->writeInt32, logicalWidth);
64 SAFE_PARCEL(parcel->writeInt32, logicalHeight);
65 SAFE_PARCEL(parcel->writeFloat, transform.dsdx());
66 SAFE_PARCEL(parcel->writeFloat, transform.dtdx());
67 SAFE_PARCEL(parcel->writeFloat, transform.tx());
68 SAFE_PARCEL(parcel->writeFloat, transform.dtdy());
69 SAFE_PARCEL(parcel->writeFloat, transform.dsdy());
70 SAFE_PARCEL(parcel->writeFloat, transform.ty());
71
72 return OK;
73}
74
Michael Wrightc9e53042022-10-22 03:18:32 +010075void DisplayInfo::dump(std::string& out, const char* prefix) const {
76 using android::base::StringAppendF;
77
78 out += prefix;
79 StringAppendF(&out, "DisplayViewport[id=%" PRId32 "]\n", displayId);
80 out += prefix;
81 StringAppendF(&out, INDENT "Width=%" PRId32 ", Height=%" PRId32 "\n", logicalWidth,
82 logicalHeight);
83 std::string transformPrefix(prefix);
84 transformPrefix.append(INDENT);
85 transform.dump(out, "Transform", transformPrefix.c_str());
86}
87
Prabir Pradhan48f8cb92021-08-26 14:05:36 -070088} // namespace android::gui