• 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/GpuCompositionResult.h>
26 #include <compositionengine/impl/Output.h>
27 #include <ui/PixelFormat.h>
28 #include <ui/Size.h>
29 
30 #include <ui/DisplayIdentification.h>
31 
32 #include "DisplayHardware/HWComposer.h"
33 #include "PowerAdvisor/PowerAdvisor.h"
34 
35 namespace android::compositionengine {
36 
37 class CompositionEngine;
38 
39 namespace impl {
40 
41 // The implementation class contains the common implementation, but does not
42 // actually contain the final display state.
43 class Display : public compositionengine::impl::Output, public virtual compositionengine::Display {
44 public:
45     virtual ~Display();
46 
47     // compositionengine::Output overrides
48     ftl::Optional<DisplayId> getDisplayId() const override;
49     ftl::Optional<DisplayIdVariant> getDisplayIdVariant() const override;
50     bool isValid() const override;
51     void dump(std::string&) const override;
52     using compositionengine::impl::Output::setReleasedLayers;
53     void setReleasedLayers(const CompositionRefreshArgs&) override;
54     void setColorTransform(const CompositionRefreshArgs&) override;
55     void setColorProfile(const ColorProfile&) override;
56 
57     void beginFrame() override;
58     using DeviceRequestedChanges = android::HWComposer::DeviceRequestedChanges;
59     bool chooseCompositionStrategy(
60             std::optional<android::HWComposer::DeviceRequestedChanges>*) override;
61     void applyCompositionStrategy(const std::optional<DeviceRequestedChanges>&) override;
62     bool getSkipColorTransform() const override;
63     compositionengine::Output::FrameFences presentFrame() override;
64     void executeCommands() override;
65     void setExpensiveRenderingExpected(bool) override;
66     void finishFrame(GpuCompositionResult&&) override;
67     bool supportsOffloadPresent() const override;
68 
69     // compositionengine::Display overrides
70     DisplayId getId() const override;
71     bool hasSecureLayers() const override;
72     bool isSecure() const override;
73     void setSecure(bool secure) override;
74     bool isVirtual() const override;
75     void disconnect() override;
76     void createDisplayColorProfile(
77             const compositionengine::DisplayColorProfileCreationArgs&) override;
78     void createRenderSurface(const compositionengine::RenderSurfaceCreationArgs&) override;
79     void createClientCompositionCache(uint32_t cacheSize) override;
80     void applyDisplayBrightness(bool applyImmediately) override;
81 
82     // Internal helpers used by chooseCompositionStrategy()
83     using ChangedTypes = android::HWComposer::DeviceRequestedChanges::ChangedTypes;
84     using DisplayRequests = android::HWComposer::DeviceRequestedChanges::DisplayRequests;
85     using LayerRequests = android::HWComposer::DeviceRequestedChanges::LayerRequests;
86     using ClientTargetProperty = android::HWComposer::DeviceRequestedChanges::ClientTargetProperty;
87     using LayerLuts = android::HWComposer::DeviceRequestedChanges::LayerLuts;
88     virtual bool allLayersRequireClientComposition() const;
89     virtual void applyChangedTypesToLayers(const ChangedTypes&);
90     virtual void applyDisplayRequests(const DisplayRequests&);
91     virtual void applyLayerRequestsToLayers(const LayerRequests&);
92     virtual void applyClientTargetRequests(const ClientTargetProperty&);
93     virtual void applyLayerLutsToLayers(const LayerLuts&);
94 
95     // Internal
96     virtual void setConfiguration(const compositionengine::DisplayCreationArgs&);
97     std::unique_ptr<compositionengine::OutputLayer> createOutputLayer(const sp<LayerFE>&) const;
98 
99 private:
100     bool isPowerHintSessionEnabled() override;
101     bool isPowerHintSessionGpuReportingEnabled() override;
102     void setHintSessionGpuStart(TimePoint startTime) override;
103     void setHintSessionGpuFence(std::unique_ptr<FenceTime>&& gpuFence) override;
104     void setHintSessionRequiresRenderEngine(bool requiresRenderEngine) override;
105     const aidl::android::hardware::graphics::composer3::OverlayProperties* getOverlaySupport()
106             override;
107     bool hasPictureProcessing() const override;
108     int32_t getMaxLayerPictureProfiles() const override;
isGpuVirtualDisplay()109     bool isGpuVirtualDisplay() const {
110         return std::holds_alternative<GpuVirtualDisplayId>(mIdVariant);
111     }
112 
113     DisplayIdVariant mIdVariant;
114     bool mIsDisconnected = false;
115     adpf::PowerAdvisor* mPowerAdvisor = nullptr;
116     bool mHasPictureProcessing = false;
117     int32_t mMaxLayerPictureProfiles = 0;
118 };
119 
120 // This template factory function standardizes the implementation details of the
121 // final class using the types actually required by the implementation. This is
122 // not possible to do in the base class as those types may not even be visible
123 // to the base code.
124 template <typename BaseDisplay, typename CompositionEngine>
createDisplayTemplated(const CompositionEngine & compositionEngine,const compositionengine::DisplayCreationArgs & args)125 std::shared_ptr<BaseDisplay> createDisplayTemplated(
126         const CompositionEngine& compositionEngine,
127         const compositionengine::DisplayCreationArgs& args) {
128     auto display = createOutputTemplated<BaseDisplay>(compositionEngine);
129 
130     display->setConfiguration(args);
131 
132     return display;
133 }
134 
135 std::shared_ptr<Display> createDisplay(const compositionengine::CompositionEngine&,
136                                        const compositionengine::DisplayCreationArgs&);
137 
138 } // namespace impl
139 } // namespace android::compositionengine
140