blob: ef017aa9d525c16029ce1c9b84d7d540e6757906 [file] [log] [blame]
David Sodmanb8af7922017-12-21 15:17:55 -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#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 Sodman7e4ae112018-02-09 15:02:28 -080023
Peiyong Lincbc184f2018-08-22 13:24:10 -070024#include <android-base/stringprintf.h>
25#include <renderengine/RenderEngine.h>
David Sodman7e4ae112018-02-09 15:02:28 -080026
27#include <string>
David Sodmanb8af7922017-12-21 15:17:55 -080028
Peiyong Linda237de2018-09-10 16:22:58 -070029namespace {
30
31const 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 Sodmanb8af7922017-12-21 15:17:55 -080051namespace android {
52
David Sodman2b727ac2017-12-21 14:28:08 -080053LayerBE::LayerBE(Layer* layer, std::string layerName)
David Sodmanb8af7922017-12-21 15:17:55 -080054 : mLayer(layer),
Peiyong Lin833074a2018-08-28 11:53:54 -070055 mMesh(renderengine::Mesh::TRIANGLE_FAN, 4, 2, 2) {
David Sodman40a3a5a2018-05-16 11:55:52 -070056 compositionInfo.layer = std::make_shared<LayerBE>(*this);
David Sodman2b727ac2017-12-21 14:28:08 -080057 compositionInfo.layerName = layerName;
David Sodmanb8af7922017-12-21 15:17:55 -080058}
59
David Sodman40a3a5a2018-05-16 11:55:52 -070060LayerBE::LayerBE(const LayerBE& layer)
61 : mLayer(layer.mLayer),
Peiyong Lin833074a2018-08-28 11:53:54 -070062 mMesh(renderengine::Mesh::TRIANGLE_FAN, 4, 2, 2) {
David Sodman40a3a5a2018-05-16 11:55:52 -070063 compositionInfo.layer = layer.compositionInfo.layer;
64 compositionInfo.layerName = layer.mLayer->getName().string();
65}
66
David Sodmanb8af7922017-12-21 15:17:55 -080067void LayerBE::onLayerDisplayed(const sp<Fence>& releaseFence) {
David Sodman10a41ff2018-08-05 12:14:17 -070068 if (mLayer) {
69 mLayer->onLayerDisplayed(releaseFence);
70 }
David Sodmanb8af7922017-12-21 15:17:55 -080071}
72
Peiyong Lin833074a2018-08-28 11:53:54 -070073void LayerBE::clear(renderengine::RenderEngine& engine) {
David Sodmanfb95bcc2017-12-22 15:45:30 -080074 engine.setupFillWithColor(0, 0, 0, 0);
75 engine.drawMesh(mMesh);
76}
77
David Sodman7e4ae112018-02-09 15:02:28 -080078void CompositionInfo::dump(const char* tag) const
79{
80 std::string logString;
81 dump(logString, tag);
82 ALOGV("%s", logString.c_str());
David Sodmanb8af7922017-12-21 15:17:55 -080083}
84
David Sodman7e4ae112018-02-09 15:02:28 -080085void CompositionInfo::dumpHwc(std::string& result, const char* tag) const {
86 if (tag == nullptr) {
87 result += base::StringPrintf("HWC parameters\n");
88 } else {
89 result += base::StringPrintf("[%s]HWC parameters\n", tag);
90 }
91
92 result += base::StringPrintf("\thwcLayer=%p\n", static_cast<HWC2::Layer*>(&*hwc.hwcLayer));
93 result += base::StringPrintf("\tfence=%p\n", hwc.fence.get());
94 result += base::StringPrintf("\tblendMode=%d\n", hwc.blendMode);
95 result += base::StringPrintf("\ttransform=%d\n", hwc.transform);
96 result += base::StringPrintf("\tz=%d\n", hwc.z);
97 result += base::StringPrintf("\ttype=%d\n", hwc.type);
98 result += base::StringPrintf("\tappId=%d\n", hwc.appId);
Peiyong Linda237de2018-09-10 16:22:58 -070099 result += base::StringPrintf("\tdisplayFrame=%4d %4d %4d %4d\n", hwc.displayFrame.left,
100 hwc.displayFrame.top, hwc.displayFrame.right,
101 hwc.displayFrame.bottom);
David Sodman7e4ae112018-02-09 15:02:28 -0800102 result += base::StringPrintf("\talpha=%.3f", hwc.alpha);
Peiyong Linda237de2018-09-10 16:22:58 -0700103 result += base::StringPrintf("\tsourceCrop=%6.1f %6.1f %6.1f %6.1f\n", hwc.sourceCrop.left,
104 hwc.sourceCrop.top, hwc.sourceCrop.right, hwc.sourceCrop.bottom);
David Sodman7e4ae112018-02-09 15:02:28 -0800105
106 {
107 //
108 // Keep a conversion from std::string to String8 and back until Region can use std::string
109 //
110 String8 regionString;
111 hwc.visibleRegion.dump(regionString, "visibleRegion");
112 hwc.surfaceDamage.dump(regionString, "surfaceDamage");
113 result += regionString.string();
114 }
David Sodmanb8af7922017-12-21 15:17:55 -0800115}
116
David Sodman7e4ae112018-02-09 15:02:28 -0800117void CompositionInfo::dumpRe(std::string& result, const char* tag) const {
118 if (tag == nullptr) {
119 result += base::StringPrintf("RenderEngine parameters:\n");
120 } else {
121 result += base::StringPrintf("[%s]RenderEngine parameters:\n", tag);
122 }
123
David Sodman7e4ae112018-02-09 15:02:28 -0800124 result += base::StringPrintf("\tblackoutLayer=%d\n", re.blackoutLayer);
125 result += base::StringPrintf("\tclearArea=%d\n", re.clearArea);
126 result += base::StringPrintf("\tpreMultipliedAlpha=%d\n", re.preMultipliedAlpha);
127 result += base::StringPrintf("\topaque=%d\n", re.opaque);
128 result += base::StringPrintf("\tdisableTexture=%d\n", re.disableTexture);
David Sodman7e4ae112018-02-09 15:02:28 -0800129 result += base::StringPrintf("\tuseIdentityTransform=%d\n", re.useIdentityTransform);
David Sodman7e4ae112018-02-09 15:02:28 -0800130}
131
132void CompositionInfo::dump(std::string& result, const char* tag) const
133{
134 if (tag == nullptr) {
135 result += base::StringPrintf("CompositionInfo\n");
136 } else {
137 result += base::StringPrintf("[%s]CompositionInfo\n", tag);
138 }
139 result += base::StringPrintf("\tLayerName: %s\n", layerName.c_str());
Peiyong Linda237de2018-09-10 16:22:58 -0700140 result += base::StringPrintf("\tCompositionType: %s\n",
141 getCompositionName(compositionType));
David Sodman7e4ae112018-02-09 15:02:28 -0800142 result += base::StringPrintf("\tmBuffer = %p\n", mBuffer.get());
143 result += base::StringPrintf("\tmBufferSlot=%d\n", mBufferSlot);
Peiyong Linda237de2018-09-10 16:22:58 -0700144 result += base::StringPrintf("\tdisplayFrame=%4d %4d %4d %4d\n", hwc.displayFrame.left,
145 hwc.displayFrame.top, hwc.displayFrame.right,
146 hwc.displayFrame.bottom);
David Sodman7e4ae112018-02-09 15:02:28 -0800147 result += base::StringPrintf("\talpha=%f\n", hwc.alpha);
Peiyong Linda237de2018-09-10 16:22:58 -0700148 result += base::StringPrintf("\tsourceCrop=%6.1f %6.1f %6.1f %6.1f\n", hwc.sourceCrop.left,
149 hwc.sourceCrop.top, hwc.sourceCrop.right, hwc.sourceCrop.bottom);
David Sodman7e4ae112018-02-09 15:02:28 -0800150
David Sodmanb8af7922017-12-21 15:17:55 -0800151 switch (compositionType) {
152 case HWC2::Composition::Device:
David Sodman7e4ae112018-02-09 15:02:28 -0800153 dumpHwc(result, tag);
David Sodmanb8af7922017-12-21 15:17:55 -0800154 break;
155 case HWC2::Composition::Client:
David Sodman7e4ae112018-02-09 15:02:28 -0800156 dumpRe(result, tag);
157 break;
David Sodmanb8af7922017-12-21 15:17:55 -0800158 default:
159 break;
160 }
161}
162
David Sodmanb8af7922017-12-21 15:17:55 -0800163}; // namespace android