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> |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame^] | 20 | #include <compositionengine/DisplaySurface.h> |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 21 | #include <compositionengine/impl/Display.h> |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 22 | #include <compositionengine/impl/DumpHelpers.h> |
Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame^] | 23 | #include <compositionengine/impl/RenderSurface.h> |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 24 | |
| 25 | #include "DisplayHardware/HWComposer.h" |
| 26 | |
| 27 | namespace android::compositionengine::impl { |
| 28 | |
| 29 | std::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 | |
| 35 | Display::Display(const CompositionEngine& compositionEngine, DisplayCreationArgs&& args) |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 36 | : compositionengine::impl::Output(compositionEngine), |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 37 | mIsVirtual(args.isVirtual), |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 38 | mId(args.displayId) { |
| 39 | editState().isSecure = args.isSecure; |
| 40 | } |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 41 | |
| 42 | Display::~Display() = default; |
| 43 | |
| 44 | const std::optional<DisplayId>& Display::getId() const { |
| 45 | return mId; |
| 46 | } |
| 47 | |
| 48 | bool Display::isSecure() const { |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 49 | return getState().isSecure; |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | bool Display::isVirtual() const { |
| 53 | return mIsVirtual; |
| 54 | } |
| 55 | |
| 56 | void Display::disconnect() { |
| 57 | if (!mId) { |
| 58 | return; |
| 59 | } |
| 60 | |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 61 | auto& hwc = getCompositionEngine().getHwComposer(); |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 62 | hwc.disconnectDisplay(*mId); |
| 63 | mId.reset(); |
| 64 | } |
| 65 | |
Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 66 | void 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 | |
| 75 | void 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 | |
| 93 | void 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 Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame^] | 112 | void Display::createRenderSurface(RenderSurfaceCreationArgs&& args) { |
| 113 | setRenderSurface(compositionengine::impl::createRenderSurface(getCompositionEngine(), *this, |
| 114 | std::move(args))); |
| 115 | } |
| 116 | |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 117 | } // namespace android::compositionengine::impl |