Skip to content

Commit

Permalink
Merge pull request #117 from Louis-C7/sig
Browse files Browse the repository at this point in the history
fix: preventing potential leak
  • Loading branch information
Louis-C7 authored May 15, 2024
2 parents 5ce4a87 + 6fdc0f8 commit 9ed619f
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 17 deletions.
2 changes: 1 addition & 1 deletion tester/harmony/svg/src/main/cpp/FontHolderBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ void FontHolderBase::InheritFont(const std::shared_ptr<FontData> &parent, double
}
}

} // namespace rnoh
} // namespace svg
} // namespace rnoh
14 changes: 7 additions & 7 deletions tester/harmony/svg/src/main/cpp/SvgGraphic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,11 @@ void SvgGraphic::SetGradientStyle(double opacity) {
OH_Drawing_Point2D center = {static_cast<float>(info.cx), static_cast<float>(info.cy)};
OH_Drawing_Matrix *concatMatrix = OH_Drawing_MatrixCreate();
OH_Drawing_MatrixConcat(concatMatrix, scaleMatrix, transMatrix);
OH_Drawing_BrushSetShaderEffect(fillBrush_, OH_Drawing_ShaderEffectCreateTwoPointConicalGradient(
&focal, 0, &center, info.rx > info.ry ? info.rx : info.ry,
colors.data(), pos.data(), colors.size(),
static_cast<OH_Drawing_TileMode>(gradient->GetSpreadMethod()),
concatMatrix));
// OH_Drawing_BrushSetShaderEffect(fillBrush_, OH_Drawing_ShaderEffectCreateTwoPointConicalGradient(
// &focal, 0, &center, info.rx > info.ry ? info.rx : info.ry,
// colors.data(), pos.data(), colors.size(),
// static_cast<OH_Drawing_TileMode>(gradient->GetSpreadMethod()),
// concatMatrix));
OH_Drawing_MatrixDestroy(concatMatrix);
OH_Drawing_MatrixDestroy(scaleMatrix);
}
Expand Down Expand Up @@ -400,8 +400,8 @@ void SvgGraphic::UpdateLineDash() {
intervals[i] = static_cast<float>(lineDashState[i]);
}
float phase = static_cast<float>(strokeState.GetStrokeDashOffset());
auto *DashPathEffect = OH_Drawing_CreateDashPathEffect(intervals, lineDashState.size(), phase);
OH_Drawing_PenSetPathEffect(strokePen_, DashPathEffect);
dashPathEffect_ = OH_Drawing_CreateDashPathEffect(intervals, lineDashState.size(), phase);
OH_Drawing_PenSetPathEffect(strokePen_, dashPathEffect_);
}
}

Expand Down
3 changes: 3 additions & 0 deletions tester/harmony/svg/src/main/cpp/SvgGraphic.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#pragma once
#include <native_drawing/drawing_brush.h>
#include <native_drawing/drawing_path_effect.h>
#include <native_drawing/drawing_pen.h>
#include "SvgNode.h"
#include "RNOH/CppComponentInstance.h"
Expand All @@ -23,6 +24,7 @@ class SvgGraphic : virtual public SvgNode {
OH_Drawing_BrushDestroy(fillBrush_);
OH_Drawing_PenDestroy(strokePen_);
OH_Drawing_PathDestroy(path_);
OH_Drawing_PathEffectDestroy(dashPathEffect_);
}


Expand All @@ -31,6 +33,7 @@ class SvgGraphic : virtual public SvgNode {
OH_Drawing_Path *path_;
OH_Drawing_Brush *fillBrush_;
OH_Drawing_Pen *strokePen_;
OH_Drawing_PathEffect *dashPathEffect_;

// Use Brush to draw fill
void OnGraphicFill(OH_Drawing_Canvas *canvas);
Expand Down
7 changes: 7 additions & 0 deletions tester/harmony/svg/src/main/cpp/SvgHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,12 @@ void SvgHost::OnChildInsertCommon(const std::shared_ptr<SvgHost> &childSvgHost)
GetSvgNode()->AppendChild(childSvgHost->GetSvgNode());
}

void SvgHost::OnChildRemoveCommon(const std::shared_ptr<SvgHost> &childSvgHost) {
if (!childSvgHost) {
return;
}
GetSvgNode()->removeChild(childSvgHost->GetSvgNode());
}

} // namespace svg
} // namespace rnoh
14 changes: 7 additions & 7 deletions tester/harmony/svg/src/main/cpp/SvgHost.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ namespace svg {

class SvgHost {
public:
void SetSvgNode(const std::shared_ptr<SvgNode>& svgNode) {
m_svgNode = svgNode;
};
const std::shared_ptr<SvgNode>& GetSvgNode() {
return m_svgNode;
};
SvgHost() = default;
virtual ~SvgHost() = default;
void SetSvgNode(const std::shared_ptr<SvgNode> &svgNode) { m_svgNode = svgNode; };
const std::shared_ptr<SvgNode> &GetSvgNode() { return m_svgNode; };

void OnChildInsertCommon(const std::shared_ptr<SvgHost>& childSvgHost);
void OnChildInsertCommon(const std::shared_ptr<SvgHost> &childSvgHost);

void OnChildRemoveCommon(const std::shared_ptr<SvgHost> &childSvgHost);

private:
std::shared_ptr<SvgNode> m_svgNode;
Expand Down
1 change: 1 addition & 0 deletions tester/harmony/svg/src/main/cpp/SvgNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ Rect SvgNode::AsBounds() {
float width = OH_Drawing_RectGetWidth(ohRect);
float height = OH_Drawing_RectGetHeight(ohRect);
auto rect = Rect(x, y, width, height);
OH_Drawing_RectDestroy(ohRect);
return rect;
}

Expand Down
8 changes: 8 additions & 0 deletions tester/harmony/svg/src/main/cpp/SvgNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ class SvgNode : public std::enable_shared_from_this<SvgNode> {

virtual void AppendChild(const std::shared_ptr<SvgNode> &child) { children_.emplace_back(child); }

virtual void removeChild(const std::shared_ptr<SvgNode> &child) {
auto it = std::find(children_.begin(), children_.end(), child);
if (it != children_.end()) {
auto child = std::move(*it);
children_.erase(it);
}
}

using ConcreteProps = std::shared_ptr<const facebook::react::RNSVGCommonProps>;
void UpdateCommonProps(const ConcreteProps &props);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class RNSVGGroupComponentInstance : public CppComponentInstance<facebook::react:
}

void onChildRemoved(ComponentInstance::Shared const &childComponentInstance) override{

OnChildRemoveCommon(std::dynamic_pointer_cast<SvgHost>(childComponentInstance));
}

SvgArkUINode &getLocalRootArkUINode() override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ class RNSVGSvgViewComponentInstance : public CppComponentInstance<facebook::reac
}

// TODO get SvgNode and delete it from svg tree
void onChildRemoved(ComponentInstance::Shared const &childComponentInstance) override {}
void onChildRemoved(ComponentInstance::Shared const &childComponentInstance) override {
OnChildRemoveCommon(std::dynamic_pointer_cast<SvgHost>(childComponentInstance));
}

SvgArkUINode &getLocalRootArkUINode() override;

Expand Down

0 comments on commit 9ed619f

Please sign in to comment.