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#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 36namespace sdm { 37 38class BlitEngine; 39 40// Subclasses set this to their type. This has to be different from DisplayType. 41// This is to avoid RTTI and dynamic_cast 42enum DisplayClass { 43 DISPLAY_CLASS_PRIMARY, 44 DISPLAY_CLASS_EXTERNAL, 45 DISPLAY_CLASS_VIRTUAL, 46 DISPLAY_CLASS_NULL 47}; 48 49 50class HWCDisplay : public DisplayEventHandler { 51 public: 52 virtual ~HWCDisplay() { } 53 virtual int Init(); 54 virtual int Deinit(); 55 virtual int Prepare(hwc_display_contents_1_t *content_list) = 0; 56 virtual int Commit(hwc_display_contents_1_t *content_list) = 0; 57 virtual int EventControl(int event, int enable); 58 virtual int SetPowerMode(int mode); 59 60 // Framebuffer configurations 61 virtual int GetDisplayConfigs(uint32_t *configs, size_t *num_configs); 62 virtual int GetDisplayAttributes(uint32_t config, const uint32_t *display_attributes, 63 int32_t *values); 64 virtual int GetActiveConfig(); 65 virtual int SetActiveConfig(int index); 66 67 virtual void SetIdleTimeoutMs(uint32_t timeout_ms); 68 virtual void SetFrameDumpConfig(uint32_t count, uint32_t bit_mask_layer_type); 69 virtual DisplayError SetMaxMixerStages(uint32_t max_mixer_stages); 70 virtual DisplayError ControlPartialUpdate(bool enable, uint32_t *pending) { 71 return kErrorNotSupported; 72 } 73 virtual uint32_t GetLastPowerMode(); 74 virtual int SetFrameBufferResolution(uint32_t x_pixels, uint32_t y_pixels); 75 virtual void GetFrameBufferResolution(uint32_t *x_pixels, uint32_t *y_pixels); 76 virtual int SetDisplayStatus(uint32_t display_status); 77 virtual int OnMinHdcpEncryptionLevelChange(uint32_t min_enc_level); 78 virtual int Perform(uint32_t operation, ...); 79 virtual int SetCursorPosition(int x, int y); 80 virtual void SetSecureDisplay(bool secure_display_active); 81 virtual DisplayError SetMixerResolution(uint32_t width, uint32_t height); 82 virtual DisplayError GetMixerResolution(uint32_t *width, uint32_t *height); 83 virtual void GetPanelResolution(uint32_t *width, uint32_t *height); 84 85 // Captures frame output in the buffer specified by output_buffer_info. The API is 86 // non-blocking and the client is expected to check operation status later on. 87 // Returns -1 if the input is invalid. 88 virtual int FrameCaptureAsync(const BufferInfo& output_buffer_info, bool post_processed) { 89 return -1; 90 } 91 // Returns the status of frame capture operation requested with FrameCaptureAsync(). 92 // -EAGAIN : No status obtain yet, call API again after another frame. 93 // < 0 : Operation happened but failed. 94 // 0 : Success. 95 virtual int GetFrameCaptureStatus() { return -EAGAIN; } 96 97 // Display Configurations 98 virtual int SetActiveDisplayConfig(int config); 99 virtual int GetActiveDisplayConfig(uint32_t *config); 100 virtual int GetDisplayConfigCount(uint32_t *count); 101 virtual int GetDisplayAttributesForConfig(int config, 102 DisplayConfigVariableInfo *display_attributes); 103 104 int SetPanelBrightness(int level); 105 int GetPanelBrightness(int *level); 106 int ToggleScreenUpdates(bool enable); 107 int ColorSVCRequestRoute(const PPDisplayAPIPayload &in_payload, 108 PPDisplayAPIPayload *out_payload, 109 PPPendingParams *pending_action); 110 int GetVisibleDisplayRect(hwc_rect_t* rect); 111 DisplayClass GetDisplayClass(); 112 113 protected: 114 enum DisplayStatus { 115 kDisplayStatusOffline = 0, 116 kDisplayStatusOnline, 117 kDisplayStatusPause, 118 kDisplayStatusResume, 119 }; 120 121 // Dim layer flag set by SurfaceFlinger service. 122 static const uint32_t kDimLayer = 0x80000000; 123 124 // Maximum number of layers supported by display manager. 125 static const uint32_t kMaxLayerCount = 32; 126 127 HWCDisplay(CoreInterface *core_intf, hwc_procs_t const **hwc_procs, DisplayType type, int id, 128 bool needs_blit, qService::QService *qservice, DisplayClass display_class); 129 130 // DisplayEventHandler methods 131 virtual DisplayError VSync(const DisplayEventVSync &vsync); 132 virtual DisplayError Refresh(); 133 virtual DisplayError CECMessage(char *message); 134 135 int AllocateLayerStack(hwc_display_contents_1_t *content_list); 136 void FreeLayerStack(); 137 virtual int PrePrepareLayerStack(hwc_display_contents_1_t *content_list); 138 virtual int PrepareLayerStack(hwc_display_contents_1_t *content_list); 139 virtual int CommitLayerStack(hwc_display_contents_1_t *content_list); 140 virtual int PostCommitLayerStack(hwc_display_contents_1_t *content_list); 141 virtual void DumpOutputBuffer(const BufferInfo& buffer_info, void *base, int fence); 142 virtual uint32_t RoundToStandardFPS(float fps); 143 virtual uint32_t SanitizeRefreshRate(uint32_t req_refresh_rate); 144 virtual void PrepareDynamicRefreshRate(Layer *layer); 145 virtual DisplayError DisablePartialUpdateOneFrame() { 146 return kErrorNotSupported; 147 } 148 inline void SetRect(const hwc_rect_t &source, LayerRect *target); 149 inline void SetRect(const hwc_frect_t &source, LayerRect *target); 150 inline void SetComposition(const int32_t &source, LayerComposition *target); 151 inline void SetComposition(const LayerComposition &source, int32_t *target); 152 inline void SetBlending(const int32_t &source, LayerBlending *target); 153 int SetFormat(const int32_t &source, const int flags, LayerBufferFormat *target); 154 LayerBufferFormat GetSDMFormat(const int32_t &source, const int flags); 155 const char *GetHALPixelFormatString(int format); 156 const char *GetDisplayString(); 157 void MarkLayersForGPUBypass(hwc_display_contents_1_t *content_list); 158 virtual void ApplyScanAdjustment(hwc_rect_t *display_frame); 159 DisplayError SetCSC(ColorSpace_t source, LayerCSC *target); 160 DisplayError SetIGC(IGC_t source, LayerIGC *target); 161 DisplayError SetMetaData(const private_handle_t *pvt_handle, Layer *layer); 162 bool NeedsFrameBufferRefresh(hwc_display_contents_1_t *content_list); 163 bool IsLayerUpdating(hwc_display_contents_1_t *content_list, const Layer *layer); 164 bool SingleLayerUpdating(uint32_t app_layer_count); 165 bool SingleVideoLayerUpdating(uint32_t app_layer_count); 166 bool IsSurfaceUpdated(const std::vector<LayerRect> &dirty_regions); 167 168 enum { 169 INPUT_LAYER_DUMP, 170 OUTPUT_LAYER_DUMP, 171 }; 172 173 CoreInterface *core_intf_; 174 hwc_procs_t const **hwc_procs_; 175 DisplayType type_; 176 int id_; 177 bool needs_blit_ = false; 178 DisplayInterface *display_intf_ = NULL; 179 LayerStack layer_stack_; 180 bool flush_on_error_ = false; 181 bool flush_ = false; 182 uint32_t dump_frame_count_ = 0; 183 uint32_t dump_frame_index_ = 0; 184 bool dump_input_layers_ = false; 185 uint32_t last_power_mode_; 186 bool swap_interval_zero_ = false; 187 bool display_paused_ = false; 188 uint32_t min_refresh_rate_ = 0; 189 uint32_t max_refresh_rate_ = 0; 190 uint32_t current_refresh_rate_ = 0; 191 bool use_metadata_refresh_rate_ = false; 192 uint32_t metadata_refresh_rate_ = 0; 193 uint32_t force_refresh_rate_ = 0; 194 bool boot_animation_completed_ = false; 195 bool shutdown_pending_ = false; 196 bool use_blit_comp_ = false; 197 bool secure_display_active_ = false; 198 bool skip_prepare_ = false; 199 bool solid_fill_enable_ = false; 200 uint32_t solid_fill_color_ = 0; 201 LayerRect display_rect_; 202 std::map<int, LayerBufferS3DFormat> s3d_format_hwc_to_sdm_; 203 bool animating_ = false; 204 205 private: 206 void DumpInputBuffers(hwc_display_contents_1_t *content_list); 207 int PrepareLayerParams(hwc_layer_1_t *hwc_layer, Layer *layer); 208 void CommitLayerParams(hwc_layer_1_t *hwc_layer, Layer *layer); 209 BlitEngine *blit_engine_ = NULL; 210 qService::QService *qservice_ = NULL; 211 DisplayClass display_class_; 212}; 213 214inline int HWCDisplay::Perform(uint32_t operation, ...) { 215 return 0; 216} 217 218} // namespace sdm 219 220#endif // __HWC_DISPLAY_H__ 221 222