1 /* 2 * Copyright (c) 2014-2016, The Linux Foundation. All rights reserved. 3 * Not a Contribution. 4 * 5 * Copyright 2015 The Android Open Source Project 6 * 7 * Licensed under the Apache License, Version 2.0 (the "License"); 8 * you may not use this file except in compliance with the License. 9 * You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, software 14 * distributed under the License is distributed on an "AS IS" BASIS, 15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 * See the License for the specific language governing permissions and 17 * limitations under the License. 18 */ 19 20 #ifndef __HWC_DISPLAY_H__ 21 #define __HWC_DISPLAY_H__ 22 23 #include <QService.h> 24 #include <core/core_interface.h> 25 #include <hardware/hwcomposer.h> 26 #include <private/color_params.h> 27 #include <qdMetaData.h> 28 #include <map> 29 #include <queue> 30 #include <set> 31 #include <string> 32 #include <utility> 33 #include <vector> 34 35 #include "hwc_callbacks.h" 36 #include "hwc_layers.h" 37 38 namespace sdm { 39 40 class BlitEngine; 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); 54 ~HWCColorMode() {} 55 HWC2::Error Init(); 56 HWC2::Error DeInit(); 57 uint32_t GetColorModeCount(); 58 HWC2::Error GetColorModes(uint32_t *out_num_modes, android_color_mode_t *out_modes); 59 HWC2::Error SetColorMode(android_color_mode_t mode); 60 HWC2::Error SetColorTransform(const float *matrix, android_color_transform_t hint); 61 62 private: 63 static const uint32_t kColorTransformMatrixCount = 16; 64 65 HWC2::Error HandleColorModeTransform(android_color_mode_t mode, 66 android_color_transform_t hint, const double *matrix); 67 void PopulateColorModes(); 68 void PopulateTransform(const android_color_mode_t &mode, const std::string &color_mode); 69 template <class T> 70 void CopyColorTransformMatrix(const T *input_matrix, double *output_matrix) { 71 for (uint32_t i = 0; i < kColorTransformMatrixCount; i++) { 72 output_matrix[i] = static_cast<double>(input_matrix[i]); 73 } 74 } 75 76 DisplayInterface *display_intf_ = NULL; 77 android_color_mode_t current_color_mode_ = HAL_COLOR_MODE_NATIVE; 78 android_color_transform_t current_color_transform_ = HAL_COLOR_TRANSFORM_IDENTITY; 79 typedef std::map<android_color_transform_t, std::string> TransformMap; 80 std::map<android_color_mode_t, TransformMap> color_mode_transform_map_ = {}; 81 double color_matrix_[kColorTransformMatrixCount] = {0}; 82 }; 83 84 class HWCDisplay : public DisplayEventHandler { 85 public: 86 virtual ~HWCDisplay() {} 87 virtual int Init(); 88 virtual int Deinit(); 89 90 // Framebuffer configurations 91 virtual void SetIdleTimeoutMs(uint32_t timeout_ms); 92 virtual void SetFrameDumpConfig(uint32_t count, uint32_t bit_mask_layer_type); 93 virtual DisplayError SetMaxMixerStages(uint32_t max_mixer_stages); 94 virtual DisplayError ControlPartialUpdate(bool enable, uint32_t *pending) { 95 return kErrorNotSupported; 96 } 97 virtual HWC2::PowerMode GetLastPowerMode(); 98 virtual int SetFrameBufferResolution(uint32_t x_pixels, uint32_t y_pixels); 99 virtual void GetFrameBufferResolution(uint32_t *x_pixels, uint32_t *y_pixels); 100 virtual int SetDisplayStatus(uint32_t display_status); 101 virtual int OnMinHdcpEncryptionLevelChange(uint32_t min_enc_level); 102 virtual int Perform(uint32_t operation, ...); 103 virtual void SetSecureDisplay(bool secure_display_active); 104 virtual DisplayError SetMixerResolution(uint32_t width, uint32_t height); 105 virtual DisplayError GetMixerResolution(uint32_t *width, uint32_t *height); 106 virtual void GetPanelResolution(uint32_t *width, uint32_t *height); 107 virtual std::string Dump(void); 108 109 // Captures frame output in the buffer specified by output_buffer_info. The API is 110 // non-blocking and the client is expected to check operation status later on. 111 // Returns -1 if the input is invalid. 112 virtual int FrameCaptureAsync(const BufferInfo &output_buffer_info, bool post_processed) { 113 return -1; 114 } 115 // Returns the status of frame capture operation requested with FrameCaptureAsync(). 116 // -EAGAIN : No status obtain yet, call API again after another frame. 117 // < 0 : Operation happened but failed. 118 // 0 : Success. 119 virtual int GetFrameCaptureStatus() { return -EAGAIN; } 120 121 virtual DisplayError SetDetailEnhancerConfig(const DisplayDetailEnhancerData &de_data) { 122 return kErrorNotSupported; 123 } 124 125 // Display Configurations 126 virtual int SetActiveDisplayConfig(int config); 127 virtual int GetActiveDisplayConfig(uint32_t *config); 128 virtual int GetDisplayConfigCount(uint32_t *count); 129 virtual int GetDisplayAttributesForConfig(int config, 130 DisplayConfigVariableInfo *display_attributes); 131 132 int SetPanelBrightness(int level); 133 int GetPanelBrightness(int *level); 134 int ToggleScreenUpdates(bool enable); 135 int ColorSVCRequestRoute(const PPDisplayAPIPayload &in_payload, PPDisplayAPIPayload *out_payload, 136 PPPendingParams *pending_action); 137 void SolidFillPrepare(); 138 void SolidFillCommit(); 139 DisplayClass GetDisplayClass(); 140 int GetVisibleDisplayRect(hwc_rect_t *rect); 141 void BuildLayerStack(void); 142 void BuildSolidFillStack(void); 143 HWCLayer *GetHWCLayer(hwc2_layer_t layer); 144 145 // HWC2 APIs 146 virtual HWC2::Error AcceptDisplayChanges(void); 147 virtual HWC2::Error GetActiveConfig(hwc2_config_t *out_config); 148 virtual HWC2::Error SetActiveConfig(hwc2_config_t config); 149 virtual HWC2::Error SetClientTarget(buffer_handle_t target, int32_t acquire_fence, 150 int32_t dataspace, hwc_region_t damage); 151 virtual HWC2::Error SetColorMode(android_color_mode_t mode) { 152 return HWC2::Error::Unsupported; 153 } 154 virtual HWC2::Error SetColorTransform(const float *matrix, android_color_transform_t hint) { 155 return HWC2::Error::Unsupported; 156 } 157 virtual HWC2::Error HandleColorModeTransform(android_color_mode_t mode, 158 android_color_transform_t hint, 159 const double *matrix) { 160 return HWC2::Error::Unsupported; 161 } 162 virtual HWC2::Error GetDisplayConfigs(uint32_t *out_num_configs, hwc2_config_t *out_configs); 163 virtual HWC2::Error GetDisplayAttribute(hwc2_config_t config, HWC2::Attribute attribute, 164 int32_t *out_value); 165 virtual HWC2::Error GetClientTargetSupport(uint32_t width, uint32_t height, int32_t format, 166 int32_t dataspace); 167 virtual HWC2::Error GetColorModes(uint32_t *outNumModes, android_color_mode_t *outModes); 168 virtual HWC2::Error GetChangedCompositionTypes(uint32_t *out_num_elements, 169 hwc2_layer_t *out_layers, int32_t *out_types); 170 virtual HWC2::Error GetDisplayRequests(int32_t *out_display_requests, uint32_t *out_num_elements, 171 hwc2_layer_t *out_layers, int32_t *out_layer_requests); 172 virtual HWC2::Error GetDisplayName(uint32_t *out_size, char *out_name); 173 virtual HWC2::Error GetDisplayType(int32_t *out_type); 174 virtual HWC2::Error SetCursorPosition(hwc2_layer_t layer, int x, int y); 175 virtual HWC2::Error SetVsyncEnabled(HWC2::Vsync enabled); 176 virtual HWC2::Error SetPowerMode(HWC2::PowerMode mode); 177 virtual HWC2::Error CreateLayer(hwc2_layer_t *out_layer_id); 178 virtual HWC2::Error DestroyLayer(hwc2_layer_t layer_id); 179 virtual HWC2::Error SetLayerZOrder(hwc2_layer_t layer_id, uint32_t z); 180 virtual HWC2::Error Validate(uint32_t *out_num_types, uint32_t *out_num_requests) = 0; 181 virtual HWC2::Error GetReleaseFences(uint32_t *out_num_elements, hwc2_layer_t *out_layers, 182 int32_t *out_fences); 183 virtual HWC2::Error Present(int32_t *out_retire_fence) = 0; 184 185 protected: 186 enum DisplayStatus { 187 kDisplayStatusOffline = 0, 188 kDisplayStatusOnline, 189 kDisplayStatusPause, 190 kDisplayStatusResume, 191 }; 192 193 // Maximum number of layers supported by display manager. 194 static const uint32_t kMaxLayerCount = 32; 195 196 HWCDisplay(CoreInterface *core_intf, HWCCallbacks *callbacks, DisplayType type, hwc2_display_t id, 197 bool needs_blit, qService::QService *qservice, DisplayClass display_class); 198 199 // DisplayEventHandler methods 200 virtual DisplayError VSync(const DisplayEventVSync &vsync); 201 virtual DisplayError Refresh(); 202 virtual DisplayError CECMessage(char *message); 203 virtual void DumpOutputBuffer(const BufferInfo &buffer_info, void *base, int fence); 204 virtual HWC2::Error PrepareLayerStack(uint32_t *out_num_types, uint32_t *out_num_requests); 205 virtual HWC2::Error CommitLayerStack(void); 206 virtual HWC2::Error PostCommitLayerStack(int32_t *out_retire_fence); 207 virtual DisplayError DisablePartialUpdateOneFrame() { 208 return kErrorNotSupported; 209 } 210 LayerBufferFormat GetSDMFormat(const int32_t &source, const int flags); 211 const char *GetHALPixelFormatString(int format); 212 const char *GetDisplayString(); 213 void MarkLayersForGPUBypass(void); 214 void MarkLayersForClientComposition(void); 215 virtual void ApplyScanAdjustment(hwc_rect_t *display_frame); 216 bool SingleLayerUpdating(void); 217 bool IsSurfaceUpdated(const std::vector<LayerRect> &dirty_regions); 218 bool IsLayerUpdating(const Layer *layer); 219 uint32_t SanitizeRefreshRate(uint32_t req_refresh_rate); 220 virtual void CloseAcquireFds(); 221 222 enum { 223 INPUT_LAYER_DUMP, 224 OUTPUT_LAYER_DUMP, 225 }; 226 227 CoreInterface *core_intf_ = nullptr; 228 HWCCallbacks *callbacks_ = nullptr; 229 DisplayType type_; 230 hwc2_display_t id_; 231 bool needs_blit_ = false; 232 DisplayInterface *display_intf_ = NULL; 233 LayerStack layer_stack_; 234 HWCLayer *client_target_ = nullptr; // Also known as framebuffer target 235 std::map<hwc2_layer_t, HWCLayer *> layer_map_; // Look up by Id - TODO 236 std::multiset<HWCLayer *, SortLayersByZ> layer_set_; // Maintain a set sorted by Z 237 std::map<hwc2_layer_t, HWC2::Composition> layer_changes_; 238 std::map<hwc2_layer_t, HWC2::LayerRequest> layer_requests_; 239 bool flush_on_error_ = false; 240 bool flush_ = false; 241 uint32_t dump_frame_count_ = 0; 242 uint32_t dump_frame_index_ = 0; 243 bool dump_input_layers_ = false; 244 HWC2::PowerMode last_power_mode_; 245 bool swap_interval_zero_ = false; 246 bool display_paused_ = false; 247 uint32_t min_refresh_rate_ = 0; 248 uint32_t max_refresh_rate_ = 0; 249 uint32_t current_refresh_rate_ = 0; 250 bool use_metadata_refresh_rate_ = false; 251 uint32_t metadata_refresh_rate_ = 0; 252 uint32_t force_refresh_rate_ = 0; 253 bool boot_animation_completed_ = false; 254 bool shutdown_pending_ = false; 255 bool use_blit_comp_ = false; 256 bool secure_display_active_ = false; 257 bool skip_prepare_ = false; 258 bool solid_fill_enable_ = false; 259 Layer *solid_fill_layer_ = NULL; 260 LayerRect solid_fill_rect_ = {}; 261 uint32_t solid_fill_color_ = 0; 262 LayerRect display_rect_; 263 bool validated_ = false; 264 bool color_tranform_failed_ = false; 265 HWCColorMode *color_mode_ = NULL; 266 267 private: 268 void DumpInputBuffers(void); 269 BlitEngine *blit_engine_ = NULL; 270 qService::QService *qservice_ = NULL; 271 DisplayClass display_class_; 272 uint32_t geometry_changes_ = GeometryChanges::kNone; 273 }; 274 275 inline int HWCDisplay::Perform(uint32_t operation, ...) { 276 return 0; 277 } 278 279 } // namespace sdm 280 281 #endif // __HWC_DISPLAY_H__ 282