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 SKIA_RUNTIME_EFFECT_H 17 #define SKIA_RUNTIME_EFFECT_H 18 19 #include "include/effects/SkRuntimeEffect.h" 20 #include "src/core/SkRuntimeEffectPriv.h" 21 22 #include "effect/blender.h" 23 #include "effect/shader_effect.h" 24 #include "impl_interface/runtime_effect_impl.h" 25 #include "utils/data.h" 26 #include "utils/matrix.h" 27 28 namespace OHOS { 29 namespace Rosen { 30 namespace Drawing { 31 class SkiaRuntimeEffect : public RuntimeEffectImpl { 32 public: 33 static inline constexpr AdapterType TYPE = AdapterType::SKIA_ADAPTER; 34 static void GlslToSksl(std::string& sksl, std::string& glsl); 35 36 SkiaRuntimeEffect() noexcept; ~SkiaRuntimeEffect()37 ~SkiaRuntimeEffect() override {}; 38 GetType()39 AdapterType GetType() const override 40 { 41 return AdapterType::SKIA_ADAPTER; 42 } 43 44 void InitForShader(const std::string& sl, const RuntimeEffectOptions& options) override; 45 void InitForShader(const std::string& sl) override; 46 void InitForES3Shader(const std::string& sl) override; 47 void InitForBlender(const std::string& sl) override; 48 std::shared_ptr<ShaderEffect> MakeShader(std::shared_ptr<Data> uniforms, 49 std::shared_ptr<ShaderEffect> children[], size_t childCount, 50 const Matrix* localMatrix, bool isOpaque) override; 51 sk_sp<SkRuntimeEffect> GetRuntimeEffect() const; 52 /* 53 * @brief Update the member variable to SkRuntimeEffect, adaptation layer calls. 54 */ 55 void SetRuntimeEffect(const sk_sp<SkRuntimeEffect>& skRuntimeEffect); 56 57 private: 58 sk_sp<SkRuntimeEffect> skRuntimeEffect_; 59 }; 60 } // namespace Drawing 61 } // namespace Rosen 62 } // namespace OHOS 63 #endif