blob: 47cec0778e90e0c30c57580d037b04c74066e92e [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
Linnan Li13bf76a2024-05-05 19:18:02 +080040 int32_t displayIdInt;
Prabir Pradhan48f8cb92021-08-26 14:05:36 -070041 float dsdx, dtdx, tx, dtdy, dsdy, ty;
Linnan Li13bf76a2024-05-05 19:18:02 +080042 SAFE_PARCEL(parcel->readInt32, &displayIdInt);
Prabir Pradhan48f8cb92021-08-26 14:05:36 -070043 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
Linnan Li13bf76a2024-05-05 19:18:02 +080052 displayId = ui::LogicalDisplayId{displayIdInt};
Prabir Pradhan48f8cb92021-08-26 14:05:36 -070053 transform.set({dsdx, dtdx, tx, dtdy, dsdy, ty, 0, 0, 1});
54
55 return OK;
56}
57
58status_t DisplayInfo::writeToParcel(android::Parcel* parcel) const {
59 if (parcel == nullptr) {
60 ALOGE("%s: Null parcel", __func__);
61 return BAD_VALUE;
62 }
63
Linnan Li13bf76a2024-05-05 19:18:02 +080064 SAFE_PARCEL(parcel->writeInt32, displayId.val());
Prabir Pradhan48f8cb92021-08-26 14:05:36 -070065 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
Michael Wrightc9e53042022-10-22 03:18:32 +010077void DisplayInfo::dump(std::string& out, const char* prefix) const {
78 using android::base::StringAppendF;
79
80 out += prefix;
Linnan Li13bf76a2024-05-05 19:18:02 +080081 StringAppendF(&out, "DisplayViewport[id=%s]\n", displayId.toString().c_str());
Michael Wrightc9e53042022-10-22 03:18:32 +010082 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
Prabir Pradhan48f8cb92021-08-26 14:05:36 -070090} // namespace android::gui