blob: 8520d70c71b75cb436ced094b0cb86b4fe5ccd46 [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>
Lloyd Pique31cb2942018-10-19 17:23:03 -070020#include <compositionengine/DisplaySurface.h>
Lloyd Pique45a165a2018-10-19 11:54:47 -070021#include <compositionengine/impl/Display.h>
Lloyd Pique3d0c02e2018-10-19 18:38:12 -070022#include <compositionengine/impl/DisplayColorProfile.h>
Lloyd Pique32cbe282018-10-19 13:09:22 -070023#include <compositionengine/impl/DumpHelpers.h>
Lloyd Pique31cb2942018-10-19 17:23:03 -070024#include <compositionengine/impl/RenderSurface.h>
Lloyd Pique45a165a2018-10-19 11:54:47 -070025
26#include "DisplayHardware/HWComposer.h"
27
28namespace android::compositionengine::impl {
29
30std::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
36Display::Display(const CompositionEngine& compositionEngine, DisplayCreationArgs&& args)
Lloyd Pique32cbe282018-10-19 13:09:22 -070037 : compositionengine::impl::Output(compositionEngine),
Lloyd Pique45a165a2018-10-19 11:54:47 -070038 mIsVirtual(args.isVirtual),
Lloyd Pique32cbe282018-10-19 13:09:22 -070039 mId(args.displayId) {
40 editState().isSecure = args.isSecure;
41}
Lloyd Pique45a165a2018-10-19 11:54:47 -070042
43Display::~Display() = default;
44
45const std::optional<DisplayId>& Display::getId() const {
46 return mId;
47}
48
49bool Display::isSecure() const {
Lloyd Pique32cbe282018-10-19 13:09:22 -070050 return getState().isSecure;
Lloyd Pique45a165a2018-10-19 11:54:47 -070051}
52
53bool Display::isVirtual() const {
54 return mIsVirtual;
55}
56
57void Display::disconnect() {
58 if (!mId) {
59 return;
60 }
61
Lloyd Pique32cbe282018-10-19 13:09:22 -070062 auto& hwc = getCompositionEngine().getHwComposer();
Lloyd Pique45a165a2018-10-19 11:54:47 -070063 hwc.disconnectDisplay(*mId);
64 mId.reset();
65}
66
Lloyd Pique32cbe282018-10-19 13:09:22 -070067void 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
76void Display::setColorMode(ui::ColorMode mode, ui::Dataspace dataspace,
Lloyd Piquef5275482019-01-29 18:42:42 -080077 ui::RenderIntent renderIntent,
78 ui::Dataspace colorSpaceAgnosticDataspace) {
79 ui::Dataspace targetDataspace =
80 getDisplayColorProfile()->getTargetDataspace(mode, dataspace,
81 colorSpaceAgnosticDataspace);
82
Lloyd Pique32cbe282018-10-19 13:09:22 -070083 if (mode == getState().colorMode && dataspace == getState().dataspace &&
Lloyd Piquef5275482019-01-29 18:42:42 -080084 renderIntent == getState().renderIntent && targetDataspace == getState().targetDataspace) {
Lloyd Pique32cbe282018-10-19 13:09:22 -070085 return;
86 }
87
88 if (mIsVirtual) {
89 ALOGW("%s: Invalid operation on virtual display", __FUNCTION__);
90 return;
91 }
92
Lloyd Piquef5275482019-01-29 18:42:42 -080093 Output::setColorMode(mode, dataspace, renderIntent, colorSpaceAgnosticDataspace);
Lloyd Pique32cbe282018-10-19 13:09:22 -070094
95 auto& hwc = getCompositionEngine().getHwComposer();
96 hwc.setActiveColorMode(*mId, mode, renderIntent);
97}
98
99void Display::dump(std::string& out) const {
100 using android::base::StringAppendF;
101
102 StringAppendF(&out, " Composition Display State: [\"%s\"]", getName().c_str());
103
104 out.append("\n ");
105
106 dumpVal(out, "isVirtual", mIsVirtual);
107 if (mId) {
108 dumpVal(out, "hwcId", to_string(*mId));
109 } else {
110 StringAppendF(&out, "no hwcId, ");
111 }
112
113 out.append("\n");
114
115 Output::dumpBase(out);
116}
117
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700118void Display::createDisplayColorProfile(DisplayColorProfileCreationArgs&& args) {
119 setDisplayColorProfile(compositionengine::impl::createDisplayColorProfile(std::move(args)));
120}
121
Lloyd Pique31cb2942018-10-19 17:23:03 -0700122void Display::createRenderSurface(RenderSurfaceCreationArgs&& args) {
123 setRenderSurface(compositionengine::impl::createRenderSurface(getCompositionEngine(), *this,
124 std::move(args)));
125}
126
Lloyd Pique45a165a2018-10-19 11:54:47 -0700127} // namespace android::compositionengine::impl