• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
16 #include "render/rs_complex_shader.h"
17 #include "common/rs_common_def.h"
18 #include "effect/runtime_shader_builder.h"
19 #include "ge_visual_effect_impl.h"
20 #include "platform/common/rs_log.h"
21 #include "ge_external_dynamic_loader.h"
22 #include "ext/gex_complex_shader.h"
23 
24 namespace OHOS {
25 namespace Rosen {
26 
RSComplexShader()27 RSComplexShader::RSComplexShader()
28 {
29     type_ = ShaderType::COMPLEX;
30 }
31 
RSComplexShader(GexComplexShaderType type)32 RSComplexShader::RSComplexShader(GexComplexShaderType type)
33     : shaderType_{type}
34 {
35     type_ = ShaderType::COMPLEX;
36 }
37 
MakeDrawingShader(const RectF & rect,const std::vector<float> & params)38 void RSComplexShader::MakeDrawingShader(const RectF &rect, const std::vector<float> &params)
39 {
40     shaderEffect_ =
41         GetShaderEffect(params, Drawing::Rect{rect.GetLeft(), rect.GetTop(), rect.GetWidth(), rect.GetHeight()});
42 }
43 
GetDrawingShader() const44 const std::shared_ptr<Drawing::ShaderEffect> &RSComplexShader::GetDrawingShader() const
45 {
46     return shaderEffect_;
47 }
48 
Marshalling(Parcel & parcel)49 bool RSComplexShader::Marshalling(Parcel &parcel)
50 {
51     return parcel.WriteUint32(static_cast<uint32_t>(shaderType_));
52 }
53 
Unmarshalling(Parcel & parcel,bool & needReset)54 bool RSComplexShader::Unmarshalling(Parcel &parcel, bool &needReset)
55 {
56     auto type = parcel.ReadUint32();
57     if (type < static_cast<uint32_t>(GexComplexShaderType::MAX)) {
58         shaderType_ = static_cast<GexComplexShaderType>(type);
59         return true;
60     }
61     return false;
62 }
63 
GetShaderEffect(const std::vector<float> & effectParam,const Drawing::RectF & rect)64 std::shared_ptr<Drawing::ShaderEffect> RSComplexShader::GetShaderEffect(
65     const std::vector<float> &effectParam, const Drawing::RectF &rect)
66 {
67     auto shader = GEXComplexShader::CreateDynamicImpl(GEXComplexShaderParams{shaderType_, effectParam});
68     if (shader == nullptr) {
69         return nullptr;
70     }
71     shader->MakeDrawingShader(rect, 0);
72     return shader->GetDrawingShader();
73 }
74 
GetShaderType() const75 GexComplexShaderType RSComplexShader::GetShaderType() const
76 {
77     return shaderType_;
78 }
79 
80 }  // namespace Rosen
81 }  // namespace OHOS
82