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