blob: c9b793377af7f5d6d3143ae7bfcbd616655a02d7 [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 }
Peiyong Lind3788632018-09-18 16:01:31 -0700115
116 result += base::StringPrintf("\tcolor transform matrix:\n"
117 "\t\t[%f, %f, %f, %f,\n"
118 "\t\t %f, %f, %f, %f,\n"
119 "\t\t %f, %f, %f, %f,\n"
120 "\t\t %f, %f, %f, %f]\n",
121 hwc.colorTransform[0][0], hwc.colorTransform[1][0],
122 hwc.colorTransform[2][0], hwc.colorTransform[3][0],
123 hwc.colorTransform[0][1], hwc.colorTransform[1][1],
124 hwc.colorTransform[2][1], hwc.colorTransform[3][1],
125 hwc.colorTransform[0][2], hwc.colorTransform[1][2],
126 hwc.colorTransform[2][2], hwc.colorTransform[3][2],
127 hwc.colorTransform[0][3], hwc.colorTransform[1][3],
128 hwc.colorTransform[2][3], hwc.colorTransform[3][3]);
David Sodmanb8af7922017-12-21 15:17:55 -0800129}
130
David Sodman7e4ae112018-02-09 15:02:28 -0800131void CompositionInfo::dumpRe(std::string& result, const char* tag) const {
132 if (tag == nullptr) {
133 result += base::StringPrintf("RenderEngine parameters:\n");
134 } else {
135 result += base::StringPrintf("[%s]RenderEngine parameters:\n", tag);
136 }
137
David Sodman7e4ae112018-02-09 15:02:28 -0800138 result += base::StringPrintf("\tblackoutLayer=%d\n", re.blackoutLayer);
139 result += base::StringPrintf("\tclearArea=%d\n", re.clearArea);
140 result += base::StringPrintf("\tpreMultipliedAlpha=%d\n", re.preMultipliedAlpha);
141 result += base::StringPrintf("\topaque=%d\n", re.opaque);
142 result += base::StringPrintf("\tdisableTexture=%d\n", re.disableTexture);
David Sodman7e4ae112018-02-09 15:02:28 -0800143 result += base::StringPrintf("\tuseIdentityTransform=%d\n", re.useIdentityTransform);
David Sodman7e4ae112018-02-09 15:02:28 -0800144}
145
146void CompositionInfo::dump(std::string& result, const char* tag) const
147{
148 if (tag == nullptr) {
149 result += base::StringPrintf("CompositionInfo\n");
150 } else {
151 result += base::StringPrintf("[%s]CompositionInfo\n", tag);
152 }
153 result += base::StringPrintf("\tLayerName: %s\n", layerName.c_str());
Peiyong Linda237de2018-09-10 16:22:58 -0700154 result += base::StringPrintf("\tCompositionType: %s\n",
155 getCompositionName(compositionType));
David Sodman7e4ae112018-02-09 15:02:28 -0800156 result += base::StringPrintf("\tmBuffer = %p\n", mBuffer.get());
157 result += base::StringPrintf("\tmBufferSlot=%d\n", mBufferSlot);
Peiyong Linda237de2018-09-10 16:22:58 -0700158 result += base::StringPrintf("\tdisplayFrame=%4d %4d %4d %4d\n", hwc.displayFrame.left,
159 hwc.displayFrame.top, hwc.displayFrame.right,
160 hwc.displayFrame.bottom);
David Sodman7e4ae112018-02-09 15:02:28 -0800161 result += base::StringPrintf("\talpha=%f\n", hwc.alpha);
Peiyong Linda237de2018-09-10 16:22:58 -0700162 result += base::StringPrintf("\tsourceCrop=%6.1f %6.1f %6.1f %6.1f\n", hwc.sourceCrop.left,
163 hwc.sourceCrop.top, hwc.sourceCrop.right, hwc.sourceCrop.bottom);
David Sodman7e4ae112018-02-09 15:02:28 -0800164
David Sodmanb8af7922017-12-21 15:17:55 -0800165 switch (compositionType) {
166 case HWC2::Composition::Device:
David Sodman7e4ae112018-02-09 15:02:28 -0800167 dumpHwc(result, tag);
David Sodmanb8af7922017-12-21 15:17:55 -0800168 break;
169 case HWC2::Composition::Client:
David Sodman7e4ae112018-02-09 15:02:28 -0800170 dumpRe(result, tag);
171 break;
David Sodmanb8af7922017-12-21 15:17:55 -0800172 default:
173 break;
174 }
175}
176
David Sodmanb8af7922017-12-21 15:17:55 -0800177}; // namespace android