David Sodman | b8af792 | 2017-12-21 15:17:55 -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 | #define LOG_NDEBUG 0 |
| 18 | #undef LOG_TAG |
| 19 | #define LOG_TAG "LayerBE" |
| 20 | #define ATRACE_TAG ATRACE_TAG_GRAPHICS |
| 21 | |
| 22 | #include "Layer.h" |
David Sodman | 7e4ae11 | 2018-02-09 15:02:28 -0800 | [diff] [blame] | 23 | |
Peiyong Lin | cbc184f | 2018-08-22 13:24:10 -0700 | [diff] [blame] | 24 | #include <android-base/stringprintf.h> |
| 25 | #include <renderengine/RenderEngine.h> |
David Sodman | 7e4ae11 | 2018-02-09 15:02:28 -0800 | [diff] [blame] | 26 | |
| 27 | #include <string> |
David Sodman | b8af792 | 2017-12-21 15:17:55 -0800 | [diff] [blame] | 28 | |
Peiyong Lin | da237de | 2018-09-10 16:22:58 -0700 | [diff] [blame] | 29 | namespace { |
| 30 | |
| 31 | const char* getCompositionName(HWC2::Composition compositionType) { |
| 32 | switch (compositionType) { |
| 33 | case HWC2::Composition::Invalid: |
| 34 | return "Invalid"; |
| 35 | case HWC2::Composition::Client: |
| 36 | return "Client"; |
| 37 | case HWC2::Composition::Device: |
| 38 | return "Device"; |
| 39 | case HWC2::Composition::SolidColor: |
| 40 | return "Solid Color"; |
| 41 | case HWC2::Composition::Cursor: |
| 42 | return "Cursor"; |
| 43 | case HWC2::Composition::Sideband: |
| 44 | return "Sideband"; |
| 45 | } |
| 46 | return "Invalid"; |
| 47 | } |
| 48 | |
| 49 | } // namespace anonymous |
| 50 | |
David Sodman | b8af792 | 2017-12-21 15:17:55 -0800 | [diff] [blame] | 51 | namespace android { |
| 52 | |
David Sodman | 2b727ac | 2017-12-21 14:28:08 -0800 | [diff] [blame] | 53 | LayerBE::LayerBE(Layer* layer, std::string layerName) |
David Sodman | b8af792 | 2017-12-21 15:17:55 -0800 | [diff] [blame] | 54 | : mLayer(layer), |
Peiyong Lin | 833074a | 2018-08-28 11:53:54 -0700 | [diff] [blame] | 55 | mMesh(renderengine::Mesh::TRIANGLE_FAN, 4, 2, 2) { |
David Sodman | 40a3a5a | 2018-05-16 11:55:52 -0700 | [diff] [blame] | 56 | compositionInfo.layer = std::make_shared<LayerBE>(*this); |
David Sodman | 2b727ac | 2017-12-21 14:28:08 -0800 | [diff] [blame] | 57 | compositionInfo.layerName = layerName; |
David Sodman | b8af792 | 2017-12-21 15:17:55 -0800 | [diff] [blame] | 58 | } |
| 59 | |
David Sodman | 40a3a5a | 2018-05-16 11:55:52 -0700 | [diff] [blame] | 60 | LayerBE::LayerBE(const LayerBE& layer) |
| 61 | : mLayer(layer.mLayer), |
Peiyong Lin | 833074a | 2018-08-28 11:53:54 -0700 | [diff] [blame] | 62 | mMesh(renderengine::Mesh::TRIANGLE_FAN, 4, 2, 2) { |
David Sodman | 40a3a5a | 2018-05-16 11:55:52 -0700 | [diff] [blame] | 63 | compositionInfo.layer = layer.compositionInfo.layer; |
| 64 | compositionInfo.layerName = layer.mLayer->getName().string(); |
| 65 | } |
| 66 | |
David Sodman | b8af792 | 2017-12-21 15:17:55 -0800 | [diff] [blame] | 67 | void LayerBE::onLayerDisplayed(const sp<Fence>& releaseFence) { |
David Sodman | 1509411 | 2018-10-11 09:39:37 -0700 | [diff] [blame] | 68 | mLayer->onLayerDisplayed(releaseFence); |
David Sodman | b8af792 | 2017-12-21 15:17:55 -0800 | [diff] [blame] | 69 | } |
| 70 | |
Peiyong Lin | 833074a | 2018-08-28 11:53:54 -0700 | [diff] [blame] | 71 | void LayerBE::clear(renderengine::RenderEngine& engine) { |
David Sodman | fb95bcc | 2017-12-22 15:45:30 -0800 | [diff] [blame] | 72 | engine.setupFillWithColor(0, 0, 0, 0); |
| 73 | engine.drawMesh(mMesh); |
| 74 | } |
| 75 | |
David Sodman | 7e4ae11 | 2018-02-09 15:02:28 -0800 | [diff] [blame] | 76 | void CompositionInfo::dump(const char* tag) const |
| 77 | { |
| 78 | std::string logString; |
| 79 | dump(logString, tag); |
| 80 | ALOGV("%s", logString.c_str()); |
David Sodman | b8af792 | 2017-12-21 15:17:55 -0800 | [diff] [blame] | 81 | } |
| 82 | |
David Sodman | 7e4ae11 | 2018-02-09 15:02:28 -0800 | [diff] [blame] | 83 | void CompositionInfo::dumpHwc(std::string& result, const char* tag) const { |
| 84 | if (tag == nullptr) { |
| 85 | result += base::StringPrintf("HWC parameters\n"); |
| 86 | } else { |
| 87 | result += base::StringPrintf("[%s]HWC parameters\n", tag); |
| 88 | } |
| 89 | |
| 90 | result += base::StringPrintf("\thwcLayer=%p\n", static_cast<HWC2::Layer*>(&*hwc.hwcLayer)); |
| 91 | result += base::StringPrintf("\tfence=%p\n", hwc.fence.get()); |
| 92 | result += base::StringPrintf("\tblendMode=%d\n", hwc.blendMode); |
| 93 | result += base::StringPrintf("\ttransform=%d\n", hwc.transform); |
| 94 | result += base::StringPrintf("\tz=%d\n", hwc.z); |
| 95 | result += base::StringPrintf("\ttype=%d\n", hwc.type); |
| 96 | result += base::StringPrintf("\tappId=%d\n", hwc.appId); |
Peiyong Lin | da237de | 2018-09-10 16:22:58 -0700 | [diff] [blame] | 97 | result += base::StringPrintf("\tdisplayFrame=%4d %4d %4d %4d\n", hwc.displayFrame.left, |
| 98 | hwc.displayFrame.top, hwc.displayFrame.right, |
| 99 | hwc.displayFrame.bottom); |
David Sodman | 7e4ae11 | 2018-02-09 15:02:28 -0800 | [diff] [blame] | 100 | result += base::StringPrintf("\talpha=%.3f", hwc.alpha); |
Peiyong Lin | da237de | 2018-09-10 16:22:58 -0700 | [diff] [blame] | 101 | result += base::StringPrintf("\tsourceCrop=%6.1f %6.1f %6.1f %6.1f\n", hwc.sourceCrop.left, |
| 102 | hwc.sourceCrop.top, hwc.sourceCrop.right, hwc.sourceCrop.bottom); |
David Sodman | 7e4ae11 | 2018-02-09 15:02:28 -0800 | [diff] [blame] | 103 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 104 | hwc.visibleRegion.dump(result, "visibleRegion"); |
| 105 | hwc.surfaceDamage.dump(result, "surfaceDamage"); |
Peiyong Lin | d378863 | 2018-09-18 16:01:31 -0700 | [diff] [blame] | 106 | |
| 107 | result += base::StringPrintf("\tcolor transform matrix:\n" |
| 108 | "\t\t[%f, %f, %f, %f,\n" |
| 109 | "\t\t %f, %f, %f, %f,\n" |
| 110 | "\t\t %f, %f, %f, %f,\n" |
| 111 | "\t\t %f, %f, %f, %f]\n", |
| 112 | hwc.colorTransform[0][0], hwc.colorTransform[1][0], |
| 113 | hwc.colorTransform[2][0], hwc.colorTransform[3][0], |
| 114 | hwc.colorTransform[0][1], hwc.colorTransform[1][1], |
| 115 | hwc.colorTransform[2][1], hwc.colorTransform[3][1], |
| 116 | hwc.colorTransform[0][2], hwc.colorTransform[1][2], |
| 117 | hwc.colorTransform[2][2], hwc.colorTransform[3][2], |
| 118 | hwc.colorTransform[0][3], hwc.colorTransform[1][3], |
| 119 | hwc.colorTransform[2][3], hwc.colorTransform[3][3]); |
David Sodman | b8af792 | 2017-12-21 15:17:55 -0800 | [diff] [blame] | 120 | } |
| 121 | |
David Sodman | 7e4ae11 | 2018-02-09 15:02:28 -0800 | [diff] [blame] | 122 | void CompositionInfo::dumpRe(std::string& result, const char* tag) const { |
| 123 | if (tag == nullptr) { |
| 124 | result += base::StringPrintf("RenderEngine parameters:\n"); |
| 125 | } else { |
| 126 | result += base::StringPrintf("[%s]RenderEngine parameters:\n", tag); |
| 127 | } |
| 128 | |
David Sodman | 7e4ae11 | 2018-02-09 15:02:28 -0800 | [diff] [blame] | 129 | result += base::StringPrintf("\tblackoutLayer=%d\n", re.blackoutLayer); |
| 130 | result += base::StringPrintf("\tclearArea=%d\n", re.clearArea); |
| 131 | result += base::StringPrintf("\tpreMultipliedAlpha=%d\n", re.preMultipliedAlpha); |
| 132 | result += base::StringPrintf("\topaque=%d\n", re.opaque); |
| 133 | result += base::StringPrintf("\tdisableTexture=%d\n", re.disableTexture); |
David Sodman | 7e4ae11 | 2018-02-09 15:02:28 -0800 | [diff] [blame] | 134 | result += base::StringPrintf("\tuseIdentityTransform=%d\n", re.useIdentityTransform); |
David Sodman | 7e4ae11 | 2018-02-09 15:02:28 -0800 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | void CompositionInfo::dump(std::string& result, const char* tag) const |
| 138 | { |
| 139 | if (tag == nullptr) { |
| 140 | result += base::StringPrintf("CompositionInfo\n"); |
| 141 | } else { |
| 142 | result += base::StringPrintf("[%s]CompositionInfo\n", tag); |
| 143 | } |
| 144 | result += base::StringPrintf("\tLayerName: %s\n", layerName.c_str()); |
Peiyong Lin | da237de | 2018-09-10 16:22:58 -0700 | [diff] [blame] | 145 | result += base::StringPrintf("\tCompositionType: %s\n", |
| 146 | getCompositionName(compositionType)); |
David Sodman | 7e4ae11 | 2018-02-09 15:02:28 -0800 | [diff] [blame] | 147 | result += base::StringPrintf("\tmBuffer = %p\n", mBuffer.get()); |
| 148 | result += base::StringPrintf("\tmBufferSlot=%d\n", mBufferSlot); |
Peiyong Lin | da237de | 2018-09-10 16:22:58 -0700 | [diff] [blame] | 149 | result += base::StringPrintf("\tdisplayFrame=%4d %4d %4d %4d\n", hwc.displayFrame.left, |
| 150 | hwc.displayFrame.top, hwc.displayFrame.right, |
| 151 | hwc.displayFrame.bottom); |
David Sodman | 7e4ae11 | 2018-02-09 15:02:28 -0800 | [diff] [blame] | 152 | result += base::StringPrintf("\talpha=%f\n", hwc.alpha); |
Peiyong Lin | da237de | 2018-09-10 16:22:58 -0700 | [diff] [blame] | 153 | result += base::StringPrintf("\tsourceCrop=%6.1f %6.1f %6.1f %6.1f\n", hwc.sourceCrop.left, |
| 154 | hwc.sourceCrop.top, hwc.sourceCrop.right, hwc.sourceCrop.bottom); |
David Sodman | 7e4ae11 | 2018-02-09 15:02:28 -0800 | [diff] [blame] | 155 | |
David Sodman | b8af792 | 2017-12-21 15:17:55 -0800 | [diff] [blame] | 156 | switch (compositionType) { |
| 157 | case HWC2::Composition::Device: |
David Sodman | 7e4ae11 | 2018-02-09 15:02:28 -0800 | [diff] [blame] | 158 | dumpHwc(result, tag); |
David Sodman | b8af792 | 2017-12-21 15:17:55 -0800 | [diff] [blame] | 159 | break; |
| 160 | case HWC2::Composition::Client: |
David Sodman | 7e4ae11 | 2018-02-09 15:02:28 -0800 | [diff] [blame] | 161 | dumpRe(result, tag); |
| 162 | break; |
David Sodman | b8af792 | 2017-12-21 15:17:55 -0800 | [diff] [blame] | 163 | default: |
| 164 | break; |
| 165 | } |
| 166 | } |
| 167 | |
David Sodman | b8af792 | 2017-12-21 15:17:55 -0800 | [diff] [blame] | 168 | }; // namespace android |