Kalle Raita | a099a24 | 2017-01-11 11:17:29 -0800 | [diff] [blame^] | 1 | /* |
| 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 | |
| 19 | #include <ui/DebugUtils.h> |
| 20 | |
| 21 | #include <binder/Parcel.h> |
| 22 | |
| 23 | #include <utils/String8.h> |
| 24 | |
| 25 | using namespace android; |
| 26 | |
| 27 | #define RETURN_ON_ERROR(X) do {status_t res = (X); if (res != NO_ERROR) return res;} while(false) |
| 28 | |
| 29 | namespace android { |
| 30 | |
| 31 | status_t LayerDebugInfo::writeToParcel(Parcel* parcel) const { |
| 32 | RETURN_ON_ERROR(parcel->writeCString(mName.c_str())); |
| 33 | RETURN_ON_ERROR(parcel->writeCString(mParentName.c_str())); |
| 34 | RETURN_ON_ERROR(parcel->writeCString(mType.c_str())); |
| 35 | RETURN_ON_ERROR(parcel->write(mTransparentRegion)); |
| 36 | RETURN_ON_ERROR(parcel->write(mVisibleRegion)); |
| 37 | RETURN_ON_ERROR(parcel->write(mSurfaceDamageRegion)); |
| 38 | RETURN_ON_ERROR(parcel->writeUint32(mLayerStack)); |
| 39 | RETURN_ON_ERROR(parcel->writeFloat(mX)); |
| 40 | RETURN_ON_ERROR(parcel->writeFloat(mY)); |
| 41 | RETURN_ON_ERROR(parcel->writeUint32(mZ)); |
| 42 | RETURN_ON_ERROR(parcel->writeInt32(mWidth)); |
| 43 | RETURN_ON_ERROR(parcel->writeInt32(mHeight)); |
| 44 | RETURN_ON_ERROR(parcel->write(mCrop)); |
| 45 | RETURN_ON_ERROR(parcel->write(mFinalCrop)); |
| 46 | RETURN_ON_ERROR(parcel->writeFloat(mAlpha)); |
| 47 | RETURN_ON_ERROR(parcel->writeUint32(mFlags)); |
| 48 | RETURN_ON_ERROR(parcel->writeInt32(mPixelFormat)); |
| 49 | RETURN_ON_ERROR(parcel->writeUint32(static_cast<uint32_t>(mDataSpace))); |
| 50 | for (size_t index = 0; index < 4; index++) { |
| 51 | RETURN_ON_ERROR(parcel->writeFloat(mMatrix[index / 2][index % 2])); |
| 52 | } |
| 53 | RETURN_ON_ERROR(parcel->writeInt32(mActiveBufferWidth)); |
| 54 | RETURN_ON_ERROR(parcel->writeInt32(mActiveBufferHeight)); |
| 55 | RETURN_ON_ERROR(parcel->writeInt32(mActiveBufferStride)); |
| 56 | RETURN_ON_ERROR(parcel->writeInt32(mActiveBufferFormat)); |
| 57 | RETURN_ON_ERROR(parcel->writeInt32(mNumQueuedFrames)); |
| 58 | RETURN_ON_ERROR(parcel->writeBool(mRefreshPending)); |
| 59 | RETURN_ON_ERROR(parcel->writeBool(mIsOpaque)); |
| 60 | RETURN_ON_ERROR(parcel->writeBool(mContentDirty)); |
| 61 | return NO_ERROR; |
| 62 | } |
| 63 | |
| 64 | status_t LayerDebugInfo::readFromParcel(const Parcel* parcel) { |
| 65 | mName = parcel->readCString(); |
| 66 | RETURN_ON_ERROR(parcel->errorCheck()); |
| 67 | mParentName = parcel->readCString(); |
| 68 | RETURN_ON_ERROR(parcel->errorCheck()); |
| 69 | mType = parcel->readCString(); |
| 70 | RETURN_ON_ERROR(parcel->errorCheck()); |
| 71 | RETURN_ON_ERROR(parcel->read(mTransparentRegion)); |
| 72 | RETURN_ON_ERROR(parcel->read(mVisibleRegion)); |
| 73 | RETURN_ON_ERROR(parcel->read(mSurfaceDamageRegion)); |
| 74 | RETURN_ON_ERROR(parcel->readUint32(&mLayerStack)); |
| 75 | RETURN_ON_ERROR(parcel->readFloat(&mX)); |
| 76 | RETURN_ON_ERROR(parcel->readFloat(&mY)); |
| 77 | RETURN_ON_ERROR(parcel->readUint32(&mZ)); |
| 78 | RETURN_ON_ERROR(parcel->readInt32(&mWidth)); |
| 79 | RETURN_ON_ERROR(parcel->readInt32(&mHeight)); |
| 80 | RETURN_ON_ERROR(parcel->read(mCrop)); |
| 81 | RETURN_ON_ERROR(parcel->read(mFinalCrop)); |
| 82 | RETURN_ON_ERROR(parcel->readFloat(&mAlpha)); |
| 83 | RETURN_ON_ERROR(parcel->readUint32(&mFlags)); |
| 84 | RETURN_ON_ERROR(parcel->readInt32(&mPixelFormat)); |
| 85 | // \todo [2017-07-25 kraita]: Static casting mDataSpace pointer to an uint32 does work. Better ways? |
| 86 | mDataSpace = static_cast<android_dataspace>(parcel->readUint32()); |
| 87 | RETURN_ON_ERROR(parcel->errorCheck()); |
| 88 | for (size_t index = 0; index < 4; index++) { |
| 89 | RETURN_ON_ERROR(parcel->readFloat(&mMatrix[index / 2][index % 2])); |
| 90 | } |
| 91 | RETURN_ON_ERROR(parcel->readInt32(&mActiveBufferWidth)); |
| 92 | RETURN_ON_ERROR(parcel->readInt32(&mActiveBufferHeight)); |
| 93 | RETURN_ON_ERROR(parcel->readInt32(&mActiveBufferStride)); |
| 94 | RETURN_ON_ERROR(parcel->readInt32(&mActiveBufferFormat)); |
| 95 | RETURN_ON_ERROR(parcel->readInt32(&mNumQueuedFrames)); |
| 96 | RETURN_ON_ERROR(parcel->readBool(&mRefreshPending)); |
| 97 | RETURN_ON_ERROR(parcel->readBool(&mIsOpaque)); |
| 98 | RETURN_ON_ERROR(parcel->readBool(&mContentDirty)); |
| 99 | return NO_ERROR; |
| 100 | } |
| 101 | |
| 102 | std::string to_string(const LayerDebugInfo& info) { |
| 103 | String8 result; |
| 104 | |
| 105 | result.appendFormat("+ %s (%s)\n", info.mType.c_str(), info.mName.c_str()); |
| 106 | info.mTransparentRegion.dump(result, "TransparentRegion"); |
| 107 | info.mVisibleRegion.dump(result, "VisibleRegion"); |
| 108 | info.mSurfaceDamageRegion.dump(result, "SurfaceDamageRegion"); |
| 109 | |
| 110 | result.appendFormat(" layerStack=%4d, z=%9d, pos=(%g,%g), size=(%4d,%4d), ", |
| 111 | info.mLayerStack, info.mZ, static_cast<double>(info.mX), static_cast<double>(info.mY), |
| 112 | info.mWidth, info.mHeight); |
| 113 | |
| 114 | result.appendFormat("crop=%s, finalCrop=%s, ", |
| 115 | to_string(info.mCrop).c_str(), to_string(info.mFinalCrop).c_str()); |
| 116 | result.appendFormat("isOpaque=%1d, invalidate=%1d, ", info.mIsOpaque, info.mContentDirty); |
| 117 | result.appendFormat("dataspace=%s, ", dataspaceDetails(info.mDataSpace).c_str()); |
| 118 | result.appendFormat("pixelformat=%s, ", decodePixelFormat(info.mPixelFormat).c_str()); |
| 119 | result.appendFormat("alpha=%.3f, flags=0x%08x, ", |
| 120 | static_cast<double>(info.mAlpha), info.mFlags); |
| 121 | result.appendFormat("tr=[%.2f, %.2f][%.2f, %.2f]", |
| 122 | static_cast<double>(info.mMatrix[0][0]), static_cast<double>(info.mMatrix[0][1]), |
| 123 | static_cast<double>(info.mMatrix[1][0]), static_cast<double>(info.mMatrix[1][1])); |
| 124 | result.append("\n"); |
| 125 | result.appendFormat(" parent=%s\n", info.mParentName.c_str()); |
| 126 | result.appendFormat(" activeBuffer=[%4ux%4u:%4u,%s],", |
| 127 | info.mActiveBufferWidth, info.mActiveBufferHeight, |
| 128 | info.mActiveBufferStride, |
| 129 | decodePixelFormat(info.mActiveBufferFormat).c_str()); |
| 130 | result.appendFormat(" queued-frames=%d, mRefreshPending=%d", |
| 131 | info.mNumQueuedFrames, info.mRefreshPending); |
| 132 | result.append("\n"); |
| 133 | return std::string(result.c_str()); |
| 134 | } |
| 135 | |
| 136 | } // android |