OSDN Git Service

Move LayerHashGenerator to Native display
[android-x86/external-IA-Hardware-Composer.git] / public / nativedisplay.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 PUBLIC_NATIVEDISPLAY_H_
18 #define PUBLIC_NATIVEDISPLAY_H_
19
20 #include <hwcdefs.h>
21 #include <platformdefines.h>
22
23 #include <stdint.h>
24
25 #include <memory>
26 #include <vector>
27
28 typedef struct _drmModeConnector drmModeConnector;
29 typedef struct _drmModeModeInfo drmModeModeInfo;
30
31 namespace hwcomposer {
32 struct HwcLayer;
33 class GpuDevice;
34 class NativeBufferHandler;
35
36 class VsyncCallback {
37  public:
38   virtual ~VsyncCallback() {
39   }
40   virtual void Callback(uint32_t display, int64_t timestamp) = 0;
41 };
42
43 class RefreshCallback {
44  public:
45   virtual ~RefreshCallback() {
46   }
47   virtual void Callback(uint32_t display) = 0;
48 };
49
50 class HotPlugCallback {
51  public:
52   virtual ~HotPlugCallback() {
53   }
54   virtual void Callback(uint32_t display, bool connected) = 0;
55 };
56
57 class NativeDisplay {
58  public:
59   virtual ~NativeDisplay() {
60   }
61
62   NativeDisplay() = default;
63
64   NativeDisplay(const NativeDisplay &rhs) = delete;
65   NativeDisplay &operator=(const NativeDisplay &rhs) = delete;
66
67   virtual bool Initialize(NativeBufferHandler *buffer_handler) = 0;
68
69   virtual DisplayType Type() const = 0;
70
71   virtual uint32_t Width() const = 0;
72
73   virtual uint32_t Height() const = 0;
74
75   virtual uint32_t PowerMode() const = 0;
76
77   virtual bool GetDisplayAttribute(uint32_t config,
78                                    HWCDisplayAttribute attribute,
79                                    int32_t *value) = 0;
80
81   virtual bool GetDisplayConfigs(uint32_t *num_configs, uint32_t *configs) = 0;
82   virtual bool GetDisplayName(uint32_t *size, char *name) = 0;
83   /**
84   * API for getting connected display's pipe id.
85   * @return "-1" for unconnected display, valid values are 0 ~ 2.
86   */
87   virtual int GetDisplayPipe() = 0;
88   virtual bool SetActiveConfig(uint32_t config) = 0;
89   virtual bool GetActiveConfig(uint32_t *config) = 0;
90
91   virtual bool SetPowerMode(uint32_t power_mode) = 0;
92
93   /**
94    * API for showing content on screen.
95    * @param source_layers, are the layers to be shown on screen for this frame.
96    * @param retire_fence will be populated with Native Fence object provided
97    *        we are able to display source_layers. When retire_fence is
98    *        signalled source_layers are shown on the output and any previous
99    *        frame composition results can be invalidated.
100    */
101   virtual bool Present(std::vector<HwcLayer *> &source_layers,
102                        int32_t *retire_fence,
103                        bool handle_constraints = false) = 0;
104
105   virtual int RegisterVsyncCallback(std::shared_ptr<VsyncCallback> callback,
106                                     uint32_t display_id) = 0;
107   virtual void VSyncControl(bool enabled) = 0;
108
109   /**
110    * API for registering for refresh callback requests.
111    * @param callback, function which will be used by HWC to request client to
112    *        trigger a screen refresh. This will be used to optimize scenarios
113    *        like idle mode.
114    * @param display_id will be populated with id of the display.
115    */
116   virtual void RegisterRefreshCallback(
117       std::shared_ptr<RefreshCallback> /*callback*/, uint32_t /*display_id*/) {
118   }
119
120   /**
121    * API for registering for hotplug callback requests.
122    * @param callback, function which will be used by HWC to notify client of
123    *        a hot plug event.
124    * @param display_id will be populated with id of the display.
125    */
126   virtual void RegisterHotPlugCallback(
127       std::shared_ptr<HotPlugCallback> /*callback*/, uint32_t /*display_id*/) {
128   }
129
130   // Color Correction related APIS.
131   /**
132   * API for setting color gamma value of display in HWC, which be used to remap
133   * original color brightness to new one by gamma color correction. HWC uses
134   * default gamma value 2.2 which popular display is using, and allow users to
135   * change gamma value for RGB colors by this API, e.g. 0 will remap all
136   * gradient brightness of the color to brightest value (solid color).
137   *
138   * @param red red color gamma value
139   * @param green blue color gamma value
140   * @param blue blue color gamma value
141   */
142   virtual void SetGamma(float /*red*/, float /*green*/, float /*blue*/) {
143   }
144
145   /**
146   * API for setting a color transform which will be applied after composition.
147   *
148   * The matrix provided is an affine color transformation of the following form:
149   *
150   * |r.r r.g r.b 0|
151   * |g.r g.g g.b 0|
152   * |b.r b.g b.b 0|
153   * |Tr  Tg  Tb  1|
154   *
155   * This matrix will be provided in row-major form: {r.r, r.g, r.b, 0, g.r, ...}.
156   *
157   * Given a matrix of this form and an input color [R_in, G_in, B_in], the output
158   * color [R_out, G_out, B_out] will be:
159   *
160   * R_out = R_in * r.r + G_in * g.r + B_in * b.r + Tr
161   * G_out = R_in * r.g + G_in * g.g + B_in * b.g + Tg
162   * B_out = R_in * r.b + G_in * g.b + B_in * b.b + Tb
163   *
164   * @param matrix a 4x4 transform matrix (16 floats) as described above
165   * @param hint a hint value to specify the transform type, applying no transform
166   *        or applying transform defined by given matrix
167   */
168   virtual void SetColorTransform(const float * /*matrix*/, HWCColorTransform /*hint*/) {
169   }
170
171   /**
172    * API for setting display color contrast in HWC
173    * @param red valid value is 0 ~ 255, bigger value with stronger contrast
174    * @param green valid value is 0 ~ 255, bigger value with stronger contrast
175    * @param blue valid value is 0 ~ 255, bigger value with stronger contrast
176    */
177   virtual void SetContrast(uint32_t /*red*/, uint32_t /*green*/,
178                            uint32_t /*blue*/) {
179   }
180   /**
181    * API for setting display color brightness in HWC
182    * @param red valid value is 0 ~ 255, bigger value with stronger brightness
183    * @param green valid value is 0 ~ 255, bigger value with stronger brightness
184    * @param blue valid value is 0 ~ 255, bigger value with stronger brightness
185    */
186   virtual void SetBrightness(uint32_t /*red*/, uint32_t /*green*/,
187                              uint32_t /*blue*/) {
188   }
189
190  /**
191   * API for setting video color in HWC
192   */
193   virtual void SetVideoColor(HWCColorControl /*color*/, float /*value*/) {
194   }
195
196   /**
197    * API for getting video color in HWC
198    */
199   virtual void GetVideoColor(HWCColorControl /*color*/, float * /*value*/,
200                              float * /*start*/, float * /*end*/) {
201   }
202
203   /**
204    * API for restoring video default color in HWC
205    */
206   virtual void RestoreVideoDefaultColor(HWCColorControl /*color*/) {
207   }
208
209   /**
210    * API for setting video scaling mode in HWC
211    */
212   virtual void SetVideoScalingMode(uint32_t /*mode*/) {
213   }
214
215   /**
216    * API for setting video deinterlace in HWC
217    */
218   virtual void SetVideoDeinterlace(HWCDeinterlaceFlag /*flags*/,
219                                    HWCDeinterlaceControl /*mode*/) {
220   }
221
222   /**
223    * API for restoring video default deinterlace in HWC
224    */
225   virtual void RestoreVideoDefaultDeinterlace() {
226   }
227
228   /**
229    * API for setting display Broadcast RGB range property
230    * @param range_property supported property string, e.g. "Full", "Automatic"
231    */
232   virtual bool SetBroadcastRGB(const char * /*range_property*/) {
233     return false;
234   }
235
236   // Virtual display related.
237   virtual void InitVirtualDisplay(uint32_t /*width*/, uint32_t /*height*/) {
238   }
239
240   // Nested display related.
241   virtual void InitNestedDisplay() {
242   }
243
244   /**
245    * API for setting output buffer for virtual display.
246    * @param buffer ownership is taken by display.
247    */
248   virtual void SetOutputBuffer(HWCNativeHandle /*buffer*/,
249                                int32_t /*acquire_fence*/) {
250   }
251   /**
252   * API to check the format support on the device
253   * @param format valid DRM formats found in drm_fourcc.h.
254   */
255   virtual bool CheckPlaneFormat(uint32_t format) = 0;
256
257   virtual void SetExplicitSyncSupport(bool /*explicit_sync_enabled*/) {
258   }
259
260   /**
261   * API to connect the display. Note that this doesn't necessarily
262   * mean display is turned on. Implementation is free to reset any display
263   * state which they seem appropriate for this state. Any subsequent calls
264   * to Present after this call will show content on screen provided
265   * Powermode is kon.
266   */
267   virtual void Connect() {
268   }
269
270   /**
271   * API to check if display is connected.
272   */
273   virtual bool IsConnected() const {
274     return false;
275   }
276
277   /**
278    * Scales layers of display to match it's resolutions in case
279    * this display is in cloned mode and resolution doesn't match
280    * with Source Display.
281    */
282   virtual void UpdateScalingRatio(uint32_t /*primary_width*/,
283                                   uint32_t /*primary_height*/,
284                                   uint32_t /*display_width*/,
285                                   uint32_t /*display_height*/) {
286   }
287
288   /**
289    * This display needs to clone source_display.
290    * We cannot have a display in cloned mode and extended mode at
291    * same time or clone more than one source_display at same time.
292    */
293   virtual void CloneDisplay(NativeDisplay * /*source_display*/) {
294   }
295
296   virtual uint32_t GetXTranslation() {
297     return 0;
298   }
299
300   virtual uint32_t GetLogicalIndex() const {
301     return 0;
302   }
303
304   virtual void HotPlugUpdate(bool /*connected*/) {
305   }
306
307   /**
308    * Use this method to initalize the display's pool of
309    * layer ids. The argument to the method is the
310    * initial size of the pool
311    */
312   virtual int InitializeLayerHashGenerator(int size) {
313     LayerIds_.clear();
314     for (int i = 0; i < size; i++) {
315       LayerIds_.push_back(i);
316     }
317
318     current_max_layer_ids_ = size;
319     return 0;
320   }
321
322   /**
323    * Once the id pool is initialzed, use this to acquire an
324    * unused id for the layer.
325    */
326   virtual uint64_t AcquireId() {
327     if (LayerIds_.empty())
328       return ++current_max_layer_ids_;
329
330     uint64_t id = LayerIds_.back();
331     LayerIds_.pop_back();
332
333     return id;
334   }
335
336   /**
337    * Method to return a destroyed layer's id back into the pool
338    */
339   virtual void ReleaseId(uint64_t id) {
340     LayerIds_.push_back(id);
341   }
342
343   /**
344    * Call this to reset the id pool back to its initial state.
345    */
346   virtual void ResetLayerHashGenerator() {
347     InitializeLayerHashGenerator(current_max_layer_ids_);
348   }
349
350   /**
351    * Call this to set HDCP state for this display. This function
352    * tries to take advantage of any HDCP support advertised by
353    * the Kernel.
354    */
355   virtual void SetHDCPState(HWCContentProtection /*state*/) {
356   }
357
358  protected:
359   friend class PhysicalDisplay;
360   friend class GpuDevice;
361   virtual void OwnPresentation(NativeDisplay * /*clone*/) {
362   }
363
364   virtual void DisOwnPresentation(NativeDisplay * /*clone*/) {
365   }
366
367   virtual bool PresentClone(std::vector<HwcLayer *> & /*source_layers*/,
368                             int32_t * /*retire_fence*/, bool /*idle_frame*/) {
369     return false;
370   }
371
372   // Physical pipe order might be different to the display order
373   // configured in hwcdisplay.ini. We need to always use any values
374   // overridden by SetDisplayOrder to determine if a display is
375   // primary or not.
376   virtual void SetDisplayOrder(uint32_t /*display_order*/) {
377   }
378
379   // Rotates content shown by this diplay as specified by
380   // rotation. This is on top of any transformations applied
381   // to individual layers shown by this display.
382   virtual void RotateDisplay(HWCRotation /*rotation*/) {
383   }
384
385 private:
386   std::vector<uint64_t> LayerIds_;
387   uint64_t current_max_layer_ids_;
388
389 };
390
391 /**
392 * This is provided for Convenience in case
393 * one doesnt want to register for hot plug
394 * callback per display.
395 */
396 class DisplayHotPlugEventCallback {
397  public:
398   virtual ~DisplayHotPlugEventCallback() {
399   }
400   virtual void Callback(std::vector<NativeDisplay*> connected_displays) = 0;
401 };
402
403 }  // namespace hwcomposer
404 #endif  // PUBLIC_NATIVEDISPLAY_H_