1 /*
2  * Copyright (c) 2022 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 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_RENDER_ADAPTER_DEBUG_BOUNDARY_MODIFIER_H
16 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_RENDER_ADAPTER_DEBUG_BOUNDARY_MODIFIER_H
17 
18 #include <functional>
19 #include <memory>
20 
21 #include "render_service_client/core/modifier/rs_extended_modifier.h"
22 
23 #include "core/components_ng/property/gradient_property.h"
24 #include "core/components_ng/render/adapter/rosen_modifier_adapter.h"
25 
26 namespace OHOS::Ace::NG {
27 
28 class DebugBoundaryModifier : public Rosen::RSForegroundStyleModifier {
29 public:
30     DebugBoundaryModifier() = default;
31     ~DebugBoundaryModifier() override = default;
32 
Draw(RSDrawingContext & context)33     void Draw(RSDrawingContext& context) const override
34     {
35         CHECK_NULL_VOID(property_);
36         CHECK_NULL_VOID(context.canvas);
37 #ifndef USE_ROSEN_DRAWING
38         std::shared_ptr<SkCanvas> skCanvas { context.canvas, [](SkCanvas* /* unused */) {} };
39         RSCanvas rsCanvas(&skCanvas);
40         CHECK_NULL_VOID(&rsCanvas);
41         paintTask_(rsCanvas);
42 #else
43         CHECK_NULL_VOID(paintTask_);
44         paintTask_(*context.canvas);
45 #endif
46     }
47 
SetCustomData(bool paint)48     void SetCustomData(bool paint)
49     {
50         if (property_ == nullptr) {
51             property_ = std::make_shared<Rosen::RSProperty<bool>>(paint);
52             AttachProperty(property_);
53         } else {
54             property_->Set(paint);
55         }
56     }
57 
SetPaintTask(const std::function<void (RSCanvas &)> & paintTask)58     void SetPaintTask(const std::function<void(RSCanvas&)>& paintTask)
59     {
60         paintTask_ = paintTask;
61     }
62 
63 private:
64     std::shared_ptr<Rosen::RSProperty<bool>> property_;
65     std::function<void(RSCanvas&)> paintTask_;
66 };
67 
68 } // namespace OHOS::Ace::NG
69 
70 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_RENDER_ADAPTER_DEBUG_BOUNDARY_MODIFIER_H
71