blob: fb783e706faa175706f0b84ef90f2e99ca54a763 [file] [log] [blame]
Lloyd Pique45a165a2018-10-19 11:54:47 -07001/*
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
Lloyd Pique32cbe282018-10-19 13:09:22 -070017#include <android-base/stringprintf.h>
Lloyd Pique45a165a2018-10-19 11:54:47 -070018#include <compositionengine/CompositionEngine.h>
19#include <compositionengine/DisplayCreationArgs.h>
20#include <compositionengine/impl/Display.h>
Lloyd Pique32cbe282018-10-19 13:09:22 -070021#include <compositionengine/impl/DumpHelpers.h>
Lloyd Pique45a165a2018-10-19 11:54:47 -070022
23#include "DisplayHardware/HWComposer.h"
24
25namespace android::compositionengine::impl {
26
27std::shared_ptr<compositionengine::Display> createDisplay(
28 const compositionengine::CompositionEngine& compositionEngine,
29 compositionengine::DisplayCreationArgs&& args) {
30 return std::make_shared<Display>(compositionEngine, std::move(args));
31}
32
33Display::Display(const CompositionEngine& compositionEngine, DisplayCreationArgs&& args)
Lloyd Pique32cbe282018-10-19 13:09:22 -070034 : compositionengine::impl::Output(compositionEngine),
Lloyd Pique45a165a2018-10-19 11:54:47 -070035 mIsVirtual(args.isVirtual),
Lloyd Pique32cbe282018-10-19 13:09:22 -070036 mId(args.displayId) {
37 editState().isSecure = args.isSecure;
38}
Lloyd Pique45a165a2018-10-19 11:54:47 -070039
40Display::~Display() = default;
41
42const std::optional<DisplayId>& Display::getId() const {
43 return mId;
44}
45
46bool Display::isSecure() const {
Lloyd Pique32cbe282018-10-19 13:09:22 -070047 return getState().isSecure;
Lloyd Pique45a165a2018-10-19 11:54:47 -070048}
49
50bool Display::isVirtual() const {
51 return mIsVirtual;
52}
53
54void Display::disconnect() {
55 if (!mId) {
56 return;
57 }
58
Lloyd Pique32cbe282018-10-19 13:09:22 -070059 auto& hwc = getCompositionEngine().getHwComposer();
Lloyd Pique45a165a2018-10-19 11:54:47 -070060 hwc.disconnectDisplay(*mId);
61 mId.reset();
62}
63
Lloyd Pique32cbe282018-10-19 13:09:22 -070064void Display::setColorTransform(const mat4& transform) {
65 Output::setColorTransform(transform);
66
67 auto& hwc = getCompositionEngine().getHwComposer();
68 status_t result = hwc.setColorTransform(*mId, transform);
69 ALOGE_IF(result != NO_ERROR, "Failed to set color transform on display \"%s\": %d",
70 mId ? to_string(*mId).c_str() : "", result);
71}
72
73void Display::setColorMode(ui::ColorMode mode, ui::Dataspace dataspace,
74 ui::RenderIntent renderIntent) {
75 if (mode == getState().colorMode && dataspace == getState().dataspace &&
76 renderIntent == getState().renderIntent) {
77 return;
78 }
79
80 if (mIsVirtual) {
81 ALOGW("%s: Invalid operation on virtual display", __FUNCTION__);
82 return;
83 }
84
85 Output::setColorMode(mode, dataspace, renderIntent);
86
87 auto& hwc = getCompositionEngine().getHwComposer();
88 hwc.setActiveColorMode(*mId, mode, renderIntent);
89}
90
91void Display::dump(std::string& out) const {
92 using android::base::StringAppendF;
93
94 StringAppendF(&out, " Composition Display State: [\"%s\"]", getName().c_str());
95
96 out.append("\n ");
97
98 dumpVal(out, "isVirtual", mIsVirtual);
99 if (mId) {
100 dumpVal(out, "hwcId", to_string(*mId));
101 } else {
102 StringAppendF(&out, "no hwcId, ");
103 }
104
105 out.append("\n");
106
107 Output::dumpBase(out);
108}
109
Lloyd Pique45a165a2018-10-19 11:54:47 -0700110} // namespace android::compositionengine::impl