• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_DRAW_DELEGATE_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_DRAW_DELEGATE_H
18 
19 #include "base/geometry/rect.h"
20 #include "core/pipeline/layers/layer.h"
21 
22 namespace OHOS::Rosen {
23 class RSNode;
24 }
25 
26 namespace OHOS::Ace {
27 
28 class DrawDelegate {
29 public:
30     using DoDrawFrame = std::function<void(RefPtr<Flutter::Layer>&, const Rect&)>;
31     using DoDrawRSFrame = std::function<void(std::shared_ptr<Rosen::RSNode>&, const Rect&)>;
32     using DoDrawLastFrame = std::function<void(const Rect&)>;
33 
34     DrawDelegate() = default;
35     ~DrawDelegate() = default;
36 
DrawFrame(RefPtr<Flutter::Layer> & rootLayer,const Rect & dirty)37     void DrawFrame(RefPtr<Flutter::Layer>& rootLayer, const Rect& dirty)
38     {
39         if (doDrawFrameCallback_) {
40             doDrawFrameCallback_(rootLayer, dirty);
41         }
42     }
43 
DrawRSFrame(std::shared_ptr<Rosen::RSNode> & node,const Rect & dirty)44     void DrawRSFrame(std::shared_ptr<Rosen::RSNode>& node, const Rect& dirty)
45     {
46         if (doDrawRSFrameCallback_) {
47             doDrawRSFrameCallback_(node, dirty);
48         }
49     }
50 
DrawLastFrame(const Rect & dirty)51     void DrawLastFrame(const Rect& dirty)
52     {
53         if (doDrawLastFrameCallback_) {
54             doDrawLastFrameCallback_(dirty);
55         }
56     }
57 
SetDrawFrameCallback(DoDrawFrame && doFrameCallback)58     void SetDrawFrameCallback(DoDrawFrame&& doFrameCallback)
59     {
60         doDrawFrameCallback_ = doFrameCallback;
61     }
62 
SetDrawRSFrameCallback(DoDrawRSFrame && doRSFrameCallback)63     void SetDrawRSFrameCallback(DoDrawRSFrame&& doRSFrameCallback)
64     {
65         doDrawRSFrameCallback_ = doRSFrameCallback;
66     }
67 
SetDrawFrameRepeatCallback(DoDrawLastFrame && doFrameCallback)68     void SetDrawFrameRepeatCallback(DoDrawLastFrame&& doFrameCallback)
69     {
70         doDrawLastFrameCallback_ = doFrameCallback;
71     }
72 
73 private:
74     DoDrawFrame doDrawFrameCallback_;
75     DoDrawRSFrame doDrawRSFrameCallback_;
76     DoDrawLastFrame doDrawLastFrameCallback_;
77 };
78 
79 } // namespace OHOS::Ace
80 
81 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_DRAW_DELEGATE_H
82