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 #ifndef __HWC_DISPLAY_H__ 26 #define __HWC_DISPLAY_H__ 27 28 #include <hardware/hwcomposer.h> 29 #include <core/core_interface.h> 30 #include <qdMetaData.h> 31 #include <QService.h> 32 #include <private/color_params.h> 33 #include <map> 34 #include <vector> 35 #include <string> 36 37 namespace sdm { 38 39 class BlitEngine; 40 class HWCToneMapper; 41 42 // Subclasses set this to their type. This has to be different from DisplayType. 43 // This is to avoid RTTI and dynamic_cast 44 enum DisplayClass { 45 DISPLAY_CLASS_PRIMARY, 46 DISPLAY_CLASS_EXTERNAL, 47 DISPLAY_CLASS_VIRTUAL, 48 DISPLAY_CLASS_NULL 49 }; 50 51 class HWCColorMode { 52 public: 53 explicit HWCColorMode(DisplayInterface *display_intf) : display_intf_(display_intf) {} 54 ~HWCColorMode() {} 55 void Init(); 56 void DeInit() {} 57 int SetColorMode(const std::string &color_mode); 58 const std::vector<std::string> &GetColorModes(); 59 int SetColorTransform(uint32_t matrix_count, const float *matrix); 60 61 private: 62 static const uint32_t kColorTransformMatrixCount = 16; 63 template <class T> 64 void CopyColorTransformMatrix(const T *input_matrix, double *output_matrix) { 65 for (uint32_t i = 0; i < kColorTransformMatrixCount; i++) { 66 output_matrix[i] = static_cast<double>(input_matrix[i]); 67 } 68 } 69 int PopulateColorModes(); 70 DisplayInterface *display_intf_ = NULL; 71 std::vector<std::string> color_modes_ = {}; 72 std::string current_color_mode_ = {}; 73 }; 74 75 class HWCDisplay : public DisplayEventHandler { 76 public: 77 enum { 78 SET_METADATA_DYN_REFRESH_RATE, 79 SET_BINDER_DYN_REFRESH_RATE, 80 SET_DISPLAY_MODE, 81 SET_QDCM_SOLID_FILL_INFO, 82 UNSET_QDCM_SOLID_FILL_INFO, 83 }; 84 85 virtual ~HWCDisplay() { } 86 virtual int Init(); 87 virtual int Deinit(); 88 virtual int Prepare(hwc_display_contents_1_t *content_list) = 0; 89 virtual int Commit(hwc_display_contents_1_t *content_list) = 0; 90 virtual int EventControl(int event, int enable); 91 virtual int SetPowerMode(int mode); 92 93 // Framebuffer configurations 94 virtual int GetDisplayConfigs(uint32_t *configs, size_t *num_configs); 95 virtual int GetDisplayAttributes(uint32_t config, const uint32_t *display_attributes, 96 int32_t *values); 97 virtual int GetActiveConfig(); 98 virtual int SetActiveConfig(int index); 99 100 virtual void SetIdleTimeoutMs(uint32_t timeout_ms); 101 virtual void SetFrameDumpConfig(uint32_t count, uint32_t bit_mask_layer_type); 102 virtual DisplayError SetMaxMixerStages(uint32_t max_mixer_stages); 103 virtual DisplayError ControlPartialUpdate(bool enable, uint32_t *pending) { 104 return kErrorNotSupported; 105 } 106 virtual uint32_t GetLastPowerMode(); 107 virtual int SetFrameBufferResolution(uint32_t x_pixels, uint32_t y_pixels); 108 virtual void GetFrameBufferResolution(uint32_t *x_pixels, uint32_t *y_pixels); 109 virtual int SetDisplayStatus(uint32_t display_status); 110 virtual int OnMinHdcpEncryptionLevelChange(uint32_t min_enc_level); 111 virtual int Perform(uint32_t operation, ...); 112 virtual int SetCursorPosition(int x, int y); 113 virtual void SetSecureDisplay(bool secure_display_active, bool force_flush); 114 virtual DisplayError SetMixerResolution(uint32_t width, uint32_t height); 115 virtual DisplayError GetMixerResolution(uint32_t *width, uint32_t *height); 116 virtual void GetPanelResolution(uint32_t *width, uint32_t *height); 117 118 // Captures frame output in the buffer specified by output_buffer_info. The API is 119 // non-blocking and the client is expected to check operation status later on. 120 // Returns -1 if the input is invalid. 121 virtual int FrameCaptureAsync(const BufferInfo& output_buffer_info, bool post_processed) { 122 return -1; 123 } 124 // Returns the status of frame capture operation requested with FrameCaptureAsync(). 125 // -EAGAIN : No status obtain yet, call API again after another frame. 126 // < 0 : Operation happened but failed. 127 // 0 : Success. 128 virtual int GetFrameCaptureStatus() { return -EAGAIN; } 129 130 virtual DisplayError SetDetailEnhancerConfig(const DisplayDetailEnhancerData &de_data) { 131 return kErrorNotSupported; 132 } 133 134 // Display Configurations 135 virtual int SetActiveDisplayConfig(int config); 136 virtual int GetActiveDisplayConfig(uint32_t *config); 137 virtual int GetDisplayConfigCount(uint32_t *count); 138 virtual int GetDisplayAttributesForConfig(int config, 139 DisplayConfigVariableInfo *display_attributes); 140 virtual int GetDisplayFixedConfig(DisplayConfigFixedInfo *fixed_info); 141 142 int SetPanelBrightness(int level); 143 int GetPanelBrightness(int *level); 144 int CachePanelBrightness(int level); 145 int ToggleScreenUpdates(bool enable); 146 int ColorSVCRequestRoute(const PPDisplayAPIPayload &in_payload, 147 PPDisplayAPIPayload *out_payload, 148 PPPendingParams *pending_action); 149 int GetVisibleDisplayRect(hwc_rect_t* rect); 150 DisplayClass GetDisplayClass(); 151 int GetDisplayPort(DisplayPort *port); 152 153 protected: 154 enum DisplayStatus { 155 kDisplayStatusOffline = 0, 156 kDisplayStatusOnline, 157 kDisplayStatusPause, 158 kDisplayStatusResume, 159 }; 160 161 // Dim layer flag set by SurfaceFlinger service. 162 static const uint32_t kDimLayer = 0x80000000; 163 164 // Maximum number of layers supported by display manager. 165 static const uint32_t kMaxLayerCount = 32; 166 167 HWCDisplay(CoreInterface *core_intf, hwc_procs_t const **hwc_procs, DisplayType type, int id, 168 bool needs_blit, qService::QService *qservice, DisplayClass display_class); 169 170 // DisplayEventHandler methods 171 virtual DisplayError VSync(const DisplayEventVSync &vsync); 172 virtual DisplayError Refresh(); 173 virtual DisplayError CECMessage(char *message); 174 175 int AllocateLayerStack(hwc_display_contents_1_t *content_list); 176 void FreeLayerStack(); 177 virtual int PrePrepareLayerStack(hwc_display_contents_1_t *content_list); 178 virtual int PrepareLayerStack(hwc_display_contents_1_t *content_list); 179 virtual int CommitLayerStack(hwc_display_contents_1_t *content_list); 180 virtual int PostCommitLayerStack(hwc_display_contents_1_t *content_list); 181 virtual void DumpOutputBuffer(const BufferInfo& buffer_info, void *base, int fence); 182 virtual uint32_t RoundToStandardFPS(float fps); 183 virtual uint32_t SanitizeRefreshRate(uint32_t req_refresh_rate); 184 virtual void PrepareDynamicRefreshRate(Layer *layer); 185 virtual DisplayError DisablePartialUpdateOneFrame() { 186 return kErrorNotSupported; 187 } 188 inline void SetRect(const hwc_rect_t &source, LayerRect *target); 189 inline void SetRect(const hwc_frect_t &source, LayerRect *target); 190 inline void SetComposition(const int32_t &source, LayerComposition *target); 191 inline void SetComposition(const LayerComposition &source, int32_t *target); 192 inline void SetBlending(const int32_t &source, LayerBlending *target); 193 int SetFormat(const int32_t &source, const int flags, LayerBufferFormat *target); 194 void SetLayerS3DMode(const LayerBufferS3DFormat &source, uint32_t *target); 195 LayerBufferFormat GetSDMFormat(const int32_t &source, const int flags); 196 const char *GetDisplayString(); 197 void MarkLayersForGPUBypass(hwc_display_contents_1_t *content_list); 198 virtual void ApplyScanAdjustment(hwc_rect_t *display_frame); 199 DisplayError SetCSC(const MetaData_t *meta_data, ColorMetaData *color_metadata); 200 DisplayError SetIGC(IGC_t source, LayerIGC *target); 201 DisplayError SetMetaData(const private_handle_t *pvt_handle, Layer *layer); 202 bool NeedsFrameBufferRefresh(hwc_display_contents_1_t *content_list); 203 bool IsLayerUpdating(hwc_display_contents_1_t *content_list, const Layer *layer); 204 bool IsNonIntegralSourceCrop(const hwc_frect_t &source); 205 uint32_t GetUpdatingLayersCount(uint32_t app_layer_count); 206 bool SingleVideoLayerUpdating(uint32_t app_layer_count); 207 bool IsSurfaceUpdated(const std::vector<LayerRect> &dirty_regions); 208 209 enum { 210 INPUT_LAYER_DUMP, 211 OUTPUT_LAYER_DUMP, 212 }; 213 214 CoreInterface *core_intf_; 215 hwc_procs_t const **hwc_procs_; 216 DisplayType type_; 217 int id_; 218 bool needs_blit_ = false; 219 DisplayInterface *display_intf_ = NULL; 220 LayerStack layer_stack_; 221 bool flush_on_error_ = false; 222 bool flush_ = false; 223 uint32_t dump_frame_count_ = 0; 224 uint32_t dump_frame_index_ = 0; 225 bool dump_input_layers_ = false; 226 uint32_t last_power_mode_; 227 bool swap_interval_zero_ = false; 228 bool display_paused_ = false; 229 uint32_t min_refresh_rate_ = 0; 230 uint32_t max_refresh_rate_ = 0; 231 uint32_t current_refresh_rate_ = 0; 232 bool use_metadata_refresh_rate_ = false; 233 uint32_t metadata_refresh_rate_ = 0; 234 uint32_t force_refresh_rate_ = 0; 235 bool boot_animation_completed_ = false; 236 bool shutdown_pending_ = false; 237 bool use_blit_comp_ = false; 238 bool secure_display_active_ = false; 239 uint32_t skip_prepare_cnt = 0; 240 bool solid_fill_enable_ = false; 241 bool disable_animation_ = false; 242 uint32_t solid_fill_color_ = 0; 243 LayerRect display_rect_; 244 std::map<int, LayerBufferS3DFormat> s3d_format_hwc_to_sdm_; 245 bool animating_ = false; 246 HWCToneMapper *tone_mapper_ = NULL; 247 HWCColorMode *color_mode_ = NULL; 248 int disable_hdr_handling_ = 0; // disables HDR handling. 249 250 private: 251 void DumpInputBuffers(hwc_display_contents_1_t *content_list); 252 int PrepareLayerParams(hwc_layer_1_t *hwc_layer, Layer *layer); 253 void CommitLayerParams(hwc_layer_1_t *hwc_layer, Layer *layer); 254 BlitEngine *blit_engine_ = NULL; 255 qService::QService *qservice_ = NULL; 256 DisplayClass display_class_; 257 }; 258 259 inline int HWCDisplay::Perform(uint32_t operation, ...) { 260 return 0; 261 } 262 263 } // namespace sdm 264 265 #endif // __HWC_DISPLAY_H__ 266 267