1 /*
2 * Copyright (c) 2016, The Linux Foundation. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification, are permitted
5 * provided that the following conditions are met:
6 *    * Redistributions of source code must retain the above copyright notice, this list of
7 *      conditions and the following disclaimer.
8 *    * Redistributions in binary form must reproduce the above copyright notice, this list of
9 *      conditions and the following disclaimer in the documentation and/or other materials provided
10 *      with the distribution.
11 *    * Neither the name of The Linux Foundation nor the names of its contributors may be used to
12 *      endorse or promote products derived from this software without specific prior written
13 *      permission.
14 *
15 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
19 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
20 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
21 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 */
24 
25 #include <hardware/hwcomposer_defs.h>
26 #include <utils/constants.h>
27 #include <utils/debug.h>
28 #include "hwc_display_null.h"
29 
30 #define __CLASS__ "HWCDisplayNull"
31 
32 namespace sdm {
33 
Create(CoreInterface * core_intf,hwc_procs_t const ** hwc_procs,HWCDisplay ** hwc_display)34 int HWCDisplayNull::Create(CoreInterface *core_intf, hwc_procs_t const **hwc_procs,
35                            HWCDisplay **hwc_display) {
36   int status;
37 
38   DLOGI("Null display is being created");
39   HWCDisplayNull *hwc_display_null = new HWCDisplayNull(core_intf, hwc_procs);
40 
41   status = hwc_display_null->Init();
42   if (status) {
43     delete hwc_display_null;
44     return status;
45   }
46 
47   *hwc_display = hwc_display_null;
48 
49   return 0;
50 }
51 
Destroy(HWCDisplay * hwc_display)52 void HWCDisplayNull::Destroy(HWCDisplay *hwc_display) {
53   DLOGI("Null display is being destroyed");
54   hwc_display->Deinit();
55   delete hwc_display;
56 }
57 
58 // We pass the display type as HWC_DISPLAY_PRIMARY to HWCDisplay, but since we override
59 // and don't chain to HWCDisplay::Init(), that type does not actually get used.
HWCDisplayNull(CoreInterface * core_intf,hwc_procs_t const ** hwc_procs)60 HWCDisplayNull::HWCDisplayNull(CoreInterface *core_intf, hwc_procs_t const **hwc_procs)
61   : HWCDisplay(core_intf, hwc_procs, kPrimary, HWC_DISPLAY_PRIMARY, false, NULL,
62                DISPLAY_CLASS_NULL) {
63 }
64 
Init()65 int HWCDisplayNull::Init() {
66   // Don't call HWCDisplay::Init() for null display, we don't want the chain of
67   // DisplayPrimary / HWPrimary etc objects to be created.
68   return 0;
69 }
70 
Deinit()71 int HWCDisplayNull::Deinit() {
72   return 0;
73 }
74 
Prepare(hwc_display_contents_1_t * content_list)75 int HWCDisplayNull::Prepare(hwc_display_contents_1_t *content_list) {
76   for (size_t i = 0; i < content_list->numHwLayers; i++) {
77     if (content_list->hwLayers[i].compositionType == HWC_FRAMEBUFFER_TARGET ||
78         content_list->hwLayers[i].compositionType == HWC_BACKGROUND) {
79       continue;
80     }
81 
82     content_list->hwLayers[i].compositionType = HWC_OVERLAY;
83   }
84 
85   return 0;
86 }
87 
Commit(hwc_display_contents_1_t * content_list)88 int HWCDisplayNull::Commit(hwc_display_contents_1_t *content_list) {
89   // HWCSession::Commit (from where this is called) already closes all the acquire
90   // fences once we return from here. So no need to close acquire fences here.
91   for (size_t i = 0; i < content_list->numHwLayers; i++) {
92     content_list->hwLayers[i].releaseFenceFd = -1;
93   }
94 
95   return 0;
96 }
97 
98 #define NULL_DISPLAY_FPS 60
99 
GetDisplayAttributes(uint32_t config,const uint32_t * display_attributes,int32_t * values)100 int HWCDisplayNull::GetDisplayAttributes(uint32_t config, const uint32_t *display_attributes,
101                                          int32_t *values) {
102   for (int i = 0; display_attributes[i] != HWC_DISPLAY_NO_ATTRIBUTE; i++) {
103     // We fake display resolution as 1080P by default, though it can be overriden through a call to
104     // SetResolution(), and DPI as 160, though what the DPI value does is not clear
105     switch (display_attributes[i]) {
106     case HWC_DISPLAY_VSYNC_PERIOD:
107       values[i] = INT32(1000000000L / NULL_DISPLAY_FPS);
108       break;
109     case HWC_DISPLAY_WIDTH:
110       values[i] = static_cast<int32_t>(x_res_);
111       break;
112     case HWC_DISPLAY_HEIGHT:
113       values[i] = static_cast<int32_t>(y_res_);
114       break;
115     }
116   }
117   return 0;
118 }
119 
120 }  // namespace sdm
121