• 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 "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 presentAndGetFrameFences() override;
63     void setExpensiveRenderingExpected(bool) override;
64     void finishFrame(GpuCompositionResult&&) override;
65 
66     // compositionengine::Display overrides
67     DisplayId getId() const override;
68     bool isSecure() const override;
69     bool isVirtual() const override;
70     void disconnect() override;
71     void createDisplayColorProfile(
72             const compositionengine::DisplayColorProfileCreationArgs&) override;
73     void createRenderSurface(const compositionengine::RenderSurfaceCreationArgs&) override;
74     void createClientCompositionCache(uint32_t cacheSize) override;
75     void applyDisplayBrightness(const bool applyImmediately) override;
76 
77     // Internal helpers used by chooseCompositionStrategy()
78     using ChangedTypes = android::HWComposer::DeviceRequestedChanges::ChangedTypes;
79     using DisplayRequests = android::HWComposer::DeviceRequestedChanges::DisplayRequests;
80     using LayerRequests = android::HWComposer::DeviceRequestedChanges::LayerRequests;
81     using ClientTargetProperty = android::HWComposer::DeviceRequestedChanges::ClientTargetProperty;
82     virtual bool allLayersRequireClientComposition() const;
83     virtual void applyChangedTypesToLayers(const ChangedTypes&);
84     virtual void applyDisplayRequests(const DisplayRequests&);
85     virtual void applyLayerRequestsToLayers(const LayerRequests&);
86     virtual void applyClientTargetRequests(const ClientTargetProperty&);
87 
88     // Internal
89     virtual void setConfiguration(const compositionengine::DisplayCreationArgs&);
90     std::unique_ptr<compositionengine::OutputLayer> createOutputLayer(const sp<LayerFE>&) const;
91 
92 private:
93     bool isPowerHintSessionEnabled() override;
94     void setHintSessionGpuFence(std::unique_ptr<FenceTime>&& gpuFence) override;
95     DisplayId mId;
96     bool mIsDisconnected = false;
97     Hwc2::PowerAdvisor* mPowerAdvisor = nullptr;
98 };
99 
100 // This template factory function standardizes the implementation details of the
101 // final class using the types actually required by the implementation. This is
102 // not possible to do in the base class as those types may not even be visible
103 // to the base code.
104 template <typename BaseDisplay, typename CompositionEngine>
createDisplayTemplated(const CompositionEngine & compositionEngine,const compositionengine::DisplayCreationArgs & args)105 std::shared_ptr<BaseDisplay> createDisplayTemplated(
106         const CompositionEngine& compositionEngine,
107         const compositionengine::DisplayCreationArgs& args) {
108     auto display = createOutputTemplated<BaseDisplay>(compositionEngine);
109 
110     display->setConfiguration(args);
111 
112     return display;
113 }
114 
115 std::shared_ptr<Display> createDisplay(const compositionengine::CompositionEngine&,
116                                        const compositionengine::DisplayCreationArgs&);
117 
118 } // namespace impl
119 } // namespace android::compositionengine
120