Home | History | Annotate | Download | only in hwc
      1 /* Copyright (c) 2015-2016, The Linux Foundataion. All rights reserved.
      2 *
      3 * Redistribution and use in source and binary forms, with or without
      4 * modification, are permitted provided that the following conditions are
      5 * met:
      6 *     * Redistributions of source code must retain the above copyright
      7 *       notice, this list of conditions and the following disclaimer.
      8 *     * Redistributions in binary form must reproduce the above
      9 *       copyright notice, this list of conditions and the following
     10 *       disclaimer in the documentation and/or other materials provided
     11 *       with the distribution.
     12 *     * Neither the name of The Linux Foundation nor the names of its
     13 *       contributors may be used to endorse or promote products derived
     14 *       from this software without specific prior written permission.
     15 *
     16 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
     17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
     19 * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
     20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
     23 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
     25 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
     26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27 *
     28 */
     29 
     30 #ifndef __HWC_COLOR_MANAGER_H__
     31 #define __HWC_COLOR_MANAGER_H__
     32 
     33 #include <stdlib.h>
     34 #include <binder/Parcel.h>
     35 #include <powermanager/IPowerManager.h>
     36 #include <binder/BinderService.h>
     37 #include <core/sdm_types.h>
     38 #include <utils/locker.h>
     39 #include <utils/sys.h>
     40 
     41 namespace sdm {
     42 
     43 // This macro defines name for display APIs interface wrapper library.
     44 // This macro shall be used to load library using dlopen().
     45 #define DISPLAY_API_INTERFACE_LIBRARY_NAME "libsdm-disp-apis.so"
     46 
     47 // This macro defines variable name of display color APIs function tables
     48 // This macro shall be used to specify name of the variable in dlsym().
     49 #define DISPLAY_API_FUNC_TABLES "display_color_apis_ftables"
     50 #define QDCM_DIAG_CLIENT_LIBRARY_NAME "libsdm-diag.so"
     51 #define INIT_QDCM_DIAG_CLIENT_NAME "QDCMDiagInit"
     52 #define DEINIT_QDCM_DIAG_CLIENT_NAME "QDCMDiagDeInit"
     53 
     54 typedef int (*QDCMDiagInit)(void *ftables);
     55 
     56 typedef int (*QDCMDiagDeInit)(void);
     57 
     58 // Class to encapsulte all details of managing QDCM operating mode.
     59 class HWCQDCMModeManager {
     60  public:
     61   static const uint32_t kSocketCMDMaxLength = 4096;
     62   static const uint32_t kFullWakeLock = 0x0000001a;
     63   static const uint32_t kAcquireCauseWakeup = 0x10000000;
     64   static const uint32_t kONAfterRelease = 0x20000000;
     65   enum ActiveFeatureID {
     66     kCABLFeature,
     67     kADFeature,
     68     kSVIFeature,
     69     kMaxNumActiveFeature,
     70   };
     71 
     72   struct ActiveFeatureCMD {
     73     const char *cmd_on = NULL;
     74     const char *cmd_off = NULL;
     75     const char *cmd_query_status = NULL;
     76     const char *running = NULL;
     77     ActiveFeatureCMD(const char *arg1, const char *arg2, const char *arg3, const char *arg4)
     78         : cmd_on(arg1), cmd_off(arg2), cmd_query_status(arg3), running(arg4) {}
     79   };
     80 
     81   static const ActiveFeatureCMD kActiveFeatureCMD[kMaxNumActiveFeature];
     82 
     83  public:
     84   static HWCQDCMModeManager *CreateQDCMModeMgr();
     85   ~HWCQDCMModeManager();
     86   int EnableQDCMMode(bool enable, HWCDisplay *hwc_display);
     87 
     88  protected:
     89   bool SendSocketCmd();
     90   int AcquireAndroidWakeLock(bool enable);
     91   int EnableActiveFeatures(bool enable);
     92   int EnableActiveFeatures(bool enable, const ActiveFeatureCMD &cmds, bool *was_running);
     93 
     94  private:
     95   bool cabl_was_running_ = false;
     96   int socket_fd_ = -1;
     97   android::sp<android::IBinder> wakelock_token_ = NULL;
     98   android::sp<android::IPowerManager> power_mgr_ = NULL;
     99   uint32_t entry_timeout_ = 0;
    100   static const char *const kSocketName;
    101   static const char *const kTagName;
    102   static const char *const kPackageName;
    103 };
    104 
    105 // Class to encapsulte all HWC/OS specific behaviours for ColorManager.
    106 class HWCColorManager {
    107  public:
    108   static const int kNumSolidFillLayers = 2;
    109   static HWCColorManager *CreateColorManager();
    110   static int CreatePayloadFromParcel(const android::Parcel &in, uint32_t *disp_id,
    111                                      PPDisplayAPIPayload *sink);
    112   static void MarshallStructIntoParcel(const PPDisplayAPIPayload &data,
    113                                        android::Parcel *out_parcel);
    114 
    115   ~HWCColorManager();
    116   void DestroyColorManager();
    117   int EnableQDCMMode(bool enable, HWCDisplay *hwc_display);
    118   int SetSolidFill(const void *params, bool enable, HWCDisplay *hwc_display);
    119   bool SolidFillLayersPrepare(hwc_display_contents_1_t **displays, HWCDisplay *hwc_display);
    120   bool SolidFillLayersSet(hwc_display_contents_1_t **displays, HWCDisplay *hwc_display);
    121   int SetFrameCapture(void *params, bool enable, HWCDisplay *hwc_display);
    122   int SetDetailedEnhancer(void *params, HWCDisplay *hwc_display);
    123   void SetColorModeDetailEnhancer(HWCDisplay *hwc_display);
    124   int SetHWDetailedEnhancerConfig(void *params, HWCDisplay *hwc_display);
    125 
    126  protected:
    127   int CreateSolidFillLayers(HWCDisplay *hwc_display);
    128   void DestroySolidFillLayers();
    129   static uint32_t Get8BitsARGBColorValue(const PPColorFillParams &params);
    130 
    131  private:
    132   DynLib color_apis_lib_;
    133   DynLib diag_client_lib_;
    134   void *color_apis_ = NULL;
    135   QDCMDiagInit qdcm_diag_init_ = NULL;
    136   QDCMDiagDeInit qdcm_diag_deinit_ = NULL;
    137   HWCQDCMModeManager *qdcm_mode_mgr_ = NULL;
    138 
    139   bool solid_fill_enable_ = false;
    140   PPColorFillParams solid_fill_params_;
    141   hwc_display_contents_1_t *solid_fill_layers_ = NULL;
    142   HWCBufferAllocator *buffer_allocator_ = NULL;
    143   BufferInfo buffer_info;
    144   Locker locker_;
    145 };
    146 
    147 }  // namespace sdm
    148 
    149 #endif  // __HWC_COLOR_MANAGER_H__
    150