blob: da98bf5ee279300cea6aa87c9e11e81474854a7b [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
29namespace android {
30
David Sodman2b727ac2017-12-21 14:28:08 -080031LayerBE::LayerBE(Layer* layer, std::string layerName)
David Sodmanb8af7922017-12-21 15:17:55 -080032 : mLayer(layer),
Peiyong Lin833074a2018-08-28 11:53:54 -070033 mMesh(renderengine::Mesh::TRIANGLE_FAN, 4, 2, 2) {
David Sodman40a3a5a2018-05-16 11:55:52 -070034 compositionInfo.layer = std::make_shared<LayerBE>(*this);
David Sodman2b727ac2017-12-21 14:28:08 -080035 compositionInfo.layerName = layerName;
David Sodmanb8af7922017-12-21 15:17:55 -080036}
37
David Sodman40a3a5a2018-05-16 11:55:52 -070038LayerBE::LayerBE(const LayerBE& layer)
39 : mLayer(layer.mLayer),
Peiyong Lin833074a2018-08-28 11:53:54 -070040 mMesh(renderengine::Mesh::TRIANGLE_FAN, 4, 2, 2) {
David Sodman40a3a5a2018-05-16 11:55:52 -070041 compositionInfo.layer = layer.compositionInfo.layer;
42 compositionInfo.layerName = layer.mLayer->getName().string();
43}
44
David Sodmanb8af7922017-12-21 15:17:55 -080045void LayerBE::onLayerDisplayed(const sp<Fence>& releaseFence) {
David Sodman10a41ff2018-08-05 12:14:17 -070046 if (mLayer) {
47 mLayer->onLayerDisplayed(releaseFence);
48 }
David Sodmanb8af7922017-12-21 15:17:55 -080049}
50
Peiyong Lin833074a2018-08-28 11:53:54 -070051void LayerBE::clear(renderengine::RenderEngine& engine) {
David Sodmanfb95bcc2017-12-22 15:45:30 -080052 engine.setupFillWithColor(0, 0, 0, 0);
53 engine.drawMesh(mMesh);
54}
55
David Sodman7e4ae112018-02-09 15:02:28 -080056void CompositionInfo::dump(const char* tag) const
57{
58 std::string logString;
59 dump(logString, tag);
60 ALOGV("%s", logString.c_str());
David Sodmanb8af7922017-12-21 15:17:55 -080061}
62
David Sodman7e4ae112018-02-09 15:02:28 -080063void CompositionInfo::dumpHwc(std::string& result, const char* tag) const {
64 if (tag == nullptr) {
65 result += base::StringPrintf("HWC parameters\n");
66 } else {
67 result += base::StringPrintf("[%s]HWC parameters\n", tag);
68 }
69
70 result += base::StringPrintf("\thwcLayer=%p\n", static_cast<HWC2::Layer*>(&*hwc.hwcLayer));
71 result += base::StringPrintf("\tfence=%p\n", hwc.fence.get());
72 result += base::StringPrintf("\tblendMode=%d\n", hwc.blendMode);
73 result += base::StringPrintf("\ttransform=%d\n", hwc.transform);
74 result += base::StringPrintf("\tz=%d\n", hwc.z);
75 result += base::StringPrintf("\ttype=%d\n", hwc.type);
76 result += base::StringPrintf("\tappId=%d\n", hwc.appId);
77 result += base::StringPrintf("\tdisplayFrame=%4d %4d %4d %4d\n", hwc.displayFrame.left, hwc.displayFrame.top, hwc.displayFrame.right, hwc.displayFrame.bottom);
78 result += base::StringPrintf("\talpha=%.3f", hwc.alpha);
79 result += base::StringPrintf("\tsourceCrop=%6.1f %6.1f %6.1f %6.1f\n", hwc.sourceCrop.left, hwc.sourceCrop.top, hwc.sourceCrop.right, hwc.sourceCrop.bottom);
80
81 {
82 //
83 // Keep a conversion from std::string to String8 and back until Region can use std::string
84 //
85 String8 regionString;
86 hwc.visibleRegion.dump(regionString, "visibleRegion");
87 hwc.surfaceDamage.dump(regionString, "surfaceDamage");
88 result += regionString.string();
89 }
David Sodmanb8af7922017-12-21 15:17:55 -080090}
91
David Sodman7e4ae112018-02-09 15:02:28 -080092void CompositionInfo::dumpRe(std::string& result, const char* tag) const {
93 if (tag == nullptr) {
94 result += base::StringPrintf("RenderEngine parameters:\n");
95 } else {
96 result += base::StringPrintf("[%s]RenderEngine parameters:\n", tag);
97 }
98
David Sodman7e4ae112018-02-09 15:02:28 -080099 result += base::StringPrintf("\tblackoutLayer=%d\n", re.blackoutLayer);
100 result += base::StringPrintf("\tclearArea=%d\n", re.clearArea);
101 result += base::StringPrintf("\tpreMultipliedAlpha=%d\n", re.preMultipliedAlpha);
102 result += base::StringPrintf("\topaque=%d\n", re.opaque);
103 result += base::StringPrintf("\tdisableTexture=%d\n", re.disableTexture);
David Sodman7e4ae112018-02-09 15:02:28 -0800104 result += base::StringPrintf("\tuseIdentityTransform=%d\n", re.useIdentityTransform);
David Sodman7e4ae112018-02-09 15:02:28 -0800105}
106
107void CompositionInfo::dump(std::string& result, const char* tag) const
108{
109 if (tag == nullptr) {
110 result += base::StringPrintf("CompositionInfo\n");
111 } else {
112 result += base::StringPrintf("[%s]CompositionInfo\n", tag);
113 }
114 result += base::StringPrintf("\tLayerName: %s\n", layerName.c_str());
115 result += base::StringPrintf("\tCompositionType: %d\n", compositionType);
116 result += base::StringPrintf("\tmBuffer = %p\n", mBuffer.get());
117 result += base::StringPrintf("\tmBufferSlot=%d\n", mBufferSlot);
118 result += base::StringPrintf("\tdisplayFrame=%4d %4d %4d %4d\n", hwc.displayFrame.left, hwc.displayFrame.top, hwc.displayFrame.right, hwc.displayFrame.bottom);
119 result += base::StringPrintf("\talpha=%f\n", hwc.alpha);
120 result += base::StringPrintf("\tsourceCrop=%6.1f %6.1f %6.1f %6.1f\n", hwc.sourceCrop.left, hwc.sourceCrop.top, hwc.sourceCrop.right, hwc.sourceCrop.bottom);
121
David Sodmanb8af7922017-12-21 15:17:55 -0800122 switch (compositionType) {
123 case HWC2::Composition::Device:
David Sodman7e4ae112018-02-09 15:02:28 -0800124 dumpHwc(result, tag);
David Sodmanb8af7922017-12-21 15:17:55 -0800125 break;
126 case HWC2::Composition::Client:
David Sodman7e4ae112018-02-09 15:02:28 -0800127 dumpRe(result, tag);
128 break;
David Sodmanb8af7922017-12-21 15:17:55 -0800129 default:
130 break;
131 }
132}
133
David Sodmanb8af7922017-12-21 15:17:55 -0800134}; // namespace android