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_SHADER_BUILDER_H 17 #define SKIA_RUNTIME_SHADER_BUILDER_H 18 19 #include "include/effects/SkRuntimeEffect.h" 20 21 #include "skia_gpu_context.h" 22 #include "skia_shader_effect.h" 23 24 #include "impl_interface/runtime_shader_builder_impl.h" 25 26 namespace OHOS { 27 namespace Rosen { 28 namespace Drawing { 29 class RuntimeEffect; 30 class Image; 31 class DRAWING_API SkiaRuntimeShaderBuilder : public RuntimeShaderBuilderImpl { 32 public: 33 static inline constexpr AdapterType TYPE = AdapterType::SKIA_ADAPTER; 34 35 SkiaRuntimeShaderBuilder() noexcept = default; 36 SkiaRuntimeShaderBuilder(std::shared_ptr<RuntimeEffect>) noexcept; ~SkiaRuntimeShaderBuilder()37 ~SkiaRuntimeShaderBuilder() override {} 38 GetType()39 AdapterType GetType() const override 40 { 41 return AdapterType::SKIA_ADAPTER; 42 } 43 44 std::shared_ptr<ShaderEffect> MakeShader(const Matrix* localMatrix, bool isOpaque) override; 45 std::shared_ptr<Image> MakeImage(GPUContext* grContext, const Matrix* localMatrix, 46 ImageInfo resultInfo, bool mipmapped) override; 47 48 void SetChild(const std::string& name, std::shared_ptr<ShaderEffect> shader) override; 49 void SetUniform(const std::string& name, float val) override; 50 void SetUniform(const std::string& name, float x, float y) override; 51 void SetUniform(const std::string& name, float x, float y, float z) override; 52 void SetUniform(const std::string& name, float x, float y, float width, float height) override; 53 void SetUniform(const std::string& name, const float values[], size_t size) override; 54 void SetUniform(const std::string& name, const Matrix& uniformMatrix33) override; 55 void SetUniform(const std::string& name, const Matrix44& uniformMatrix44) override; 56 void SetUniformVec4(const std::string& name, float x, float y, float z, float w) override; 57 58 private: 59 std::shared_ptr<SkRuntimeShaderBuilder> skRuntimeShaderBuilder_ = nullptr; 60 }; 61 } // namespace Drawing 62 } // namespace Rosen 63 } // namespace OHOS 64 #endif