2 // Copyright (c) 2016 Intel Corporation
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
8 // http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef WSI_PHYSICALDISPLAY_H_
18 #define WSI_PHYSICALDISPLAY_H_
23 #include <nativedisplay.h>
28 #include "platformdefines.h"
29 #include "displayplanestate.h"
30 #include "displayplanehandler.h"
33 namespace hwcomposer {
34 class DisplayPlaneState;
35 class DisplayPlaneManager;
37 class NativeBufferHandler;
41 class PhysicalDisplay : public NativeDisplay, public DisplayPlaneHandler {
43 PhysicalDisplay(uint32_t gpu_fd, uint32_t pipe_id);
44 ~PhysicalDisplay() override;
46 bool Initialize(NativeBufferHandler *buffer_handler) override;
48 DisplayType Type() const override {
49 return DisplayType::kInternal;
52 uint32_t Width() const override {
56 uint32_t Height() const override {
60 uint32_t PowerMode() const override;
62 int GetDisplayPipe() override;
63 bool SetActiveConfig(uint32_t config) override;
64 bool GetActiveConfig(uint32_t *config) override;
66 bool SetPowerMode(uint32_t power_mode) override;
68 bool Present(std::vector<HwcLayer *> &source_layers, int32_t *retire_fence,
69 bool handle_constraints = false) override;
71 int RegisterVsyncCallback(std::shared_ptr<VsyncCallback> callback,
72 uint32_t display_id) override;
74 void RegisterRefreshCallback(std::shared_ptr<RefreshCallback> callback,
75 uint32_t display_id) override;
77 void RegisterHotPlugCallback(std::shared_ptr<HotPlugCallback> callback,
78 uint32_t display_id) override;
80 void VSyncControl(bool enabled) override;
81 bool CheckPlaneFormat(uint32_t format) override;
82 void SetGamma(float red, float green, float blue) override;
83 void SetContrast(uint32_t red, uint32_t green, uint32_t blue) override;
84 void SetColorTransform(const float *matrix, HWCColorTransform hint) override;
85 void SetBrightness(uint32_t red, uint32_t green, uint32_t blue) override;
86 void SetExplicitSyncSupport(bool disable_explicit_sync) override;
87 void SetVideoScalingMode(uint32_t mode) override;
88 void SetVideoColor(HWCColorControl color, float value) override;
89 void GetVideoColor(HWCColorControl color, float *value, float *start,
91 void RestoreVideoDefaultColor(HWCColorControl color) override;
92 void SetVideoDeinterlace(HWCDeinterlaceFlag flag,
93 HWCDeinterlaceControl mode) override;
94 void RestoreVideoDefaultDeinterlace() override;
96 void Connect() override;
98 bool IsConnected() const override;
101 const std::vector<OverlayPlane> &commit_planes) const override;
104 std::vector<std::unique_ptr<DisplayPlane>> &overlay_planes) override;
106 void UpdateScalingRatio(uint32_t primary_width, uint32_t primary_height,
107 uint32_t display_width,
108 uint32_t display_height) override;
110 void CloneDisplay(NativeDisplay *source_display) override;
112 bool PresentClone(std::vector<HwcLayer *> &source_layers,
113 int32_t *retire_fence, bool idle_frame) override;
115 bool GetDisplayAttribute(uint32_t /*config*/, HWCDisplayAttribute attribute,
116 int32_t *value) override;
118 bool GetDisplayConfigs(uint32_t *num_configs, uint32_t *configs) override;
119 bool GetDisplayName(uint32_t *size, char *name) override;
121 void OwnPresentation(NativeDisplay *clone) override;
123 void DisOwnPresentation(NativeDisplay *clone) override;
125 void SetDisplayOrder(uint32_t display_order) override;
127 void RotateDisplay(HWCRotation rotation) override;
130 * API for setting color correction for display.
132 virtual void SetColorCorrection(struct gamma_colors gamma, uint32_t contrast,
133 uint32_t brightness) const = 0;
135 * API for setting color transform matrix.
137 virtual void SetColorTransformMatrix(const float *color_transform_matrix,
138 HWCColorTransform color_transform_hint) const = 0;
141 * API is called when display needs to be disabled.
142 * @param composition_planes contains list of planes enabled last
145 virtual void Disable(const DisplayPlaneStateList &composition_planes) = 0;
148 * API for showing content on display
149 * @param composition_planes contains list of layers which need to displayed.
150 * @param previous_composition_planes contains list of planes enabled last
152 * @param disable_explicit_fence is set to true if we want a hardware fence
153 * associated with this commit request set to commit_fence.
154 * @param commit_fence hardware fence associated with this commit request.
156 virtual bool Commit(const DisplayPlaneStateList &composition_planes,
157 const DisplayPlaneStateList &previous_composition_planes,
158 bool disable_explicit_fence, int32_t *commit_fence) = 0;
161 * API is called if current active display configuration has changed.
162 * Implementations need to reset any state in this case.
164 virtual void UpdateDisplayConfig() = 0;
167 * API for powering on the display
169 virtual void PowerOn() = 0;
172 * API for initializing display. Implementation needs to handle all things
173 * needed to set up the physical display.
175 virtual bool InitializeDisplay() = 0;
177 virtual void NotifyClientsOfDisplayChangeStatus() = 0;
180 * API for informing the display that it might be disconnected in near
183 void MarkForDisconnect();
186 * API for informing the clients resgistered via RegisterHotPlugCallback
187 * that this display had been disconnected.
189 void NotifyClientOfConnectedState();
192 * API for informing the clients resgistered via RegisterHotPlugCallback
193 * that this display had been connected.
195 void NotifyClientOfDisConnectedState();
198 * API to disconnect the display. This is called when this display
199 * is physically disconnected.
201 virtual void DisConnect();
204 * API to handle any lazy initializations which need to be handled
205 * during first present call.
207 virtual void HandleLazyInitialization() {
211 bool UpdatePowerMode();
212 void RefreshClones();
213 void HandleClonedDisplays(std::vector<HwcLayer *> &source_layers);
216 enum DisplayConnectionStatus {
217 kDisconnected = 1 << 0,
219 kDisconnectionInProgress = 1 << 2
224 kNeedsModeset = 1 << 1,
225 kPendingPowerMode = 1 << 2,
226 kUpdateDisplay = 1 << 3,
227 kInitialized = 1 << 4, // Display Queue is initialized.
228 kRefreshClonedDisplays = 1 << 5,
229 kHandlePendingHotPlugNotifications = 1 << 6,
230 kNotifyClient = 1 << 7, // Notify client as display connection physical
231 // status has changed.
232 kUpdateConfig = 1 << 8
236 #ifdef ENABLE_ANDROID_WA
237 uint32_t config_ = 1;
239 uint32_t config_ = 0;
244 uint32_t power_mode_ = kOn;
245 int display_state_ = kNone;
246 int connection_state_ = kDisconnected;
247 uint32_t hot_plug_display_id_ = 0;
248 // This differs from pipe_ as upper layers can
249 // change order of physical display from setting
250 // file. This may or may not be same as pipe_.
251 uint32_t ordered_display_id_ = 0;
252 SpinLock modeset_lock_;
253 std::unique_ptr<DisplayQueue> display_queue_;
254 std::shared_ptr<HotPlugCallback> hotplug_callback_ = NULL;
255 NativeDisplay *source_display_ = NULL;
256 std::vector<NativeDisplay *> cloned_displays_;
257 std::vector<NativeDisplay *> clones_;
260 } // namespace hwcomposer
261 #endif // WSI_PHYSICALDISPLAY_H_