1 /*
2  * Copyright (c) 2023 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 "effect/runtime_effect.h"
17 
18 #include "impl_factory.h"
19 
20 namespace OHOS {
21 namespace Rosen {
22 namespace Drawing {
RuntimeEffect(const std::string & sl,const RuntimeEffectOptions & options)23 RuntimeEffect::RuntimeEffect(const std::string& sl, const RuntimeEffectOptions& options) noexcept : RuntimeEffect()
24 {
25     impl_->InitForShader(sl, options);
26 }
27 
RuntimeEffect(const std::string & sl)28 RuntimeEffect::RuntimeEffect(const std::string& sl) noexcept : RuntimeEffect()
29 {
30     impl_->InitForShader(sl);
31 }
32 
RuntimeEffect(const std::string & sl,const RuntimeEffectOptions & options,bool isES3)33 RuntimeEffect::RuntimeEffect(const std::string& sl, const RuntimeEffectOptions& options,
34     bool isES3) noexcept : RuntimeEffect()
35 {
36     impl_->InitForES3Shader(sl);
37 }
38 
RuntimeEffect(const std::string & sl,bool isBlender)39 RuntimeEffect::RuntimeEffect(const std::string& sl, bool isBlender) noexcept : RuntimeEffect()
40 {
41     impl_->InitForBlender(sl);
42 }
43 
RuntimeEffect()44 RuntimeEffect::RuntimeEffect() noexcept : impl_(ImplFactory::CreateRuntimeEffectImpl())
45 {}
46 
CreateForShader(const std::string & sl,const RuntimeEffectOptions & options)47 std::shared_ptr<RuntimeEffect> RuntimeEffect::CreateForShader(const std::string& sl,
48     const RuntimeEffectOptions& options)
49 {
50     return std::make_shared<RuntimeEffect>(sl, options);
51 }
52 
CreateForShader(const std::string & sl)53 std::shared_ptr<RuntimeEffect> RuntimeEffect::CreateForShader(const std::string& sl)
54 {
55     return std::make_shared<RuntimeEffect>(sl);
56 }
57 
CreateForES3Shader(const std::string & sl)58 std::shared_ptr<RuntimeEffect> RuntimeEffect::CreateForES3Shader(const std::string& sl)
59 {
60     return std::make_shared<RuntimeEffect>(sl, RuntimeEffectOptions(), true);
61 }
62 
CreateForBlender(const std::string & sl)63 std::shared_ptr<RuntimeEffect> RuntimeEffect::CreateForBlender(const std::string& sl)
64 {
65     return std::make_shared<RuntimeEffect>(sl, true);
66 }
67 
MakeShader(std::shared_ptr<Data> uniforms,std::shared_ptr<ShaderEffect> children[],size_t childCount,const Matrix * localMatrix,bool isOpaque)68 std::shared_ptr<ShaderEffect> RuntimeEffect::MakeShader(std::shared_ptr<Data> uniforms,
69     std::shared_ptr<ShaderEffect> children[], size_t childCount, const Matrix* localMatrix,
70     bool isOpaque)
71 {
72     return impl_->MakeShader(uniforms, children, childCount, localMatrix, isOpaque);
73 }
74 } // namespace Drawing
75 } // namespace Rosen
76 } // namespace OHOS