Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 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 | |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame^] | 17 | #include <android-base/stringprintf.h> |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 18 | #include <compositionengine/CompositionEngine.h> |
| 19 | #include <compositionengine/DisplayCreationArgs.h> |
| 20 | #include <compositionengine/impl/Display.h> |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame^] | 21 | #include <compositionengine/impl/DumpHelpers.h> |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 22 | |
| 23 | #include "DisplayHardware/HWComposer.h" |
| 24 | |
| 25 | namespace android::compositionengine::impl { |
| 26 | |
| 27 | std::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 | |
| 33 | Display::Display(const CompositionEngine& compositionEngine, DisplayCreationArgs&& args) |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame^] | 34 | : compositionengine::impl::Output(compositionEngine), |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 35 | mIsVirtual(args.isVirtual), |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame^] | 36 | mId(args.displayId) { |
| 37 | editState().isSecure = args.isSecure; |
| 38 | } |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 39 | |
| 40 | Display::~Display() = default; |
| 41 | |
| 42 | const std::optional<DisplayId>& Display::getId() const { |
| 43 | return mId; |
| 44 | } |
| 45 | |
| 46 | bool Display::isSecure() const { |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame^] | 47 | return getState().isSecure; |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | bool Display::isVirtual() const { |
| 51 | return mIsVirtual; |
| 52 | } |
| 53 | |
| 54 | void Display::disconnect() { |
| 55 | if (!mId) { |
| 56 | return; |
| 57 | } |
| 58 | |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame^] | 59 | auto& hwc = getCompositionEngine().getHwComposer(); |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 60 | hwc.disconnectDisplay(*mId); |
| 61 | mId.reset(); |
| 62 | } |
| 63 | |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame^] | 64 | void 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 | |
| 73 | void 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 | |
| 91 | void 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 Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 110 | } // namespace android::compositionengine::impl |