1 /*
2 * Copyright (c) 2019-2020, 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 //!
24 //! \file hw_filter.cpp
25 //! \brief Defines the common interface for vp features manager
26 //! \details The vp manager is further sub-divided by vp type
27 //! this file is for the base interface which is shared by all components.
28 //!
29 #include "hw_filter.h"
30 #include "sw_filter_pipe.h"
31 #include "vp_obj_factories.h"
32 #include "vp_pipeline.h"
33
34 using namespace vp;
35
36 /****************************************************************************************************/
37 /* HwFilter */
38 /****************************************************************************************************/
39
HwFilter(VpInterface & vpInterface,EngineType type)40 HwFilter::HwFilter(VpInterface &vpInterface,EngineType type) : m_vpInterface(vpInterface)
41 {
42 m_Params.Type = type;
43 }
44
~HwFilter()45 HwFilter::~HwFilter()
46 {
47 Clean();
48 }
49
Initialize(HW_FILTER_PARAMS & param)50 MOS_STATUS HwFilter::Initialize(HW_FILTER_PARAMS ¶m)
51 {
52 VP_FUNC_CALL();
53
54 bool bRet = true;
55
56 Clean();
57
58 m_swFilterPipe = param.executedFilters;
59 m_vpExecuteCaps = param.vpExecuteCaps;
60 m_Params.Type = param.Type;
61
62 // Clear executedFilters, which will be destroyed during hwFilter destroying.
63 param.executedFilters = nullptr;
64
65 std::vector<HwFilterParameter *>::iterator it = param.Params.begin();
66 for (; it != param.Params.end(); ++it)
67 {
68 VP_PUBLIC_CHK_STATUS_RETURN((*it)->ConfigParams(*this));
69 }
70 return MOS_STATUS_SUCCESS;
71 }
72
ConfigParam(HW_FILTER_PARAM & param)73 MOS_STATUS HwFilter::ConfigParam(HW_FILTER_PARAM& param)
74 {
75 VP_FUNC_CALL();
76
77 if (!param.pfnCreatePacketParam)
78 {
79 VP_PUBLIC_ASSERTMESSAGE("Create packet params function is Null, return invalid params");
80 return MOS_STATUS_INVALID_PARAMETER;
81 }
82
83 VpPacketParameter* p = param.pfnCreatePacketParam(param);
84 VP_PUBLIC_CHK_NULL_RETURN(p);
85 m_Params.Params.push_back(p);
86 return MOS_STATUS_SUCCESS;
87 }
88
Clean()89 MOS_STATUS HwFilter::Clean()
90 {
91 VP_FUNC_CALL();
92
93 std::vector<VpPacketParameter *>::iterator it = m_Params.Params.begin();
94 for (; it != m_Params.Params.end(); ++it)
95 {
96 VpPacketParameter *p = *it;
97 VpPacketParameter::Destory(p);
98 }
99 m_Params.Params.clear();
100
101 m_vpInterface.GetSwFilterPipeFactory().Destory(m_swFilterPipe);
102
103 return MOS_STATUS_SUCCESS;
104 }
105
GetRenderTargetType()106 RenderTargetType HwFilter::GetRenderTargetType()
107 {
108 VP_FUNC_CALL();
109
110 if (m_swFilterPipe)
111 {
112 return m_swFilterPipe->GetRenderTargetType();
113 }
114 else
115 {
116 return RenderTargetTypeInvalid;
117 }
118 }
119
120 /****************************************************************************************************/
121 /* HwFilterVebox */
122 /****************************************************************************************************/
123
HwFilterVebox(VpInterface & vpInterface)124 HwFilterVebox::HwFilterVebox(VpInterface &vpInterface) : HwFilter(vpInterface, EngineTypeVebox)
125 {
126 }
127
HwFilterVebox(VpInterface & vpInterface,EngineType type)128 HwFilterVebox::HwFilterVebox(VpInterface &vpInterface, EngineType type) : HwFilter(vpInterface, type)
129 {
130 }
131
~HwFilterVebox()132 HwFilterVebox::~HwFilterVebox()
133 {
134 }
135
SetPacketParams(VpCmdPacket & packet)136 MOS_STATUS HwFilterVebox::SetPacketParams(VpCmdPacket &packet)
137 {
138 VP_FUNC_CALL();
139
140 bool bRet = true;
141
142 PVPHAL_SURFACE pSrcSurface = nullptr;
143 PVPHAL_SURFACE pOutputSurface = nullptr;
144
145 VP_PUBLIC_CHK_NULL_RETURN(m_swFilterPipe);
146 VP_SURFACE *inputSurf = m_swFilterPipe->GetSurface(true, 0);
147 VP_SURFACE *outputSurf = m_swFilterPipe->GetSurface(false, 0);
148 // previousSurf can be nullptr;
149 VP_SURFACE *previousSurf = m_swFilterPipe->GetPastSurface(0);
150 auto &surfSetting = m_swFilterPipe->GetSurfacesSetting();
151 VP_PUBLIC_CHK_NULL_RETURN(inputSurf);
152 VP_PUBLIC_CHK_NULL_RETURN(outputSurf);
153 VP_PUBLIC_CHK_STATUS_RETURN(packet.PacketInit(inputSurf, outputSurf,
154 previousSurf, surfSetting, m_vpExecuteCaps));
155
156 for (auto handler : m_Params.Params)
157 {
158 if (handler)
159 {
160 bRet = handler->SetPacketParam(&packet) && bRet;
161 }
162 }
163 return bRet ? MOS_STATUS_SUCCESS : MOS_STATUS_UNKNOWN;
164 }
165
166 /****************************************************************************************************/
167 /* HwFilterVeboxSfc */
168 /****************************************************************************************************/
169
HwFilterVeboxSfc(VpInterface & vpInterface)170 HwFilterVeboxSfc::HwFilterVeboxSfc(VpInterface &vpInterface) : HwFilterVebox(vpInterface, EngineTypeVeboxSfc)
171 {}
172
~HwFilterVeboxSfc()173 HwFilterVeboxSfc::~HwFilterVeboxSfc()
174 {}
175
SetPacketParams(VpCmdPacket & packet)176 MOS_STATUS HwFilterVeboxSfc::SetPacketParams(VpCmdPacket &packet)
177 {
178 VP_FUNC_CALL();
179
180 return HwFilterVebox::SetPacketParams(packet);
181 }
182
183 /****************************************************************************************************/
184 /* HwFilterRender */
185 /****************************************************************************************************/
186
HwFilterRender(VpInterface & vpInterface)187 HwFilterRender::HwFilterRender(VpInterface &vpInterface) : HwFilter(vpInterface, EngineTypeRender)
188 {}
189
~HwFilterRender()190 HwFilterRender::~HwFilterRender()
191 {}
192
SetPacketParams(VpCmdPacket & packet)193 MOS_STATUS HwFilterRender::SetPacketParams(VpCmdPacket &packet)
194 {
195 VP_FUNC_CALL();
196
197 bool bRet = true;
198
199 PVPHAL_SURFACE pSrcSurface = nullptr;
200 PVPHAL_SURFACE pOutputSurface = nullptr;
201
202 // Remove dependence on vphal surface later.
203 VP_PUBLIC_CHK_NULL_RETURN(m_swFilterPipe);
204 VP_SURFACE* inputSurf = m_swFilterPipe->GetSurface(true, 0);
205 VP_SURFACE* outputSurf = m_swFilterPipe->GetSurface(false, 0);
206 // previousSurf can be nullptr;
207 VP_SURFACE* previousSurf = m_swFilterPipe->GetPastSurface(0);
208 auto& surfSetting = m_swFilterPipe->GetSurfacesSetting();
209
210 // There exist some features without input surface.
211 if (inputSurf == nullptr)
212 {
213 VP_PUBLIC_NORMALMESSAGE("No render input!");
214 }
215 VP_PUBLIC_CHK_NULL_RETURN(outputSurf);
216 VP_PUBLIC_CHK_STATUS_RETURN(packet.PacketInit(inputSurf, outputSurf,
217 previousSurf, surfSetting, m_vpExecuteCaps));
218
219 for (auto handler : m_Params.Params)
220 {
221 if (handler)
222 {
223 bRet = handler->SetPacketParam(&packet) && bRet;
224 }
225 }
226 return bRet ? MOS_STATUS_SUCCESS : MOS_STATUS_UNKNOWN;
227 }
228