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