blob: 9558266a34d2ef005a51d94f5bddab05d523a383 [file] [log] [blame]
Lloyd Pique70d91362018-10-18 16:02:55 -07001/*
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 Piqueab039b52019-02-13 14:22:42 -080017#include <compositionengine/CompositionRefreshArgs.h>
18#include <compositionengine/LayerFE.h>
Lloyd Pique70d91362018-10-18 16:02:55 -070019#include <compositionengine/impl/CompositionEngine.h>
Lloyd Pique45a165a2018-10-19 11:54:47 -070020#include <compositionengine/impl/Display.h>
Lloyd Piquefeb73d72018-12-04 17:23:44 -080021#include <compositionengine/impl/Layer.h>
Lloyd Piqueb97e04f2018-10-18 17:07:05 -070022#include <renderengine/RenderEngine.h>
Lloyd Piqueab039b52019-02-13 14:22:42 -080023#include <utils/Trace.h>
Lloyd Pique70d91362018-10-18 16:02:55 -070024
Lloyd Pique441d5042018-10-18 16:49:51 -070025#include "DisplayHardware/HWComposer.h"
26
Lloyd Pique70d91362018-10-18 16:02:55 -070027namespace android::compositionengine {
28
29CompositionEngine::~CompositionEngine() = default;
30
31namespace impl {
32
33std::unique_ptr<compositionengine::CompositionEngine> createCompositionEngine() {
34 return std::make_unique<CompositionEngine>();
35}
36
37CompositionEngine::CompositionEngine() = default;
38CompositionEngine::~CompositionEngine() = default;
39
Lloyd Pique45a165a2018-10-19 11:54:47 -070040std::shared_ptr<compositionengine::Display> CompositionEngine::createDisplay(
41 DisplayCreationArgs&& args) {
42 return compositionengine::impl::createDisplay(*this, std::move(args));
43}
44
Lloyd Piquefeb73d72018-12-04 17:23:44 -080045std::shared_ptr<compositionengine::Layer> CompositionEngine::createLayer(LayerCreationArgs&& args) {
46 return compositionengine::impl::createLayer(*this, std::move(args));
47}
48
Lloyd Pique441d5042018-10-18 16:49:51 -070049HWComposer& CompositionEngine::getHwComposer() const {
50 return *mHwComposer.get();
51}
52
53void CompositionEngine::setHwComposer(std::unique_ptr<HWComposer> hwComposer) {
54 mHwComposer = std::move(hwComposer);
55}
56
Lloyd Piqueb97e04f2018-10-18 17:07:05 -070057renderengine::RenderEngine& CompositionEngine::getRenderEngine() const {
58 return *mRenderEngine.get();
59}
60
61void CompositionEngine::setRenderEngine(std::unique_ptr<renderengine::RenderEngine> renderEngine) {
62 mRenderEngine = std::move(renderEngine);
63}
64
Lloyd Piqueab039b52019-02-13 14:22:42 -080065bool CompositionEngine::needsAnotherUpdate() const {
66 return mNeedsAnotherUpdate;
67}
68
69nsecs_t CompositionEngine::getLastFrameRefreshTimestamp() const {
70 return mRefreshStartTime;
71}
72
73void 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
91void CompositionEngine::setNeedsAnotherUpdateForTest(bool value) {
92 mNeedsAnotherUpdate = value;
93}
94
Lloyd Pique70d91362018-10-18 16:02:55 -070095} // namespace impl
96} // namespace android::compositionengine