blob: 4bf5325b455d9038270ca93c84020367103e3990 [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 Sodman15094112018-10-11 09:39:37 -070068 mLayer->onLayerDisplayed(releaseFence);
David Sodmanb8af7922017-12-21 15:17:55 -080069}
70
Peiyong Lin833074a2018-08-28 11:53:54 -070071void LayerBE::clear(renderengine::RenderEngine& engine) {
David Sodmanfb95bcc2017-12-22 15:45:30 -080072 engine.setupFillWithColor(0, 0, 0, 0);
73 engine.drawMesh(mMesh);
74}
75
David Sodman7e4ae112018-02-09 15:02:28 -080076void CompositionInfo::dump(const char* tag) const
77{
78 std::string logString;
79 dump(logString, tag);
80 ALOGV("%s", logString.c_str());
David Sodmanb8af7922017-12-21 15:17:55 -080081}
82
David Sodman7e4ae112018-02-09 15:02:28 -080083void 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
David Sodman7e4ae112018-02-09 15:02:28 -080090 result += base::StringPrintf("\tfence=%p\n", hwc.fence.get());
91 result += base::StringPrintf("\tblendMode=%d\n", hwc.blendMode);
David Sodman7e4ae112018-02-09 15:02:28 -080092 result += base::StringPrintf("\ttype=%d\n", hwc.type);
93 result += base::StringPrintf("\tappId=%d\n", hwc.appId);
David Sodman7e4ae112018-02-09 15:02:28 -080094 result += base::StringPrintf("\talpha=%.3f", hwc.alpha);
David Sodman7e4ae112018-02-09 15:02:28 -080095
Yiwei Zhang5434a782018-12-05 18:06:32 -080096 hwc.surfaceDamage.dump(result, "surfaceDamage");
Peiyong Lind3788632018-09-18 16:01:31 -070097
98 result += base::StringPrintf("\tcolor transform matrix:\n"
99 "\t\t[%f, %f, %f, %f,\n"
100 "\t\t %f, %f, %f, %f,\n"
101 "\t\t %f, %f, %f, %f,\n"
102 "\t\t %f, %f, %f, %f]\n",
103 hwc.colorTransform[0][0], hwc.colorTransform[1][0],
104 hwc.colorTransform[2][0], hwc.colorTransform[3][0],
105 hwc.colorTransform[0][1], hwc.colorTransform[1][1],
106 hwc.colorTransform[2][1], hwc.colorTransform[3][1],
107 hwc.colorTransform[0][2], hwc.colorTransform[1][2],
108 hwc.colorTransform[2][2], hwc.colorTransform[3][2],
109 hwc.colorTransform[0][3], hwc.colorTransform[1][3],
110 hwc.colorTransform[2][3], hwc.colorTransform[3][3]);
David Sodmanb8af7922017-12-21 15:17:55 -0800111}
112
David Sodman7e4ae112018-02-09 15:02:28 -0800113void CompositionInfo::dumpRe(std::string& result, const char* tag) const {
114 if (tag == nullptr) {
115 result += base::StringPrintf("RenderEngine parameters:\n");
116 } else {
117 result += base::StringPrintf("[%s]RenderEngine parameters:\n", tag);
118 }
119
David Sodman7e4ae112018-02-09 15:02:28 -0800120 result += base::StringPrintf("\tblackoutLayer=%d\n", re.blackoutLayer);
121 result += base::StringPrintf("\tclearArea=%d\n", re.clearArea);
122 result += base::StringPrintf("\tpreMultipliedAlpha=%d\n", re.preMultipliedAlpha);
123 result += base::StringPrintf("\topaque=%d\n", re.opaque);
124 result += base::StringPrintf("\tdisableTexture=%d\n", re.disableTexture);
David Sodman7e4ae112018-02-09 15:02:28 -0800125 result += base::StringPrintf("\tuseIdentityTransform=%d\n", re.useIdentityTransform);
David Sodman7e4ae112018-02-09 15:02:28 -0800126}
127
128void CompositionInfo::dump(std::string& result, const char* tag) const
129{
130 if (tag == nullptr) {
131 result += base::StringPrintf("CompositionInfo\n");
132 } else {
133 result += base::StringPrintf("[%s]CompositionInfo\n", tag);
134 }
135 result += base::StringPrintf("\tLayerName: %s\n", layerName.c_str());
Peiyong Linda237de2018-09-10 16:22:58 -0700136 result += base::StringPrintf("\tCompositionType: %s\n",
137 getCompositionName(compositionType));
David Sodman7e4ae112018-02-09 15:02:28 -0800138 result += base::StringPrintf("\tmBuffer = %p\n", mBuffer.get());
139 result += base::StringPrintf("\tmBufferSlot=%d\n", mBufferSlot);
David Sodman7e4ae112018-02-09 15:02:28 -0800140 result += base::StringPrintf("\talpha=%f\n", hwc.alpha);
David Sodman7e4ae112018-02-09 15:02:28 -0800141
David Sodmanb8af7922017-12-21 15:17:55 -0800142 switch (compositionType) {
143 case HWC2::Composition::Device:
David Sodman7e4ae112018-02-09 15:02:28 -0800144 dumpHwc(result, tag);
David Sodmanb8af7922017-12-21 15:17:55 -0800145 break;
146 case HWC2::Composition::Client:
David Sodman7e4ae112018-02-09 15:02:28 -0800147 dumpRe(result, tag);
148 break;
David Sodmanb8af7922017-12-21 15:17:55 -0800149 default:
150 break;
151 }
152}
153
David Sodmanb8af7922017-12-21 15:17:55 -0800154}; // namespace android