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 #ifndef RUNTIME_EFFECT_H 17 #define RUNTIME_EFFECT_H 18 19 #include "drawing/engine_adapter/impl_interface/runtime_effect_impl.h" 20 21 #include "effect/blender.h" 22 #include "effect/shader_effect.h" 23 #include "utils/data.h" 24 #include "utils/matrix.h" 25 26 namespace OHOS { 27 namespace Rosen { 28 namespace Drawing { 29 class RuntimeEffectOptions { 30 public: 31 bool forceNoInline = false; 32 bool useAF = false; 33 }; 34 35 class DRAWING_API RuntimeEffect { 36 public: 37 static std::shared_ptr<RuntimeEffect> CreateForShader(const std::string& sl, 38 const RuntimeEffectOptions&); 39 static std::shared_ptr<RuntimeEffect> CreateForShader(const std::string& sl); 40 static std::shared_ptr<RuntimeEffect> CreateForBlender(const std::string& sl); 41 42 explicit RuntimeEffect(const std::string& sl) noexcept; 43 RuntimeEffect(const std::string& sl, const RuntimeEffectOptions&) noexcept; 44 RuntimeEffect(const std::string& sl, bool isBlender) noexcept; 45 std::shared_ptr<ShaderEffect> MakeShader(std::shared_ptr<Data> uniforms, 46 std::shared_ptr<ShaderEffect> children[], 47 size_t childCount, const Matrix* localMatrix, 48 bool isOpaque); 49 virtual ~RuntimeEffect() = default; GetDrawingType()50 virtual DrawingType GetDrawingType() const 51 { 52 return DrawingType::COMMON; 53 } 54 55 template<typename T> GetImpl()56 T* GetImpl() const 57 { 58 return impl_->DowncastingTo<T>(); 59 } 60 61 protected: 62 RuntimeEffect() noexcept; 63 64 private: 65 std::shared_ptr<RuntimeEffectImpl> impl_; 66 }; 67 } // namespace Drawing 68 } // namespace Rosen 69 } // namespace OHOS 70 #endif 71