!17330 draw方法结束后标记pixelmap dirty

Merge pull request !17330 from 难过的馅/master
This commit is contained in:
openharmony_ci 2024-11-21 11:01:46 +00:00 committed by Gitee
commit 8c452c0425
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 114 additions and 7 deletions

View File

@ -20,7 +20,6 @@
#include "src/utils/SkUTF.h"
#ifdef ROSEN_OHOS
#include "pixel_map.h"
#include "pixel_map_napi.h"
#endif
#include "native_value.h"
@ -347,6 +346,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 +489,11 @@ 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 +509,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 +549,11 @@ 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 +586,11 @@ 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,11 @@ 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 +671,11 @@ 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 +746,9 @@ 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 +811,11 @@ 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 +842,11 @@ 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 +874,11 @@ 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;
}
@ -876,13 +917,11 @@ napi_value JsCanvas::OnDrawPoints(napi_env env, napi_callback_info info)
size_t argc = ARGC_TWO;
napi_value argv[ARGC_TWO] = {nullptr};
CHECK_PARAM_NUMBER_WITH_OPTIONAL_PARAMS(argv, argc, ARGC_ONE, ARGC_TWO);
napi_value array = argv[ARGC_ZERO];
uint32_t size = 0;
if (napi_get_array_length(env, array, &size) != napi_ok || (size == 0)) {
return NapiThrowError(env, DrawingErrorCode::ERROR_INVALID_PARAM, "Incorrect src array size.");
}
if (argc == ARGC_ONE) {
Point* points = new(std::nothrow) Point[size];
if (points == nullptr) {
@ -894,13 +933,17 @@ 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;
}
int32_t pointMode = 0;
GET_ENUM_PARAM(ARGC_ONE, pointMode, 0, static_cast<int32_t>(PointMode::POLYGON_POINTMODE));
Point* points = new(std::nothrow) Point[size];
if (points == nullptr) {
return nullptr;
@ -911,6 +954,11 @@ 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 +990,11 @@ 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 +1026,11 @@ 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 +1060,11 @@ 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 +1119,11 @@ 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 +1209,9 @@ 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 +1238,9 @@ 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 +1271,11 @@ 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 +1303,11 @@ 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 +1331,11 @@ 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 +1362,11 @@ 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 +2118,9 @@ 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 +2234,11 @@ 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