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 "DisplayHardware/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 std::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 virtual bool allLayersRequireClientComposition() const;
86 virtual void applyChangedTypesToLayers(const ChangedTypes&);
87 virtual void applyDisplayRequests(const DisplayRequests&);
88 virtual void applyLayerRequestsToLayers(const LayerRequests&);
89 virtual void applyClientTargetRequests(const ClientTargetProperty&);
90
91 // Internal
92 virtual void setConfiguration(const compositionengine::DisplayCreationArgs&);
93 std::unique_ptr<compositionengine::OutputLayer> createOutputLayer(const sp<LayerFE>&) const;
94
95 private:
96 bool isPowerHintSessionEnabled() override;
97 bool isPowerHintSessionGpuReportingEnabled() override;
98 void setHintSessionGpuStart(TimePoint startTime) override;
99 void setHintSessionGpuFence(std::unique_ptr<FenceTime>&& gpuFence) override;
100 void setHintSessionRequiresRenderEngine(bool requiresRenderEngine) override;
101 DisplayId mId;
102 bool mIsDisconnected = false;
103 Hwc2::PowerAdvisor* mPowerAdvisor = nullptr;
104 };
105
106 // This template factory function standardizes the implementation details of the
107 // final class using the types actually required by the implementation. This is
108 // not possible to do in the base class as those types may not even be visible
109 // to the base code.
110 template <typename BaseDisplay, typename CompositionEngine>
createDisplayTemplated(const CompositionEngine & compositionEngine,const compositionengine::DisplayCreationArgs & args)111 std::shared_ptr<BaseDisplay> createDisplayTemplated(
112 const CompositionEngine& compositionEngine,
113 const compositionengine::DisplayCreationArgs& args) {
114 auto display = createOutputTemplated<BaseDisplay>(compositionEngine);
115
116 display->setConfiguration(args);
117
118 return display;
119 }
120
121 std::shared_ptr<Display> createDisplay(const compositionengine::CompositionEngine&,
122 const compositionengine::DisplayCreationArgs&);
123
124 } // namespace impl
125 } // namespace android::compositionengine
126