1 /*
2 * Copyright (c) 2024 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 "ge_visual_effect_container.h"
17
18 #include "ge_log.h"
19 #include "ge_visual_effect_impl.h"
20
21 namespace OHOS {
22 namespace Rosen {
23 namespace Drawing {
24
GEVisualEffectContainer()25 GEVisualEffectContainer::GEVisualEffectContainer() {}
26
AddToChainedFilter(std::shared_ptr<Drawing::GEVisualEffect> visualEffect)27 void GEVisualEffectContainer::AddToChainedFilter(std::shared_ptr<Drawing::GEVisualEffect> visualEffect)
28 {
29 if (!visualEffect) {
30 LOGD("GEVisualEffectContainer::AddToChainedFilter visualEffect is nullptr");
31 return;
32 }
33 LOGD("GEVisualEffectContainer::AddToChainedFilter %{public}s", visualEffect->GetName().c_str());
34 filterVec_.push_back(visualEffect);
35 }
36
UpdateCacheDataFrom(const std::shared_ptr<GEVisualEffectContainer> & ge)37 void GEVisualEffectContainer::UpdateCacheDataFrom(const std::shared_ptr<GEVisualEffectContainer>& ge)
38 {
39 if (ge == nullptr) {
40 return;
41 }
42 for (auto vef : ge->GetFilters()) {
43 if (vef == nullptr || vef->GetImpl() == nullptr) {
44 LOGD("GEVisualEffectContainer::UpdateCacheDataFrom vef is null");
45 continue;
46 }
47 auto vefTarget = GetGEVisualEffect(vef->GetName());
48 if (vefTarget == nullptr || vefTarget->GetImpl() == nullptr) {
49 LOGD("GEVisualEffectContainer::UpdateCacheDataFrom ve is null");
50 continue;
51 }
52 vefTarget->GetImpl()->SetCache(vef->GetImpl()->GetCache());
53 }
54 }
55
GetGEVisualEffect(const std::string & name)56 std::shared_ptr<GEVisualEffect> GEVisualEffectContainer::GetGEVisualEffect(const std::string& name)
57 {
58 for (auto vef : filterVec_) {
59 if (vef == nullptr) {
60 LOGD("GEVisualEffectContainer::GetGEVisualEffect vef is null");
61 continue;
62 }
63 if (vef->GetName() == name) {
64 return vef;
65 }
66 }
67 return nullptr;
68 }
69
70
SetGeometry(const Drawing::Canvas & canvas,float geoWidth,float geoHeight)71 void GEVisualEffectContainer::SetGeometry(const Drawing::Canvas& canvas, float geoWidth, float geoHeight)
72 {
73 auto dst = canvas.GetDeviceClipBounds();
74 Drawing::CanvasInfo info { std::ceil(geoWidth), std::ceil(geoHeight),
75 dst.GetLeft(), dst.GetTop(), canvas.GetTotalMatrix() };
76 for (auto vef : GetFilters()) {
77 if (vef) {
78 vef->SetCanvasInfo(info);
79 }
80 }
81 }
82
SetDisplayHeadroom(float headroom)83 void GEVisualEffectContainer::SetDisplayHeadroom(float headroom)
84 {
85 for (auto vef : GetFilters()) {
86 if (vef) {
87 vef->SetSupportHeadroom(headroom);
88 }
89 }
90 }
91 } // namespace Drawing
92 } // namespace Rosen
93 } // namespace OHOS
94