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 __COMP_MANAGER_H__
26#define __COMP_MANAGER_H__
27
28#include <core/display_interface.h>
29#include <private/extension_interface.h>
30#include <utils/locker.h>
31#include <bitset>
32
33#include "strategy.h"
34#include "resource_default.h"
35#include "hw_interface.h"
36#include "dump_impl.h"
37
38namespace sdm {
39
40class CompManager : public DumpImpl {
41 public:
42  DisplayError Init(const HWResourceInfo &hw_res_info_, ExtensionInterface *extension_intf,
43                    BufferAllocator *buffer_allocator, BufferSyncHandler *buffer_sync_handler,
44                    SocketHandler *socket_handler);
45  DisplayError Deinit();
46  DisplayError RegisterDisplay(DisplayType type, const HWDisplayAttributes &display_attributes,
47                               const HWPanelInfo &hw_panel_info,
48                               const HWMixerAttributes &mixer_attributes,
49                               const DisplayConfigVariableInfo &fb_config, Handle *display_ctx);
50  DisplayError UnregisterDisplay(Handle display_ctx);
51  DisplayError ReconfigureDisplay(Handle display_ctx, const HWDisplayAttributes &display_attributes,
52                                  const HWPanelInfo &hw_panel_info,
53                                  const HWMixerAttributes &mixer_attributes,
54                                  const DisplayConfigVariableInfo &fb_config);
55  void PrePrepare(Handle display_ctx, HWLayers *hw_layers);
56  DisplayError Prepare(Handle display_ctx, HWLayers *hw_layers);
57  DisplayError Commit(Handle display_ctx, HWLayers *hw_layers);
58  DisplayError PostPrepare(Handle display_ctx, HWLayers *hw_layers);
59  DisplayError ReConfigure(Handle display_ctx, HWLayers *hw_layers);
60  DisplayError PostCommit(Handle display_ctx, HWLayers *hw_layers);
61  void Purge(Handle display_ctx);
62  DisplayError SetIdleTimeoutMs(Handle display_ctx, uint32_t active_ms);
63  void ProcessIdleTimeout(Handle display_ctx);
64  void ProcessThermalEvent(Handle display_ctx, int64_t thermal_level);
65  void ProcessIdlePowerCollapse(Handle display_ctx);
66  DisplayError SetMaxMixerStages(Handle display_ctx, uint32_t max_mixer_stages);
67  void ControlPartialUpdate(Handle display_ctx, bool enable);
68  DisplayError ValidateScaling(const LayerRect &crop, const LayerRect &dst, bool rotate90);
69  DisplayError ValidateCursorPosition(Handle display_ctx, HWLayers *hw_layers, int x, int y);
70  bool SupportLayerAsCursor(Handle display_ctx, HWLayers *hw_layers);
71  bool SetDisplayState(Handle display_ctx, DisplayState state, DisplayType display_type);
72  DisplayError SetMaxBandwidthMode(HWBwModes mode);
73  DisplayError GetScaleLutConfig(HWScaleLutInfo *lut_info);
74  DisplayError SetDetailEnhancerData(Handle display_ctx, const DisplayDetailEnhancerData &de_data);
75  DisplayError SetCompositionState(Handle display_ctx, LayerComposition composition_type,
76                                   bool enable);
77  DisplayError ControlDpps(bool enable);
78
79  // DumpImpl method
80  virtual void AppendDump(char *buffer, uint32_t length);
81
82 private:
83  static const int kSafeModeThreshold = 4;
84
85  void PrepareStrategyConstraints(Handle display_ctx, HWLayers *hw_layers);
86
87  struct DisplayCompositionContext {
88    Strategy *strategy = NULL;
89    StrategyConstraints constraints;
90    Handle display_resource_ctx = NULL;
91    DisplayType display_type = kPrimary;
92    uint32_t max_strategies = 0;
93    uint32_t remaining_strategies = 0;
94    bool idle_fallback = false;
95    bool thermal_fallback_ = false;
96    // Using primary panel flag of hw panel to configure Constraints. We do not need other hw
97    // panel parameters for now.
98    bool is_primary_panel = false;
99    bool valid_cursor = false;
100    PUConstraints pu_constraints = {};
101    bool scaled_composition = false;
102  };
103
104  Locker locker_;
105  ResourceInterface *resource_intf_ = NULL;
106  std::bitset<kDisplayMax> registered_displays_;  // Bit mask of registered displays
107  std::bitset<kDisplayMax> configured_displays_;  // Bit mask of sucessfully configured displays
108  uint32_t display_state_[kDisplayMax] = {};
109  bool safe_mode_ = false;              // Flag to notify all displays to be in resource crunch
110                                        // mode, where strategy manager chooses the best strategy
111                                        // that uses optimal number of pipes for each display
112  HWResourceInfo hw_res_info_;
113  BufferAllocator *buffer_allocator_ = NULL;
114  ExtensionInterface *extension_intf_ = NULL;
115  uint32_t max_layers_ = kMaxSDELayers;
116  uint32_t max_sde_ext_layers_ = 0;
117  DppsControlInterface *dpps_ctrl_intf_ = NULL;
118};
119
120}  // namespace sdm
121
122#endif  // __COMP_MANAGER_H__
123
124