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 <dlfcn.h>
     26 #include <utils/locker.h>
     27 #include <utils/constants.h>
     28 #include <utils/debug.h>
     29 
     30 #include "core_impl.h"
     31 #include "display_primary.h"
     32 #include "display_hdmi.h"
     33 #include "display_virtual.h"
     34 #include "hw_info_interface.h"
     35 #include "color_manager.h"
     36 
     37 #define __CLASS__ "CoreImpl"
     38 
     39 namespace sdm {
     40 
     41 CoreImpl::CoreImpl(BufferAllocator *buffer_allocator,
     42                    BufferSyncHandler *buffer_sync_handler)
     43   : buffer_allocator_(buffer_allocator), buffer_sync_handler_(buffer_sync_handler) {
     44 }
     45 
     46 DisplayError CoreImpl::Init() {
     47   SCOPE_LOCK(locker_);
     48   DisplayError error = kErrorNone;
     49 
     50   // Try to load extension library & get handle to its interface.
     51   if (extension_lib_.Open(EXTENSION_LIBRARY_NAME)) {
     52     if (!extension_lib_.Sym(CREATE_EXTENSION_INTERFACE_NAME,
     53                             reinterpret_cast<void **>(&create_extension_intf_)) ||
     54         !extension_lib_.Sym(DESTROY_EXTENSION_INTERFACE_NAME,
     55                             reinterpret_cast<void **>(&destroy_extension_intf_))) {
     56       DLOGE("Unable to load symbols, error = %s", extension_lib_.Error());
     57       return kErrorUndefined;
     58     }
     59 
     60     error = create_extension_intf_(EXTENSION_VERSION_TAG, &extension_intf_);
     61     if (error != kErrorNone) {
     62       DLOGE("Unable to create interface");
     63       return error;
     64     }
     65   } else {
     66     DLOGW("Unable to load = %s, error = %s", EXTENSION_LIBRARY_NAME, extension_lib_.Error());
     67   }
     68 
     69   error = HWInfoInterface::Create(&hw_info_intf_);
     70   if (error != kErrorNone) {
     71     goto CleanupOnError;
     72   }
     73 
     74   error = hw_info_intf_->GetHWResourceInfo(&hw_resource_);
     75   if (error != kErrorNone) {
     76     goto CleanupOnError;
     77   }
     78 
     79   error = comp_mgr_.Init(hw_resource_, extension_intf_, buffer_sync_handler_);
     80   if (error != kErrorNone) {
     81     goto CleanupOnError;
     82   }
     83 
     84   if (extension_intf_ && hw_resource_.hw_rot_info.num_rotator) {
     85     error = extension_intf_->CreateRotator(hw_resource_.hw_rot_info, buffer_allocator_,
     86                                            buffer_sync_handler_, &rotator_intf_);
     87     if (error != kErrorNone) {
     88       DLOGW("rotation is not supported");
     89     }
     90   }
     91 
     92   error = ColorManagerProxy::Init(hw_resource_);
     93   // if failed, doesn't affect display core functionalities.
     94   if (error != kErrorNone) {
     95     DLOGW("Unable creating color manager and continue without it.");
     96   }
     97 
     98   return kErrorNone;
     99 
    100 CleanupOnError:
    101   if (hw_info_intf_) {
    102     HWInfoInterface::Destroy(hw_info_intf_);
    103   }
    104 
    105   return error;
    106 }
    107 
    108 DisplayError CoreImpl::Deinit() {
    109   SCOPE_LOCK(locker_);
    110 
    111   if (extension_intf_ && hw_resource_.hw_rot_info.num_rotator) {
    112     extension_intf_->DestroyRotator(rotator_intf_);
    113   }
    114 
    115   ColorManagerProxy::Deinit();
    116 
    117   comp_mgr_.Deinit();
    118   HWInfoInterface::Destroy(hw_info_intf_);
    119 
    120   return kErrorNone;
    121 }
    122 
    123 DisplayError CoreImpl::CreateDisplay(DisplayType type, DisplayEventHandler *event_handler,
    124                                      DisplayInterface **intf) {
    125   SCOPE_LOCK(locker_);
    126 
    127   if (!event_handler || !intf) {
    128     return kErrorParameters;
    129   }
    130 
    131   DisplayBase *display_base = NULL;
    132 
    133   switch (type) {
    134   case kPrimary:
    135     display_base = new DisplayPrimary(event_handler, hw_info_intf_, buffer_sync_handler_,
    136                                       &comp_mgr_, rotator_intf_);
    137     break;
    138   case kHDMI:
    139     display_base = new DisplayHDMI(event_handler, hw_info_intf_, buffer_sync_handler_,
    140                                    &comp_mgr_, rotator_intf_);
    141     break;
    142   case kVirtual:
    143     display_base = new DisplayVirtual(event_handler, hw_info_intf_, buffer_sync_handler_,
    144                                       &comp_mgr_, rotator_intf_);
    145     break;
    146   default:
    147     DLOGE("Spurious display type %d", type);
    148     return kErrorParameters;
    149   }
    150 
    151   if (!display_base) {
    152     return kErrorMemory;
    153   }
    154 
    155   DisplayError error = display_base->Init();
    156   if (error != kErrorNone) {
    157     delete display_base;
    158     return error;
    159   }
    160 
    161   *intf = display_base;
    162   return kErrorNone;
    163 }
    164 
    165 DisplayError CoreImpl::DestroyDisplay(DisplayInterface *intf) {
    166   SCOPE_LOCK(locker_);
    167 
    168   if (!intf) {
    169     return kErrorParameters;
    170   }
    171 
    172   DisplayBase *display_base = static_cast<DisplayBase *>(intf);
    173   display_base->Deinit();
    174   delete display_base;
    175 
    176   return kErrorNone;
    177 }
    178 
    179 DisplayError CoreImpl::SetMaxBandwidthMode(HWBwModes mode) {
    180   SCOPE_LOCK(locker_);
    181 
    182   return comp_mgr_.SetMaxBandwidthMode(mode);
    183 }
    184 
    185 DisplayError CoreImpl::GetFirstDisplayInterfaceType(HWDisplayInterfaceInfo *hw_disp_info) {
    186   return hw_info_intf_->GetFirstDisplayInterfaceType(hw_disp_info);
    187 }
    188 
    189 }  // namespace sdm
    190 
    191