1 /*
2 * Copyright (c) 2025 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 #include "render/rs_border_light_shader.h"
16 #include "platform/common/rs_log.h"
17 #include "ge_border_light_shader.h"
18 #include "ge_visual_effect_impl.h"
19
20 namespace OHOS {
21 namespace Rosen {
22
RSBorderLightShader()23 RSBorderLightShader::RSBorderLightShader()
24 {
25 type_ = ShaderType::BORDER_LIGHT;
26 }
27
RSBorderLightShader(const RSBorderLightParams & borderLightParam)28 RSBorderLightShader::RSBorderLightShader(const RSBorderLightParams& borderLightParam)
29 {
30 borderLightParam_ = borderLightParam;
31 type_ = ShaderType::BORDER_LIGHT;
32 }
33
MakeDrawingShader(const RectF & rect,float progress)34 void RSBorderLightShader::MakeDrawingShader(const RectF& rect, float progress)
35 {
36 Drawing::Rect drawingRect = Drawing::Rect(rect.GetLeft(), rect.GetTop(), rect.GetRight(), rect.GetBottom());
37 if (geShader_) {
38 geShader_->MakeDrawingShader(drawingRect, progress);
39 }
40 }
41
GetDrawingShader() const42 const std::shared_ptr<Drawing::ShaderEffect>& RSBorderLightShader::GetDrawingShader() const
43 {
44 if (geShader_) {
45 return geShader_->GetDrawingShader();
46 }
47 return RSShader::GetDrawingShader();
48 }
49
SetRSBorderLightParams(const RSBorderLightParams & borderLightParam)50 void RSBorderLightShader::SetRSBorderLightParams(const RSBorderLightParams& borderLightParam)
51 {
52 borderLightParam_ = borderLightParam;
53 if (geShader_ == nullptr) {
54 return;
55 }
56 }
57
SetRotationAngle(const Vector3f & rotationAngle)58 void RSBorderLightShader::SetRotationAngle(const Vector3f& rotationAngle)
59 {
60 borderLightParam_.rotationAngle_ = rotationAngle;
61 }
62
SetCornerRadius(float cornerRadius)63 void RSBorderLightShader::SetCornerRadius(float cornerRadius)
64 {
65 borderLightParam_.cornerRadius_ = cornerRadius;
66 }
67
Marshalling(Parcel & parcel)68 bool RSBorderLightShader::Marshalling(Parcel& parcel)
69 {
70 if (!RSMarshallingHelper::Marshalling(parcel, borderLightParam_.lightPosition_)
71 || !RSMarshallingHelper::Marshalling(parcel, borderLightParam_.lightColor_)
72 || !RSMarshallingHelper::Marshalling(parcel, borderLightParam_.lightIntensity_)
73 || !RSMarshallingHelper::Marshalling(parcel, borderLightParam_.lightWidth_)) {
74 ROSEN_LOGE("unirender: RSBorderLightShader::Marshalling failed");
75 return false;
76 }
77 return true;
78 }
79
Unmarshalling(Parcel & parcel,bool & needReset)80 bool RSBorderLightShader::Unmarshalling(Parcel& parcel, bool& needReset)
81 {
82 needReset = false;
83 bool unmarshallingFailed = !RSMarshallingHelper::Unmarshalling(parcel, borderLightParam_.lightPosition_)
84 || !RSMarshallingHelper::Unmarshalling(parcel, borderLightParam_.lightColor_)
85 || !RSMarshallingHelper::Unmarshalling(parcel, borderLightParam_.lightIntensity_)
86 || !RSMarshallingHelper::Unmarshalling(parcel, borderLightParam_.lightWidth_);
87 if (unmarshallingFailed) {
88 ROSEN_LOGE("unirender: RSBorderLightShader::Unmarshalling failed");
89 return false;
90 }
91 return true;
92 }
93
94 } // namespace Rosen
95 } // namespace OHOS