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_SHADER_BUILDER_H 17 #define RUNTIME_SHADER_BUILDER_H 18 19 #include "drawing/engine_adapter/impl_interface/runtime_shader_builder_impl.h" 20 #include "utils/drawing_macros.h" 21 #include "utils/matrix44.h" 22 23 namespace OHOS { 24 namespace Rosen { 25 namespace Drawing { 26 class RuntimeEffect; 27 class Canvas; 28 class DRAWING_API RuntimeShaderBuilder { 29 public: 30 RuntimeShaderBuilder(std::shared_ptr<RuntimeEffect> runtimeEffect) noexcept; 31 virtual ~RuntimeShaderBuilder() = default; 32 33 std::shared_ptr<ShaderEffect> MakeShader(const Matrix* localMatrix, bool isOpaque); 34 std::shared_ptr<Image> MakeImage(GPUContext* gpuContext, 35 const Matrix* localMatrix, ImageInfo resultInfo, bool mipmapped); 36 std::shared_ptr<Image> MakeImage(Canvas& canvas, 37 const Matrix* localMatrix, ImageInfo resultInfo, bool mipmapped); 38 39 void SetChild(const std::string& name, std::shared_ptr<ShaderEffect> shader); 40 void SetUniform(const std::string& name, float val); 41 void SetUniform(const std::string& name, float x, float y); 42 void SetUniform(const std::string& name, float x, float y, float z); 43 void SetUniform(const std::string& name, float x, float y, float width, float height); 44 void SetUniform(const std::string& name, const float values[], size_t size); 45 void SetUniform(const std::string& name, const Matrix& uniformMatrix33); 46 void SetUniform(const std::string& name, const Matrix44& uniformMatrix44); 47 void SetUniformVec4(const std::string& name, float x, float y, float z, float w); 48 private: 49 std::shared_ptr<RuntimeShaderBuilderImpl> impl_; 50 }; 51 } // namespace Drawing 52 } // namespace Rosen 53 } // namespace OHOS 54 #endif // RUNTIMR_SHADER_BUILDER_H