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