blob: f9d70e3c91da9cff4464f6ac695bf6d309130479 [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,
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
94void 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
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700113void Display::createDisplayColorProfile(DisplayColorProfileCreationArgs&& args) {
114 setDisplayColorProfile(compositionengine::impl::createDisplayColorProfile(std::move(args)));
115}
116
Lloyd Pique31cb2942018-10-19 17:23:03 -0700117void Display::createRenderSurface(RenderSurfaceCreationArgs&& args) {
118 setRenderSurface(compositionengine::impl::createRenderSurface(getCompositionEngine(), *this,
119 std::move(args)));
120}
121
Lloyd Pique45a165a2018-10-19 11:54:47 -0700122} // namespace android::compositionengine::impl