1 /*
2 * Copyright 2019 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 #include <android-base/stringprintf.h>
18 #include <compositionengine/CompositionEngine.h>
19 #include <compositionengine/DisplayCreationArgs.h>
20 #include <compositionengine/DisplaySurface.h>
21 #include <compositionengine/impl/Display.h>
22 #include <compositionengine/impl/DisplayColorProfile.h>
23 #include <compositionengine/impl/DumpHelpers.h>
24 #include <compositionengine/impl/RenderSurface.h>
25
26 #include "DisplayHardware/HWComposer.h"
27
28 namespace android::compositionengine::impl {
29
createDisplay(const compositionengine::CompositionEngine & compositionEngine,compositionengine::DisplayCreationArgs && args)30 std::shared_ptr<compositionengine::Display> createDisplay(
31 const compositionengine::CompositionEngine& compositionEngine,
32 compositionengine::DisplayCreationArgs&& args) {
33 return std::make_shared<Display>(compositionEngine, std::move(args));
34 }
35
Display(const CompositionEngine & compositionEngine,DisplayCreationArgs && args)36 Display::Display(const CompositionEngine& compositionEngine, DisplayCreationArgs&& args)
37 : compositionengine::impl::Output(compositionEngine),
38 mIsVirtual(args.isVirtual),
39 mId(args.displayId) {
40 editState().isSecure = args.isSecure;
41 }
42
43 Display::~Display() = default;
44
getId() const45 const std::optional<DisplayId>& Display::getId() const {
46 return mId;
47 }
48
isSecure() const49 bool Display::isSecure() const {
50 return getState().isSecure;
51 }
52
isVirtual() const53 bool Display::isVirtual() const {
54 return mIsVirtual;
55 }
56
disconnect()57 void Display::disconnect() {
58 if (!mId) {
59 return;
60 }
61
62 auto& hwc = getCompositionEngine().getHwComposer();
63 hwc.disconnectDisplay(*mId);
64 mId.reset();
65 }
66
setColorTransform(const mat4 & transform)67 void Display::setColorTransform(const mat4& transform) {
68 Output::setColorTransform(transform);
69
70 auto& hwc = getCompositionEngine().getHwComposer();
71 status_t result = hwc.setColorTransform(*mId, transform);
72 ALOGE_IF(result != NO_ERROR, "Failed to set color transform on display \"%s\": %d",
73 mId ? to_string(*mId).c_str() : "", result);
74 }
75
setColorMode(ui::ColorMode mode,ui::Dataspace dataspace,ui::RenderIntent renderIntent)76 void Display::setColorMode(ui::ColorMode mode, ui::Dataspace dataspace,
77 ui::RenderIntent renderIntent) {
78 if (mode == getState().colorMode && dataspace == getState().dataspace &&
79 renderIntent == getState().renderIntent) {
80 return;
81 }
82
83 if (mIsVirtual) {
84 ALOGW("%s: Invalid operation on virtual display", __FUNCTION__);
85 return;
86 }
87
88 Output::setColorMode(mode, dataspace, renderIntent);
89
90 auto& hwc = getCompositionEngine().getHwComposer();
91 hwc.setActiveColorMode(*mId, mode, renderIntent);
92 }
93
dump(std::string & out) const94 void Display::dump(std::string& out) const {
95 using android::base::StringAppendF;
96
97 StringAppendF(&out, " Composition Display State: [\"%s\"]", getName().c_str());
98
99 out.append("\n ");
100
101 dumpVal(out, "isVirtual", mIsVirtual);
102 if (mId) {
103 dumpVal(out, "hwcId", to_string(*mId));
104 } else {
105 StringAppendF(&out, "no hwcId, ");
106 }
107
108 out.append("\n");
109
110 Output::dumpBase(out);
111 }
112
createDisplayColorProfile(DisplayColorProfileCreationArgs && args)113 void Display::createDisplayColorProfile(DisplayColorProfileCreationArgs&& args) {
114 setDisplayColorProfile(compositionengine::impl::createDisplayColorProfile(std::move(args)));
115 }
116
createRenderSurface(RenderSurfaceCreationArgs && args)117 void Display::createRenderSurface(RenderSurfaceCreationArgs&& args) {
118 setRenderSurface(compositionengine::impl::createRenderSurface(getCompositionEngine(), *this,
119 std::move(args)));
120 }
121
122 } // namespace android::compositionengine::impl
123