draw方法结束后标记pixelmap dirty

Signed-off-by: tetsuou <wangzhe231@huawei.com>
This commit is contained in:
tetsuou 2024-11-21 15:28:36 +08:00
parent d33f246954
commit 80986e1d10
3 changed files with 95 additions and 4 deletions

View File

@ -147,6 +147,7 @@ if (is_arkui_x) {
external_deps += [
"hilog:libhilog",
"image_framework:image_native",
"image_framework:image_utils",
"init:libbegetutil",
]
deps += [ "../../../../../utils:libgraphic_utils" ]

View File

@ -20,7 +20,7 @@
#include "src/utils/SkUTF.h"
#ifdef ROSEN_OHOS
#include "pixel_map.h"
#include "image_utils.h"
#include "pixel_map_napi.h"
#endif
#include "native_value.h"
@ -114,6 +114,8 @@ struct PixelMapReleaseContext {
~PixelMapReleaseContext()
{
if (pixelMap_ != nullptr)
pixelMap_->MarkDirty();
pixelMap_ = nullptr;
}
@ -347,6 +349,7 @@ napi_value JsCanvas::Constructor(napi_env env, napi_callback_info info)
Canvas* canvas = new Canvas();
canvas->Bind(bitmap);
JsCanvas *jsCanvas = new JsCanvas(canvas, true);
jsCanvas->mPixelMap_ = pixelMapNapi->GetPixelNapiInner();
status = napi_wrap(env, jsThis, jsCanvas, JsCanvas::Destructor, nullptr, nullptr);
if (status != napi_ok) {
delete jsCanvas;
@ -489,6 +492,10 @@ napi_value JsCanvas::OnClear(napi_env env, napi_callback_info info)
auto color = Color::ColorQuadSetARGB(argb[ARGC_ZERO], argb[ARGC_ONE], argb[ARGC_TWO], argb[ARGC_THREE]);
JS_CALL_DRAWING_FUNC(m_canvas->Clear(color));
#ifdef ROSEN_OHOS
if (mPixelMap_ != nullptr)
mPixelMap_->MarkDirty();
#endif
return nullptr;
}
@ -504,10 +511,8 @@ napi_value JsCanvas::OnDrawShadow(napi_env env, napi_callback_info info)
ROSEN_LOGE("JsCanvas::OnDrawShadow canvas is null.");
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
}
napi_value argv[ARGC_SEVEN] = { nullptr };
CHECK_PARAM_NUMBER_WITHOUT_OPTIONAL_PARAMS(argv, ARGC_SEVEN);
JsPath* jsPath = nullptr;
GET_UNWRAP_PARAM(ARGC_ZERO, jsPath);
@ -546,6 +551,10 @@ napi_value JsCanvas::OnDrawShadow(napi_env env, napi_callback_info info)
spotColor[ARGC_TWO], spotColor[ARGC_THREE]);
m_canvas->DrawShadow(*jsPath->GetPath(), offset, lightPos, lightRadius, ambientColorPara, spotColorPara,
static_cast<ShadowFlags>(shadowFlag));
#ifdef ROSEN_OHOS
if (mPixelMap_ != nullptr)
mPixelMap_->MarkDirty();
#endif
return nullptr;
}
@ -578,6 +587,10 @@ napi_value JsCanvas::OnDrawArc(napi_env env, napi_callback_info info)
GET_DOUBLE_PARAM(ARGC_TWO, sweepAngle);
JS_CALL_DRAWING_FUNC(m_canvas->DrawArc(drawingRect, startAngle, sweepAngle));
#ifdef ROSEN_OHOS
if (mPixelMap_ != nullptr)
mPixelMap_->MarkDirty();
#endif
return nullptr;
}
@ -623,6 +636,10 @@ napi_value JsCanvas::OnDrawRect(napi_env env, napi_callback_info info)
DRAWING_PERFORMANCE_TEST_NAP_RETURN(nullptr);
m_canvas->DrawRect(drawingRect);
#ifdef ROSEN_OHOS
if (mPixelMap_ != nullptr)
mPixelMap_->MarkDirty();
#endif
return nullptr;
}
@ -653,6 +670,10 @@ napi_value JsCanvas::OnDrawCircle(napi_env env, napi_callback_info info)
Drawing::Point centerPt = Drawing::Point(x, y);
DRAWING_PERFORMANCE_TEST_NAP_RETURN(nullptr);
m_canvas->DrawCircle(centerPt, radius);
#ifdef ROSEN_OHOS
if (mPixelMap_ != nullptr)
mPixelMap_->MarkDirty();
#endif
return nullptr;
}
@ -723,6 +744,8 @@ napi_value JsCanvas::OnDrawImage(napi_env env, napi_callback_info info)
m_canvas->DrawImage(*image, px, py, *samplingOptions.get());
}
if (mPixelMap_ != nullptr)
mPixelMap_->MarkDirty();
#endif
return nullptr;
}
@ -785,6 +808,10 @@ napi_value JsCanvas::OnDrawColor(napi_env env, napi_callback_info info)
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Invalid params.");
}
#ifdef ROSEN_OHOS
if (mPixelMap_ != nullptr)
mPixelMap_->MarkDirty();
#endif
return nullptr;
}
@ -811,6 +838,10 @@ napi_value JsCanvas::OnDrawOval(napi_env env, napi_callback_info info)
Drawing::Rect drawingRect = Drawing::Rect(ltrb[ARGC_ZERO], ltrb[ARGC_ONE], ltrb[ARGC_TWO], ltrb[ARGC_THREE]);
JS_CALL_DRAWING_FUNC(m_canvas->DrawOval(drawingRect));
#ifdef ROSEN_OHOS
if (mPixelMap_ != nullptr)
mPixelMap_->MarkDirty();
#endif
return nullptr;
}
@ -838,6 +869,10 @@ napi_value JsCanvas::OnDrawPoint(napi_env env, napi_callback_info info)
DRAWING_PERFORMANCE_TEST_NAP_RETURN(nullptr);
m_canvas->DrawPoint(Point(px, py));
#ifdef ROSEN_OHOS
if (mPixelMap_ != nullptr)
mPixelMap_->MarkDirty();
#endif
return nullptr;
}
@ -894,6 +929,10 @@ napi_value JsCanvas::OnDrawPoints(napi_env env, napi_callback_info info)
return nullptr;
}
JS_CALL_DRAWING_FUNC(m_canvas->DrawPoints(PointMode::POINTS_POINTMODE, size, points));
#ifdef ROSEN_OHOS
if (mPixelMap_ != nullptr)
mPixelMap_->MarkDirty();
#endif
delete [] points;
return nullptr;
}
@ -911,6 +950,10 @@ napi_value JsCanvas::OnDrawPoints(napi_env env, napi_callback_info info)
return nullptr;
}
JS_CALL_DRAWING_FUNC(m_canvas->DrawPoints(static_cast<PointMode>(pointMode), size, points));
#ifdef ROSEN_OHOS
if (mPixelMap_ != nullptr)
mPixelMap_->MarkDirty();
#endif
delete [] points;
return nullptr;
}
@ -942,6 +985,10 @@ napi_value JsCanvas::OnDrawPath(napi_env env, napi_callback_info info)
DRAWING_PERFORMANCE_TEST_NAP_RETURN(nullptr);
m_canvas->DrawPath(*jsPath->GetPath());
#ifdef ROSEN_OHOS
if (mPixelMap_ != nullptr)
mPixelMap_->MarkDirty();
#endif
return nullptr;
}
@ -973,6 +1020,10 @@ napi_value JsCanvas::OnDrawLine(napi_env env, napi_callback_info info)
DRAWING_PERFORMANCE_TEST_NAP_RETURN(nullptr);
m_canvas->DrawLine(Point(startPx, startPy), Point(endPx, endPy));
#ifdef ROSEN_OHOS
if (mPixelMap_ != nullptr)
mPixelMap_->MarkDirty();
#endif
return nullptr;
}
@ -1002,6 +1053,10 @@ napi_value JsCanvas::OnDrawText(napi_env env, napi_callback_info info)
DRAWING_PERFORMANCE_TEST_NAP_RETURN(nullptr);
m_canvas->DrawTextBlob(jsTextBlob->GetTextBlob().get(), x, y);
#ifdef ROSEN_OHOS
if (mPixelMap_ != nullptr)
mPixelMap_->MarkDirty();
#endif
return nullptr;
}
@ -1056,6 +1111,10 @@ napi_value JsCanvas::OnDrawSingleCharacter(napi_env env, napi_callback_info info
"Parameter verification failed. Input parameter0 should be single character.");
}
m_canvas->DrawSingleCharacter(unicode, *font, x, y);
#ifdef ROSEN_OHOS
if (mPixelMap_ != nullptr)
mPixelMap_->MarkDirty();
#endif
return nullptr;
}
@ -1141,6 +1200,8 @@ napi_value JsCanvas::OnDrawPixelMapMesh(napi_env env, napi_callback_info info)
if (colorsSize == 0) {
DrawingPixelMapMesh(pixelMap, column, row, verticesMesh, nullptr, m_canvas);
if (mPixelMap_ != nullptr)
mPixelMap_->MarkDirty();
delete []vertices;
return nullptr;
}
@ -1167,6 +1228,8 @@ napi_value JsCanvas::OnDrawPixelMapMesh(napi_env env, napi_callback_info info)
uint32_t* colorsMesh = colors + colorOffset;
DrawingPixelMapMesh(pixelMap, column, row, verticesMesh, colorsMesh, m_canvas);
if (mPixelMap_ != nullptr)
mPixelMap_->MarkDirty();
delete []vertices;
delete []colors;
return nullptr;
@ -1197,6 +1260,10 @@ napi_value JsCanvas::OnDrawRegion(napi_env env, napi_callback_info info)
return nullptr;
}
JS_CALL_DRAWING_FUNC(m_canvas->DrawRegion(*jsRegion->GetRegion()));
#ifdef ROSEN_OHOS
if (mPixelMap_ != nullptr)
mPixelMap_->MarkDirty();
#endif
return nullptr;
}
@ -1224,6 +1291,10 @@ napi_value JsCanvas::OnDrawBackground(napi_env env, napi_callback_info info)
}
m_canvas->DrawBackground(*jsBrush->GetBrush());
#ifdef ROSEN_OHOS
if (mPixelMap_ != nullptr)
mPixelMap_->MarkDirty();
#endif
return nullptr;
}
@ -1247,6 +1318,10 @@ napi_value JsCanvas::OnDrawRoundRect(napi_env env, napi_callback_info info)
GET_UNWRAP_PARAM(ARGC_ZERO, jsRoundRect);
m_canvas->DrawRoundRect(jsRoundRect->GetRoundRect());
#ifdef ROSEN_OHOS
if (mPixelMap_ != nullptr)
mPixelMap_->MarkDirty();
#endif
return nullptr;
}
@ -1273,6 +1348,10 @@ napi_value JsCanvas::OnDrawNestedRoundRect(napi_env env, napi_callback_info info
GET_UNWRAP_PARAM(ARGC_ONE, jsInner);
m_canvas->DrawNestedRoundRect(jsOuter->GetRoundRect(), jsInner->GetRoundRect());
#ifdef ROSEN_OHOS
if (mPixelMap_ != nullptr)
mPixelMap_->MarkDirty();
#endif
return nullptr;
}
@ -2024,6 +2103,8 @@ napi_value JsCanvas::OnDrawImageRect(napi_env env, napi_callback_info info)
}
m_canvas->DrawImageRect(*image, dstRect, *samplingOptions.get());
}
if (mPixelMap_ != nullptr)
mPixelMap_->MarkDirty();
#endif
return nullptr;
}
@ -2137,7 +2218,10 @@ napi_value JsCanvas::OnDrawImageRectWithSrc(napi_env env, napi_callback_info inf
}
Drawing::Rect dstRect = Drawing::Rect(ltrb[ARGC_ZERO], ltrb[ARGC_ONE], ltrb[ARGC_TWO], ltrb[ARGC_THREE]);
return OnDrawingImageRectWithSrc(env, argv, argc, *m_canvas, pixel, srcRect, dstRect);
napi_value result = OnDrawingImageRectWithSrc(env, argv, argc, *m_canvas, pixel, srcRect, dstRect);
if (mPixelMap_ != nullptr)
mPixelMap_->MarkDirty();
return result;
#else
return nullptr;
#endif

View File

@ -18,6 +18,9 @@
#include <native_engine/native_engine.h>
#include <native_engine/native_value.h>
#ifdef ROSEN_OHOS
#include "pixel_map.h"
#endif
namespace OHOS::Rosen {
namespace Drawing {
@ -150,6 +153,9 @@ private:
static thread_local napi_ref constructor_;
Canvas* m_canvas = nullptr;
bool owned_ = false;
#ifdef ROSEN_OHOS
std::shared_ptr<Media::PixelMap> mPixelMap_ = nullptr;
#endif
};
} // namespace Drawing
} // namespace OHOS::Rosen