LayerDebugInfo.cpp 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. #include <gui/LayerDebugInfo.h>
  17. #include <android-base/stringprintf.h>
  18. #include <ui/DebugUtils.h>
  19. #include <binder/Parcel.h>
  20. using namespace android;
  21. using android::base::StringAppendF;
  22. #define RETURN_ON_ERROR(X) do {status_t res = (X); if (res != NO_ERROR) return res;} while(false)
  23. namespace android {
  24. status_t LayerDebugInfo::writeToParcel(Parcel* parcel) const {
  25. RETURN_ON_ERROR(parcel->writeCString(mName.c_str()));
  26. RETURN_ON_ERROR(parcel->writeCString(mParentName.c_str()));
  27. RETURN_ON_ERROR(parcel->writeCString(mType.c_str()));
  28. RETURN_ON_ERROR(parcel->write(mTransparentRegion));
  29. RETURN_ON_ERROR(parcel->write(mVisibleRegion));
  30. RETURN_ON_ERROR(parcel->write(mSurfaceDamageRegion));
  31. RETURN_ON_ERROR(parcel->writeUint32(mLayerStack));
  32. RETURN_ON_ERROR(parcel->writeFloat(mX));
  33. RETURN_ON_ERROR(parcel->writeFloat(mY));
  34. RETURN_ON_ERROR(parcel->writeUint32(mZ));
  35. RETURN_ON_ERROR(parcel->writeInt32(mWidth));
  36. RETURN_ON_ERROR(parcel->writeInt32(mHeight));
  37. RETURN_ON_ERROR(parcel->write(mCrop));
  38. RETURN_ON_ERROR(parcel->writeFloat(mColor.r));
  39. RETURN_ON_ERROR(parcel->writeFloat(mColor.g));
  40. RETURN_ON_ERROR(parcel->writeFloat(mColor.b));
  41. RETURN_ON_ERROR(parcel->writeFloat(mColor.a));
  42. RETURN_ON_ERROR(parcel->writeUint32(mFlags));
  43. RETURN_ON_ERROR(parcel->writeInt32(mPixelFormat));
  44. RETURN_ON_ERROR(parcel->writeUint32(static_cast<uint32_t>(mDataSpace)));
  45. for (size_t index = 0; index < 4; index++) {
  46. RETURN_ON_ERROR(parcel->writeFloat(mMatrix[index / 2][index % 2]));
  47. }
  48. RETURN_ON_ERROR(parcel->writeInt32(mActiveBufferWidth));
  49. RETURN_ON_ERROR(parcel->writeInt32(mActiveBufferHeight));
  50. RETURN_ON_ERROR(parcel->writeInt32(mActiveBufferStride));
  51. RETURN_ON_ERROR(parcel->writeInt32(mActiveBufferFormat));
  52. RETURN_ON_ERROR(parcel->writeInt32(mNumQueuedFrames));
  53. RETURN_ON_ERROR(parcel->writeBool(mRefreshPending));
  54. RETURN_ON_ERROR(parcel->writeBool(mIsOpaque));
  55. RETURN_ON_ERROR(parcel->writeBool(mContentDirty));
  56. return NO_ERROR;
  57. }
  58. status_t LayerDebugInfo::readFromParcel(const Parcel* parcel) {
  59. mName = parcel->readCString();
  60. RETURN_ON_ERROR(parcel->errorCheck());
  61. mParentName = parcel->readCString();
  62. RETURN_ON_ERROR(parcel->errorCheck());
  63. mType = parcel->readCString();
  64. RETURN_ON_ERROR(parcel->errorCheck());
  65. RETURN_ON_ERROR(parcel->read(mTransparentRegion));
  66. RETURN_ON_ERROR(parcel->read(mVisibleRegion));
  67. RETURN_ON_ERROR(parcel->read(mSurfaceDamageRegion));
  68. RETURN_ON_ERROR(parcel->readUint32(&mLayerStack));
  69. RETURN_ON_ERROR(parcel->readFloat(&mX));
  70. RETURN_ON_ERROR(parcel->readFloat(&mY));
  71. RETURN_ON_ERROR(parcel->readUint32(&mZ));
  72. RETURN_ON_ERROR(parcel->readInt32(&mWidth));
  73. RETURN_ON_ERROR(parcel->readInt32(&mHeight));
  74. RETURN_ON_ERROR(parcel->read(mCrop));
  75. mColor.r = parcel->readFloat();
  76. RETURN_ON_ERROR(parcel->errorCheck());
  77. mColor.g = parcel->readFloat();
  78. RETURN_ON_ERROR(parcel->errorCheck());
  79. mColor.b = parcel->readFloat();
  80. RETURN_ON_ERROR(parcel->errorCheck());
  81. mColor.a = parcel->readFloat();
  82. RETURN_ON_ERROR(parcel->errorCheck());
  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. std::string to_string(const LayerDebugInfo& info) {
  102. std::string result;
  103. StringAppendF(&result, "+ %s (%s)\n", info.mType.c_str(), info.mName.c_str());
  104. info.mTransparentRegion.dump(result, "TransparentRegion");
  105. info.mVisibleRegion.dump(result, "VisibleRegion");
  106. info.mSurfaceDamageRegion.dump(result, "SurfaceDamageRegion");
  107. StringAppendF(&result, " layerStack=%4d, z=%9d, pos=(%g,%g), size=(%4d,%4d), ",
  108. info.mLayerStack, info.mZ, static_cast<double>(info.mX),
  109. static_cast<double>(info.mY), info.mWidth, info.mHeight);
  110. StringAppendF(&result, "crop=%s, ", to_string(info.mCrop).c_str());
  111. StringAppendF(&result, "isOpaque=%1d, invalidate=%1d, ", info.mIsOpaque, info.mContentDirty);
  112. StringAppendF(&result, "dataspace=%s, ", dataspaceDetails(info.mDataSpace).c_str());
  113. StringAppendF(&result, "pixelformat=%s, ", decodePixelFormat(info.mPixelFormat).c_str());
  114. StringAppendF(&result, "color=(%.3f,%.3f,%.3f,%.3f), flags=0x%08x, ",
  115. static_cast<double>(info.mColor.r), static_cast<double>(info.mColor.g),
  116. static_cast<double>(info.mColor.b), static_cast<double>(info.mColor.a),
  117. info.mFlags);
  118. StringAppendF(&result, "tr=[%.2f, %.2f][%.2f, %.2f]", static_cast<double>(info.mMatrix[0][0]),
  119. static_cast<double>(info.mMatrix[0][1]), static_cast<double>(info.mMatrix[1][0]),
  120. static_cast<double>(info.mMatrix[1][1]));
  121. result.append("\n");
  122. StringAppendF(&result, " parent=%s\n", info.mParentName.c_str());
  123. StringAppendF(&result, " activeBuffer=[%4ux%4u:%4u,%s],", info.mActiveBufferWidth,
  124. info.mActiveBufferHeight, info.mActiveBufferStride,
  125. decodePixelFormat(info.mActiveBufferFormat).c_str());
  126. StringAppendF(&result, " queued-frames=%d, mRefreshPending=%d", info.mNumQueuedFrames,
  127. info.mRefreshPending);
  128. result.append("\n");
  129. return result;
  130. }
  131. } // android