OSDN Git Service

Move LayerHashGenerator to Native display
[android-x86/external-IA-Hardware-Composer.git] / wsi / physicaldisplay.h
1 /*
2 // Copyright (c) 2016 Intel Corporation
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 #ifndef WSI_PHYSICALDISPLAY_H_
18 #define WSI_PHYSICALDISPLAY_H_
19
20 #include <stdlib.h>
21 #include <stdint.h>
22
23 #include <nativedisplay.h>
24
25 #include <memory>
26 #include <vector>
27
28 #include "platformdefines.h"
29 #include "displayplanestate.h"
30 #include "displayplanehandler.h"
31 #include <spinlock.h>
32
33 namespace hwcomposer {
34 class DisplayPlaneState;
35 class DisplayPlaneManager;
36 class DisplayQueue;
37 class NativeBufferHandler;
38 class GpuDevice;
39 struct HwcLayer;
40
41 class PhysicalDisplay : public NativeDisplay, public DisplayPlaneHandler {
42  public:
43   PhysicalDisplay(uint32_t gpu_fd, uint32_t pipe_id);
44   ~PhysicalDisplay() override;
45
46   bool Initialize(NativeBufferHandler *buffer_handler) override;
47
48   DisplayType Type() const override {
49     return DisplayType::kInternal;
50   }
51
52   uint32_t Width() const override {
53     return width_;
54   }
55
56   uint32_t Height() const override {
57     return height_;
58   }
59
60   uint32_t PowerMode() const override;
61
62   int GetDisplayPipe() override;
63   bool SetActiveConfig(uint32_t config) override;
64   bool GetActiveConfig(uint32_t *config) override;
65
66   bool SetPowerMode(uint32_t power_mode) override;
67
68   bool Present(std::vector<HwcLayer *> &source_layers, int32_t *retire_fence,
69                bool handle_constraints = false) override;
70
71   int RegisterVsyncCallback(std::shared_ptr<VsyncCallback> callback,
72                             uint32_t display_id) override;
73
74   void RegisterRefreshCallback(std::shared_ptr<RefreshCallback> callback,
75                                uint32_t display_id) override;
76
77   void RegisterHotPlugCallback(std::shared_ptr<HotPlugCallback> callback,
78                                uint32_t display_id) override;
79
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,
90                      float *end) override;
91   void RestoreVideoDefaultColor(HWCColorControl color) override;
92   void SetVideoDeinterlace(HWCDeinterlaceFlag flag,
93                            HWCDeinterlaceControl mode) override;
94   void RestoreVideoDefaultDeinterlace() override;
95
96   void Connect() override;
97
98   bool IsConnected() const override;
99
100   bool TestCommit(
101       const std::vector<OverlayPlane> &commit_planes) const override;
102
103   bool PopulatePlanes(
104       std::vector<std::unique_ptr<DisplayPlane>> &overlay_planes) override;
105
106   void UpdateScalingRatio(uint32_t primary_width, uint32_t primary_height,
107                           uint32_t display_width,
108                           uint32_t display_height) override;
109
110   void CloneDisplay(NativeDisplay *source_display) override;
111
112   bool PresentClone(std::vector<HwcLayer *> &source_layers,
113                     int32_t *retire_fence, bool idle_frame) override;
114
115   bool GetDisplayAttribute(uint32_t /*config*/, HWCDisplayAttribute attribute,
116                            int32_t *value) override;
117
118   bool GetDisplayConfigs(uint32_t *num_configs, uint32_t *configs) override;
119   bool GetDisplayName(uint32_t *size, char *name) override;
120
121   void OwnPresentation(NativeDisplay *clone) override;
122
123   void DisOwnPresentation(NativeDisplay *clone) override;
124
125   void SetDisplayOrder(uint32_t display_order) override;
126
127   void RotateDisplay(HWCRotation rotation) override;
128
129   /**
130   * API for setting color correction for display.
131   */
132   virtual void SetColorCorrection(struct gamma_colors gamma, uint32_t contrast,
133                                   uint32_t brightness) const = 0;
134   /**
135   * API for setting color transform matrix.
136   */
137   virtual void SetColorTransformMatrix(const float *color_transform_matrix,
138                                        HWCColorTransform color_transform_hint) const = 0;
139
140   /**
141   * API is called when display needs to be disabled.
142   * @param composition_planes contains list of planes enabled last
143   * frame.
144   */
145   virtual void Disable(const DisplayPlaneStateList &composition_planes) = 0;
146
147   /**
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
151   * frame.
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.
155   */
156   virtual bool Commit(const DisplayPlaneStateList &composition_planes,
157                       const DisplayPlaneStateList &previous_composition_planes,
158                       bool disable_explicit_fence, int32_t *commit_fence) = 0;
159
160   /**
161   * API is called if current active display configuration has changed.
162   * Implementations need to reset any state in this case.
163   */
164   virtual void UpdateDisplayConfig() = 0;
165
166   /**
167   * API for powering on the display
168   */
169   virtual void PowerOn() = 0;
170
171   /**
172   * API for initializing display. Implementation needs to handle all things
173   * needed to set up the physical display.
174   */
175   virtual bool InitializeDisplay() = 0;
176
177   virtual void NotifyClientsOfDisplayChangeStatus() = 0;
178
179   /**
180   * API for informing the display that it might be disconnected in near
181   * future.
182   */
183   void MarkForDisconnect();
184
185   /**
186   * API for informing the clients resgistered via RegisterHotPlugCallback
187   * that this display had been disconnected.
188   */
189   void NotifyClientOfConnectedState();
190
191   /**
192   * API for informing the clients resgistered via RegisterHotPlugCallback
193   * that this display had been connected.
194   */
195   void NotifyClientOfDisConnectedState();
196
197   /**
198   * API to disconnect the display. This is called when this display
199   * is physically disconnected.
200   */
201   virtual void DisConnect();
202
203   /**
204   * API to handle any lazy initializations which need to be handled
205   * during first present call.
206   */
207   virtual void HandleLazyInitialization() {
208   }
209
210  private:
211   bool UpdatePowerMode();
212   void RefreshClones();
213   void HandleClonedDisplays(std::vector<HwcLayer *> &source_layers);
214
215  protected:
216   enum DisplayConnectionStatus {
217     kDisconnected = 1 << 0,
218     kConnected = 1 << 1,
219     kDisconnectionInProgress = 1 << 2
220   };
221
222   enum DisplayState {
223     kNone = 1 << 0,
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
233   };
234
235   uint32_t pipe_;
236 #ifdef ENABLE_ANDROID_WA
237   uint32_t config_ = 1;
238 #else
239   uint32_t config_ = 0;
240 #endif
241   int32_t width_;
242   int32_t height_;
243   uint32_t gpu_fd_;
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_;
258 };
259
260 }  // namespace hwcomposer
261 #endif  // WSI_PHYSICALDISPLAY_H_