1 /*
2 * Copyright (c) 2018-2020, The Linux Foundation. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *     * Redistributions of source code must retain the above copyright
8 *       notice, this list of conditions and the following disclaimer.
9 *     * Redistributions in binary form must reproduce the above
10 *       copyright notice, this list of conditions and the following
11 *       disclaimer in the documentation and/or other materials provided
12 *       with the distribution.
13 *     * Neither the name of The Linux Foundation nor the names of its
14 *       contributors may be used to endorse or promote products derived
15 *       from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
20 * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
21 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29 
30 #include "hwc_display_dummy.h"
31 #include <utils/debug.h>
32 
33 #define __CLASS__ "HWCDisplayDummy"
34 
35 namespace sdm {
36 
Create(CoreInterface * core_intf,BufferAllocator * buffer_allocator,HWCCallbacks * callbacks,HWCDisplayEventHandler * event_handler,qService::QService * qservice,hwc2_display_t id,int32_t sdm_id,HWCDisplay ** hwc_display)37 int HWCDisplayDummy::Create(CoreInterface *core_intf, BufferAllocator *buffer_allocator,
38                             HWCCallbacks *callbacks, HWCDisplayEventHandler *event_handler,
39                             qService::QService *qservice, hwc2_display_t id, int32_t sdm_id,
40                             HWCDisplay **hwc_display) {
41   HWCDisplay *hwc_display_dummy = new HWCDisplayDummy(core_intf, buffer_allocator, callbacks,
42                                       event_handler, qservice, id, sdm_id);
43   *hwc_display = hwc_display_dummy;
44   return kErrorNone;
45 }
46 
Destroy(HWCDisplay * hwc_display)47 void HWCDisplayDummy::Destroy(HWCDisplay *hwc_display) {
48   delete hwc_display;
49 }
50 
Validate(uint32_t * out_num_types,uint32_t * out_num_requests)51 HWC2::Error HWCDisplayDummy::Validate(uint32_t *out_num_types, uint32_t *out_num_requests) {
52   return HWC2::Error::None;
53 }
54 
Present(shared_ptr<Fence> * out_retire_fence)55 HWC2::Error HWCDisplayDummy::Present(shared_ptr<Fence> *out_retire_fence) {
56   for (auto hwc_layer : layer_set_) {
57     hwc_layer->PushBackReleaseFence(nullptr);
58   }
59   return HWC2::Error::None;
60 }
61 
SetColorMode(ColorMode mode)62 HWC2::Error HWCDisplayDummy::SetColorMode(ColorMode mode) {
63   return HWC2::Error::None;
64 }
65 
HWCDisplayDummy(CoreInterface * core_intf,BufferAllocator * buffer_allocator,HWCCallbacks * callbacks,HWCDisplayEventHandler * event_handler,qService::QService * qservice,hwc2_display_t id,int32_t sdm_id)66 HWCDisplayDummy::HWCDisplayDummy(CoreInterface *core_intf, BufferAllocator *buffer_allocator,
67                                  HWCCallbacks *callbacks, HWCDisplayEventHandler *event_handler,
68                                  qService::QService *qservice, hwc2_display_t id,
69                                  int32_t sdm_id) :HWCDisplay(core_intf, buffer_allocator,
70                                  callbacks, event_handler, qservice, kBuiltIn, id, sdm_id,
71                                  DISPLAY_CLASS_BUILTIN) {
72   DisplayConfigVariableInfo config;
73   config.x_pixels = 720;
74   config.y_pixels = 1280;
75   config.x_dpi = 200.0f;
76   config.y_dpi = 200.0f;
77   config.fps = 60;
78   config.vsync_period_ns = 16600000;
79   display_null_.SetFrameBufferConfig(config);
80   num_configs_ = 1;
81   display_intf_ = &display_null_;
82 }
83 
GetActiveConfig(hwc2_config_t * out_config)84 HWC2::Error HWCDisplayDummy::GetActiveConfig(hwc2_config_t *out_config) {
85   *out_config = 0;
86   return HWC2::Error::None;
87 }
88 
UpdatePowerMode(HWC2::PowerMode mode)89 HWC2::Error HWCDisplayDummy::UpdatePowerMode(HWC2::PowerMode mode) {
90   current_power_mode_ = mode;
91   return HWC2::Error::None;
92 }
93 
SetVsyncEnabled(HWC2::Vsync enabled)94 HWC2::Error HWCDisplayDummy::SetVsyncEnabled(HWC2::Vsync enabled) {
95   bool state = false;
96   if (enabled == HWC2::Vsync::Enable) {
97     state = true;
98   }
99   vsync_enable_ = state;
100   return HWC2::Error::None;
101 }
102 
VsyncEnablePending()103 bool HWCDisplayDummy::VsyncEnablePending() {
104   return vsync_enable_;
105 }
GetDisplayVsyncPeriod(VsyncPeriodNanos * vsync_period)106 HWC2::Error HWCDisplayDummy::GetDisplayVsyncPeriod(VsyncPeriodNanos *vsync_period) {
107   *vsync_period = vsync_period_;
108   return HWC2::Error::None;
109 }
SetDisplayVsyncPeriod(VsyncPeriodNanos vsync_period)110 HWC2::Error HWCDisplayDummy::SetDisplayVsyncPeriod(VsyncPeriodNanos vsync_period) {
111   vsync_period_ = vsync_period;
112   return HWC2::Error::None;
113 }
114 
SetClientTarget(buffer_handle_t target,shared_ptr<Fence> acquire_fence,int32_t dataspace,hwc_region_t damage)115 HWC2::Error HWCDisplayDummy::SetClientTarget(buffer_handle_t target,
116                                              shared_ptr<Fence> acquire_fence,
117                                              int32_t dataspace, hwc_region_t damage) {
118   client_target_handle_ = target;
119   client_acquire_fence_ = acquire_fence;
120   client_dataspace_     = dataspace;
121   client_damage_region_ = damage;
122   return HWC2::Error::None;
123 }
124 
125 }  // namespace sdm
126