Prabir Pradhan | 48f8cb9 | 2021-08-26 14:05:36 -0700 | [diff] [blame] | 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 | |
Michael Wright | c9e5304 | 2022-10-22 03:18:32 +0100 | [diff] [blame] | 23 | #include <android-base/stringprintf.h> |
Prabir Pradhan | 48f8cb9 | 2021-08-26 14:05:36 -0700 | [diff] [blame] | 24 | #include <log/log.h> |
| 25 | |
Michael Wright | c9e5304 | 2022-10-22 03:18:32 +0100 | [diff] [blame] | 26 | #include <inttypes.h> |
| 27 | |
| 28 | #define INDENT " " |
| 29 | |
Prabir Pradhan | 48f8cb9 | 2021-08-26 14:05:36 -0700 | [diff] [blame] | 30 | namespace android::gui { |
| 31 | |
| 32 | // --- DisplayInfo --- |
| 33 | |
| 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 | |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 40 | int32_t displayIdInt; |
Prabir Pradhan | 48f8cb9 | 2021-08-26 14:05:36 -0700 | [diff] [blame] | 41 | float dsdx, dtdx, tx, dtdy, dsdy, ty; |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 42 | SAFE_PARCEL(parcel->readInt32, &displayIdInt); |
Prabir Pradhan | 48f8cb9 | 2021-08-26 14:05:36 -0700 | [diff] [blame] | 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 | |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 52 | displayId = ui::LogicalDisplayId{displayIdInt}; |
Prabir Pradhan | 48f8cb9 | 2021-08-26 14:05:36 -0700 | [diff] [blame] | 53 | transform.set({dsdx, dtdx, tx, dtdy, dsdy, ty, 0, 0, 1}); |
| 54 | |
| 55 | return OK; |
| 56 | } |
| 57 | |
| 58 | status_t DisplayInfo::writeToParcel(android::Parcel* parcel) const { |
| 59 | if (parcel == nullptr) { |
| 60 | ALOGE("%s: Null parcel", __func__); |
| 61 | return BAD_VALUE; |
| 62 | } |
| 63 | |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 64 | SAFE_PARCEL(parcel->writeInt32, displayId.val()); |
Prabir Pradhan | 48f8cb9 | 2021-08-26 14:05:36 -0700 | [diff] [blame] | 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 | |
Michael Wright | c9e5304 | 2022-10-22 03:18:32 +0100 | [diff] [blame] | 77 | void DisplayInfo::dump(std::string& out, const char* prefix) const { |
| 78 | using android::base::StringAppendF; |
| 79 | |
| 80 | out += prefix; |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 81 | StringAppendF(&out, "DisplayViewport[id=%s]\n", displayId.toString().c_str()); |
Michael Wright | c9e5304 | 2022-10-22 03:18:32 +0100 | [diff] [blame] | 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 | |
Prabir Pradhan | 48f8cb9 | 2021-08-26 14:05:36 -0700 | [diff] [blame] | 90 | } // namespace android::gui |