!48369 修复context在解绑canvas后仍能在该canvas上绘制的问题

Merge pull request !48369 from 陈俞池/cc1112
This commit is contained in:
openharmony_ci 2024-11-19 02:39:10 +00:00 committed by Gitee
commit 3afbd3bbd6
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
4 changed files with 10 additions and 7 deletions

View File

@ -38,11 +38,6 @@ void CanvasPattern::OnDetachFromFrameNode(FrameNode* frameNode)
DetachRenderContext();
}
void CanvasPattern::OnDetachFromMainTree()
{
DetachRenderContext();
}
void CanvasPattern::AttachRenderContext()
{
isAttached_ = true;

View File

@ -194,7 +194,6 @@ public:
private:
void OnAttachToFrameNode() override;
void OnDetachFromFrameNode(FrameNode* frameNode) override;
void OnDetachFromMainTree() override;
void FireOnContext2DAttach();
void FireOnContext2DDetach();
bool OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper>& dirty, const DirtySwapConfig& config) override;

View File

@ -60,6 +60,9 @@ void CanvasRenderingContext2DModelNG::OnDetachFromCanvas()
if (onContext2DDetach_) {
onContext2DDetach_();
}
if (apiVersion_ > static_cast<int32_t>(PlatformVersion::VERSION_FOURTEEN)) {
weakPattern_ = nullptr;
}
}
void CanvasRenderingContext2DModelNG::SetPattern(RefPtr<AceType> newPattern)

View File

@ -20,6 +20,7 @@
#include "base/geometry/dimension.h"
#include "base/memory/ace_type.h"
#include "core/common/container.h"
#include "core/components/common/layout/constants.h"
#include "core/components_ng/pattern/canvas/canvas_renderer_type.h"
#include <stdint.h>
@ -29,7 +30,10 @@ class RenderingContext2DModel : public AceType {
DECLARE_ACE_TYPE(RenderingContext2DModel, AceType)
public:
RenderingContext2DModel() = default;
RenderingContext2DModel()
{
apiVersion_ = Container::GetCurrentApiTargetVersion();
}
virtual ~RenderingContext2DModel() = default;
virtual void SetPattern(RefPtr<AceType> pattern) = 0;
@ -131,6 +135,8 @@ public:
pattern->SetTranslateY(transform.translateY);
}
protected:
int32_t apiVersion_ = 0;
ACE_DISALLOW_COPY_AND_MOVE(RenderingContext2DModel);
};