blob: ae776145369e976a3e98263dc3a77efd1ca3624b [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 Pique32cbe282018-10-19 13:09:22 -070022#include <compositionengine/impl/DumpHelpers.h>
Lloyd Pique31cb2942018-10-19 17:23:03 -070023#include <compositionengine/impl/RenderSurface.h>
Lloyd Pique45a165a2018-10-19 11:54:47 -070024
25#include "DisplayHardware/HWComposer.h"
26
27namespace android::compositionengine::impl {
28
29std::shared_ptr<compositionengine::Display> createDisplay(
30 const compositionengine::CompositionEngine& compositionEngine,
31 compositionengine::DisplayCreationArgs&& args) {
32 return std::make_shared<Display>(compositionEngine, std::move(args));
33}
34
35Display::Display(const CompositionEngine& compositionEngine, DisplayCreationArgs&& args)
Lloyd Pique32cbe282018-10-19 13:09:22 -070036 : compositionengine::impl::Output(compositionEngine),
Lloyd Pique45a165a2018-10-19 11:54:47 -070037 mIsVirtual(args.isVirtual),
Lloyd Pique32cbe282018-10-19 13:09:22 -070038 mId(args.displayId) {
39 editState().isSecure = args.isSecure;
40}
Lloyd Pique45a165a2018-10-19 11:54:47 -070041
42Display::~Display() = default;
43
44const std::optional<DisplayId>& Display::getId() const {
45 return mId;
46}
47
48bool Display::isSecure() const {
Lloyd Pique32cbe282018-10-19 13:09:22 -070049 return getState().isSecure;
Lloyd Pique45a165a2018-10-19 11:54:47 -070050}
51
52bool Display::isVirtual() const {
53 return mIsVirtual;
54}
55
56void Display::disconnect() {
57 if (!mId) {
58 return;
59 }
60
Lloyd Pique32cbe282018-10-19 13:09:22 -070061 auto& hwc = getCompositionEngine().getHwComposer();
Lloyd Pique45a165a2018-10-19 11:54:47 -070062 hwc.disconnectDisplay(*mId);
63 mId.reset();
64}
65
Lloyd Pique32cbe282018-10-19 13:09:22 -070066void Display::setColorTransform(const mat4& transform) {
67 Output::setColorTransform(transform);
68
69 auto& hwc = getCompositionEngine().getHwComposer();
70 status_t result = hwc.setColorTransform(*mId, transform);
71 ALOGE_IF(result != NO_ERROR, "Failed to set color transform on display \"%s\": %d",
72 mId ? to_string(*mId).c_str() : "", result);
73}
74
75void Display::setColorMode(ui::ColorMode mode, ui::Dataspace dataspace,
76 ui::RenderIntent renderIntent) {
77 if (mode == getState().colorMode && dataspace == getState().dataspace &&
78 renderIntent == getState().renderIntent) {
79 return;
80 }
81
82 if (mIsVirtual) {
83 ALOGW("%s: Invalid operation on virtual display", __FUNCTION__);
84 return;
85 }
86
87 Output::setColorMode(mode, dataspace, renderIntent);
88
89 auto& hwc = getCompositionEngine().getHwComposer();
90 hwc.setActiveColorMode(*mId, mode, renderIntent);
91}
92
93void Display::dump(std::string& out) const {
94 using android::base::StringAppendF;
95
96 StringAppendF(&out, " Composition Display State: [\"%s\"]", getName().c_str());
97
98 out.append("\n ");
99
100 dumpVal(out, "isVirtual", mIsVirtual);
101 if (mId) {
102 dumpVal(out, "hwcId", to_string(*mId));
103 } else {
104 StringAppendF(&out, "no hwcId, ");
105 }
106
107 out.append("\n");
108
109 Output::dumpBase(out);
110}
111
Lloyd Pique31cb2942018-10-19 17:23:03 -0700112void Display::createRenderSurface(RenderSurfaceCreationArgs&& args) {
113 setRenderSurface(compositionengine::impl::createRenderSurface(getCompositionEngine(), *this,
114 std::move(args)));
115}
116
Lloyd Pique45a165a2018-10-19 11:54:47 -0700117} // namespace android::compositionengine::impl