blob: 70b00dd22afcb02084ff0660ea8dc33b79c89703 [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
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 Linda237de2018-09-10 16:22:58 -070097 result += base::StringPrintf("\tdisplayFrame=%4d %4d %4d %4d\n", hwc.displayFrame.left,
98 hwc.displayFrame.top, hwc.displayFrame.right,
99 hwc.displayFrame.bottom);
David Sodman7e4ae112018-02-09 15:02:28 -0800100 result += base::StringPrintf("\talpha=%.3f", hwc.alpha);
Peiyong Linda237de2018-09-10 16:22:58 -0700101 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 Sodman7e4ae112018-02-09 15:02:28 -0800103
104 {
105 //
106 // Keep a conversion from std::string to String8 and back until Region can use std::string
107 //
108 String8 regionString;
109 hwc.visibleRegion.dump(regionString, "visibleRegion");
110 hwc.surfaceDamage.dump(regionString, "surfaceDamage");
111 result += regionString.string();
112 }
Peiyong Lind3788632018-09-18 16:01:31 -0700113
114 result += base::StringPrintf("\tcolor transform matrix:\n"
115 "\t\t[%f, %f, %f, %f,\n"
116 "\t\t %f, %f, %f, %f,\n"
117 "\t\t %f, %f, %f, %f,\n"
118 "\t\t %f, %f, %f, %f]\n",
119 hwc.colorTransform[0][0], hwc.colorTransform[1][0],
120 hwc.colorTransform[2][0], hwc.colorTransform[3][0],
121 hwc.colorTransform[0][1], hwc.colorTransform[1][1],
122 hwc.colorTransform[2][1], hwc.colorTransform[3][1],
123 hwc.colorTransform[0][2], hwc.colorTransform[1][2],
124 hwc.colorTransform[2][2], hwc.colorTransform[3][2],
125 hwc.colorTransform[0][3], hwc.colorTransform[1][3],
126 hwc.colorTransform[2][3], hwc.colorTransform[3][3]);
David Sodmanb8af7922017-12-21 15:17:55 -0800127}
128
David Sodman7e4ae112018-02-09 15:02:28 -0800129void CompositionInfo::dumpRe(std::string& result, const char* tag) const {
130 if (tag == nullptr) {
131 result += base::StringPrintf("RenderEngine parameters:\n");
132 } else {
133 result += base::StringPrintf("[%s]RenderEngine parameters:\n", tag);
134 }
135
David Sodman7e4ae112018-02-09 15:02:28 -0800136 result += base::StringPrintf("\tblackoutLayer=%d\n", re.blackoutLayer);
137 result += base::StringPrintf("\tclearArea=%d\n", re.clearArea);
138 result += base::StringPrintf("\tpreMultipliedAlpha=%d\n", re.preMultipliedAlpha);
139 result += base::StringPrintf("\topaque=%d\n", re.opaque);
140 result += base::StringPrintf("\tdisableTexture=%d\n", re.disableTexture);
David Sodman7e4ae112018-02-09 15:02:28 -0800141 result += base::StringPrintf("\tuseIdentityTransform=%d\n", re.useIdentityTransform);
David Sodman7e4ae112018-02-09 15:02:28 -0800142}
143
144void CompositionInfo::dump(std::string& result, const char* tag) const
145{
146 if (tag == nullptr) {
147 result += base::StringPrintf("CompositionInfo\n");
148 } else {
149 result += base::StringPrintf("[%s]CompositionInfo\n", tag);
150 }
151 result += base::StringPrintf("\tLayerName: %s\n", layerName.c_str());
Peiyong Linda237de2018-09-10 16:22:58 -0700152 result += base::StringPrintf("\tCompositionType: %s\n",
153 getCompositionName(compositionType));
David Sodman7e4ae112018-02-09 15:02:28 -0800154 result += base::StringPrintf("\tmBuffer = %p\n", mBuffer.get());
155 result += base::StringPrintf("\tmBufferSlot=%d\n", mBufferSlot);
Peiyong Linda237de2018-09-10 16:22:58 -0700156 result += base::StringPrintf("\tdisplayFrame=%4d %4d %4d %4d\n", hwc.displayFrame.left,
157 hwc.displayFrame.top, hwc.displayFrame.right,
158 hwc.displayFrame.bottom);
David Sodman7e4ae112018-02-09 15:02:28 -0800159 result += base::StringPrintf("\talpha=%f\n", hwc.alpha);
Peiyong Linda237de2018-09-10 16:22:58 -0700160 result += base::StringPrintf("\tsourceCrop=%6.1f %6.1f %6.1f %6.1f\n", hwc.sourceCrop.left,
161 hwc.sourceCrop.top, hwc.sourceCrop.right, hwc.sourceCrop.bottom);
David Sodman7e4ae112018-02-09 15:02:28 -0800162
David Sodmanb8af7922017-12-21 15:17:55 -0800163 switch (compositionType) {
164 case HWC2::Composition::Device:
David Sodman7e4ae112018-02-09 15:02:28 -0800165 dumpHwc(result, tag);
David Sodmanb8af7922017-12-21 15:17:55 -0800166 break;
167 case HWC2::Composition::Client:
David Sodman7e4ae112018-02-09 15:02:28 -0800168 dumpRe(result, tag);
169 break;
David Sodmanb8af7922017-12-21 15:17:55 -0800170 default:
171 break;
172 }
173}
174
David Sodmanb8af7922017-12-21 15:17:55 -0800175}; // namespace android