blob: a7ab472d68dcfd1953cd76df9cd700772286c5cd [file] [log] [blame]
Lloyd Pique32cbe282018-10-19 13:09:22 -07001/*
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 <cstdint>
20#include <string>
21
22#include <math/mat4.h>
23#include <ui/GraphicTypes.h>
24#include <ui/Region.h>
25#include <ui/Transform.h>
Lloyd Piquecc01a452018-12-04 17:24:00 -080026#include <utils/StrongPointer.h>
Lloyd Pique32cbe282018-10-19 13:09:22 -070027
28namespace android::compositionengine {
29
Lloyd Pique3d0c02e2018-10-19 18:38:12 -070030class DisplayColorProfile;
Lloyd Piquecc01a452018-12-04 17:24:00 -080031class Layer;
32class LayerFE;
Lloyd Pique31cb2942018-10-19 17:23:03 -070033class RenderSurface;
Lloyd Piquecc01a452018-12-04 17:24:00 -080034class OutputLayer;
Lloyd Pique31cb2942018-10-19 17:23:03 -070035
Lloyd Pique32cbe282018-10-19 13:09:22 -070036namespace impl {
37struct OutputCompositionState;
38} // namespace impl
39
40/**
41 * Encapsulates all the state involved with composing layers for an output
42 */
43class Output {
44public:
Lloyd Piquecc01a452018-12-04 17:24:00 -080045 using OutputLayers = std::vector<std::unique_ptr<compositionengine::OutputLayer>>;
46
Lloyd Piquefeb73d72018-12-04 17:23:44 -080047 virtual ~Output();
48
Lloyd Pique32cbe282018-10-19 13:09:22 -070049 // Returns true if the output is valid. This is meant to be checked post-
50 // construction and prior to use, as not everything is set up by the
51 // constructor.
52 virtual bool isValid() const = 0;
53
54 // Enables (or disables) composition on this output
55 virtual void setCompositionEnabled(bool) = 0;
56
57 // Sets the projection state to use
58 virtual void setProjection(const ui::Transform&, int32_t orientation, const Rect& frame,
59 const Rect& viewport, const Rect& scissor, bool needsFiltering) = 0;
60 // Sets the bounds to use
Lloyd Pique31cb2942018-10-19 17:23:03 -070061 virtual void setBounds(const ui::Size&) = 0;
Lloyd Pique32cbe282018-10-19 13:09:22 -070062
Lloyd Piqueef36b002019-01-23 17:52:04 -080063 // Sets the layer stack filtering settings for this output. See
64 // belongsInOutput for full details.
65 virtual void setLayerStackFilter(uint32_t layerStackId, bool isInternal) = 0;
Lloyd Pique32cbe282018-10-19 13:09:22 -070066
67 // Sets the color transform matrix to use
68 virtual void setColorTransform(const mat4&) = 0;
69
70 // Sets the output color mode
71 virtual void setColorMode(ui::ColorMode, ui::Dataspace, ui::RenderIntent) = 0;
72
73 // Outputs a string with a state dump
74 virtual void dump(std::string&) const = 0;
75
76 // Gets the debug name for the output
77 virtual const std::string& getName() const = 0;
78
79 // Sets a debug name for the output
80 virtual void setName(const std::string&) = 0;
81
Lloyd Pique3d0c02e2018-10-19 18:38:12 -070082 // Gets the current render color mode for the output
83 virtual DisplayColorProfile* getDisplayColorProfile() const = 0;
84
Lloyd Pique31cb2942018-10-19 17:23:03 -070085 // Gets the current render surface for the output
86 virtual RenderSurface* getRenderSurface() const = 0;
87
Lloyd Pique32cbe282018-10-19 13:09:22 -070088 using OutputCompositionState = compositionengine::impl::OutputCompositionState;
89
90 // Gets the raw composition state data for the output
91 // TODO(lpique): Make this protected once it is only internally called.
92 virtual const OutputCompositionState& getState() const = 0;
93
94 // Allows mutable access to the raw composition state data for the output.
95 // This is meant to be used by the various functions that are part of the
96 // composition process.
97 // TODO(lpique): Make this protected once it is only internally called.
98 virtual OutputCompositionState& editState() = 0;
99
Alec Mouri79108df2019-02-04 19:33:44 +0000100 // Gets the physical space dirty region. If repaintEverything is true, this
101 // will be the full display bounds. Internally the dirty region is stored in
102 // logical (aka layer stack) space.
103 virtual Region getPhysicalSpaceDirtyRegion(bool repaintEverything) const = 0;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700104
Lloyd Piqueef36b002019-01-23 17:52:04 -0800105 // Tests whether a given layerStackId belongs in this output.
106 // A layer belongs to the output if its layerStackId matches the of the output layerStackId,
107 // unless the layer should display on the primary output only and this is not the primary output
108
109 // A layer belongs to the output if its layerStackId matches. Additionally
110 // if the layer should only show in the internal (primary) display only and
111 // this output allows that.
112 virtual bool belongsInOutput(uint32_t layerStackId, bool internalOnly) const = 0;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700113
Lloyd Piquecc01a452018-12-04 17:24:00 -0800114 // Returns a pointer to the output layer corresponding to the given layer on
115 // this output, or nullptr if the layer does not have one
116 virtual OutputLayer* getOutputLayerForLayer(Layer*) const = 0;
117
118 // Gets the OutputLayer corresponding to the input Layer instance from the
119 // current ordered set of output layers. If there is no such layer, a new
120 // one is created and returned.
121 virtual std::unique_ptr<OutputLayer> getOrCreateOutputLayer(std::shared_ptr<Layer>,
122 sp<LayerFE>) = 0;
123
124 // Sets the new ordered set of output layers for this output
125 virtual void setOutputLayersOrderedByZ(OutputLayers&&) = 0;
126
127 // Gets the ordered set of output layers for this output
128 virtual const OutputLayers& getOutputLayersOrderedByZ() const = 0;
129
Lloyd Pique32cbe282018-10-19 13:09:22 -0700130protected:
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700131 virtual void setDisplayColorProfile(std::unique_ptr<DisplayColorProfile>) = 0;
132 virtual void setRenderSurface(std::unique_ptr<RenderSurface>) = 0;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700133};
134
135} // namespace android::compositionengine