Home | History | Annotate | Download | only in core
      1 /*
      2 * Copyright (c) 2014 - 2017, 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 
     32 #define __CLASS__ "DisplayVirtual"
     33 
     34 namespace sdm {
     35 
     36 DisplayVirtual::DisplayVirtual(DisplayEventHandler *event_handler, HWInfoInterface *hw_info_intf,
     37                                BufferSyncHandler *buffer_sync_handler,
     38                                BufferAllocator *buffer_allocator, CompManager *comp_manager)
     39   : DisplayBase(kVirtual, event_handler, kDeviceVirtual, buffer_sync_handler, buffer_allocator,
     40                 comp_manager, hw_info_intf) {
     41 }
     42 
     43 DisplayError DisplayVirtual::Init() {
     44   lock_guard<recursive_mutex> obj(recursive_mutex_);
     45 
     46   DisplayError error = HWInterface::Create(kVirtual, hw_info_intf_, buffer_sync_handler_,
     47                                            buffer_allocator_, &hw_intf_);
     48   if (error != kErrorNone) {
     49     return error;
     50   }
     51 
     52   hw_intf_->GetDisplayAttributes(0 /* active_index */, &display_attributes_);
     53 
     54   error = DisplayBase::Init();
     55   if (error != kErrorNone) {
     56     HWInterface::Destroy(hw_intf_);
     57   }
     58 
     59   return error;
     60 }
     61 
     62 DisplayError DisplayVirtual::GetNumVariableInfoConfigs(uint32_t *count) {
     63   lock_guard<recursive_mutex> obj(recursive_mutex_);
     64   *count = 1;
     65   return kErrorNone;
     66 }
     67 
     68 DisplayError DisplayVirtual::GetConfig(uint32_t index, DisplayConfigVariableInfo *variable_info) {
     69   lock_guard<recursive_mutex> obj(recursive_mutex_);
     70   *variable_info = display_attributes_;
     71   return kErrorNone;
     72 }
     73 
     74 DisplayError DisplayVirtual::GetActiveConfig(uint32_t *index) {
     75   lock_guard<recursive_mutex> obj(recursive_mutex_);
     76   *index = 0;
     77   return kErrorNone;
     78 }
     79 
     80 DisplayError DisplayVirtual::SetActiveConfig(DisplayConfigVariableInfo *variable_info) {
     81   lock_guard<recursive_mutex> obj(recursive_mutex_);
     82 
     83   if (!variable_info) {
     84     return kErrorParameters;
     85   }
     86 
     87   DisplayError error = kErrorNone;
     88   HWDisplayAttributes display_attributes;
     89   HWMixerAttributes mixer_attributes;
     90 
     91   display_attributes.x_pixels = variable_info->x_pixels;
     92   display_attributes.y_pixels = variable_info->y_pixels;
     93   display_attributes.fps = variable_info->fps;
     94 
     95   if (display_attributes == display_attributes_) {
     96     return kErrorNone;
     97   }
     98 
     99   error = hw_intf_->SetDisplayAttributes(display_attributes);
    100   if (error != kErrorNone) {
    101     return error;
    102   }
    103 
    104   error = hw_intf_->GetMixerAttributes(&mixer_attributes);
    105   if (error != kErrorNone) {
    106     return error;
    107   }
    108 
    109   // if display is already connected, unregister display from composition manager and register
    110   // the display with new configuration.
    111   if (display_comp_ctx_) {
    112     comp_manager_->UnregisterDisplay(display_comp_ctx_);
    113   }
    114 
    115   error = comp_manager_->RegisterDisplay(display_type_, display_attributes, hw_panel_info_,
    116                                          mixer_attributes, fb_config_, &display_comp_ctx_);
    117   if (error != kErrorNone) {
    118     return error;
    119   }
    120 
    121   display_attributes_ = display_attributes;
    122   mixer_attributes_ = mixer_attributes;
    123 
    124   DLOGI("Virtual display resolution changed to[%dx%d]", display_attributes_.x_pixels,
    125         display_attributes_.y_pixels);
    126 
    127   return kErrorNone;
    128 }
    129 
    130 DisplayError DisplayVirtual::Prepare(LayerStack *layer_stack) {
    131   lock_guard<recursive_mutex> obj(recursive_mutex_);
    132 
    133   // Clean hw layers for reuse.
    134   hw_layers_ = HWLayers();
    135 
    136   return DisplayBase::Prepare(layer_stack);
    137 }
    138 
    139 
    140 }  // namespace sdm
    141 
    142