xref: /aosp_15_r20/external/intel-media-driver/media_softlet/agnostic/common/vp/hal/features/vp_filter.cpp (revision ba62d9d3abf0e404f2022b4cd7a85e107f48596f)
1 /*
2 * Copyright (c) 2018-2021, Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included
12 * in all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 */
22 //!
23 //! \file     vp_fliter.cpp
24 //! \brief    Defines the common interface for vp filters
25 //!           this file is for the base interface which is shared by all features.
26 //!
27 
28 #include "vp_filter.h"
29 #include "sw_filter_pipe.h"
30 #include "sw_filter.h"
31 #include "vp_feature_caps.h"
32 
33 using namespace vp;
34 /****************************************************************************************************/
35 /*                                      VpFilter                                                      */
36 /****************************************************************************************************/
VpFilter(PVP_MHWINTERFACE vpMhwInterface)37 VpFilter::VpFilter(PVP_MHWINTERFACE vpMhwInterface) :
38     m_pvpMhwInterface(vpMhwInterface)
39 {
40 
41 }
42 
43 /****************************************************************************************************/
44 /*                                     HwFilter Parameters                                          */
45 /****************************************************************************************************/
HwFilterParameter(FeatureType featureType)46 HwFilterParameter::HwFilterParameter(FeatureType featureType) : m_FeatureType(featureType)
47 {
48 }
49 
~HwFilterParameter()50 HwFilterParameter::~HwFilterParameter()
51 {
52 }
53 
54 /****************************************************************************************************/
55 /*                                      Packet Parameters                                           */
56 /****************************************************************************************************/
VpPacketParameter(PacketParamFactoryBase * packetParamFactory)57 VpPacketParameter::VpPacketParameter(PacketParamFactoryBase *packetParamFactory) : m_packetParamFactory(packetParamFactory)
58 {
59 }
60 
~VpPacketParameter()61 VpPacketParameter::~VpPacketParameter()
62 {
63 }
64 
Destory(VpPacketParameter * & p)65 void VpPacketParameter::Destory(VpPacketParameter *&p)
66 {
67     VP_FUNC_CALL();
68 
69     if (nullptr == p)
70     {
71         return;
72     }
73 
74     PacketParamFactoryBase *packetParamFactory = p->m_packetParamFactory;
75     if (nullptr == packetParamFactory)
76     {
77         MOS_Delete(p);
78         return;
79     }
80 
81     packetParamFactory->ReturnPacketParameter(p);
82 }
83 
84 /****************************************************************************************************/
85 /*                                  Policy Feature Handler                                          */
86 /****************************************************************************************************/
PolicyFeatureHandler(VP_HW_CAPS & hwCaps)87 PolicyFeatureHandler::PolicyFeatureHandler(VP_HW_CAPS &hwCaps) : m_hwCaps(hwCaps)
88 {
89 }
90 
~PolicyFeatureHandler()91 PolicyFeatureHandler::~PolicyFeatureHandler()
92 {
93     while(!m_Pool.empty())
94     {
95         HwFilterParameter *p = m_Pool.back();
96         m_Pool.pop_back();
97         MOS_Delete(p);
98     }
99 }
100 
IsFeatureEnabled(SwFilterPipe & swFilterPipe)101 bool PolicyFeatureHandler::IsFeatureEnabled(SwFilterPipe &swFilterPipe)
102 {
103     VP_FUNC_CALL();
104 
105     return false;
106 }
107 
CreateHwFilterParam(VP_EXECUTE_CAPS vpExecuteCaps,SwFilterPipe & swFilterPipe,PVP_MHWINTERFACE pHwInterface)108 HwFilterParameter *PolicyFeatureHandler::CreateHwFilterParam(VP_EXECUTE_CAPS vpExecuteCaps, SwFilterPipe &swFilterPipe, PVP_MHWINTERFACE pHwInterface)
109 {
110     VP_FUNC_CALL();
111 
112     return nullptr;
113 }
114 
UpdateFeaturePipe(VP_EXECUTE_CAPS caps,SwFilter & feature,SwFilterPipe & featurePipe,SwFilterPipe & executePipe,bool isInputPipe,int index)115 MOS_STATUS PolicyFeatureHandler::UpdateFeaturePipe(VP_EXECUTE_CAPS caps, SwFilter &feature, SwFilterPipe &featurePipe, SwFilterPipe &executePipe, bool isInputPipe, int index)
116 {
117     VP_FUNC_CALL();
118 
119     if (isInputPipe)
120     {
121         featurePipe.RemoveSwFilter(&feature);
122         executePipe.AddSwFilterUnordered(&feature, isInputPipe, index);
123     }
124     else
125     {
126         bool removeFeatureFromFeaturePipe = featurePipe.IsAllInputPipeSurfaceFeatureEmpty();
127         if (removeFeatureFromFeaturePipe)
128         {
129             featurePipe.RemoveSwFilter(&feature);
130             executePipe.AddSwFilterUnordered(&feature, isInputPipe, index);
131         }
132         else
133         {
134             SwFilter *swFilter = feature.Clone();
135             executePipe.AddSwFilterUnordered(swFilter, isInputPipe, index);
136             feature.ResetFeatureType();
137         }
138     }
139     return MOS_STATUS_SUCCESS;
140 }
141 
UpdateUnusedFeature(VP_EXECUTE_CAPS caps,SwFilter & feature,SwFilterPipe & featurePipe,SwFilterPipe & executePipe,bool isInputPipe,int index)142 MOS_STATUS PolicyFeatureHandler::UpdateUnusedFeature(VP_EXECUTE_CAPS caps, SwFilter &feature, SwFilterPipe &featurePipe, SwFilterPipe &executePipe, bool isInputPipe, int index)
143 {
144     VP_FUNC_CALL();
145     return MOS_STATUS_SUCCESS;
146 }
147 
IsFeatureEnabled(VP_EXECUTE_CAPS vpExecuteCaps)148 bool PolicyFeatureHandler::IsFeatureEnabled(VP_EXECUTE_CAPS vpExecuteCaps)
149 {
150     VP_FUNC_CALL();
151 
152     return false;
153 }
154 
GetType()155 FeatureType PolicyFeatureHandler::GetType()
156 {
157     VP_FUNC_CALL();
158 
159     return m_Type;
160 }
161 
GetHwFeatureParameterFromPool()162 HwFilterParameter *PolicyFeatureHandler::GetHwFeatureParameterFromPool()
163 {
164     VP_FUNC_CALL();
165 
166     if (m_Pool.empty())
167     {
168         return nullptr;
169     }
170     HwFilterParameter *p = m_Pool.back();
171     m_Pool.pop_back();
172     return p;
173 }
174 
ReleaseHwFeatureParameter(HwFilterParameter * & pParam)175 MOS_STATUS PolicyFeatureHandler::ReleaseHwFeatureParameter(HwFilterParameter *&pParam)
176 {
177     VP_FUNC_CALL();
178 
179     VP_PUBLIC_CHK_NULL_RETURN(pParam);
180     m_Pool.push_back(pParam);
181     pParam = nullptr;
182     return MOS_STATUS_SUCCESS;
183 }
184 
185 /****************************************************************************************************/
186 /*                                  Packet Param Factory Base                                       */
187 /****************************************************************************************************/
PacketParamFactoryBase()188 PacketParamFactoryBase::PacketParamFactoryBase()
189 {
190 }
191 
~PacketParamFactoryBase()192 PacketParamFactoryBase::~PacketParamFactoryBase()
193 {
194     while (!m_Pool.empty())
195     {
196         VpPacketParameter *p = m_Pool.back();
197         m_Pool.pop_back();
198         MOS_Delete(p);
199     }
200 }
201 
GetPacketParameter(PVP_MHWINTERFACE pHwInterface)202 VpPacketParameter *PacketParamFactoryBase::GetPacketParameter(PVP_MHWINTERFACE pHwInterface)
203 {
204     VP_FUNC_CALL();
205 
206     return nullptr;
207 }
208 
ReturnPacketParameter(VpPacketParameter * & p)209 void PacketParamFactoryBase::ReturnPacketParameter(VpPacketParameter *&p)
210 {
211     VP_FUNC_CALL();
212 
213     if (p)
214     {
215         m_Pool.push_back(p);
216         p = nullptr;
217     }
218 }
219