Home | History | Annotate | Download | only in compositionengine
      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 <cstdint>
     20 #include <optional>
     21 #include <string>
     22 
     23 #include <math/mat4.h>
     24 #include <ui/GraphicTypes.h>
     25 #include <ui/Region.h>
     26 #include <ui/Transform.h>
     27 #include <utils/StrongPointer.h>
     28 
     29 #include "DisplayHardware/DisplayIdentification.h"
     30 
     31 namespace android::compositionengine {
     32 
     33 class DisplayColorProfile;
     34 class Layer;
     35 class LayerFE;
     36 class RenderSurface;
     37 class OutputLayer;
     38 
     39 namespace impl {
     40 struct OutputCompositionState;
     41 } // namespace impl
     42 
     43 /**
     44  * Encapsulates all the state involved with composing layers for an output
     45  */
     46 class Output {
     47 public:
     48     using OutputLayers = std::vector<std::unique_ptr<compositionengine::OutputLayer>>;
     49 
     50     virtual ~Output();
     51 
     52     // Returns true if the output is valid. This is meant to be checked post-
     53     // construction and prior to use, as not everything is set up by the
     54     // constructor.
     55     virtual bool isValid() const = 0;
     56 
     57     // Enables (or disables) composition on this output
     58     virtual void setCompositionEnabled(bool) = 0;
     59 
     60     // Sets the projection state to use
     61     virtual void setProjection(const ui::Transform&, int32_t orientation, const Rect& frame,
     62                                const Rect& viewport, const Rect& scissor, bool needsFiltering) = 0;
     63     // Sets the bounds to use
     64     virtual void setBounds(const ui::Size&) = 0;
     65 
     66     // Sets the layer stack filtering settings for this output. See
     67     // belongsInOutput for full details.
     68     virtual void setLayerStackFilter(uint32_t layerStackId, bool isInternal) = 0;
     69 
     70     // Sets the color transform matrix to use
     71     virtual void setColorTransform(const mat4&) = 0;
     72 
     73     // Sets the output color mode
     74     virtual void setColorMode(ui::ColorMode, ui::Dataspace, ui::RenderIntent) = 0;
     75 
     76     // Outputs a string with a state dump
     77     virtual void dump(std::string&) const = 0;
     78 
     79     // Gets the debug name for the output
     80     virtual const std::string& getName() const = 0;
     81 
     82     // Sets a debug name for the output
     83     virtual void setName(const std::string&) = 0;
     84 
     85     // Gets the current render color mode for the output
     86     virtual DisplayColorProfile* getDisplayColorProfile() const = 0;
     87 
     88     // Gets the current render surface for the output
     89     virtual RenderSurface* getRenderSurface() const = 0;
     90 
     91     using OutputCompositionState = compositionengine::impl::OutputCompositionState;
     92 
     93     // Gets the raw composition state data for the output
     94     // TODO(lpique): Make this protected once it is only internally called.
     95     virtual const OutputCompositionState& getState() const = 0;
     96 
     97     // Allows mutable access to the raw composition state data for the output.
     98     // This is meant to be used by the various functions that are part of the
     99     // composition process.
    100     // TODO(lpique): Make this protected once it is only internally called.
    101     virtual OutputCompositionState& editState() = 0;
    102 
    103     // Gets the dirty region in layer stack space.
    104     // If repaintEverything is true, this will be the full display bounds.
    105     virtual Region getDirtyRegion(bool repaintEverything) const = 0;
    106 
    107     // Tests whether a given layerStackId belongs in this output.
    108     // A layer belongs to the output if its layerStackId matches the of the output layerStackId,
    109     // unless the layer should display on the primary output only and this is not the primary output
    110 
    111     // A layer belongs to the output if its layerStackId matches. Additionally
    112     // if the layer should only show in the internal (primary) display only and
    113     // this output allows that.
    114     virtual bool belongsInOutput(uint32_t layerStackId, bool internalOnly) const = 0;
    115 
    116     // Returns a pointer to the output layer corresponding to the given layer on
    117     // this output, or nullptr if the layer does not have one
    118     virtual OutputLayer* getOutputLayerForLayer(Layer*) const = 0;
    119 
    120     // Gets the OutputLayer corresponding to the input Layer instance from the
    121     // current ordered set of output layers. If there is no such layer, a new
    122     // one is created and returned.
    123     virtual std::unique_ptr<OutputLayer> getOrCreateOutputLayer(std::optional<DisplayId>,
    124                                                                 std::shared_ptr<Layer>,
    125                                                                 sp<LayerFE>) = 0;
    126 
    127     // Sets the new ordered set of output layers for this output
    128     virtual void setOutputLayersOrderedByZ(OutputLayers&&) = 0;
    129 
    130     // Gets the ordered set of output layers for this output
    131     virtual const OutputLayers& getOutputLayersOrderedByZ() const = 0;
    132 
    133 protected:
    134     virtual void setDisplayColorProfile(std::unique_ptr<DisplayColorProfile>) = 0;
    135     virtual void setRenderSurface(std::unique_ptr<RenderSurface>) = 0;
    136 };
    137 
    138 } // namespace android::compositionengine
    139