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