1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "rs_trace.h"
17 #include "filter.h"
18 
19 namespace OHOS {
20 namespace Rosen {
Process(ProcessData & data)21 bool Filter::Process(ProcessData& data)
22 {
23     ROSEN_TRACE_BEGIN(HITRACE_TAG_GRAPHIC_AGP, "Filter::DoProcess");
24     DoProcess(data);
25     ROSEN_TRACE_END(HITRACE_TAG_GRAPHIC_AGP);
26     if (this->GetFilterType() == FILTER_TYPE::ALGOFILTER) {
27         std::swap(data.srcTextureID, data.dstTextureID);
28     }
29     if (data.textureWidth == 0 || data.textureHeight == 0) {
30         return false;
31     }
32     if (GetNextFilter() != nullptr) {
33         GetNextFilter()->Process(data);
34     }
35     return true;
36 }
37 
AddNextFilter(std::shared_ptr<Filter> next)38 void Filter::AddNextFilter(std::shared_ptr<Filter> next)
39 {
40     if (nextNum_ < nextPtrMax_) {
41         next_ = next;
42     }
43     if (nextNum_ == nextPtrMax_) {
44         return;
45     }
46     nextNum_++;
47 }
48 
AddPreviousFilter(std::shared_ptr<Filter> previous)49 void Filter::AddPreviousFilter(std::shared_ptr<Filter> previous)
50 {
51     if (preNum_ < prePtrMax_) {
52         previous_ = previous;
53     }
54     if (preNum_ == prePtrMax_) {
55         return;
56     }
57     preNum_++;
58 }
59 
GetNextFilter()60 std::shared_ptr<Filter> Filter::GetNextFilter()
61 {
62     return next_;
63 }
64 
GetPreviousFilter()65 std::shared_ptr<Filter> Filter::GetPreviousFilter()
66 {
67     return previous_;
68 }
69 
GetInputNumber()70 int Filter::GetInputNumber()
71 {
72     return preNum_;
73 }
74 
GetOutputNumber()75 int Filter::GetOutputNumber()
76 {
77     return nextNum_;
78 }
79 
GetMaxInputNumber()80 int Filter::GetMaxInputNumber()
81 {
82     return prePtrMax_;
83 }
84 
GetMaxOutputNumber()85 int Filter::GetMaxOutputNumber()
86 {
87     return nextPtrMax_;
88 }
89 } // namespcae Rosen
90 } // namespace OHOS