Home | History | Annotate | Download | only in core
      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 
     32 #define __CLASS__ "DisplayVirtual"
     33 
     34 namespace sdm {
     35 
     36 DisplayVirtual::DisplayVirtual(DisplayEventHandler *event_handler, HWInfoInterface *hw_info_intf,
     37                                BufferSyncHandler *buffer_sync_handler, CompManager *comp_manager,
     38                                RotatorInterface *rotator_intf)
     39   : DisplayBase(kVirtual, event_handler, kDeviceVirtual, buffer_sync_handler, comp_manager,
     40                 rotator_intf, 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                                            &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   DisplayConfigVariableInfo fb_config = *variable_info;
     91 
     92   display_attributes.x_pixels = variable_info->x_pixels;
     93   display_attributes.y_pixels = variable_info->y_pixels;
     94   display_attributes.fps = variable_info->fps;
     95 
     96   if (display_attributes == display_attributes_) {
     97     return kErrorNone;
     98   }
     99 
    100   error = hw_intf_->SetDisplayAttributes(display_attributes);
    101   if (error != kErrorNone) {
    102     return error;
    103   }
    104 
    105   error = hw_intf_->GetMixerAttributes(&mixer_attributes);
    106   if (error != kErrorNone) {
    107     return error;
    108   }
    109 
    110   // Override x_pixels and y_pixels of frame buffer with mixer width and height
    111   fb_config.x_pixels = mixer_attributes.width;
    112   fb_config.y_pixels = mixer_attributes.height;
    113 
    114   // if display is already connected, unregister display from composition manager and register
    115   // the display with new configuration.
    116   if (display_comp_ctx_) {
    117     comp_manager_->UnregisterDisplay(display_comp_ctx_);
    118   }
    119 
    120   error = comp_manager_->RegisterDisplay(display_type_, display_attributes, hw_panel_info_,
    121                                          mixer_attributes, fb_config, &display_comp_ctx_);
    122   if (error != kErrorNone) {
    123     return error;
    124   }
    125 
    126   display_attributes_ = display_attributes;
    127   mixer_attributes_ = mixer_attributes;
    128   fb_config_ = fb_config;
    129 
    130   return kErrorNone;
    131 }
    132 
    133 DisplayError DisplayVirtual::Prepare(LayerStack *layer_stack) {
    134   lock_guard<recursive_mutex> obj(recursive_mutex_);
    135 
    136   // Clean hw layers for reuse.
    137   hw_layers_ = HWLayers();
    138 
    139   return DisplayBase::Prepare(layer_stack);
    140 }
    141 
    142 
    143 }  // namespace sdm
    144 
    145