• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 * Copyright (c) 2014 - 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 <utils/constants.h>
26 #include <utils/debug.h>
27 
28 #include "display_virtual.h"
29 #include "hw_interface.h"
30 #include "hw_info_interface.h"
31 #include "fb/hw_virtual.h"
32 
33 #define __CLASS__ "DisplayVirtual"
34 
35 namespace sdm {
36 
DisplayVirtual(DisplayEventHandler * event_handler,HWInfoInterface * hw_info_intf,BufferSyncHandler * buffer_sync_handler,CompManager * comp_manager,RotatorInterface * rotator_intf)37 DisplayVirtual::DisplayVirtual(DisplayEventHandler *event_handler, HWInfoInterface *hw_info_intf,
38                                BufferSyncHandler *buffer_sync_handler, CompManager *comp_manager,
39                                RotatorInterface *rotator_intf)
40   : DisplayBase(kVirtual, event_handler, kDeviceVirtual, buffer_sync_handler, comp_manager,
41                 rotator_intf, hw_info_intf) {
42 }
43 
Init()44 DisplayError DisplayVirtual::Init() {
45   lock_guard<recursive_mutex> obj(recursive_mutex_);
46 
47   DisplayError error = HWVirtual::Create(&hw_intf_, hw_info_intf_,
48                                          DisplayBase::buffer_sync_handler_);
49   if (error != kErrorNone) {
50     return error;
51   }
52 
53   hw_intf_->GetDisplayAttributes(0 /* active_index */, &display_attributes_);
54 
55   error = DisplayBase::Init();
56   if (error != kErrorNone) {
57     HWVirtual::Destroy(hw_intf_);
58   }
59 
60   return error;
61 }
62 
Deinit()63 DisplayError DisplayVirtual::Deinit() {
64   lock_guard<recursive_mutex> obj(recursive_mutex_);
65 
66   DisplayError error = DisplayBase::Deinit();
67   HWVirtual::Destroy(hw_intf_);
68 
69   return error;
70 }
71 
GetNumVariableInfoConfigs(uint32_t * count)72 DisplayError DisplayVirtual::GetNumVariableInfoConfigs(uint32_t *count) {
73   lock_guard<recursive_mutex> obj(recursive_mutex_);
74   *count = 1;
75   return kErrorNone;
76 }
77 
GetConfig(uint32_t index,DisplayConfigVariableInfo * variable_info)78 DisplayError DisplayVirtual::GetConfig(uint32_t index, DisplayConfigVariableInfo *variable_info) {
79   lock_guard<recursive_mutex> obj(recursive_mutex_);
80   *variable_info = display_attributes_;
81   return kErrorNone;
82 }
83 
GetActiveConfig(uint32_t * index)84 DisplayError DisplayVirtual::GetActiveConfig(uint32_t *index) {
85   lock_guard<recursive_mutex> obj(recursive_mutex_);
86   *index = 0;
87   return kErrorNone;
88 }
89 
SetActiveConfig(DisplayConfigVariableInfo * variable_info)90 DisplayError DisplayVirtual::SetActiveConfig(DisplayConfigVariableInfo *variable_info) {
91   lock_guard<recursive_mutex> obj(recursive_mutex_);
92 
93   if (!variable_info) {
94     return kErrorParameters;
95   }
96 
97   DisplayError error = kErrorNone;
98   HWDisplayAttributes display_attributes;
99   HWMixerAttributes mixer_attributes;
100   DisplayConfigVariableInfo fb_config = *variable_info;
101 
102   display_attributes.x_pixels = variable_info->x_pixels;
103   display_attributes.y_pixels = variable_info->y_pixels;
104   display_attributes.fps = variable_info->fps;
105 
106   if (display_attributes == display_attributes_) {
107     return kErrorNone;
108   }
109 
110   error = hw_intf_->SetDisplayAttributes(display_attributes);
111   if (error != kErrorNone) {
112     return error;
113   }
114 
115   error = hw_intf_->GetMixerAttributes(&mixer_attributes);
116   if (error != kErrorNone) {
117     return error;
118   }
119 
120   // Override x_pixels and y_pixels of frame buffer with mixer width and height
121   fb_config.x_pixels = mixer_attributes.width;
122   fb_config.y_pixels = mixer_attributes.height;
123 
124   // if display is already connected, unregister display from composition manager and register
125   // the display with new configuration.
126   if (display_comp_ctx_) {
127     comp_manager_->UnregisterDisplay(display_comp_ctx_);
128   }
129 
130   error = comp_manager_->RegisterDisplay(display_type_, display_attributes, hw_panel_info_,
131                                          mixer_attributes, fb_config, &display_comp_ctx_);
132   if (error != kErrorNone) {
133     return error;
134   }
135 
136   display_attributes_ = display_attributes;
137   mixer_attributes_ = mixer_attributes;
138   fb_config_ = fb_config;
139 
140   return kErrorNone;
141 }
142 
143 }  // namespace sdm
144 
145