Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018 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 | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame^] | 17 | #include <compositionengine/CompositionRefreshArgs.h> |
| 18 | #include <compositionengine/LayerFE.h> |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 19 | #include <compositionengine/impl/CompositionEngine.h> |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 20 | #include <compositionengine/impl/Display.h> |
Lloyd Pique | feb73d7 | 2018-12-04 17:23:44 -0800 | [diff] [blame] | 21 | #include <compositionengine/impl/Layer.h> |
Lloyd Pique | b97e04f | 2018-10-18 17:07:05 -0700 | [diff] [blame] | 22 | #include <renderengine/RenderEngine.h> |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame^] | 23 | #include <utils/Trace.h> |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 24 | |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 25 | #include "DisplayHardware/HWComposer.h" |
| 26 | |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 27 | namespace android::compositionengine { |
| 28 | |
| 29 | CompositionEngine::~CompositionEngine() = default; |
| 30 | |
| 31 | namespace impl { |
| 32 | |
| 33 | std::unique_ptr<compositionengine::CompositionEngine> createCompositionEngine() { |
| 34 | return std::make_unique<CompositionEngine>(); |
| 35 | } |
| 36 | |
| 37 | CompositionEngine::CompositionEngine() = default; |
| 38 | CompositionEngine::~CompositionEngine() = default; |
| 39 | |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 40 | std::shared_ptr<compositionengine::Display> CompositionEngine::createDisplay( |
| 41 | DisplayCreationArgs&& args) { |
| 42 | return compositionengine::impl::createDisplay(*this, std::move(args)); |
| 43 | } |
| 44 | |
Lloyd Pique | feb73d7 | 2018-12-04 17:23:44 -0800 | [diff] [blame] | 45 | std::shared_ptr<compositionengine::Layer> CompositionEngine::createLayer(LayerCreationArgs&& args) { |
| 46 | return compositionengine::impl::createLayer(*this, std::move(args)); |
| 47 | } |
| 48 | |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 49 | HWComposer& CompositionEngine::getHwComposer() const { |
| 50 | return *mHwComposer.get(); |
| 51 | } |
| 52 | |
| 53 | void CompositionEngine::setHwComposer(std::unique_ptr<HWComposer> hwComposer) { |
| 54 | mHwComposer = std::move(hwComposer); |
| 55 | } |
| 56 | |
Lloyd Pique | b97e04f | 2018-10-18 17:07:05 -0700 | [diff] [blame] | 57 | renderengine::RenderEngine& CompositionEngine::getRenderEngine() const { |
| 58 | return *mRenderEngine.get(); |
| 59 | } |
| 60 | |
| 61 | void CompositionEngine::setRenderEngine(std::unique_ptr<renderengine::RenderEngine> renderEngine) { |
| 62 | mRenderEngine = std::move(renderEngine); |
| 63 | } |
| 64 | |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame^] | 65 | bool CompositionEngine::needsAnotherUpdate() const { |
| 66 | return mNeedsAnotherUpdate; |
| 67 | } |
| 68 | |
| 69 | nsecs_t CompositionEngine::getLastFrameRefreshTimestamp() const { |
| 70 | return mRefreshStartTime; |
| 71 | } |
| 72 | |
| 73 | void CompositionEngine::preComposition(CompositionRefreshArgs& args) { |
| 74 | ATRACE_CALL(); |
| 75 | ALOGV(__FUNCTION__); |
| 76 | |
| 77 | bool needsAnotherUpdate = false; |
| 78 | |
| 79 | mRefreshStartTime = systemTime(SYSTEM_TIME_MONOTONIC); |
| 80 | |
| 81 | for (auto& layer : args.layers) { |
| 82 | sp<compositionengine::LayerFE> layerFE = layer->getLayerFE(); |
| 83 | if (layerFE && layerFE->onPreComposition(mRefreshStartTime)) { |
| 84 | needsAnotherUpdate = true; |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | mNeedsAnotherUpdate = needsAnotherUpdate; |
| 89 | } |
| 90 | |
| 91 | void CompositionEngine::setNeedsAnotherUpdateForTest(bool value) { |
| 92 | mNeedsAnotherUpdate = value; |
| 93 | } |
| 94 | |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 95 | } // namespace impl |
| 96 | } // namespace android::compositionengine |