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 __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 
32 #include "strategy.h"
33 #include "resource_default.h"
34 #include "hw_interface.h"
35 #include "dump_impl.h"
36 
37 namespace sdm {
38 
39 class CompManager : public DumpImpl {
40  public:
41   DisplayError Init(const HWResourceInfo &hw_res_info_, ExtensionInterface *extension_intf,
42                   BufferSyncHandler *buffer_sync_handler);
43   DisplayError Deinit();
44   DisplayError RegisterDisplay(DisplayType type, const HWDisplayAttributes &attributes,
45                                const HWPanelInfo &hw_panel_info, Handle *res_mgr_hnd);
46   DisplayError UnregisterDisplay(Handle res_mgr_hnd);
47   DisplayError ReconfigureDisplay(Handle display_ctx, const HWDisplayAttributes &attributes,
48                                   const HWPanelInfo &hw_panel_info);
49   void PrePrepare(Handle display_ctx, HWLayers *hw_layers);
50   DisplayError Prepare(Handle display_ctx, HWLayers *hw_layers);
51   DisplayError PostPrepare(Handle display_ctx, HWLayers *hw_layers);
52   DisplayError ReConfigure(Handle display_ctx, HWLayers *hw_layers);
53   DisplayError PostCommit(Handle display_ctx, HWLayers *hw_layers);
54   void Purge(Handle display_ctx);
55   void ProcessIdleTimeout(Handle display_ctx);
56   void ProcessThermalEvent(Handle display_ctx, int64_t thermal_level);
57   DisplayError SetMaxMixerStages(Handle display_ctx, uint32_t max_mixer_stages);
58   void ControlPartialUpdate(Handle display_ctx, bool enable);
59   DisplayError ValidateScaling(const LayerRect &crop, const LayerRect &dst, bool rotate90);
60   DisplayError ValidateCursorPosition(Handle display_ctx, HWLayers *hw_layers, int x, int y);
61   bool SupportLayerAsCursor(Handle display_ctx, HWLayers *hw_layers);
62   bool CanSetIdleTimeout(Handle display_ctx);
63   DisplayError SetMaxBandwidthMode(HWBwModes mode);
64 
65   // DumpImpl method
66   virtual void AppendDump(char *buffer, uint32_t length);
67 
68  private:
69   static const int kMaxThermalLevel = 3;
70 
71   void PrepareStrategyConstraints(Handle display_ctx, HWLayers *hw_layers);
72 
73   struct DisplayCompositionContext {
74     Strategy *strategy = NULL;
75     StrategyConstraints constraints;
76     Handle display_resource_ctx = NULL;
77     DisplayType display_type = kPrimary;
78     uint32_t max_strategies = 0;
79     uint32_t remaining_strategies = 0;
80     bool idle_fallback = false;
81     bool fallback_ = false;
82     uint32_t partial_update_enable = true;
83   };
84 
85   Locker locker_;
86   ResourceInterface *resource_intf_ = NULL;
87   ResourceDefault resource_default_;
88   uint32_t registered_displays_ = 0;    // Stores the bit mask of registered displays
89   uint32_t configured_displays_ = 0;    // Stores the bit mask of sucessfully configured displays
90   bool safe_mode_ = false;              // Flag to notify all displays to be in resource crunch
91                                         // mode, where strategy manager chooses the best strategy
92                                         // that uses optimal number of pipes for each display
93   HWResourceInfo hw_res_info_;
94   ExtensionInterface *extension_intf_ = NULL;
95   uint32_t max_layers_ = kMaxSDELayers;
96 };
97 
98 }  // namespace sdm
99 
100 #endif  // __COMP_MANAGER_H__
101 
102