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 #include <utils/constants.h> 26 #include <utils/debug.h> 27 28 #include "strategy.h" 29 30 #define __CLASS__ "Strategy" 31 32 namespace sdm { 33 34 Strategy::Strategy(ExtensionInterface *extension_intf, DisplayType type, 35 const HWResourceInfo &hw_resource_info, const HWPanelInfo &hw_panel_info, 36 const HWMixerAttributes &mixer_attributes, 37 const HWDisplayAttributes &display_attributes, 38 const DisplayConfigVariableInfo &fb_config) 39 : extension_intf_(extension_intf), display_type_(type), hw_resource_info_(hw_resource_info), 40 hw_panel_info_(hw_panel_info), mixer_attributes_(mixer_attributes), 41 display_attributes_(display_attributes), fb_config_(fb_config) { 42 } 43 44 DisplayError Strategy::Init() { 45 DisplayError error = kErrorNone; 46 47 if (extension_intf_) { 48 error = extension_intf_->CreateStrategyExtn(display_type_, hw_panel_info_.mode, 49 hw_panel_info_.s3d_mode, mixer_attributes_, 50 fb_config_, &strategy_intf_); 51 if (error != kErrorNone) { 52 DLOGE("Failed to create strategy"); 53 return error; 54 } 55 56 error = extension_intf_->CreatePartialUpdate(display_type_, hw_resource_info_, hw_panel_info_, 57 mixer_attributes_, display_attributes_, 58 &partial_update_intf_); 59 } 60 61 return kErrorNone; 62 } 63 64 DisplayError Strategy::Deinit() { 65 if (strategy_intf_) { 66 if (partial_update_intf_) { 67 extension_intf_->DestroyPartialUpdate(partial_update_intf_); 68 } 69 70 extension_intf_->DestroyStrategyExtn(strategy_intf_); 71 } 72 73 return kErrorNone; 74 } 75 76 DisplayError Strategy::Start(HWLayersInfo *hw_layers_info, uint32_t *max_attempts, 77 bool partial_update_enable) { 78 DisplayError error = kErrorNone; 79 80 hw_layers_info_ = hw_layers_info; 81 extn_start_success_ = false; 82 tried_default_ = false; 83 84 if (partial_update_intf_) { 85 partial_update_intf_->ControlPartialUpdate(partial_update_enable); 86 } 87 GenerateROI(); 88 89 if (strategy_intf_) { 90 error = strategy_intf_->Start(hw_layers_info_, max_attempts); 91 if (error == kErrorNone) { 92 extn_start_success_ = true; 93 return kErrorNone; 94 } 95 } 96 97 *max_attempts = 1; 98 99 return kErrorNone; 100 } 101 102 DisplayError Strategy::Stop() { 103 if (strategy_intf_) { 104 return strategy_intf_->Stop(); 105 } 106 107 return kErrorNone; 108 } 109 110 DisplayError Strategy::GetNextStrategy(StrategyConstraints *constraints) { 111 DisplayError error = kErrorNone; 112 113 if (extn_start_success_) { 114 error = strategy_intf_->GetNextStrategy(constraints); 115 if (error == kErrorNone) { 116 return kErrorNone; 117 } 118 } 119 120 // Default composition is not possible if GPU composition is not supported. 121 if (!hw_layers_info_->gpu_target_index) { 122 return kErrorNotSupported; 123 } 124 125 // Default composition is already tried. 126 if (tried_default_) { 127 return kErrorUndefined; 128 } 129 130 // Mark all application layers for GPU composition. Find GPU target buffer and store its index for 131 // programming the hardware. 132 LayerStack *layer_stack = hw_layers_info_->stack; 133 uint32_t &hw_layer_count = hw_layers_info_->count; 134 hw_layer_count = 0; 135 136 for (uint32_t i = 0; i < hw_layers_info_->app_layer_count; i++) { 137 layer_stack->layers.at(i)->composition = kCompositionGPU; 138 } 139 140 Layer *gpu_target_layer = layer_stack->layers.at(hw_layers_info_->gpu_target_index); 141 hw_layers_info_->updated_src_rect[hw_layer_count] = gpu_target_layer->src_rect; 142 hw_layers_info_->updated_dst_rect[hw_layer_count] = gpu_target_layer->dst_rect; 143 hw_layers_info_->index[hw_layer_count++] = hw_layers_info_->gpu_target_index; 144 145 tried_default_ = true; 146 147 return kErrorNone; 148 } 149 150 void Strategy::GenerateROI() { 151 bool split_display = false; 152 153 if (partial_update_intf_ && partial_update_intf_->GenerateROI(hw_layers_info_) == kErrorNone) { 154 return; 155 } 156 157 float layer_mixer_width = mixer_attributes_.width; 158 float layer_mixer_height = mixer_attributes_.height; 159 160 if (!hw_resource_info_.is_src_split && 161 ((layer_mixer_width > hw_resource_info_.max_mixer_width) || 162 ((hw_panel_info_.is_primary_panel) && hw_panel_info_.split_info.right_split))) { 163 split_display = true; 164 } 165 166 if (split_display) { 167 float left_split = FLOAT(mixer_attributes_.split_left); 168 hw_layers_info_->left_partial_update = (LayerRect) {0.0f, 0.0f, left_split, layer_mixer_height}; 169 hw_layers_info_->right_partial_update = (LayerRect) {left_split, 0.0f, layer_mixer_width, 170 layer_mixer_height}; 171 } else { 172 hw_layers_info_->left_partial_update = (LayerRect) {0.0f, 0.0f, layer_mixer_width, 173 layer_mixer_height}; 174 hw_layers_info_->right_partial_update = (LayerRect) {0.0f, 0.0f, 0.0f, 0.0f}; 175 } 176 } 177 178 DisplayError Strategy::Reconfigure(const HWPanelInfo &hw_panel_info, 179 const HWDisplayAttributes &display_attributes, 180 const HWMixerAttributes &mixer_attributes, 181 const DisplayConfigVariableInfo &fb_config) { 182 hw_panel_info_ = hw_panel_info; 183 display_attributes_ = display_attributes; 184 mixer_attributes_ = mixer_attributes; 185 186 if (!extension_intf_) { 187 return kErrorNone; 188 } 189 190 // TODO(user): PU Intf will not be created for video mode panels, hence re-evaluate if 191 // reconfigure is needed. 192 if (partial_update_intf_) { 193 extension_intf_->DestroyPartialUpdate(partial_update_intf_); 194 partial_update_intf_ = NULL; 195 } 196 197 extension_intf_->CreatePartialUpdate(display_type_, hw_resource_info_, hw_panel_info_, 198 mixer_attributes_, display_attributes_, 199 &partial_update_intf_); 200 201 return strategy_intf_->Reconfigure(hw_panel_info_.mode, hw_panel_info_.s3d_mode, mixer_attributes, 202 fb_config); 203 } 204 205 } // namespace sdm 206