blob: 15b2221464d5ed649d477af79fce1fb98ae7db9c [file] [log] [blame]
Kalle Raitaa099a242017-01-11 11:17:29 -08001/*
2 * Copyright (C) 2017 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 <gui/LayerDebugInfo.h>
18
Yiwei Zhang5434a782018-12-05 18:06:32 -080019#include <android-base/stringprintf.h>
20
Kalle Raitaa099a242017-01-11 11:17:29 -080021#include <ui/DebugUtils.h>
22
23#include <binder/Parcel.h>
24
Kalle Raitaa099a242017-01-11 11:17:29 -080025using namespace android;
Yiwei Zhang5434a782018-12-05 18:06:32 -080026using android::base::StringAppendF;
Kalle Raitaa099a242017-01-11 11:17:29 -080027
28#define RETURN_ON_ERROR(X) do {status_t res = (X); if (res != NO_ERROR) return res;} while(false)
29
Huihong Luo05539a12022-02-23 10:29:40 -080030namespace android::gui {
Kalle Raitaa099a242017-01-11 11:17:29 -080031
32status_t LayerDebugInfo::writeToParcel(Parcel* parcel) const {
33 RETURN_ON_ERROR(parcel->writeCString(mName.c_str()));
34 RETURN_ON_ERROR(parcel->writeCString(mParentName.c_str()));
35 RETURN_ON_ERROR(parcel->writeCString(mType.c_str()));
36 RETURN_ON_ERROR(parcel->write(mTransparentRegion));
37 RETURN_ON_ERROR(parcel->write(mVisibleRegion));
38 RETURN_ON_ERROR(parcel->write(mSurfaceDamageRegion));
39 RETURN_ON_ERROR(parcel->writeUint32(mLayerStack));
40 RETURN_ON_ERROR(parcel->writeFloat(mX));
41 RETURN_ON_ERROR(parcel->writeFloat(mY));
42 RETURN_ON_ERROR(parcel->writeUint32(mZ));
43 RETURN_ON_ERROR(parcel->writeInt32(mWidth));
44 RETURN_ON_ERROR(parcel->writeInt32(mHeight));
45 RETURN_ON_ERROR(parcel->write(mCrop));
chaviw13fdc492017-06-27 12:40:18 -070046 RETURN_ON_ERROR(parcel->writeFloat(mColor.r));
47 RETURN_ON_ERROR(parcel->writeFloat(mColor.g));
48 RETURN_ON_ERROR(parcel->writeFloat(mColor.b));
49 RETURN_ON_ERROR(parcel->writeFloat(mColor.a));
Kalle Raitaa099a242017-01-11 11:17:29 -080050 RETURN_ON_ERROR(parcel->writeUint32(mFlags));
51 RETURN_ON_ERROR(parcel->writeInt32(mPixelFormat));
52 RETURN_ON_ERROR(parcel->writeUint32(static_cast<uint32_t>(mDataSpace)));
53 for (size_t index = 0; index < 4; index++) {
54 RETURN_ON_ERROR(parcel->writeFloat(mMatrix[index / 2][index % 2]));
55 }
56 RETURN_ON_ERROR(parcel->writeInt32(mActiveBufferWidth));
57 RETURN_ON_ERROR(parcel->writeInt32(mActiveBufferHeight));
58 RETURN_ON_ERROR(parcel->writeInt32(mActiveBufferStride));
59 RETURN_ON_ERROR(parcel->writeInt32(mActiveBufferFormat));
60 RETURN_ON_ERROR(parcel->writeInt32(mNumQueuedFrames));
Kalle Raitaa099a242017-01-11 11:17:29 -080061 RETURN_ON_ERROR(parcel->writeBool(mIsOpaque));
62 RETURN_ON_ERROR(parcel->writeBool(mContentDirty));
John Reckc00c6692021-02-16 11:37:33 -050063 RETURN_ON_ERROR(parcel->write(mStretchEffect));
Kalle Raitaa099a242017-01-11 11:17:29 -080064 return NO_ERROR;
65}
66
67status_t LayerDebugInfo::readFromParcel(const Parcel* parcel) {
68 mName = parcel->readCString();
69 RETURN_ON_ERROR(parcel->errorCheck());
70 mParentName = parcel->readCString();
71 RETURN_ON_ERROR(parcel->errorCheck());
72 mType = parcel->readCString();
73 RETURN_ON_ERROR(parcel->errorCheck());
74 RETURN_ON_ERROR(parcel->read(mTransparentRegion));
75 RETURN_ON_ERROR(parcel->read(mVisibleRegion));
76 RETURN_ON_ERROR(parcel->read(mSurfaceDamageRegion));
77 RETURN_ON_ERROR(parcel->readUint32(&mLayerStack));
78 RETURN_ON_ERROR(parcel->readFloat(&mX));
79 RETURN_ON_ERROR(parcel->readFloat(&mY));
80 RETURN_ON_ERROR(parcel->readUint32(&mZ));
81 RETURN_ON_ERROR(parcel->readInt32(&mWidth));
82 RETURN_ON_ERROR(parcel->readInt32(&mHeight));
83 RETURN_ON_ERROR(parcel->read(mCrop));
chaviw13fdc492017-06-27 12:40:18 -070084 mColor.r = parcel->readFloat();
85 RETURN_ON_ERROR(parcel->errorCheck());
86 mColor.g = parcel->readFloat();
87 RETURN_ON_ERROR(parcel->errorCheck());
88 mColor.b = parcel->readFloat();
89 RETURN_ON_ERROR(parcel->errorCheck());
90 mColor.a = parcel->readFloat();
91 RETURN_ON_ERROR(parcel->errorCheck());
Kalle Raitaa099a242017-01-11 11:17:29 -080092 RETURN_ON_ERROR(parcel->readUint32(&mFlags));
93 RETURN_ON_ERROR(parcel->readInt32(&mPixelFormat));
94 // \todo [2017-07-25 kraita]: Static casting mDataSpace pointer to an uint32 does work. Better ways?
95 mDataSpace = static_cast<android_dataspace>(parcel->readUint32());
96 RETURN_ON_ERROR(parcel->errorCheck());
97 for (size_t index = 0; index < 4; index++) {
98 RETURN_ON_ERROR(parcel->readFloat(&mMatrix[index / 2][index % 2]));
99 }
100 RETURN_ON_ERROR(parcel->readInt32(&mActiveBufferWidth));
101 RETURN_ON_ERROR(parcel->readInt32(&mActiveBufferHeight));
102 RETURN_ON_ERROR(parcel->readInt32(&mActiveBufferStride));
103 RETURN_ON_ERROR(parcel->readInt32(&mActiveBufferFormat));
104 RETURN_ON_ERROR(parcel->readInt32(&mNumQueuedFrames));
Kalle Raitaa099a242017-01-11 11:17:29 -0800105 RETURN_ON_ERROR(parcel->readBool(&mIsOpaque));
106 RETURN_ON_ERROR(parcel->readBool(&mContentDirty));
John Reckc00c6692021-02-16 11:37:33 -0500107 RETURN_ON_ERROR(parcel->read(mStretchEffect));
Kalle Raitaa099a242017-01-11 11:17:29 -0800108 return NO_ERROR;
109}
110
111std::string to_string(const LayerDebugInfo& info) {
Yiwei Zhang5434a782018-12-05 18:06:32 -0800112 std::string result;
Kalle Raitaa099a242017-01-11 11:17:29 -0800113
Yiwei Zhang5434a782018-12-05 18:06:32 -0800114 StringAppendF(&result, "+ %s (%s)\n", info.mType.c_str(), info.mName.c_str());
Kalle Raitaa099a242017-01-11 11:17:29 -0800115 info.mTransparentRegion.dump(result, "TransparentRegion");
116 info.mVisibleRegion.dump(result, "VisibleRegion");
117 info.mSurfaceDamageRegion.dump(result, "SurfaceDamageRegion");
John Reckc00c6692021-02-16 11:37:33 -0500118 if (info.mStretchEffect.hasEffect()) {
119 const auto& se = info.mStretchEffect;
Nader Jawad2dfc98b2021-04-08 20:35:39 -0700120 StringAppendF(&result,
121 " StretchEffect width = %f, height = %f vec=(%f, %f) "
122 "maxAmount=(%f, %f)\n",
123 se.width, se.height,
124 se.vectorX, se.vectorY, se.maxAmountX, se.maxAmountY);
John Reckc00c6692021-02-16 11:37:33 -0500125 }
Kalle Raitaa099a242017-01-11 11:17:29 -0800126
Yiwei Zhang5434a782018-12-05 18:06:32 -0800127 StringAppendF(&result, " layerStack=%4d, z=%9d, pos=(%g,%g), size=(%4d,%4d), ",
128 info.mLayerStack, info.mZ, static_cast<double>(info.mX),
129 static_cast<double>(info.mY), info.mWidth, info.mHeight);
Kalle Raitaa099a242017-01-11 11:17:29 -0800130
Yiwei Zhang5434a782018-12-05 18:06:32 -0800131 StringAppendF(&result, "crop=%s, ", to_string(info.mCrop).c_str());
132 StringAppendF(&result, "isOpaque=%1d, invalidate=%1d, ", info.mIsOpaque, info.mContentDirty);
133 StringAppendF(&result, "dataspace=%s, ", dataspaceDetails(info.mDataSpace).c_str());
134 StringAppendF(&result, "pixelformat=%s, ", decodePixelFormat(info.mPixelFormat).c_str());
135 StringAppendF(&result, "color=(%.3f,%.3f,%.3f,%.3f), flags=0x%08x, ",
136 static_cast<double>(info.mColor.r), static_cast<double>(info.mColor.g),
137 static_cast<double>(info.mColor.b), static_cast<double>(info.mColor.a),
138 info.mFlags);
139 StringAppendF(&result, "tr=[%.2f, %.2f][%.2f, %.2f]", static_cast<double>(info.mMatrix[0][0]),
140 static_cast<double>(info.mMatrix[0][1]), static_cast<double>(info.mMatrix[1][0]),
141 static_cast<double>(info.mMatrix[1][1]));
Kalle Raitaa099a242017-01-11 11:17:29 -0800142 result.append("\n");
Yiwei Zhang5434a782018-12-05 18:06:32 -0800143 StringAppendF(&result, " parent=%s\n", info.mParentName.c_str());
144 StringAppendF(&result, " activeBuffer=[%4ux%4u:%4u,%s],", info.mActiveBufferWidth,
145 info.mActiveBufferHeight, info.mActiveBufferStride,
146 decodePixelFormat(info.mActiveBufferFormat).c_str());
Vishnu Nair1b700192022-02-04 10:09:47 -0800147 StringAppendF(&result, " queued-frames=%d", info.mNumQueuedFrames);
Kalle Raitaa099a242017-01-11 11:17:29 -0800148 result.append("\n");
Yiwei Zhang5434a782018-12-05 18:06:32 -0800149 return result;
Kalle Raitaa099a242017-01-11 11:17:29 -0800150}
151
Huihong Luo05539a12022-02-23 10:29:40 -0800152} // namespace android::gui