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 #pragma once
18 
19 #include <optional>
20 #include <string>
21 
22 #include <ui/Transform.h>
23 #include <utils/StrongPointer.h>
24 
25 // TODO(b/129481165): remove the #pragma below and fix conversion issues
26 #pragma clang diagnostic push
27 #pragma clang diagnostic ignored "-Wconversion"
28 
29 #include "DisplayHardware/ComposerHal.h"
30 #include "DisplayHardware/DisplayIdentification.h"
31 
32 // TODO(b/129481165): remove the #pragma below and fix conversion issues
33 #pragma clang diagnostic pop // ignored "-Wconversion"
34 
35 namespace android {
36 
37 namespace HWC2 {
38 class Layer;
39 } // namespace HWC2
40 
41 namespace compositionengine {
42 
43 class CompositionEngine;
44 class Output;
45 class LayerFE;
46 
47 namespace impl {
48 struct OutputLayerCompositionState;
49 } // namespace impl
50 
51 /**
52  * An output layer contains the output-dependent composition state for a layer
53  */
54 class OutputLayer {
55 public:
56     virtual ~OutputLayer();
57 
58     // Sets the HWC2::Layer associated with this layer
59     virtual void setHwcLayer(std::shared_ptr<HWC2::Layer>) = 0;
60 
61     // Gets the output which owns this output layer
62     virtual const Output& getOutput() const = 0;
63 
64     // Gets the front-end layer interface this output layer represents
65     virtual LayerFE& getLayerFE() const = 0;
66 
67     using CompositionState = compositionengine::impl::OutputLayerCompositionState;
68 
69     // Gets the raw composition state data for the layer
70     // TODO(lpique): Make this protected once it is only internally called.
71     virtual const CompositionState& getState() const = 0;
72 
73     // Allows mutable access to the raw composition state data for the layer.
74     // This is meant to be used by the various functions that are part of the
75     // composition process.
76     // TODO(lpique): Make this protected once it is only internally called.
77     virtual CompositionState& editState() = 0;
78 
79     // Recalculates the state of the output layer from the output-independent
80     // layer. If includeGeometry is false, the geometry state can be skipped.
81     // internalDisplayRotationFlags must be set to the rotation flags for the
82     // internal display, and is used to properly compute the inverse-display
83     // transform, if needed.
84     virtual void updateCompositionState(
85             bool includeGeometry, bool forceClientComposition,
86             ui::Transform::RotationFlags internalDisplayRotationFlags) = 0;
87 
88     // Writes the geometry state to the HWC, or does nothing if this layer does
89     // not use the HWC. If includeGeometry is false, the geometry state can be
90     // skipped.
91     virtual void writeStateToHWC(bool includeGeometry) = 0;
92 
93     // Updates the cursor position with the HWC
94     virtual void writeCursorPositionToHWC() const = 0;
95 
96     // Returns the HWC2::Layer associated with this layer, if it exists
97     virtual HWC2::Layer* getHwcLayer() const = 0;
98 
99     // Returns true if the current layer state requires client composition
100     virtual bool requiresClientComposition() const = 0;
101 
102     // Returns true if the current layer should be treated as a cursor layer
103     virtual bool isHardwareCursor() const = 0;
104 
105     // Applies a HWC device requested composition type change
106     virtual void applyDeviceCompositionTypeChange(Hwc2::IComposerClient::Composition) = 0;
107 
108     // Prepares to apply any HWC device layer requests
109     virtual void prepareForDeviceLayerRequests() = 0;
110 
111     // Applies a HWC device layer request
112     virtual void applyDeviceLayerRequest(Hwc2::IComposerClient::LayerRequest request) = 0;
113 
114     // Returns true if the composition settings scale pixels
115     virtual bool needsFiltering() const = 0;
116 
117     // Debugging
118     virtual void dump(std::string& result) const = 0;
119 };
120 
121 } // namespace compositionengine
122 } // namespace android
123