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 __RESOURCE_DEFAULT_H__ 26 #define __RESOURCE_DEFAULT_H__ 27 28 #include <core/display_interface.h> 29 #include <private/resource_interface.h> 30 #include <utils/locker.h> 31 #include <vector> 32 33 #include "hw_interface.h" 34 35 namespace sdm { 36 37 class ResourceDefault : public ResourceInterface { 38 public: 39 static DisplayError CreateResourceDefault(const HWResourceInfo &hw_resource_info, 40 ResourceInterface **resource_intf); 41 static DisplayError DestroyResourceDefault(ResourceInterface *resource_intf); 42 virtual DisplayError RegisterDisplay(DisplayType type, 43 const HWDisplayAttributes &display_attributes, 44 const HWPanelInfo &hw_panel_info, 45 const HWMixerAttributes &mixer_attributes, 46 Handle *display_ctx); 47 virtual DisplayError UnregisterDisplay(Handle display_ctx); 48 virtual DisplayError ReconfigureDisplay(Handle display_ctx, 49 const HWDisplayAttributes &display_attributes, 50 const HWPanelInfo &hw_panel_info, 51 const HWMixerAttributes &mixer_attributes); 52 virtual DisplayError Start(Handle display_ctx); 53 virtual DisplayError Stop(Handle display_ctx, HWLayers *hw_layers); 54 virtual DisplayError Prepare(Handle display_ctx, HWLayers *hw_layers); 55 virtual DisplayError PostPrepare(Handle display_ctx, HWLayers *hw_layers); 56 virtual DisplayError Commit(Handle display_ctx, HWLayers *hw_layers); 57 virtual DisplayError PostCommit(Handle display_ctx, HWLayers *hw_layers); 58 virtual void Purge(Handle display_ctx); 59 virtual DisplayError SetMaxMixerStages(Handle display_ctx, uint32_t max_mixer_stages); 60 virtual DisplayError ValidateScaling(const LayerRect &crop, const LayerRect &dst, bool rotate90, 61 BufferLayout layout, bool use_rotator_downscale); 62 DisplayError ValidateCursorConfig(Handle display_ctx, const Layer *layer, bool is_top); 63 DisplayError ValidateAndSetCursorPosition(Handle display_ctx, HWLayers *hw_layers, int x, int y, 64 DisplayConfigVariableInfo *fb_config); 65 DisplayError SetMaxBandwidthMode(HWBwModes mode); 66 virtual DisplayError SetDetailEnhancerData(Handle display_ctx, 67 const DisplayDetailEnhancerData &de_data); 68 virtual DisplayError Perform(int cmd, ...) { return kErrorNone; } 69 70 private: 71 enum PipeOwner { 72 kPipeOwnerUserMode, // Pipe state when it is available for reservation 73 kPipeOwnerKernelMode, // Pipe state when pipe is owned by kernel 74 }; 75 76 // todo: retrieve all these from kernel 77 enum { 78 kMaxDecimationDownScaleRatio = 16, 79 }; 80 81 struct SourcePipe { 82 PipeType type; 83 PipeOwner owner; 84 uint32_t mdss_pipe_id; 85 uint32_t index; 86 HWBlockType hw_block_id; 87 int priority; 88 89 SourcePipe() : type(kPipeTypeUnused), owner(kPipeOwnerUserMode), mdss_pipe_id(0), 90 index(0), hw_block_id(kHWBlockMax), priority(0) { } 91 92 inline void ResetState() { hw_block_id = kHWBlockMax;} 93 }; 94 95 struct DisplayResourceContext { 96 HWDisplayAttributes display_attributes; 97 HWBlockType hw_block_id; 98 uint64_t frame_count; 99 HWMixerAttributes mixer_attributes; 100 101 DisplayResourceContext() : hw_block_id(kHWBlockMax), frame_count(0) { } 102 }; 103 104 struct HWBlockContext { 105 bool is_in_use; 106 HWBlockContext() : is_in_use(false) { } 107 }; 108 109 explicit ResourceDefault(const HWResourceInfo &hw_res_info); 110 DisplayError Init(); 111 DisplayError Deinit(); 112 uint32_t NextPipe(PipeType pipe_type, HWBlockType hw_block_id); 113 uint32_t SearchPipe(HWBlockType hw_block_id, SourcePipe *src_pipes, uint32_t num_pipe); 114 uint32_t GetPipe(HWBlockType hw_block_id, bool need_scale); 115 bool IsScalingNeeded(const HWPipeInfo *pipe_info); 116 DisplayError Config(DisplayResourceContext *display_resource_ctx, HWLayers *hw_layers); 117 DisplayError DisplaySplitConfig(DisplayResourceContext *display_resource_ctx, 118 const LayerRect &src_rect, const LayerRect &dst_rect, 119 HWLayerConfig *layer_config); 120 DisplayError SrcSplitConfig(DisplayResourceContext *display_resource_ctx, 121 const LayerRect &src_rect, const LayerRect &dst_rect, 122 HWLayerConfig *layer_config); 123 bool CalculateCropRects(const LayerRect &scissor, LayerRect *crop, LayerRect *dst); 124 DisplayError ValidateLayerParams(const Layer *layer); 125 DisplayError ValidateDimensions(const LayerRect &crop, const LayerRect &dst); 126 DisplayError ValidatePipeParams(HWPipeInfo *pipe_info, LayerBufferFormat format); 127 DisplayError ValidateDownScaling(float scale_x, float scale_y, bool ubwc_tiled); 128 DisplayError ValidateUpScaling(float scale_x, float scale_y); 129 DisplayError GetScaleFactor(const LayerRect &crop, const LayerRect &dst, float *scale_x, 130 float *scale_y); 131 DisplayError SetDecimationFactor(HWPipeInfo *pipe); 132 void SplitRect(const LayerRect &src_rect, const LayerRect &dst_rect, LayerRect *src_left, 133 LayerRect *dst_left, LayerRect *src_right, LayerRect *dst_right); 134 DisplayError AlignPipeConfig(const Layer *layer, HWPipeInfo *left_pipe, 135 HWPipeInfo *right_pipe); 136 void ResourceStateLog(void); 137 DisplayError CalculateDecimation(float downscale, uint8_t *decimation); 138 DisplayError GetScaleLutConfig(HWScaleLutInfo *lut_info); 139 140 Locker locker_; 141 HWResourceInfo hw_res_info_; 142 HWBlockContext hw_block_ctx_[kHWBlockMax]; 143 std::vector<SourcePipe> src_pipes_; 144 uint32_t num_pipe_ = 0; 145 }; 146 147 } // namespace sdm 148 149 #endif // __RESOURCE_DEFAULT_H__ 150 151