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 
17 #pragma once
18 
19 #include <TimeStats/TimeStats.h>
20 #include <utils/Timers.h>
21 #include <memory>
22 
23 #include "Feature.h"
24 
25 namespace android {
26 
27 class HWComposer;
28 
29 namespace renderengine {
30 class RenderEngine;
31 } // namespace renderengine
32 
33 namespace compositionengine {
34 
35 class Display;
36 
37 struct CompositionRefreshArgs;
38 struct DisplayCreationArgs;
39 struct LayerCreationArgs;
40 struct LayerFECompositionState;
41 
42 /**
43  * Encapsulates all the interfaces and implementation details for performing
44  * display output composition.
45  */
46 class CompositionEngine {
47 public:
48     virtual ~CompositionEngine();
49 
50     // Create a composition Display
51     virtual std::shared_ptr<Display> createDisplay(const DisplayCreationArgs&) = 0;
52     virtual std::unique_ptr<compositionengine::LayerFECompositionState>
53     createLayerFECompositionState() = 0;
54 
55     virtual HWComposer& getHwComposer() const = 0;
56     virtual void setHwComposer(std::unique_ptr<HWComposer>) = 0;
57 
58     virtual renderengine::RenderEngine& getRenderEngine() const = 0;
59     virtual void setRenderEngine(renderengine::RenderEngine*) = 0;
60 
61     virtual TimeStats* getTimeStats() const = 0;
62     virtual void setTimeStats(const std::shared_ptr<TimeStats>&) = 0;
63 
64     virtual bool needsAnotherUpdate() const = 0;
65     virtual nsecs_t getLastFrameRefreshTimestamp() const = 0;
66 
67     // Presents the indicated outputs
68     virtual void present(CompositionRefreshArgs&) = 0;
69 
70     // Updates the cursor position for the indicated outputs.
71     virtual void updateCursorAsync(CompositionRefreshArgs&) = 0;
72 
73     // TODO(b/121291683): These will become private/internal
74     virtual void preComposition(CompositionRefreshArgs&) = 0;
75 
76     // Resolves any unfulfilled promises for release fences
77     virtual void postComposition(CompositionRefreshArgs&) = 0;
78 
79     virtual FeatureFlags getFeatureFlags() const = 0;
80 
81     // Debugging
82     virtual void dump(std::string&) const = 0;
83 };
84 
85 } // namespace compositionengine
86 } // namespace android
87