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_COMPONENTS_BASE_RENDER_CONTEXT_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_BASE_RENDER_CONTEXT_H
18 
19 #include "base/geometry/offset.h"
20 #include "base/geometry/rect.h"
21 #include "base/memory/ace_type.h"
22 #include "core/pipeline/base/render_layer.h"
23 
24 namespace OHOS::Ace {
25 
26 template<typename T>
CastLayerAs(RenderLayer layer)27 T* CastLayerAs(RenderLayer layer)
28 {
29     return static_cast<T*>(layer);
30 }
31 
32 class RenderNode;
33 class RenderContext : public virtual AceType {
34     DECLARE_ACE_TYPE(RenderContext, AceType);
35 
36 public:
37     ~RenderContext() override = default;
38 
39     static RefPtr<RenderContext> Create();
40 
41     virtual void Repaint(const RefPtr<RenderNode>&) = 0;
42     virtual void PaintChild(const RefPtr<RenderNode>&, const Offset& offset) = 0;
IsIntersectWith(const RefPtr<RenderNode> & child,Offset & offset)43     virtual bool IsIntersectWith(const RefPtr<RenderNode>& child, Offset& offset) { return true; }
44     virtual void Restore() = 0;
SetClipHole(Rect clipHole)45     virtual void SetClipHole(Rect clipHole)
46     {
47         clipHole_ = clipHole;
48     }
49 
SetNeedRestoreHole(bool restore)50     void SetNeedRestoreHole(bool restore)
51     {
52         needRestoreHole_ = restore;
53     }
54 
GetNeedRestoreHole()55     bool GetNeedRestoreHole() const
56     {
57         return needRestoreHole_;
58     }
59 
60 protected:
61     RenderContext() = default;
62     Rect clipHole_;
63     bool needRestoreHole_ = false;
64 };
65 
66 } // namespace OHOS::Ace
67 
68 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_BASE_RENDER_CONTEXT_H
69