• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <memory>
20 
21 #include <compositionengine/Display.h>
22 #include <compositionengine/DisplayColorProfile.h>
23 #include <compositionengine/DisplayCreationArgs.h>
24 #include <compositionengine/RenderSurface.h>
25 #include <compositionengine/impl/Output.h>
26 #include <ui/PixelFormat.h>
27 #include <ui/Size.h>
28 
29 #include "DisplayHardware/DisplayIdentification.h"
30 #include "DisplayHardware/HWComposer.h"
31 #include "DisplayHardware/PowerAdvisor.h"
32 
33 namespace android::compositionengine {
34 
35 class CompositionEngine;
36 
37 namespace impl {
38 
39 // The implementation class contains the common implementation, but does not
40 // actually contain the final display state.
41 class Display : public compositionengine::impl::Output, public virtual compositionengine::Display {
42 public:
43     virtual ~Display();
44 
45     // compositionengine::Output overrides
46     std::optional<DisplayId> getDisplayId() const override;
47     bool isValid() const override;
48     void dump(std::string&) const override;
49     using compositionengine::impl::Output::setReleasedLayers;
50     void setReleasedLayers(const CompositionRefreshArgs&) override;
51     void setColorTransform(const CompositionRefreshArgs&) override;
52     void setColorProfile(const ColorProfile&) override;
53     void chooseCompositionStrategy() override;
54     bool getSkipColorTransform() const override;
55     compositionengine::Output::FrameFences presentAndGetFrameFences() override;
56     void setExpensiveRenderingExpected(bool) override;
57     void finishFrame(const CompositionRefreshArgs&) override;
58 
59     // compositionengine::Display overrides
60     DisplayId getId() const override;
61     bool isSecure() const override;
62     bool isVirtual() const override;
63     void disconnect() override;
64     void createDisplayColorProfile(
65             const compositionengine::DisplayColorProfileCreationArgs&) override;
66     void createRenderSurface(const compositionengine::RenderSurfaceCreationArgs&) override;
67     void createClientCompositionCache(uint32_t cacheSize) override;
68 
69     // Internal helpers used by chooseCompositionStrategy()
70     using ChangedTypes = android::HWComposer::DeviceRequestedChanges::ChangedTypes;
71     using DisplayRequests = android::HWComposer::DeviceRequestedChanges::DisplayRequests;
72     using LayerRequests = android::HWComposer::DeviceRequestedChanges::LayerRequests;
73     using ClientTargetProperty = android::HWComposer::DeviceRequestedChanges::ClientTargetProperty;
74     virtual bool anyLayersRequireClientComposition() const;
75     virtual bool allLayersRequireClientComposition() const;
76     virtual void applyChangedTypesToLayers(const ChangedTypes&);
77     virtual void applyDisplayRequests(const DisplayRequests&);
78     virtual void applyLayerRequestsToLayers(const LayerRequests&);
79     virtual void applyClientTargetRequests(const ClientTargetProperty&);
80 
81     // Internal
82     virtual void setConfiguration(const compositionengine::DisplayCreationArgs&);
83     std::unique_ptr<compositionengine::OutputLayer> createOutputLayer(const sp<LayerFE>&) const;
84 
85 private:
86     bool mIsVirtual = false;
87     bool mIsDisconnected = false;
88     DisplayId mId;
89     Hwc2::PowerAdvisor* mPowerAdvisor = nullptr;
90 };
91 
92 // This template factory function standardizes the implementation details of the
93 // final class using the types actually required by the implementation. This is
94 // not possible to do in the base class as those types may not even be visible
95 // to the base code.
96 template <typename BaseDisplay, typename CompositionEngine>
createDisplayTemplated(const CompositionEngine & compositionEngine,const compositionengine::DisplayCreationArgs & args)97 std::shared_ptr<BaseDisplay> createDisplayTemplated(
98         const CompositionEngine& compositionEngine,
99         const compositionengine::DisplayCreationArgs& args) {
100     auto display = createOutputTemplated<BaseDisplay>(compositionEngine);
101 
102     display->setConfiguration(args);
103 
104     return display;
105 }
106 
107 std::shared_ptr<Display> createDisplay(const compositionengine::CompositionEngine&,
108                                        const compositionengine::DisplayCreationArgs&);
109 
110 } // namespace impl
111 } // namespace android::compositionengine
112