| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -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 |  | 
 | 17 | #include <android-base/stringprintf.h> | 
 | 18 | #include <compositionengine/CompositionEngine.h> | 
| Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 19 | #include <compositionengine/DisplayColorProfile.h> | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 20 | #include <compositionengine/RenderSurface.h> | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 21 | #include <compositionengine/impl/Output.h> | 
 | 22 | #include <ui/DebugUtils.h> | 
 | 23 |  | 
 | 24 | namespace android::compositionengine::impl { | 
 | 25 |  | 
 | 26 | Output::Output(const CompositionEngine& compositionEngine) | 
 | 27 |       : mCompositionEngine(compositionEngine) {} | 
 | 28 |  | 
 | 29 | Output::~Output() = default; | 
 | 30 |  | 
 | 31 | const CompositionEngine& Output::getCompositionEngine() const { | 
 | 32 |     return mCompositionEngine; | 
 | 33 | } | 
 | 34 |  | 
 | 35 | bool Output::isValid() const { | 
| Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 36 |     return mDisplayColorProfile && mDisplayColorProfile->isValid() && mRenderSurface && | 
 | 37 |             mRenderSurface->isValid(); | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 38 | } | 
 | 39 |  | 
 | 40 | const std::string& Output::getName() const { | 
 | 41 |     return mName; | 
 | 42 | } | 
 | 43 |  | 
 | 44 | void Output::setName(const std::string& name) { | 
 | 45 |     mName = name; | 
 | 46 | } | 
 | 47 |  | 
 | 48 | void Output::setCompositionEnabled(bool enabled) { | 
 | 49 |     if (mState.isEnabled == enabled) { | 
 | 50 |         return; | 
 | 51 |     } | 
 | 52 |  | 
 | 53 |     mState.isEnabled = enabled; | 
 | 54 |     dirtyEntireOutput(); | 
 | 55 | } | 
 | 56 |  | 
 | 57 | void Output::setProjection(const ui::Transform& transform, int32_t orientation, const Rect& frame, | 
 | 58 |                            const Rect& viewport, const Rect& scissor, bool needsFiltering) { | 
 | 59 |     mState.transform = transform; | 
 | 60 |     mState.orientation = orientation; | 
 | 61 |     mState.scissor = scissor; | 
 | 62 |     mState.frame = frame; | 
 | 63 |     mState.viewport = viewport; | 
 | 64 |     mState.needsFiltering = needsFiltering; | 
 | 65 |  | 
 | 66 |     dirtyEntireOutput(); | 
 | 67 | } | 
 | 68 |  | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 69 | // TODO(lpique): Rename setSize() once more is moved. | 
 | 70 | void Output::setBounds(const ui::Size& size) { | 
 | 71 |     mRenderSurface->setDisplaySize(size); | 
 | 72 |     // TODO(lpique): Rename mState.size once more is moved. | 
 | 73 |     mState.bounds = Rect(mRenderSurface->getSize()); | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 74 |  | 
 | 75 |     dirtyEntireOutput(); | 
 | 76 | } | 
 | 77 |  | 
 | 78 | void Output::setLayerStackFilter(bool singleLayerStack, uint32_t singleLayerStackId) { | 
 | 79 |     mState.singleLayerStack = singleLayerStack; | 
 | 80 |     mState.singleLayerStackId = singleLayerStackId; | 
 | 81 |  | 
 | 82 |     dirtyEntireOutput(); | 
 | 83 | } | 
 | 84 |  | 
 | 85 | void Output::setColorTransform(const mat4& transform) { | 
 | 86 |     const bool isIdentity = (transform == mat4()); | 
 | 87 |  | 
 | 88 |     mState.colorTransform = | 
 | 89 |             isIdentity ? HAL_COLOR_TRANSFORM_IDENTITY : HAL_COLOR_TRANSFORM_ARBITRARY_MATRIX; | 
 | 90 | } | 
 | 91 |  | 
 | 92 | void Output::setColorMode(ui::ColorMode mode, ui::Dataspace dataspace, | 
 | 93 |                           ui::RenderIntent renderIntent) { | 
 | 94 |     mState.colorMode = mode; | 
 | 95 |     mState.dataspace = dataspace; | 
 | 96 |     mState.renderIntent = renderIntent; | 
 | 97 |  | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 98 |     mRenderSurface->setBufferDataspace(dataspace); | 
 | 99 |  | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 100 |     ALOGV("Set active color mode: %s (%d), active render intent: %s (%d)", | 
 | 101 |           decodeColorMode(mode).c_str(), mode, decodeRenderIntent(renderIntent).c_str(), | 
 | 102 |           renderIntent); | 
 | 103 | } | 
 | 104 |  | 
 | 105 | void Output::dump(std::string& out) const { | 
 | 106 |     using android::base::StringAppendF; | 
 | 107 |  | 
 | 108 |     StringAppendF(&out, "   Composition Output State: [\"%s\"]", mName.c_str()); | 
 | 109 |  | 
 | 110 |     out.append("\n   "); | 
 | 111 |  | 
 | 112 |     dumpBase(out); | 
 | 113 | } | 
 | 114 |  | 
 | 115 | void Output::dumpBase(std::string& out) const { | 
 | 116 |     mState.dump(out); | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 117 |  | 
| Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 118 |     if (mDisplayColorProfile) { | 
 | 119 |         mDisplayColorProfile->dump(out); | 
 | 120 |     } else { | 
 | 121 |         out.append("    No display color profile!\n"); | 
 | 122 |     } | 
 | 123 |  | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 124 |     if (mRenderSurface) { | 
 | 125 |         mRenderSurface->dump(out); | 
 | 126 |     } else { | 
 | 127 |         out.append("    No render surface!\n"); | 
 | 128 |     } | 
 | 129 | } | 
 | 130 |  | 
| Lloyd Pique | 3d0c02e | 2018-10-19 18:38:12 -0700 | [diff] [blame] | 131 | compositionengine::DisplayColorProfile* Output::getDisplayColorProfile() const { | 
 | 132 |     return mDisplayColorProfile.get(); | 
 | 133 | } | 
 | 134 |  | 
 | 135 | void Output::setDisplayColorProfile(std::unique_ptr<compositionengine::DisplayColorProfile> mode) { | 
 | 136 |     mDisplayColorProfile = std::move(mode); | 
 | 137 | } | 
 | 138 |  | 
 | 139 | void Output::setDisplayColorProfileForTest( | 
 | 140 |         std::unique_ptr<compositionengine::DisplayColorProfile> mode) { | 
 | 141 |     mDisplayColorProfile = std::move(mode); | 
 | 142 | } | 
 | 143 |  | 
| Lloyd Pique | 31cb294 | 2018-10-19 17:23:03 -0700 | [diff] [blame] | 144 | compositionengine::RenderSurface* Output::getRenderSurface() const { | 
 | 145 |     return mRenderSurface.get(); | 
 | 146 | } | 
 | 147 |  | 
 | 148 | void Output::setRenderSurface(std::unique_ptr<compositionengine::RenderSurface> surface) { | 
 | 149 |     mRenderSurface = std::move(surface); | 
 | 150 |     mState.bounds = Rect(mRenderSurface->getSize()); | 
 | 151 |  | 
 | 152 |     dirtyEntireOutput(); | 
 | 153 | } | 
 | 154 |  | 
 | 155 | void Output::setRenderSurfaceForTest(std::unique_ptr<compositionengine::RenderSurface> surface) { | 
 | 156 |     mRenderSurface = std::move(surface); | 
| Lloyd Pique | 32cbe28 | 2018-10-19 13:09:22 -0700 | [diff] [blame] | 157 | } | 
 | 158 |  | 
 | 159 | const OutputCompositionState& Output::getState() const { | 
 | 160 |     return mState; | 
 | 161 | } | 
 | 162 |  | 
 | 163 | OutputCompositionState& Output::editState() { | 
 | 164 |     return mState; | 
 | 165 | } | 
 | 166 |  | 
 | 167 | Region Output::getPhysicalSpaceDirtyRegion(bool repaintEverything) const { | 
 | 168 |     Region dirty; | 
 | 169 |     if (repaintEverything) { | 
 | 170 |         dirty.set(mState.bounds); | 
 | 171 |     } else { | 
 | 172 |         dirty = mState.transform.transform(mState.dirtyRegion); | 
 | 173 |         dirty.andSelf(mState.bounds); | 
 | 174 |     } | 
 | 175 |     return dirty; | 
 | 176 | } | 
 | 177 |  | 
 | 178 | bool Output::belongsInOutput(uint32_t layerStackId) const { | 
 | 179 |     return !mState.singleLayerStack || (layerStackId == mState.singleLayerStackId); | 
 | 180 | } | 
 | 181 |  | 
 | 182 | void Output::dirtyEntireOutput() { | 
 | 183 |     mState.dirtyRegion.set(mState.bounds); | 
 | 184 | } | 
 | 185 |  | 
 | 186 | } // namespace android::compositionengine::impl |