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 PUBLIC_NATIVEDISPLAY_H_
18 #define PUBLIC_NATIVEDISPLAY_H_
21 #include <platformdefines.h>
28 typedef struct _drmModeConnector drmModeConnector;
29 typedef struct _drmModeModeInfo drmModeModeInfo;
31 namespace hwcomposer {
34 class NativeBufferHandler;
38 virtual ~VsyncCallback() {
40 virtual void Callback(uint32_t display, int64_t timestamp) = 0;
43 class RefreshCallback {
45 virtual ~RefreshCallback() {
47 virtual void Callback(uint32_t display) = 0;
50 class HotPlugCallback {
52 virtual ~HotPlugCallback() {
54 virtual void Callback(uint32_t display, bool connected) = 0;
59 virtual ~NativeDisplay() {
62 NativeDisplay() = default;
64 NativeDisplay(const NativeDisplay &rhs) = delete;
65 NativeDisplay &operator=(const NativeDisplay &rhs) = delete;
67 virtual bool Initialize(NativeBufferHandler *buffer_handler) = 0;
69 virtual DisplayType Type() const = 0;
71 virtual uint32_t Width() const = 0;
73 virtual uint32_t Height() const = 0;
75 virtual uint32_t PowerMode() const = 0;
77 virtual bool GetDisplayAttribute(uint32_t config,
78 HWCDisplayAttribute attribute,
81 virtual bool GetDisplayConfigs(uint32_t *num_configs, uint32_t *configs) = 0;
82 virtual bool GetDisplayName(uint32_t *size, char *name) = 0;
84 * API for getting connected display's pipe id.
85 * @return "-1" for unconnected display, valid values are 0 ~ 2.
87 virtual int GetDisplayPipe() = 0;
88 virtual bool SetActiveConfig(uint32_t config) = 0;
89 virtual bool GetActiveConfig(uint32_t *config) = 0;
91 virtual bool SetPowerMode(uint32_t power_mode) = 0;
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.
101 virtual bool Present(std::vector<HwcLayer *> &source_layers,
102 int32_t *retire_fence,
103 bool handle_constraints = false) = 0;
105 virtual int RegisterVsyncCallback(std::shared_ptr<VsyncCallback> callback,
106 uint32_t display_id) = 0;
107 virtual void VSyncControl(bool enabled) = 0;
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
114 * @param display_id will be populated with id of the display.
116 virtual void RegisterRefreshCallback(
117 std::shared_ptr<RefreshCallback> /*callback*/, uint32_t /*display_id*/) {
121 * API for registering for hotplug callback requests.
122 * @param callback, function which will be used by HWC to notify client of
124 * @param display_id will be populated with id of the display.
126 virtual void RegisterHotPlugCallback(
127 std::shared_ptr<HotPlugCallback> /*callback*/, uint32_t /*display_id*/) {
130 // Color Correction related APIS.
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).
138 * @param red red color gamma value
139 * @param green blue color gamma value
140 * @param blue blue color gamma value
142 virtual void SetGamma(float /*red*/, float /*green*/, float /*blue*/) {
146 * API for setting a color transform which will be applied after composition.
148 * The matrix provided is an affine color transformation of the following form:
155 * This matrix will be provided in row-major form: {r.r, r.g, r.b, 0, g.r, ...}.
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:
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
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
168 virtual void SetColorTransform(const float * /*matrix*/, HWCColorTransform /*hint*/) {
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
177 virtual void SetContrast(uint32_t /*red*/, uint32_t /*green*/,
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
186 virtual void SetBrightness(uint32_t /*red*/, uint32_t /*green*/,
191 * API for setting video color in HWC
193 virtual void SetVideoColor(HWCColorControl /*color*/, float /*value*/) {
197 * API for getting video color in HWC
199 virtual void GetVideoColor(HWCColorControl /*color*/, float * /*value*/,
200 float * /*start*/, float * /*end*/) {
204 * API for restoring video default color in HWC
206 virtual void RestoreVideoDefaultColor(HWCColorControl /*color*/) {
210 * API for setting video scaling mode in HWC
212 virtual void SetVideoScalingMode(uint32_t /*mode*/) {
216 * API for setting video deinterlace in HWC
218 virtual void SetVideoDeinterlace(HWCDeinterlaceFlag /*flags*/,
219 HWCDeinterlaceControl /*mode*/) {
223 * API for restoring video default deinterlace in HWC
225 virtual void RestoreVideoDefaultDeinterlace() {
229 * API for setting display Broadcast RGB range property
230 * @param range_property supported property string, e.g. "Full", "Automatic"
232 virtual bool SetBroadcastRGB(const char * /*range_property*/) {
236 // Virtual display related.
237 virtual void InitVirtualDisplay(uint32_t /*width*/, uint32_t /*height*/) {
240 // Nested display related.
241 virtual void InitNestedDisplay() {
245 * API for setting output buffer for virtual display.
246 * @param buffer ownership is taken by display.
248 virtual void SetOutputBuffer(HWCNativeHandle /*buffer*/,
249 int32_t /*acquire_fence*/) {
252 * API to check the format support on the device
253 * @param format valid DRM formats found in drm_fourcc.h.
255 virtual bool CheckPlaneFormat(uint32_t format) = 0;
257 virtual void SetExplicitSyncSupport(bool /*explicit_sync_enabled*/) {
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
267 virtual void Connect() {
271 * API to check if display is connected.
273 virtual bool IsConnected() const {
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.
282 virtual void UpdateScalingRatio(uint32_t /*primary_width*/,
283 uint32_t /*primary_height*/,
284 uint32_t /*display_width*/,
285 uint32_t /*display_height*/) {
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.
293 virtual void CloneDisplay(NativeDisplay * /*source_display*/) {
296 virtual uint32_t GetXTranslation() {
300 virtual uint32_t GetLogicalIndex() const {
304 virtual void HotPlugUpdate(bool /*connected*/) {
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
312 virtual int InitializeLayerHashGenerator(int size) {
314 for (int i = 0; i < size; i++) {
315 LayerIds_.push_back(i);
318 current_max_layer_ids_ = size;
323 * Once the id pool is initialzed, use this to acquire an
324 * unused id for the layer.
326 virtual uint64_t AcquireId() {
327 if (LayerIds_.empty())
328 return ++current_max_layer_ids_;
330 uint64_t id = LayerIds_.back();
331 LayerIds_.pop_back();
337 * Method to return a destroyed layer's id back into the pool
339 virtual void ReleaseId(uint64_t id) {
340 LayerIds_.push_back(id);
344 * Call this to reset the id pool back to its initial state.
346 virtual void ResetLayerHashGenerator() {
347 InitializeLayerHashGenerator(current_max_layer_ids_);
351 * Call this to set HDCP state for this display. This function
352 * tries to take advantage of any HDCP support advertised by
355 virtual void SetHDCPState(HWCContentProtection /*state*/) {
359 friend class PhysicalDisplay;
360 friend class GpuDevice;
361 virtual void OwnPresentation(NativeDisplay * /*clone*/) {
364 virtual void DisOwnPresentation(NativeDisplay * /*clone*/) {
367 virtual bool PresentClone(std::vector<HwcLayer *> & /*source_layers*/,
368 int32_t * /*retire_fence*/, bool /*idle_frame*/) {
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
376 virtual void SetDisplayOrder(uint32_t /*display_order*/) {
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*/) {
386 std::vector<uint64_t> LayerIds_;
387 uint64_t current_max_layer_ids_;
392 * This is provided for Convenience in case
393 * one doesnt want to register for hot plug
394 * callback per display.
396 class DisplayHotPlugEventCallback {
398 virtual ~DisplayHotPlugEventCallback() {
400 virtual void Callback(std::vector<NativeDisplay*> connected_displays) = 0;
403 } // namespace hwcomposer
404 #endif // PUBLIC_NATIVEDISPLAY_H_