• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 GRAPHICS_EFFECT_GE_SHADER_H
17 #define GRAPHICS_EFFECT_GE_SHADER_H
18 
19 #include <any>
20 #include "draw/canvas.h"
21 #include "utils/rect.h"
22 #include "effect/shader_effect.h"
23 #include "ge_common.h"
24 
25 namespace OHOS {
26 namespace Rosen {
27 class GE_EXPORT GEShader {
28 public:
29     GEShader() = default;
30     GEShader(const GEShader&) = delete;
31     virtual ~GEShader() = default;
32 
33     virtual void MakeDrawingShader(const Drawing::Rect& rect, float progress) = 0;
34 
GetDrawingShader()35     virtual const std::shared_ptr<Drawing::ShaderEffect>& GetDrawingShader() { return drShader_; }
36 
37     virtual void DrawShader(Drawing::Canvas& canvas, const Drawing::Rect& rect);
38 
Hash()39     uint32_t Hash() const { return hash_; }
40 
SetCache(std::shared_ptr<std::any> cacheData)41     void SetCache(std::shared_ptr<std::any> cacheData)
42     {
43         cacheAnyPtr_ = cacheData;
44     }
45 
GetCache()46     std::shared_ptr<std::any> GetCache()
47     {
48         return cacheAnyPtr_;
49     }
50 
SetSupportHeadroom(float supportHeadroom)51     void SetSupportHeadroom(float supportHeadroom)
52     {
53         supportHeadroom_ = supportHeadroom;
54     }
55 
56 protected:
Preprocess(Drawing::Canvas & canvas,const Drawing::Rect & rect)57     virtual void Preprocess(Drawing::Canvas& canvas, const Drawing::Rect& rect) {}
58 
59 protected:
60     uint32_t hash_ = 0;
61     float supportHeadroom_ = 0.0f;
62     std::shared_ptr<Drawing::ShaderEffect> drShader_ = nullptr;
63     std::shared_ptr<std::any> cacheAnyPtr_ = nullptr;
64 };
65 } // namespace Rosen
66 } // namespace OHOS
67 
68 #endif // GRAPHICS_EFFECT_GE_SHADER_H
69