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); 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 ValidateCursorPosition(Handle display_ctx, HWLayers *hw_layers, int x, int y); 64 DisplayError SetMaxBandwidthMode(HWBwModes mode); 65 virtual DisplayError SetDetailEnhancerData(Handle display_ctx, 66 const DisplayDetailEnhancerData &de_data); 67 virtual DisplayError Perform(int cmd, ...) { return kErrorNone; } 68 69 private: 70 enum PipeOwner { 71 kPipeOwnerUserMode, // Pipe state when it is available for reservation 72 kPipeOwnerKernelMode, // Pipe state when pipe is owned by kernel 73 }; 74 75 // todo: retrieve all these from kernel 76 enum { 77 kMaxDecimationDownScaleRatio = 16, 78 }; 79 80 struct SourcePipe { 81 PipeType type; 82 PipeOwner owner; 83 uint32_t mdss_pipe_id; 84 uint32_t index; 85 HWBlockType hw_block_id; 86 int priority; 87 88 SourcePipe() : type(kPipeTypeUnused), owner(kPipeOwnerUserMode), mdss_pipe_id(0), 89 index(0), hw_block_id(kHWBlockMax), priority(0) { } 90 91 inline void ResetState() { hw_block_id = kHWBlockMax;} 92 }; 93 94 struct DisplayResourceContext { 95 HWDisplayAttributes display_attributes; 96 HWBlockType hw_block_id; 97 uint64_t frame_count; 98 HWMixerAttributes mixer_attributes; 99 100 DisplayResourceContext() : hw_block_id(kHWBlockMax), frame_count(0) { } 101 }; 102 103 struct HWBlockContext { 104 bool is_in_use; 105 HWBlockContext() : is_in_use(false) { } 106 }; 107 108 explicit ResourceDefault(const HWResourceInfo &hw_res_info); 109 DisplayError Init(); 110 DisplayError Deinit(); 111 uint32_t NextPipe(PipeType pipe_type, HWBlockType hw_block_id); 112 uint32_t SearchPipe(HWBlockType hw_block_id, SourcePipe *src_pipes, uint32_t num_pipe); 113 uint32_t GetPipe(HWBlockType hw_block_id, bool need_scale); 114 bool IsScalingNeeded(const HWPipeInfo *pipe_info); 115 DisplayError Config(DisplayResourceContext *display_resource_ctx, HWLayers *hw_layers); 116 DisplayError DisplaySplitConfig(DisplayResourceContext *display_resource_ctx, 117 const LayerRect &src_rect, const LayerRect &dst_rect, 118 HWLayerConfig *layer_config); 119 DisplayError SrcSplitConfig(DisplayResourceContext *display_resource_ctx, 120 const LayerRect &src_rect, const LayerRect &dst_rect, 121 HWLayerConfig *layer_config); 122 bool CalculateCropRects(const LayerRect &scissor, LayerRect *crop, LayerRect *dst); 123 DisplayError ValidateLayerParams(const Layer *layer); 124 DisplayError ValidateDimensions(const LayerRect &crop, const LayerRect &dst); 125 DisplayError ValidatePipeParams(HWPipeInfo *pipe_info, LayerBufferFormat format); 126 DisplayError ValidateDownScaling(float scale_x, float scale_y, bool ubwc_tiled); 127 DisplayError ValidateUpScaling(float scale_x, float scale_y); 128 DisplayError GetScaleFactor(const LayerRect &crop, const LayerRect &dst, float *scale_x, 129 float *scale_y); 130 DisplayError SetDecimationFactor(HWPipeInfo *pipe); 131 void SplitRect(const LayerRect &src_rect, const LayerRect &dst_rect, LayerRect *src_left, 132 LayerRect *dst_left, LayerRect *src_right, LayerRect *dst_right); 133 DisplayError AlignPipeConfig(const Layer *layer, HWPipeInfo *left_pipe, 134 HWPipeInfo *right_pipe); 135 void ResourceStateLog(void); 136 DisplayError CalculateDecimation(float downscale, uint8_t *decimation); 137 DisplayError GetScaleLutConfig(HWScaleLutInfo *lut_info); 138 139 Locker locker_; 140 HWResourceInfo hw_res_info_; 141 HWBlockContext hw_block_ctx_[kHWBlockMax]; 142 std::vector<SourcePipe> src_pipes_; 143 uint32_t num_pipe_ = 0; 144 }; 145 146 } // namespace sdm 147 148 #endif // __RESOURCE_DEFAULT_H__ 149 150