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 <binder/BinderService.h>
36#include <core/sdm_types.h>
37#include <utils/locker.h>
38
39namespace sdm {
40
41// This macro defines name for display APIs interface wrapper library.
42// This macro shall be used to load library using dlopen().
43#define DISPLAY_API_INTERFACE_LIBRARY_NAME "libsdm-disp-apis.so"
44
45// This macro defines variable name of display color APIs function tables
46// This macro shall be used to specify name of the variable in dlsym().
47#define DISPLAY_API_FUNC_TABLES "display_color_apis_ftables"
48#define QDCM_DIAG_CLIENT_LIBRARY_NAME "libsdm-diag.so"
49#define INIT_QDCM_DIAG_CLIENT_NAME "QDCMDiagInit"
50#define DEINIT_QDCM_DIAG_CLIENT_NAME "QDCMDiagDeInit"
51
52typedef int (*QDCMDiagInit)(void *ftables);
53
54typedef int (*QDCMDiagDeInit)(void);
55
56// Class to encapsulte all details of managing QDCM operating mode.
57class HWCQDCMModeManager {
58 public:
59  static const uint32_t kSocketCMDMaxLength = 4096;
60  static const uint32_t kFullWakeLock = 0x0000001a;
61  static const uint32_t kAcquireCauseWakeup = 0x10000000;
62  static const uint32_t kONAfterRelease = 0x20000000;
63  enum ActiveFeatureID {
64    kCABLFeature,
65    kADFeature,
66    kSVIFeature,
67    kMaxNumActiveFeature,
68  };
69
70  struct ActiveFeatureCMD {
71    const char *cmd_on = NULL;
72    const char *cmd_off = NULL;
73    const char *cmd_query_status = NULL;
74    const char *running = NULL;
75    ActiveFeatureCMD(const char *arg1, const char *arg2, const char *arg3, const char *arg4)
76        : cmd_on(arg1), cmd_off(arg2), cmd_query_status(arg3), running(arg4) {}
77  };
78
79  static const ActiveFeatureCMD kActiveFeatureCMD[kMaxNumActiveFeature];
80
81 public:
82  static HWCQDCMModeManager *CreateQDCMModeMgr();
83  ~HWCQDCMModeManager();
84  int EnableQDCMMode(bool enable, HWCDisplay *hwc_display);
85
86 protected:
87  bool SendSocketCmd();
88  int AcquireAndroidWakeLock(bool enable);
89  int EnableActiveFeatures(bool enable);
90  int EnableActiveFeatures(bool enable, const ActiveFeatureCMD &cmds, bool *was_running);
91
92 private:
93  bool cabl_was_running_ = false;
94  int socket_fd_ = -1;
95  android::sp<android::IBinder> wakelock_token_ = NULL;
96  uint32_t entry_timeout_ = 0;
97  static const char *const kSocketName;
98  static const char *const kTagName;
99  static const char *const kPackageName;
100};
101
102// Class to encapsulte all HWC/OS specific behaviours for ColorManager.
103class HWCColorManager {
104 public:
105  static const int kNumSolidFillLayers = 2;
106  static HWCColorManager *CreateColorManager(HWCBufferAllocator *buffer_allocator);
107  static int CreatePayloadFromParcel(const android::Parcel &in, uint32_t *disp_id,
108                                     PPDisplayAPIPayload *sink);
109  static void MarshallStructIntoParcel(const PPDisplayAPIPayload &data,
110                                       android::Parcel *out_parcel);
111
112  explicit HWCColorManager(HWCBufferAllocator *buffer_allocator);
113  ~HWCColorManager();
114  void DestroyColorManager();
115  int EnableQDCMMode(bool enable, HWCDisplay *hwc_display);
116  int SetSolidFill(const void *params, bool enable, HWCDisplay *hwc_display);
117  int SetFrameCapture(void *params, bool enable, HWCDisplay *hwc_display);
118  int SetDetailedEnhancer(void *params, HWCDisplay *hwc_display);
119  void SetColorModeDetailEnhancer(HWCDisplay *hwc_display);
120  int SetHWDetailedEnhancerConfig(void *params, HWCDisplay *hwc_display);
121
122 protected:
123  int CreateSolidFillLayers(HWCDisplay *hwc_display);
124  void DestroySolidFillLayers();
125  static uint32_t Get8BitsARGBColorValue(const PPColorFillParams &params);
126
127 private:
128  DynLib color_apis_lib_;
129  DynLib diag_client_lib_;
130  void *color_apis_ = NULL;
131  QDCMDiagInit qdcm_diag_init_ = NULL;
132  QDCMDiagDeInit qdcm_diag_deinit_ = NULL;
133  HWCQDCMModeManager *qdcm_mode_mgr_ = NULL;
134
135  PPColorFillParams solid_fill_params_;
136  HWCBufferAllocator *buffer_allocator_ = NULL;
137  BufferInfo buffer_info;
138  Locker locker_;
139};
140
141}  // namespace sdm
142
143#endif  // __HWC_COLOR_MANAGER_H__
144