功能封装到painter类

Signed-off-by: xiexiyun <xiexiyun@huawei.com>
Change-Id: Ieef52b6a384bf12ab5afa650d21cac0991cfe90e
This commit is contained in:
xiexiyun
2022-04-18 11:03:13 +08:00
parent 1bc695349e
commit eab172c271
12 changed files with 494 additions and 120 deletions
+316
View File
@@ -0,0 +1,316 @@
diff --git a/adapter/ohos/osal/system_properties.cpp b/adapter/ohos/osal/system_properties.cpp
index 7860a264..3bc3dad0 100644
--- a/adapter/ohos/osal/system_properties.cpp
+++ b/adapter/ohos/osal/system_properties.cpp
@@ -36,7 +36,7 @@ const char PROPERTY_DEVICE_TYPE_WATCH[] = "watch";
const char PROPERTY_DEVICE_TYPE_CAR[] = "car";
const char DISABLE_ROSEN_FILE_PATH[] = "/etc/disablerosen";
const char DISABLE_WINDOW_ANIMATION_PATH[] = "/etc/disable_window_size_animation";
-const char ENABLE_PAINT_BOUNDARY_FILE_PATH[] = "/etc/enable_paint_boundary";
+const char ENABLE_DEBUG_BOUNDARY_FILE_PATH[] = "/etc/enable_paint_boundary";
constexpr int32_t ORIENTATION_PORTRAIT = 0;
constexpr int32_t ORIENTATION_LANDSCAPE = 1;
@@ -54,9 +54,9 @@ bool IsTraceEnabled()
system::GetParameter("debug.ace.trace.enabled", "0") == "1");
}
-bool IsPaintBoundaryEnabled()
+bool IsDebugBoundaryEnabled()
{
- return access(ENABLE_PAINT_BOUNDARY_FILE_PATH, F_OK) == 0;
+ return access(ENABLE_DEBUG_BOUNDARY_FILE_PATH, F_OK) == 0;
}
bool IsRosenBackendEnabled()
@@ -165,7 +165,7 @@ ColorMode SystemProperties::colorMode_ { ColorMode::LIGHT };
ScreenShape SystemProperties::screenShape_ { ScreenShape::NOT_ROUND };
LongScreenType SystemProperties::LongScreen_ { LongScreenType::NOT_LONG };
bool SystemProperties::rosenBackendEnabled_ = IsRosenBackendEnabled();
-bool SystemProperties::paintBoundaryEnabled_ = IsPaintBoundaryEnabled();
+bool SystemProperties::debugBoundaryEnabled_ = IsDebugBoundaryEnabled();
bool SystemProperties::windowAnimationEnabled_ = IsWindowAnimationEnabled();
bool SystemProperties::debugEnabled_ = IsDebugEnabled();
int32_t SystemProperties::windowPosX_ = 0;
@@ -220,7 +220,7 @@ void SystemProperties::InitDeviceInfo(
traceEnabled_ = IsTraceEnabled();
accessibilityEnabled_ = IsAccessibilityEnabled();
rosenBackendEnabled_ = IsRosenBackendEnabled();
- paintBoundaryEnabled_ = IsPaintBoundaryEnabled();
+ debugBoundaryEnabled_ = IsDebugBoundaryEnabled();
if (isRound_) {
screenShape_ = ScreenShape::ROUND;
diff --git a/frameworks/base/utils/system_properties.h b/frameworks/base/utils/system_properties.h
index b1a7ae3d..0de2b94c 100644
--- a/frameworks/base/utils/system_properties.h
+++ b/frameworks/base/utils/system_properties.h
@@ -177,9 +177,9 @@ public:
return rosenBackendEnabled_;
}
- static bool GetPaintBoundaryEnabled()
+ static bool GetDebugBoundaryEnabled()
{
- return paintBoundaryEnabled_;
+ return debugBoundaryEnabled_;
}
static bool GetTraceEnabled()
@@ -296,7 +296,7 @@ private:
static bool debugEnabled_;
static int32_t windowPosX_;
static int32_t windowPosY_;
- static bool paintBoundaryEnabled_;
+ static bool debugBoundaryEnabled_;
};
} // namespace OHOS::Ace
diff --git a/frameworks/bridge/declarative_frontend/view_stack_processor.cpp b/frameworks/bridge/declarative_frontend/view_stack_processor.cpp
index d0af92c0..52f0f44a 100644
--- a/frameworks/bridge/declarative_frontend/view_stack_processor.cpp
+++ b/frameworks/bridge/declarative_frontend/view_stack_processor.cpp
@@ -197,8 +197,8 @@ RefPtr<BoxComponent> ViewStackProcessor::GetBoxComponent()
}
RefPtr<BoxComponent> boxComponent = AceType::MakeRefPtr<OHOS::Ace::BoxComponent>();
- if (SystemProperties::GetPaintBoundaryEnabled()) {
- boxComponent->SetNeedPaintBoundary(true);
+ if (SystemProperties::GetDebugBoundaryEnabled()) {
+ boxComponent->SetEnableDebugBoundary(true);
}
wrappingComponentsMap.emplace("box", boxComponent);
return boxComponent;
@@ -544,7 +544,6 @@ void ViewStackProcessor::DumpStack()
RefPtr<Component> ViewStackProcessor::WrapComponents()
{
-
auto& wrappingComponentsMap = componentsStack_.top();
std::vector<RefPtr<Component>> components;
diff --git a/frameworks/core/components/box/box_component.h b/frameworks/core/components/box/box_component.h
index 2368862f..19df8dd1 100644
--- a/frameworks/core/components/box/box_component.h
+++ b/frameworks/core/components/box/box_component.h
@@ -354,14 +354,14 @@ public:
hasBackgroundColor_ = hasBackgroundColor;
}
- void SetNeedPaintBoundary(bool needPaintBoundary)
+ void SetEnableDebugBoundary(bool enableDebugBoundary)
{
- needPaintBoundary_ = needPaintBoundary;
+ enableDebugBoundary_ = enableDebugBoundary;
}
- bool GetNeedPaintBoundary()
+ bool GetEnableDebugBoundary()
{
- return needPaintBoundary_;
+ return enableDebugBoundary_;
}
private:
@@ -395,7 +395,7 @@ private:
RefPtr<StateAttributes<BoxStateAttribute>> stateAttributeList_ = nullptr;
EventMarker remoteMessageId_;
bool hasBackgroundColor_;
- bool needPaintBoundary_ = false;
+ bool enableDebugBoundary_ = false;
};
} // namespace OHOS::Ace
diff --git a/frameworks/core/components/box/render_box.cpp b/frameworks/core/components/box/render_box.cpp
index d53794b5..dafec5d7 100644
--- a/frameworks/core/components/box/render_box.cpp
+++ b/frameworks/core/components/box/render_box.cpp
@@ -96,7 +96,7 @@ void RenderBox::Update(const RefPtr<Component>& component)
inspectorDirection_ = box->GetInspectorDirection();
RenderBoxBase::Update(component);
UpdateBackDecoration(box->GetBackDecoration());
- needPaintBoxBoundary_ = box->GetNeedPaintBoundary();
+ needPaintDebugBoundary_ = box->GetEnableDebugBoundary();
UpdateFrontDecoration(box->GetFrontDecoration());
hoverColorBegin_ = box->GetColor();
hoverAnimationType_ = box->GetMouseAnimationType();
diff --git a/frameworks/core/components/box/render_box.h b/frameworks/core/components/box/render_box.h
index 3018c89f..fc05f737 100644
--- a/frameworks/core/components/box/render_box.h
+++ b/frameworks/core/components/box/render_box.h
@@ -297,7 +297,7 @@ protected:
bool isHoveredScale = false;
bool isAccessibilityFocus_ = false;
bool needFocusBorder_ = false;
- bool needPaintBoxBoundary_ = false;
+ bool needPaintDebugBoundary_ = false;
private:
void UpdateBackDecoration(const RefPtr<Decoration>& newDecoration);
diff --git a/frameworks/core/components/box/rosen_render_box.cpp b/frameworks/core/components/box/rosen_render_box.cpp
index b86c0841..742dc277 100644
--- a/frameworks/core/components/box/rosen_render_box.cpp
+++ b/frameworks/core/components/box/rosen_render_box.cpp
@@ -33,6 +33,7 @@
#include "core/components/image/image_component.h"
#include "core/components/image/rosen_render_image.h"
#include "core/pipeline/base/rosen_render_context.h"
+#include "core/components/common/painter/rosen_debug_boundary_painter.h"
namespace OHOS::Ace {
namespace {
@@ -53,9 +54,6 @@ constexpr uint32_t FOCUS_COLOR = 0xff0a59f7;
constexpr double FOCUS_WIDTH = 2.0;
constexpr double FOCUS_RADIUS_X = 4.0;
constexpr double FOCUS_RADIUS_Y = 4.0;
-
-constexpr double BOUNDARY_STROKE_WIDTH = 3.0;
-constexpr double BOUNDARY_CORNER_LENGTH = 8.0;
} // namespace
RosenRenderBox::RosenRenderBox()
@@ -268,97 +266,6 @@ void RosenRenderBox::PerformLayout()
#endif
}
-void RosenRenderBox::PaintMargin(RenderContext& context, const Offset& offset)
-{
- EdgePx margin = RenderBoxBase::margin_;
- SkPaint skpaint;
- auto canvas = static_cast<RosenRenderContext*>(&context)->GetCanvas();
- auto startPointX = offset.GetX();
- auto startPointY = offset.GetY();
- auto horizontalRectWidth = GetLayoutSize().Width() - margin.LeftPx() - margin.RightPx();
- auto verticalRectHeight = GetLayoutSize().Height() - margin.TopPx() - margin.BottomPx();
- skpaint.setColor(0xB3FFC0CB);
- skpaint.setStyle(SkPaint::Style::kFill_Style);
-
- auto layoutRect = SkRect::MakeXYWH(startPointX, startPointY,
- margin.LeftPx(), margin.TopPx());
- canvas->drawRect(layoutRect, skpaint);
-
- layoutRect = SkRect::MakeXYWH(startPointX + GetLayoutSize().Width() - margin.RightPx(), startPointY,
- margin.RightPx(), margin.TopPx());
- canvas->drawRect(layoutRect, skpaint);
-
- layoutRect = SkRect::MakeXYWH(startPointX, startPointY + GetLayoutSize().Height() - margin.BottomPx(),
- margin.LeftPx(), margin.BottomPx());
- canvas->drawRect(layoutRect, skpaint);
-
- layoutRect = SkRect::MakeXYWH(startPointX + GetLayoutSize().Width() - margin.RightPx(),
- startPointY + GetLayoutSize().Height() - margin.BottomPx(),
- margin.RightPx(), margin.BottomPx());
- canvas->drawRect(layoutRect, skpaint);
-
- layoutRect = SkRect::MakeXYWH(startPointX + margin.LeftPx(), startPointY,
- horizontalRectWidth, margin.TopPx());
- canvas->drawRect(layoutRect, skpaint);
-
- layoutRect = SkRect::MakeXYWH(startPointX + margin.LeftPx(), startPointY + GetLayoutSize().Height() - margin.BottomPx(),
- horizontalRectWidth, margin.BottomPx());
- canvas->drawRect(layoutRect, skpaint);
-
- layoutRect = SkRect::MakeXYWH(startPointX, startPointY + margin.TopPx(),
- margin.LeftPx(), verticalRectHeight);
- canvas->drawRect(layoutRect, skpaint);
-
- layoutRect = SkRect::MakeXYWH(startPointX + GetLayoutSize().Width() - margin.RightPx(), startPointY + margin.TopPx(),
- margin.RightPx(), verticalRectHeight);
- canvas->drawRect(layoutRect, skpaint);
-}
-
-void RosenRenderBox::PaintCorner(RenderContext& context, const Offset& offset)
-{
- SkPaint skpaint;
- auto canvas = static_cast<RosenRenderContext*>(&context)->GetCanvas();
- auto startPointX = offset.GetX();
- auto startPointY = offset.GetY();
- skpaint.setColor(0xFF6633FF);
- skpaint.setStyle(SkPaint::Style::kStroke_Style);
- skpaint.setStrokeWidth(BOUNDARY_STROKE_WIDTH);
- canvas->drawLine(startPointX, startPointY,
- startPointX + BOUNDARY_CORNER_LENGTH, startPointY, skpaint);
-
- canvas->drawLine(startPointX, startPointY,
- startPointX, startPointY + BOUNDARY_CORNER_LENGTH, skpaint);
-
- canvas->drawLine(startPointX + GetLayoutSize().Width() - BOUNDARY_CORNER_LENGTH, startPointY,
- startPointX + GetLayoutSize().Width(), startPointY, skpaint);
-
- canvas->drawLine(startPointX + GetLayoutSize().Width(), startPointY,
- startPointX + GetLayoutSize().Width(), startPointY + BOUNDARY_CORNER_LENGTH, skpaint);
-
- canvas->drawLine(startPointX, startPointY + GetLayoutSize().Height(),
- startPointX + BOUNDARY_CORNER_LENGTH, startPointY + GetLayoutSize().Height(), skpaint);
-
- canvas->drawLine(startPointX, startPointY + GetLayoutSize().Height() - BOUNDARY_CORNER_LENGTH,
- startPointX, startPointY + GetLayoutSize().Height(), skpaint);
-
- canvas->drawLine(startPointX + GetLayoutSize().Width() - BOUNDARY_CORNER_LENGTH, startPointY + GetLayoutSize().Height(),
- startPointX + GetLayoutSize().Width(), startPointY + GetLayoutSize().Height(), skpaint);
-
- canvas->drawLine(startPointX + GetLayoutSize().Width(), startPointY + GetLayoutSize().Height() - BOUNDARY_CORNER_LENGTH,
- startPointX + GetLayoutSize().Width(), startPointY + GetLayoutSize().Height(), skpaint);
-}
-
-void RosenRenderBox::PaintBoundary(RenderContext& context, const Offset& offset)
-{
- SkPaint skpaint;
- auto canvas = static_cast<RosenRenderContext*>(&context)->GetCanvas();
- auto layoutRect = SkRect::MakeXYWH(offset.GetX(), offset.GetY(), GetLayoutSize().Width(), GetLayoutSize().Height());
- skpaint.setColor(0xFFFF0000);
- skpaint.setStyle(SkPaint::Style::kStroke_Style);
- skpaint.setStrokeWidth(BOUNDARY_STROKE_WIDTH);
- canvas->drawRect(layoutRect, skpaint);
-}
-
void RosenRenderBox::Paint(RenderContext& context, const Offset& offset)
{
if (backDecoration_ && backDecoration_->GetImage() && renderImage_ &&
@@ -402,10 +309,15 @@ void RosenRenderBox::Paint(RenderContext& context, const Offset& offset)
}
}
RenderNode::Paint(context, offset);
- if (RenderBox::needPaintBoxBoundary_) {
- PaintBoundary(context, offset);
- PaintCorner(context, offset);
- PaintMargin(context, offset);
+ if (RenderBox::needPaintDebugBoundary_) {
+ auto canvas = static_cast<RosenRenderContext*>(&context)->GetCanvas();
+ if (canvas == nullptr) {
+ LOGE("Paint canvas is null.");
+ return;
+ }
+ RosenDebugBoundaryPainter::PaintDebugBoundary(canvas, offset, GetLayoutSize());
+ RosenDebugBoundaryPainter::PaintDebugCorner(canvas, offset, GetLayoutSize());
+ RosenDebugBoundaryPainter::PaintDebugMargin(canvas, offset, GetLayoutSize(), RenderBoxBase::margin_);
}
if (frontDecoration_) {
auto canvas = static_cast<RosenRenderContext*>(&context)->GetCanvas();
diff --git a/frameworks/core/components/box/rosen_render_box.h b/frameworks/core/components/box/rosen_render_box.h
index 8b23a2dd..7ba4f3e0 100644
--- a/frameworks/core/components/box/rosen_render_box.h
+++ b/frameworks/core/components/box/rosen_render_box.h
@@ -74,10 +74,6 @@ public:
void AnimateMouseHoverEnter() override;
void AnimateMouseHoverExit() override;
- void PaintBoundary(RenderContext& context, const Offset& offset);
- void PaintMargin(RenderContext& context, const Offset& offset);
- void PaintCorner(RenderContext& context, const Offset& offset);
-
protected:
bool MaybeRelease() override;
diff --git a/frameworks/core/components/common/BUILD.gn b/frameworks/core/components/common/BUILD.gn
index a6899d62..d8e33671 100644
--- a/frameworks/core/components/common/BUILD.gn
+++ b/frameworks/core/components/common/BUILD.gn
@@ -50,6 +50,7 @@ build_component("common") {
]
rosen_sources = [
"painter/rosen_checkable_painter.cpp",
+ "painter/rosen_debug_boundary_painter.cpp",
"painter/rosen_decoration_painter.cpp",
"painter/rosen_scroll_bar_painter.cpp",
"painter/rosen_scroll_fade_painter.cpp",
+5 -5
View File
@@ -36,7 +36,7 @@ const char PROPERTY_DEVICE_TYPE_WATCH[] = "watch";
const char PROPERTY_DEVICE_TYPE_CAR[] = "car";
const char DISABLE_ROSEN_FILE_PATH[] = "/etc/disablerosen";
const char DISABLE_WINDOW_ANIMATION_PATH[] = "/etc/disable_window_size_animation";
const char ENABLE_PAINT_BOUNDARY_FILE_PATH[] = "/etc/enable_paint_boundary";
const char ENABLE_DEBUG_BOUNDARY_FILE_PATH[] = "/etc/enable_paint_boundary";
constexpr int32_t ORIENTATION_PORTRAIT = 0;
constexpr int32_t ORIENTATION_LANDSCAPE = 1;
@@ -54,9 +54,9 @@ bool IsTraceEnabled()
system::GetParameter("debug.ace.trace.enabled", "0") == "1");
}
bool IsPaintBoundaryEnabled()
bool IsDebugBoundaryEnabled()
{
return access(ENABLE_PAINT_BOUNDARY_FILE_PATH, F_OK) == 0;
return access(ENABLE_DEBUG_BOUNDARY_FILE_PATH, F_OK) == 0;
}
bool IsRosenBackendEnabled()
@@ -165,7 +165,7 @@ ColorMode SystemProperties::colorMode_ { ColorMode::LIGHT };
ScreenShape SystemProperties::screenShape_ { ScreenShape::NOT_ROUND };
LongScreenType SystemProperties::LongScreen_ { LongScreenType::NOT_LONG };
bool SystemProperties::rosenBackendEnabled_ = IsRosenBackendEnabled();
bool SystemProperties::paintBoundaryEnabled_ = IsPaintBoundaryEnabled();
bool SystemProperties::debugBoundaryEnabled_ = IsDebugBoundaryEnabled();
bool SystemProperties::windowAnimationEnabled_ = IsWindowAnimationEnabled();
bool SystemProperties::debugEnabled_ = IsDebugEnabled();
int32_t SystemProperties::windowPosX_ = 0;
@@ -220,7 +220,7 @@ void SystemProperties::InitDeviceInfo(
traceEnabled_ = IsTraceEnabled();
accessibilityEnabled_ = IsAccessibilityEnabled();
rosenBackendEnabled_ = IsRosenBackendEnabled();
paintBoundaryEnabled_ = IsPaintBoundaryEnabled();
debugBoundaryEnabled_ = IsDebugBoundaryEnabled();
if (isRound_) {
screenShape_ = ScreenShape::ROUND;
+3 -3
View File
@@ -177,9 +177,9 @@ public:
return rosenBackendEnabled_;
}
static bool GetPaintBoundaryEnabled()
static bool GetDebugBoundaryEnabled()
{
return paintBoundaryEnabled_;
return debugBoundaryEnabled_;
}
static bool GetTraceEnabled()
@@ -296,7 +296,7 @@ private:
static bool debugEnabled_;
static int32_t windowPosX_;
static int32_t windowPosY_;
static bool paintBoundaryEnabled_;
static bool debugBoundaryEnabled_;
};
} // namespace OHOS::Ace
@@ -197,8 +197,8 @@ RefPtr<BoxComponent> ViewStackProcessor::GetBoxComponent()
}
RefPtr<BoxComponent> boxComponent = AceType::MakeRefPtr<OHOS::Ace::BoxComponent>();
if (SystemProperties::GetPaintBoundaryEnabled()) {
boxComponent->SetNeedPaintBoundary(true);
if (SystemProperties::GetDebugBoundaryEnabled()) {
boxComponent->SetEnableDebugBoundary(true);
}
wrappingComponentsMap.emplace("box", boxComponent);
return boxComponent;
@@ -544,7 +544,6 @@ void ViewStackProcessor::DumpStack()
RefPtr<Component> ViewStackProcessor::WrapComponents()
{
auto& wrappingComponentsMap = componentsStack_.top();
std::vector<RefPtr<Component>> components;
@@ -354,14 +354,14 @@ public:
hasBackgroundColor_ = hasBackgroundColor;
}
void SetNeedPaintBoundary(bool needPaintBoundary)
void SetEnableDebugBoundary(bool enableDebugBoundary)
{
needPaintBoundary_ = needPaintBoundary;
enableDebugBoundary_ = enableDebugBoundary;
}
bool GetNeedPaintBoundary()
bool GetEnableDebugBoundary()
{
return needPaintBoundary_;
return enableDebugBoundary_;
}
private:
@@ -395,7 +395,7 @@ private:
RefPtr<StateAttributes<BoxStateAttribute>> stateAttributeList_ = nullptr;
EventMarker remoteMessageId_;
bool hasBackgroundColor_;
bool needPaintBoundary_ = false;
bool enableDebugBoundary_ = false;
};
} // namespace OHOS::Ace
@@ -96,7 +96,7 @@ void RenderBox::Update(const RefPtr<Component>& component)
inspectorDirection_ = box->GetInspectorDirection();
RenderBoxBase::Update(component);
UpdateBackDecoration(box->GetBackDecoration());
needPaintBoxBoundary_ = box->GetNeedPaintBoundary();
needPaintDebugBoundary_ = box->GetEnableDebugBoundary();
UpdateFrontDecoration(box->GetFrontDecoration());
hoverColorBegin_ = box->GetColor();
hoverAnimationType_ = box->GetMouseAnimationType();
+1 -1
View File
@@ -297,7 +297,7 @@ protected:
bool isHoveredScale = false;
bool isAccessibilityFocus_ = false;
bool needFocusBorder_ = false;
bool needPaintBoxBoundary_ = false;
bool needPaintDebugBoundary_ = false;
private:
void UpdateBackDecoration(const RefPtr<Decoration>& newDecoration);
@@ -33,6 +33,7 @@
#include "core/components/image/image_component.h"
#include "core/components/image/rosen_render_image.h"
#include "core/pipeline/base/rosen_render_context.h"
#include "core/components/common/painter/rosen_debug_boundary_painter.h"
namespace OHOS::Ace {
namespace {
@@ -53,9 +54,6 @@ constexpr uint32_t FOCUS_COLOR = 0xff0a59f7;
constexpr double FOCUS_WIDTH = 2.0;
constexpr double FOCUS_RADIUS_X = 4.0;
constexpr double FOCUS_RADIUS_Y = 4.0;
constexpr double BOUNDARY_STROKE_WIDTH = 3.0;
constexpr double BOUNDARY_CORNER_LENGTH = 8.0;
} // namespace
RosenRenderBox::RosenRenderBox()
@@ -268,97 +266,6 @@ void RosenRenderBox::PerformLayout()
#endif
}
void RosenRenderBox::PaintMargin(RenderContext& context, const Offset& offset)
{
EdgePx margin = RenderBoxBase::margin_;
SkPaint skpaint;
auto canvas = static_cast<RosenRenderContext*>(&context)->GetCanvas();
auto startPointX = offset.GetX();
auto startPointY = offset.GetY();
auto horizontalRectWidth = GetLayoutSize().Width() - margin.LeftPx() - margin.RightPx();
auto verticalRectHeight = GetLayoutSize().Height() - margin.TopPx() - margin.BottomPx();
skpaint.setColor(0xB3FFC0CB);
skpaint.setStyle(SkPaint::Style::kFill_Style);
auto layoutRect = SkRect::MakeXYWH(startPointX, startPointY,
margin.LeftPx(), margin.TopPx());
canvas->drawRect(layoutRect, skpaint);
layoutRect = SkRect::MakeXYWH(startPointX + GetLayoutSize().Width() - margin.RightPx(), startPointY,
margin.RightPx(), margin.TopPx());
canvas->drawRect(layoutRect, skpaint);
layoutRect = SkRect::MakeXYWH(startPointX, startPointY + GetLayoutSize().Height() - margin.BottomPx(),
margin.LeftPx(), margin.BottomPx());
canvas->drawRect(layoutRect, skpaint);
layoutRect = SkRect::MakeXYWH(startPointX + GetLayoutSize().Width() - margin.RightPx(),
startPointY + GetLayoutSize().Height() - margin.BottomPx(),
margin.RightPx(), margin.BottomPx());
canvas->drawRect(layoutRect, skpaint);
layoutRect = SkRect::MakeXYWH(startPointX + margin.LeftPx(), startPointY,
horizontalRectWidth, margin.TopPx());
canvas->drawRect(layoutRect, skpaint);
layoutRect = SkRect::MakeXYWH(startPointX + margin.LeftPx(), startPointY + GetLayoutSize().Height() - margin.BottomPx(),
horizontalRectWidth, margin.BottomPx());
canvas->drawRect(layoutRect, skpaint);
layoutRect = SkRect::MakeXYWH(startPointX, startPointY + margin.TopPx(),
margin.LeftPx(), verticalRectHeight);
canvas->drawRect(layoutRect, skpaint);
layoutRect = SkRect::MakeXYWH(startPointX + GetLayoutSize().Width() - margin.RightPx(), startPointY + margin.TopPx(),
margin.RightPx(), verticalRectHeight);
canvas->drawRect(layoutRect, skpaint);
}
void RosenRenderBox::PaintCorner(RenderContext& context, const Offset& offset)
{
SkPaint skpaint;
auto canvas = static_cast<RosenRenderContext*>(&context)->GetCanvas();
auto startPointX = offset.GetX();
auto startPointY = offset.GetY();
skpaint.setColor(0xFF6633FF);
skpaint.setStyle(SkPaint::Style::kStroke_Style);
skpaint.setStrokeWidth(BOUNDARY_STROKE_WIDTH);
canvas->drawLine(startPointX, startPointY,
startPointX + BOUNDARY_CORNER_LENGTH, startPointY, skpaint);
canvas->drawLine(startPointX, startPointY,
startPointX, startPointY + BOUNDARY_CORNER_LENGTH, skpaint);
canvas->drawLine(startPointX + GetLayoutSize().Width() - BOUNDARY_CORNER_LENGTH, startPointY,
startPointX + GetLayoutSize().Width(), startPointY, skpaint);
canvas->drawLine(startPointX + GetLayoutSize().Width(), startPointY,
startPointX + GetLayoutSize().Width(), startPointY + BOUNDARY_CORNER_LENGTH, skpaint);
canvas->drawLine(startPointX, startPointY + GetLayoutSize().Height(),
startPointX + BOUNDARY_CORNER_LENGTH, startPointY + GetLayoutSize().Height(), skpaint);
canvas->drawLine(startPointX, startPointY + GetLayoutSize().Height() - BOUNDARY_CORNER_LENGTH,
startPointX, startPointY + GetLayoutSize().Height(), skpaint);
canvas->drawLine(startPointX + GetLayoutSize().Width() - BOUNDARY_CORNER_LENGTH, startPointY + GetLayoutSize().Height(),
startPointX + GetLayoutSize().Width(), startPointY + GetLayoutSize().Height(), skpaint);
canvas->drawLine(startPointX + GetLayoutSize().Width(), startPointY + GetLayoutSize().Height() - BOUNDARY_CORNER_LENGTH,
startPointX + GetLayoutSize().Width(), startPointY + GetLayoutSize().Height(), skpaint);
}
void RosenRenderBox::PaintBoundary(RenderContext& context, const Offset& offset)
{
SkPaint skpaint;
auto canvas = static_cast<RosenRenderContext*>(&context)->GetCanvas();
auto layoutRect = SkRect::MakeXYWH(offset.GetX(), offset.GetY(), GetLayoutSize().Width(), GetLayoutSize().Height());
skpaint.setColor(0xFFFF0000);
skpaint.setStyle(SkPaint::Style::kStroke_Style);
skpaint.setStrokeWidth(BOUNDARY_STROKE_WIDTH);
canvas->drawRect(layoutRect, skpaint);
}
void RosenRenderBox::Paint(RenderContext& context, const Offset& offset)
{
if (backDecoration_ && backDecoration_->GetImage() && renderImage_ &&
@@ -402,10 +309,15 @@ void RosenRenderBox::Paint(RenderContext& context, const Offset& offset)
}
}
RenderNode::Paint(context, offset);
if (RenderBox::needPaintBoxBoundary_) {
PaintBoundary(context, offset);
PaintCorner(context, offset);
PaintMargin(context, offset);
if (RenderBox::needPaintDebugBoundary_) {
auto canvas = static_cast<RosenRenderContext*>(&context)->GetCanvas();
if (canvas == nullptr) {
LOGE("Paint canvas is null.");
return;
}
RosenDebugBoundaryPainter::PaintDebugBoundary(canvas, offset, GetLayoutSize());
RosenDebugBoundaryPainter::PaintDebugCorner(canvas, offset, GetLayoutSize());
RosenDebugBoundaryPainter::PaintDebugMargin(canvas, offset, GetLayoutSize(), RenderBoxBase::margin_);
}
if (frontDecoration_) {
auto canvas = static_cast<RosenRenderContext*>(&context)->GetCanvas();
@@ -74,10 +74,6 @@ public:
void AnimateMouseHoverEnter() override;
void AnimateMouseHoverExit() override;
void PaintBoundary(RenderContext& context, const Offset& offset);
void PaintMargin(RenderContext& context, const Offset& offset);
void PaintCorner(RenderContext& context, const Offset& offset);
protected:
bool MaybeRelease() override;
@@ -50,6 +50,7 @@ build_component("common") {
]
rosen_sources = [
"painter/rosen_checkable_painter.cpp",
"painter/rosen_debug_boundary_painter.cpp",
"painter/rosen_decoration_painter.cpp",
"painter/rosen_scroll_bar_painter.cpp",
"painter/rosen_scroll_fade_painter.cpp",
@@ -0,0 +1,106 @@
#include "core/components/common/painter/rosen_debug_boundary_painter.h"
#include <cmath>
#include <functional>
// #include "include/core/SkBitmap.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkColorFilter.h"
// #include "include/core/SkMaskFilter.h"
// #include "include/effects/Sk1DPathEffect.h"
// #include "include/effects/SkBlurImageFilter.h"
// #include "include/effects/SkDashPathEffect.h"
// #include "include/effects/SkGradientShader.h"
// #include "include/utils/SkShadowUtils.h"
#include "render_service_client/core/ui/rs_node.h"
#include "core/components/common/properties/color.h"
#include "core/pipeline/base/render_node.h"
#include "core/pipeline/base/rosen_render_context.h"
#include "core/pipeline/pipeline_context.h"
namespace OHOS::Ace {
namespace {
constexpr double BOUNDARY_STROKE_WIDTH = 3.0;
constexpr double BOUNDARY_CORNER_LENGTH = 8.0;
constexpr uint32_t BOUNDARY_COLOR = 0xFFFF0000;
constexpr uint32_t BOUNDARY_CORNER_COLOR = 0xFF637FFF;
constexpr uint32_t BOUNDARY_MARGIN_COLOR = 0xB3FFC0CB;
}
void RosenDebugBoundaryPainter::PaintDebugBoundary(SkCanvas* canvas, const Offset& offset, const Size& layoutSize)
{
SkPaint skpaint;
// auto canvas = static_cast<RosenRenderContext*>(&context)->GetCanvas();
auto layoutRect = SkRect::MakeXYWH(offset.GetX(), offset.GetY(), layoutSize.Width(), layoutSize.Height());
skpaint.setColor(BOUNDARY_COLOR);
skpaint.setStyle(SkPaint::Style::kStroke_Style);
skpaint.setStrokeWidth(BOUNDARY_STROKE_WIDTH);
canvas->drawRect(layoutRect, skpaint);
}
void RosenDebugBoundaryPainter::PaintDebugMargin(SkCanvas* canvas, const Offset& offset,
const Size& layoutSize, const EdgePx margin)
{
SkPaint skpaint;
// auto canvas = static_cast<RosenRenderContext*>(&context)->GetCanvas();
auto startPointX = offset.GetX();
auto startPointY = offset.GetY();
auto verticalRectHeight = layoutSize.Height() - margin.TopPx() - margin.BottomPx();
skpaint.setColor(BOUNDARY_MARGIN_COLOR);
skpaint.setStyle(SkPaint::Style::kFill_Style);
auto layoutRect = SkRect::MakeXYWH(startPointX, startPointY,
layoutSize.Width(), margin.TopPx());
canvas->drawRect(layoutRect, skpaint);
layoutRect = SkRect::MakeXYWH(startPointX, startPointY + layoutSize.Height() - margin.BottomPx(),
layoutSize.Width(), margin.BottomPx());
canvas->drawRect(layoutRect, skpaint);
layoutRect = SkRect::MakeXYWH(startPointX, startPointY + margin.TopPx(),
margin.LeftPx(), verticalRectHeight);
canvas->drawRect(layoutRect, skpaint);
layoutRect = SkRect::MakeXYWH(startPointX + layoutSize.Width() - margin.RightPx(), startPointY + margin.TopPx(),
margin.RightPx(), verticalRectHeight);
canvas->drawRect(layoutRect, skpaint);
}
void RosenDebugBoundaryPainter::PaintDebugCorner(SkCanvas* canvas, const Offset& offset, const Size& layoutSize)
{
SkPaint skpaint;
// auto canvas = static_cast<RosenRenderContext*>(&context)->GetCanvas();
auto startPointX = offset.GetX();
auto startPointY = offset.GetY();
skpaint.setColor(BOUNDARY_CORNER_COLOR);
skpaint.setStyle(SkPaint::Style::kStroke_Style);
skpaint.setStrokeWidth(BOUNDARY_STROKE_WIDTH);
canvas->drawLine(startPointX, startPointY,
startPointX + BOUNDARY_CORNER_LENGTH, startPointY, skpaint);
canvas->drawLine(startPointX, startPointY,
startPointX, startPointY + BOUNDARY_CORNER_LENGTH, skpaint);
canvas->drawLine(startPointX + layoutSize.Width() - BOUNDARY_CORNER_LENGTH, startPointY,
startPointX + layoutSize.Width(), startPointY, skpaint);
canvas->drawLine(startPointX + layoutSize.Width(), startPointY,
startPointX + layoutSize.Width(), startPointY + BOUNDARY_CORNER_LENGTH, skpaint);
canvas->drawLine(startPointX, startPointY + layoutSize.Height(),
startPointX + BOUNDARY_CORNER_LENGTH, startPointY + layoutSize.Height(), skpaint);
canvas->drawLine(startPointX, startPointY + layoutSize.Height() - BOUNDARY_CORNER_LENGTH,
startPointX, startPointY + layoutSize.Height(), skpaint);
canvas->drawLine(startPointX + layoutSize.Width() - BOUNDARY_CORNER_LENGTH, startPointY + layoutSize.Height(),
startPointX + layoutSize.Width(), startPointY + layoutSize.Height(), skpaint);
canvas->drawLine(startPointX + layoutSize.Width(), startPointY + layoutSize.Height() - BOUNDARY_CORNER_LENGTH,
startPointX + layoutSize.Width(), startPointY + layoutSize.Height(), skpaint);
}
}
@@ -0,0 +1,44 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_PAINTER_ROSEN_DEBUG_BOUNDARY_PAINTER_H
#define FOUNDATION_ACE_FRAMEWORKS_CORE_PAINTER_ROSEN_DEBUG_BOUNDARY_PAINTER_H
#include <math.h>
#include "base/memory/ace_type.h"
#include "base/utils/utils.h"
#include "core/components/common/layout/constants.h"
#include "core/components/common/properties/border.h"
#include "core/components/common/properties/border_edge.h"
#include "core/components/common/properties/border_image_edge.h"
#include "core/components/common/properties/decoration.h"
#include "core/components/common/properties/edge.h"
#include "core/components/image/render_image.h"
#include "core/pipeline/base/rosen_render_context.h"
namespace OHOS::Ace {
class RosenDebugBoundaryPainter : public virtual AceType {
DECLARE_ACE_TYPE(RosenDebugBoundaryPainter, AceType);
public:
static void PaintDebugBoundary(SkCanvas* canvas, const Offset& offset, const Size& layoutSize);
static void PaintDebugMargin(SkCanvas* canvas, const Offset& offset, const Size& layoutSize, const EdgePx margin);
static void PaintDebugCorner(SkCanvas* canvas, const Offset& offset, const Size& layoutSize);
};
}
#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_PAINTER_ROSEN_DEBUG_BOUNDARY_PAINTER_H