diff --git a/BUILD.gn b/BUILD.gn index de96224d5bff33710081a3e6467f9c987e3f5b5a..1c424bfbb2553848653793e92d62a54d6baa6e32 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -73,6 +73,7 @@ config("graphic_define_config") { } else if (ohos_kernel_type == "liteos_m") { include_dirs += [ "//third_party/freetype/include" ] defines += [ + "ENABLE_CANVAS_EXTEND=0", "GRAPHIC_ENABLE_DASH_GENERATE_FLAG=1", "GRAPHIC_ENABLE_BLUR_EFFECT_FLAG=1", "GRAPHIC_ENABLE_PATTERN_FILL_FLAG=1", diff --git a/frameworks/components/ui_canvas.cpp b/frameworks/components/ui_canvas.cpp index ba6398f9e44aa0b8825717d020a6ee2942a1e8c6..85e7d5a692c16f9b40852f526e56412a5697a524 100644 --- a/frameworks/components/ui_canvas.cpp +++ b/frameworks/components/ui_canvas.cpp @@ -17,7 +17,6 @@ #include "draw/clip_utils.h" #include "draw/draw_arc.h" -#include "draw/draw_canvas.h" #include "draw/draw_image.h" #include "gfx_utils/graphic_log.h" #include "render/render_buffer.h" @@ -25,6 +24,12 @@ #include "render/render_scanline.h" namespace OHOS { +UICanvas::UICanvasPath::~UICanvasPath() +{ + points_.Clear(); + cmd_.Clear(); + arcParam_.Clear(); +} BufferInfo* UICanvas::gfxMapBuffer_ = nullptr; @@ -35,6 +40,7 @@ void RenderSolid(const Paint& paint, void UICanvas::BeginPath() { +#if defined(ENABLE_CANVAS_EXTEND) && ENABLE_CANVAS_EXTEND /* If the previous path is not added to the drawing linked list, it should be destroyed directly. */ if (vertices_ != nullptr && vertices_->GetTotalVertices() == 0) { delete vertices_; @@ -46,26 +52,68 @@ void UICanvas::BeginPath() GRAPHIC_LOGE("new UICanvasVertices fail"); return; } +#else + if (path_ != nullptr && path_->strokeCount_ == 0) { + delete path_; + path_ = nullptr; + } + + path_ = new UICanvasPath(); + if (path_ == nullptr) { + GRAPHIC_LOGE("new UICanvasPath fail"); + return; + } +#endif } void UICanvas::MoveTo(const Point& point) { +#if defined(ENABLE_CANVAS_EXTEND) && ENABLE_CANVAS_EXTEND if (vertices_ == nullptr) { return; } vertices_->MoveTo(point.x, point.y); +#else + if (path_ == nullptr) { + return; + } + + path_->startPos_ = point; + /* If the previous command is also CMD_MOVE_TO, the previous command is overwritten. */ + if ((path_->cmd_.Size() != 0) && (path_->cmd_.Tail()->data_ == CMD_MOVE_TO)) { + path_->points_.Tail()->data_ = point; + return; + } + path_->points_.PushBack(point); + path_->cmd_.PushBack(CMD_MOVE_TO); +#endif } void UICanvas::LineTo(const Point& point) { +#if defined(ENABLE_CANVAS_EXTEND) && ENABLE_CANVAS_EXTEND if (vertices_ == nullptr) { return; } vertices_->LineTo(point.x, point.y); +#else + if (path_ == nullptr) { + return; + } + + path_->points_.PushBack(point); + if (path_->cmd_.Size() == 0) { + path_->startPos_ = point; + path_->cmd_.PushBack(CMD_MOVE_TO); + } else { + path_->cmd_.PushBack(CMD_LINE_TO); + } +#endif } void UICanvas::ArcTo(const Point& center, uint16_t radius, int16_t startAngle, int16_t endAngle) { +#if defined(ENABLE_CANVAS_EXTEND) && ENABLE_CANVAS_EXTEND if (vertices_ == nullptr || startAngle == endAngle) { return; } @@ -86,10 +134,55 @@ void UICanvas::ArcTo(const Point& center, uint16_t radius, int16_t startAngle, i largeArcFlag = true; } vertices_->ArcTo(radius, radius, angle, largeArcFlag, 1, float(center.x + sinma), float(center.y - cosma)); +#else + if (path_ == nullptr) { + return; + } + + /* + * If there is no command before CMD_ARC, only the arc is drawn. If there is a command in front of + * CMD_ARC, the start point of arc must be connected to the end point of the path. + */ + float sinma = radius * Sin(startAngle); + float cosma = radius * Sin(QUARTER_IN_DEGREE - startAngle); + if (path_->cmd_.Size() != 0) { + path_->points_.PushBack({MATH_ROUND(center.x + sinma), MATH_ROUND(center.y - cosma)}); + path_->cmd_.PushBack(CMD_LINE_TO); + } else { + path_->startPos_ = {MATH_ROUND(center.x + sinma), MATH_ROUND(center.y - cosma)}; + } + + /* If the ARC scan range exceeds 360 degrees, the end point of the path is the position of the start angle. */ + if (MATH_ABS(startAngle - endAngle) < CIRCLE_IN_DEGREE) { + sinma = radius * Sin(endAngle); + cosma = radius * Sin(QUARTER_IN_DEGREE - endAngle); + } + path_->points_.PushBack({MATH_ROUND(center.x + sinma), MATH_ROUND(center.y - cosma)}); + path_->cmd_.PushBack(CMD_ARC); + + int16_t start; + int16_t end; + if (startAngle > endAngle) { + start = endAngle; + end = startAngle; + } else { + start = startAngle; + end = endAngle; + } + + DrawArc::GetInstance()->GetDrawRange(start, end); + ArcParam param; + param.center = center; + param.radius = radius; + param.startAngle = start; + param.endAngle = end; + path_->arcParam_.PushBack(param); +#endif } void UICanvas::AddRect(const Point& point, int16_t height, int16_t width) { +#if defined(ENABLE_CANVAS_EXTEND) && ENABLE_CANVAS_EXTEND if (vertices_ == nullptr) { return; } @@ -106,23 +199,48 @@ void UICanvas::AddRect(const Point& point, int16_t height, int16_t width) if (fBottom > INT16_MAX) { bottom += setup; } + MoveTo(point); LineTo({right, point.y}); LineTo({right, bottom}); LineTo({point.x, bottom}); +#else + if (path_ == nullptr) { + return; + } + + MoveTo(point); + LineTo({static_cast(point.x + width), point.y}); + LineTo({static_cast(point.x + width), static_cast(point.y + height)}); + LineTo({point.x, static_cast(point.y + height)}); + +#endif ClosePath(); } void UICanvas::ClosePath() { +#if defined(ENABLE_CANVAS_EXTEND) && ENABLE_CANVAS_EXTEND if (vertices_ == nullptr) { return; } vertices_->ClosePolygon(); +#else + if ((path_ == nullptr) || (path_->cmd_.Size() == 0)) { + return; + } + + path_->points_.PushBack(path_->startPos_); + path_->cmd_.PushBack(CMD_CLOSE); +#endif } UICanvas::~UICanvas() { + if ((path_ != nullptr) && (path_->strokeCount_ == 0)) { + delete path_; + path_ = nullptr; + } void* param = nullptr; ListNode* curDraw = drawCmdList_.Begin(); for (; curDraw != drawCmdList_.End(); curDraw = curDraw->next_) { @@ -140,6 +258,10 @@ UICanvas::~UICanvas() void UICanvas::Clear() { + if ((path_ != nullptr) && (path_->strokeCount_ == 0)) { + delete path_; + path_ = nullptr; + } void* param = nullptr; ListNode* curDraw = drawCmdList_.Begin(); for (; curDraw != drawCmdList_.End(); curDraw = curDraw->next_) { @@ -155,7 +277,7 @@ void UICanvas::Clear() Invalidate(); } -void DeleteImageParam(void* param) +void UICanvas::DeleteImageParam(void* param) { ImageParam* imageParam = static_cast(param); if (imageParam->image != nullptr) { @@ -166,9 +288,10 @@ void DeleteImageParam(void* param) imageParam = nullptr; } -void DeletePathParam(void* param) +void UICanvas::DeletePathParam(void* param) { PathParam* pathParam = static_cast(param); +#if defined(ENABLE_CANVAS_EXTEND) && ENABLE_CANVAS_EXTEND if (pathParam->vertices != nullptr) { pathParam->vertices->FreeAll(); pathParam->vertices = nullptr; @@ -176,6 +299,12 @@ void DeletePathParam(void* param) if (pathParam->imageParam != nullptr) { DeleteImageParam(pathParam->imageParam); } +#else + pathParam->path->strokeCount_--; + if (pathParam->path->strokeCount_ == 0) { + delete pathParam->path; + } +#endif delete pathParam; pathParam = nullptr; } @@ -243,6 +372,7 @@ void UICanvas::DrawCurve(const Point& startPoint, void UICanvas::DrawRect(const Point& startPoint, int16_t height, int16_t width, const Paint& paint) { +#if defined(ENABLE_CANVAS_EXTEND) && ENABLE_CANVAS_EXTEND if (!paint.GetChangeFlag()) { if (static_cast(paint.GetStyle()) & Paint::PaintStyle::STROKE_STYLE) { DrawRectSetCmd(startPoint, height, width, paint, Paint::PaintStyle::STROKE_STYLE); @@ -261,6 +391,43 @@ void UICanvas::DrawRect(const Point& startPoint, int16_t height, int16_t width, FillPath(paint); DrawPath(paint); } +#else + if (static_cast(paint.GetStyle()) & Paint::PaintStyle::STROKE_STYLE) { + RectParam* rectParam = new RectParam; + if (rectParam == nullptr) { + GRAPHIC_LOGE("new RectParam fail"); + return; + } + rectParam->start = startPoint; + rectParam->height = height; + rectParam->width = width; + + DrawCmd cmd; + cmd.paint = paint; + cmd.param = rectParam; + cmd.DeleteParam = DeleteRectParam; + cmd.DrawGraphics = DoDrawRect; + drawCmdList_.PushBack(cmd); + } + + if (static_cast(paint.GetStyle()) & Paint::PaintStyle::FILL_STYLE) { + RectParam* rectParam = new RectParam; + if (rectParam == nullptr) { + GRAPHIC_LOGE("new RectParam fail"); + return; + } + rectParam->start = startPoint; + rectParam->height = height; + rectParam->width = width; + + DrawCmd cmd; + cmd.paint = paint; + cmd.param = rectParam; + cmd.DeleteParam = DeleteRectParam; + cmd.DrawGraphics = DoFillRect; + drawCmdList_.PushBack(cmd); + } +#endif Invalidate(); } @@ -288,6 +455,7 @@ void UICanvas::DrawRectSetCmd(const Point& startPoint, int16_t height, int16_t w drawCmdList_.PushBack(cmd); } +#if defined(ENABLE_CANVAS_EXTEND) && ENABLE_CANVAS_EXTEND void UICanvas::StrokeRect(const Point& startPoint, int16_t height, int16_t width, const Paint& paint) { if (!paint.GetChangeFlag()) { @@ -331,9 +499,11 @@ void UICanvas::ClearRect(const Point& startPoint, int16_t height, int16_t width) ClosePath(); FillPath(paint); } +#endif void UICanvas::DrawCircle(const Point& center, uint16_t radius, const Paint& paint) { +#if defined(ENABLE_CANVAS_EXTEND) && ENABLE_CANVAS_EXTEND if (paint.GetChangeFlag()) { #if defined(GRAPHIC_ENABLE_BEZIER_ARC_FLAG) && GRAPHIC_ENABLE_BEZIER_ARC_FLAG if (vertices_ == nullptr) { @@ -366,7 +536,22 @@ void UICanvas::DrawCircle(const Point& center, uint16_t radius, const Paint& pai cmd.DrawGraphics = DoDrawCircle; drawCmdList_.PushBack(cmd); } +#else + CircleParam* circleParam = new CircleParam; + if (circleParam == nullptr) { + GRAPHIC_LOGE("new CircleParam fail"); + return; + } + circleParam->center = center; + circleParam->radius = radius; + DrawCmd cmd; + cmd.paint = paint; + cmd.param = circleParam; + cmd.DeleteParam = DeleteCircleParam; + cmd.DrawGraphics = DoDrawCircle; + drawCmdList_.PushBack(cmd); +#endif Invalidate(); } @@ -376,6 +561,7 @@ void UICanvas::DrawSector(const Point& center, int16_t endAngle, const Paint& paint) { +#if defined(ENABLE_CANVAS_EXTEND) && ENABLE_CANVAS_EXTEND BeginPath(); MoveTo(center); ArcTo(center, radius, startAngle, endAngle); @@ -386,16 +572,29 @@ void UICanvas::DrawSector(const Point& center, if (static_cast(paint.GetStyle()) & Paint::PaintStyle::FILL_STYLE) { FillPath(paint); } +#else + if (static_cast(paint.GetStyle()) & Paint::PaintStyle::FILL_STYLE) { + Paint innerPaint = paint; + innerPaint.SetStyle(Paint::PaintStyle::STROKE_STYLE); + innerPaint.SetStrokeWidth(radius); + innerPaint.SetStrokeColor(paint.GetFillColor()); + radius >>= 1; + DrawArc(center, radius, startAngle, endAngle, innerPaint); + } +#endif } void UICanvas::DrawArc(const Point& center, uint16_t radius, int16_t startAngle, int16_t endAngle, const Paint& paint) { if (static_cast(paint.GetStyle()) & Paint::PaintStyle::STROKE_STYLE) { +#if defined(ENABLE_CANVAS_EXTEND) && ENABLE_CANVAS_EXTEND if (paint.GetChangeFlag()) { ArcTo(center, radius, startAngle, endAngle); DrawPath(paint); - } else { + } else +#endif + { ArcParam* arcParam = new ArcParam; if (arcParam == nullptr) { GRAPHIC_LOGE("new ArcParam fail"); @@ -535,6 +734,7 @@ void UICanvas::DrawImage(const Point& startPoint, const char* image, void UICanvas::DrawPath(const Paint& paint) { +#if defined(ENABLE_CANVAS_EXTEND) && ENABLE_CANVAS_EXTEND if (vertices_ == nullptr) { return; } @@ -571,6 +771,20 @@ void UICanvas::DrawPath(const Paint& paint) pathParam->imageParam = imageParam; } +#endif +#else + if ((path_ == nullptr) || (path_->cmd_.Size() == 0)) { + return; + } + + path_->strokeCount_++; + PathParam* pathParam = new PathParam; + if (pathParam == nullptr) { + GRAPHIC_LOGE("new PathParam fail"); + return; + } + pathParam->path = path_; + pathParam->count = path_->cmd_.Size(); #endif DrawCmd cmd; cmd.paint = paint; @@ -581,6 +795,7 @@ void UICanvas::DrawPath(const Paint& paint) Invalidate(); } +#if defined(ENABLE_CANVAS_EXTEND) && ENABLE_CANVAS_EXTEND void UICanvas::FillPath(const Paint& paint) { if (vertices_ == nullptr) { @@ -627,6 +842,7 @@ void UICanvas::FillPath(const Paint& paint) drawCmdList_.PushBack(cmd); Invalidate(); } +#endif void UICanvas::OnDraw(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea) { @@ -640,6 +856,7 @@ void UICanvas::OnDraw(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea) if (!trunc.Intersect(trunc, coords)) { return; } +#if defined(ENABLE_CANVAS_EXTEND) && ENABLE_CANVAS_EXTEND bool haveComposite = false; for (; curDraw != drawCmdList_.End(); curDraw = curDraw->next_) { if (curDraw->data_.paint.HaveComposite()) { @@ -650,7 +867,9 @@ void UICanvas::OnDraw(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea) if (haveComposite) { OnBlendDraw(gfxDstBuffer, trunc); - } else { + } else +#endif + { curDraw = drawCmdList_.Begin(); for (; curDraw != drawCmdList_.End(); curDraw = curDraw->next_) { param = curDraw->data_.param; @@ -659,6 +878,7 @@ void UICanvas::OnDraw(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea) } } +#if defined(ENABLE_CANVAS_EXTEND) && ENABLE_CANVAS_EXTEND void OnBlendDrawPattern(ListNode* curDraw, UICanvas::DrawCmd& drawCmd, Rect& rect, @@ -791,6 +1011,7 @@ void UICanvas::OnBlendDraw(BufferInfo& gfxDstBuffer, const Rect& trunc) rasterizer, renBase, transform, pathParamBlend); } } +#endif void UICanvas::GetAbsolutePosition(const Point& prePoint, const Rect& rect, const Style& style, Point& point) { @@ -1071,7 +1292,94 @@ void UICanvas::DoDrawPath(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea, const Style& style) { +#if defined(ENABLE_CANVAS_EXTEND) && ENABLE_CANVAS_EXTEND BaseGfxEngine::GetInstance()->DrawPath(gfxDstBuffer, param, paint, rect, invalidatedArea, style); +#else + if (param == nullptr) { + return; + } + PathParam* pathParam = static_cast(param); + const UICanvasPath* path = pathParam->path; + if (path == nullptr) { + return; + } + Point pathEnd = {COORD_MIN, COORD_MIN}; + + ListNode* pointIter = path->points_.Begin(); + ListNode* arcIter = path->arcParam_.Begin(); + ListNode* iter = path->cmd_.Begin(); + for (uint16_t i = 0; (i < pathParam->count) && (iter != path->cmd_.End()); i++, iter = iter->next_) { + switch (iter->data_) { + case CMD_MOVE_TO: { + pointIter = pointIter->next_; + break; + } + case CMD_LINE_TO: { + Point start = pointIter->prev_->data_; + Point end = pointIter->data_; + pointIter = pointIter->next_; + if ((start.x == end.x) && (start.y == end.y)) { + break; + } + + GetAbsolutePosition(start, rect, style, start); + GetAbsolutePosition(end, rect, style, end); + BaseGfxEngine::GetInstance()->DrawLine(gfxDstBuffer, start, end, invalidatedArea, + paint.GetStrokeWidth(), paint.GetStrokeColor(), OPA_OPAQUE); + if ((pathEnd.x == start.x) && (pathEnd.y == start.y)) { + DoDrawLineJoin(gfxDstBuffer, start, invalidatedArea, paint); + } + pathEnd = end; + break; + } + case CMD_ARC: { + ArcInfo arcInfo = {{0}}; + arcInfo.imgPos = Point{0, 0}; + arcInfo.startAngle = arcIter->data_.startAngle; + arcInfo.endAngle = arcIter->data_.endAngle; + Style drawStyle = StyleDefault::GetDefaultStyle(); + drawStyle.lineWidth_ = static_cast(paint.GetStrokeWidth()); + drawStyle.lineColor_ = paint.GetStrokeColor(); + drawStyle.lineOpa_ = OPA_OPAQUE; + arcInfo.radius = arcIter->data_.radius + ((paint.GetStrokeWidth() + 1) >> 1); + + GetAbsolutePosition(arcIter->data_.center, rect, style, arcInfo.center); + BaseGfxEngine::GetInstance()->DrawArc(gfxDstBuffer, arcInfo, invalidatedArea, drawStyle, OPA_OPAQUE, + CapType::CAP_NONE); + if (pointIter != path->points_.Begin()) { + DoDrawLineJoin(gfxDstBuffer, pathEnd, invalidatedArea, paint); + } + + GetAbsolutePosition(pointIter->data_, rect, style, pathEnd); + pointIter = pointIter->next_; + arcIter = arcIter->next_; + break; + } + case CMD_CLOSE: { + Point start = pointIter->prev_->data_; + Point end = pointIter->data_; + GetAbsolutePosition(start, rect, style, start); + GetAbsolutePosition(end, rect, style, end); + if ((start.x != end.x) || (start.y != end.y)) { + BaseGfxEngine::GetInstance()->DrawLine(gfxDstBuffer, start, end, invalidatedArea, + paint.GetStrokeWidth(), paint.GetStrokeColor(), OPA_OPAQUE); + if ((pathEnd.x == start.x) && (pathEnd.y == start.y)) { + DoDrawLineJoin(gfxDstBuffer, start, invalidatedArea, paint); + } + pathEnd = end; + } + + if ((pathEnd.x == end.x) && (pathEnd.y == end.y)) { + DoDrawLineJoin(gfxDstBuffer, end, invalidatedArea, paint); + } + pointIter = pointIter->next_; + break; + } + default: + break; + } + } +#endif } void UICanvas::DoFillPath(BufferInfo& gfxDstBuffer, @@ -1264,6 +1572,7 @@ void UICanvas::DestroyMapBufferInfo() } } +#if defined(ENABLE_CANVAS_EXTEND) && ENABLE_CANVAS_EXTEND void UICanvas::BlendRaster(const Paint& paint, void* param, RasterizerScanlineAntialias& blendRasterizer, @@ -1333,4 +1642,5 @@ void UICanvas::BlendRaster(const Paint& paint, } #endif } +#endif // ENABLE_CANVAS_EXTEND } // namespace OHOS diff --git a/frameworks/draw/draw_canvas.cpp b/frameworks/draw/draw_canvas.cpp index b50e965c702d9a4070c86bc8de1df69879900a4f..e19877b379885abf5867f66c6bb4b74e582d6f09 100644 --- a/frameworks/draw/draw_canvas.cpp +++ b/frameworks/draw/draw_canvas.cpp @@ -32,6 +32,7 @@ void RenderSolid(const Paint& paint, RasterizerScanlineAntialias& rasterizer, Re RenderScanlinesAntiAliasSolid(rasterizer, scanline, renBase, color); } +#if defined(ENABLE_CANVAS_EXTEND) && ENABLE_CANVAS_EXTEND void DrawCanvas::DoRender(BufferInfo& gfxDstBuffer, void* param, const Paint& paint, @@ -140,6 +141,7 @@ void DrawCanvas::DoDrawShadow(BufferInfo& gfxDstBuffer, #endif // GRAPHIC_ENABLE_BLUR_EFFECT_FLAG } #endif // GRAPHIC_ENABLE_SHADOW_EFFECT_FLAG +#endif // ENABLE_CANVAS_EXTEND void DrawCanvas::InitRenderAndTransform(BufferInfo& gfxDstBuffer, RenderBuffer& renderBuffer, @@ -267,6 +269,7 @@ void DrawCanvas::BuildRadialGradientMatrix(const Paint& paint, #endif // GRAPHIC_ENABLE_GRADIENT_FILL_FLAG #if defined(GRAPHIC_ENABLE_PATTERN_FILL_FLAG) && GRAPHIC_ENABLE_PATTERN_FILL_FLAG +#if defined(ENABLE_CANVAS_EXTEND) && ENABLE_CANVAS_EXTEND void DrawCanvas::RenderPattern(const Paint& paint, void* param, RasterizerScanlineAntialias& rasterizer, @@ -286,6 +289,7 @@ void DrawCanvas::RenderPattern(const Paint& paint, rect.GetTop()); RenderScanlinesAntiAlias(rasterizer, scanline, renBase, allocator, spanPattern); } +#endif #endif // GRAPHIC_ENABLE_PATTERN_FILL_FLAG } // namespace OHOS diff --git a/frameworks/draw/draw_canvas.h b/frameworks/draw/draw_canvas.h index 0c68349f95745d2ca26afcb607e7d45b1068ffae..0a29fecd969ff91243e8e35c2a486147804c1b62 100644 --- a/frameworks/draw/draw_canvas.h +++ b/frameworks/draw/draw_canvas.h @@ -23,9 +23,9 @@ #include "gfx_utils/diagram/rasterizer/rasterizer_scanline_antialias.h" #include "gfx_utils/diagram/spancolorfill/fill_gradient_lut.h" - namespace OHOS { +#if defined(ENABLE_CANVAS_EXTEND) && ENABLE_CANVAS_EXTEND struct ImageParam : public HeapBase { Point start; uint16_t height; @@ -40,11 +40,13 @@ struct PathParam : public HeapBase { ImageParam* imageParam = nullptr; bool isStroke; }; +#endif class RenderBuffer; class RenderBase; class DrawCanvas : public HeapBase { public: +#if defined(ENABLE_CANVAS_EXTEND) && ENABLE_CANVAS_EXTEND static void DoRender(BufferInfo& gfxDstBuffer, void* param, const Paint& paint, @@ -62,7 +64,7 @@ public: const Style& style, const bool& isStroke); #endif - +#endif static void InitRenderAndTransform(BufferInfo& gfxDstBuffer, RenderBuffer& renderBuffer, const Rect& rect, @@ -114,6 +116,7 @@ public: #endif // GRAPHIC_ENABLE_GRADIENT_FILL_FLAG #if defined(GRAPHIC_ENABLE_PATTERN_FILL_FLAG) && GRAPHIC_ENABLE_PATTERN_FILL_FLAG +#if defined(ENABLE_CANVAS_EXTEND) && ENABLE_CANVAS_EXTEND /** * Render pattern mode */ @@ -123,6 +126,7 @@ public: RenderBase& renBase, FillBase& allocator, const Rect& rect); +#endif #endif // GRAPHIC_ENABLE_PATTERN_FILL_FLAG static void ChangeColor(Rgba8T& color, ColorType colorType, uint8_t alpha) diff --git a/frameworks/engines/gfx/soft_engine.cpp b/frameworks/engines/gfx/soft_engine.cpp index 7087a09dd03224b921a467659e3d582b442c6a61..bc50ab3adb19af023f9f7f95d50b4c4b970bb582 100644 --- a/frameworks/engines/gfx/soft_engine.cpp +++ b/frameworks/engines/gfx/soft_engine.cpp @@ -121,7 +121,9 @@ void SoftEngine::DrawPath(BufferInfo& dst, const Rect& invalidatedArea, const Style& style) { +#if defined(ENABLE_CANVAS_EXTEND) && ENABLE_CANVAS_EXTEND DrawCanvas::DoRender(dst, param, paint, rect, invalidatedArea, style, true); +#endif } void SoftEngine::FillPath(BufferInfo& dst, @@ -131,7 +133,9 @@ void SoftEngine::FillPath(BufferInfo& dst, const Rect& invalidatedArea, const Style& style) { +#if defined(ENABLE_CANVAS_EXTEND) && ENABLE_CANVAS_EXTEND DrawCanvas::DoRender(dst, param, paint, rect, invalidatedArea, style, false); +#endif } uint8_t* SoftEngine::AllocBuffer(uint32_t size, uint32_t usage) diff --git a/interfaces/kits/components/ui_canvas.h b/interfaces/kits/components/ui_canvas.h index ad583bbe7d9ad46dcd4707802a50017c1a7df90e..bdaa4b31a8f13ea68b421252e169f1fa0f3686e2 100644 --- a/interfaces/kits/components/ui_canvas.h +++ b/interfaces/kits/components/ui_canvas.h @@ -72,7 +72,7 @@ public: * @since 1.0 * @version 1.0 */ - UICanvas() : startPoint_({0, 0}), vertices_(nullptr) {} + UICanvas() : startPoint_({0, 0}), vertices_(nullptr), path_(nullptr) {} /** * @brief A destructor used to delete the UICanvas instance. @@ -197,6 +197,7 @@ public: */ void DrawRect(const Point& startPoint, int16_t height, int16_t width, const Paint& paint); +#if defined(ENABLE_CANVAS_EXTEND) && ENABLE_CANVAS_EXTEND /** * @brief Draws a rectangular path with no fill. * @param startPoint starting point @@ -213,6 +214,7 @@ public: * @param width */ void ClearRect(const Point& startPoint, int16_t height, int16_t width); +#endif /** * @brief Draws a circle. @@ -390,6 +392,7 @@ public: */ void DrawPath(const Paint& paint); +#if defined(ENABLE_CANVAS_EXTEND) && ENABLE_CANVAS_EXTEND /** * @brief Fill polygon path * @param paint fill paint @@ -397,6 +400,7 @@ public: * @version 5.0 */ void FillPath(const Paint& paint); +#endif #if defined(GRAPHIC_ENABLE_DRAW_TEXT_FLAG) && GRAPHIC_ENABLE_DRAW_TEXT_FLAG /* Draw text on canvas */ @@ -429,7 +433,9 @@ public: return paint; } +#if defined(ENABLE_CANVAS_EXTEND) && ENABLE_CANVAS_EXTEND void OnBlendDraw(BufferInfo& gfxDstBuffer, const Rect& trunc); +#endif void OnDraw(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea) override; @@ -442,6 +448,8 @@ public: SpanBase& spanGen, const Rect& rect, bool isStroke); + static void DeleteImageParam(void* param); + static void DeletePathParam(void* param); protected: constexpr static uint8_t MAX_CURVE_WIDTH = 3; @@ -475,6 +483,38 @@ protected: int16_t endAngle; }; + enum PathCmd { + CMD_MOVE_TO, + CMD_LINE_TO, + CMD_ARC, + CMD_CLOSE, + }; + + class UICanvasPath : public HeapBase { + public: + UICanvasPath() : startPos_({ 0, 0 }), strokeCount_(0) {}; + ~UICanvasPath(); + List points_; + List cmd_; + List arcParam_; + Point startPos_; + uint16_t strokeCount_; + }; + +#if (!(defined(ENABLE_CANVAS_EXTEND) && ENABLE_CANVAS_EXTEND)) + struct PathParam : public HeapBase { + UICanvasPath* path; + uint16_t count; + }; + + struct ImageParam : public HeapBase { + Point start; + uint16_t height; + uint16_t width; + Image* image; + }; +#endif + struct TextParam : public HeapBase { const char* text; Point position; @@ -504,6 +544,7 @@ protected: Point startPoint_; UICanvasVertices* vertices_; + UICanvasPath* path_; List drawCmdList_; // Save historical modification information of paint List paintStack_; diff --git a/test/uitest/test_canvas/ui_test_canvas.cpp b/test/uitest/test_canvas/ui_test_canvas.cpp index 1abb3876e7dcd24c87987b4f7ae6264d2bb4213a..b079e8219a119e8c64061aa8f63d8341ac113589 100644 --- a/test/uitest/test_canvas/ui_test_canvas.cpp +++ b/test/uitest/test_canvas/ui_test_canvas.cpp @@ -40,21 +40,28 @@ void UITestCanvas::TearDown() const UIView* UITestCanvas::GetTestView() { UIKitCanvasTestDrawImage002(); +#if defined(ENABLE_CANVAS_EXTEND) && ENABLE_CANVAS_EXTEND RM008UIKitCanvasTest001(); RM008UIKitCanvasTest002(); +#endif RM008UIKitCanvasTest003(); +#if defined(ENABLE_CANVAS_EXTEND) && ENABLE_CANVAS_EXTEND RM008UIKitCanvasTest004(); RM008UIKitCanvasTest005(); RM008UIKitCanvasTest006(); RM008UIKitCanvasTest007(); RM008UIKitCanvasShadowTest008(); +#endif RM009LineCapDrawPath(); RM009LineJoinDrawPath(); RM009LineDashDrawPath(); +#if defined(ENABLE_CANVAS_EXTEND) && ENABLE_CANVAS_EXTEND RM009StrokeAndClearRectDrawPath(); +#endif RM011StrokeText001(); RM011CanvasScale001(); RM011CanvasRotate001(); +#if defined(ENABLE_CANVAS_EXTEND) && ENABLE_CANVAS_EXTEND RM012globalAlpha001(); RM012SaveOrRestore002(); RM012GlobalCompositeOperationSourceOver(); @@ -68,6 +75,7 @@ const UIView* UITestCanvas::GetTestView() RM012GlobalCompositeOperationLIGHTER(); RM012GlobalCompositeOperationCopy(); RM012GlobalCompositeOperationXOR(); +#endif UIKitCanvasTestDrawLine001(); UIKitCanvasTestDrawLine002(); UIKitCanvasTestDrawCurve001(); @@ -1144,6 +1152,7 @@ void UITestCanvas::RM009LineDashDrawPath() #endif } +#if defined(ENABLE_CANVAS_EXTEND) && ENABLE_CANVAS_EXTEND void UITestCanvas::RM009StrokeAndClearRectDrawPath() { if (container_ == nullptr) { @@ -1242,6 +1251,7 @@ void UITestCanvas::RM008UIKitCanvasTest002() canvas->ClosePath(); canvas->FillPath(paint); } +#endif void UITestCanvas::RM008UIKitCanvasTest003() { @@ -1290,6 +1300,7 @@ void UITestCanvas::RM008UIKitCanvasTest003() canvas->DrawPath(paint); } +#if defined(ENABLE_CANVAS_EXTEND) && ENABLE_CANVAS_EXTEND void UITestCanvas::RM008UIKitCanvasTest004() { if (container_ == nullptr) { @@ -1498,6 +1509,7 @@ void UITestCanvas::RM008UIKitCanvasShadowTest008() #endif } +#endif void UITestCanvas::RM011StrokeText001() { CreateTitleLabel("RM011_StrokeText_多国文字加旋转放大"); @@ -1622,6 +1634,7 @@ void UITestCanvas::RM011CanvasRotate001() canvas->DrawPath(paint); } +#if defined(ENABLE_CANVAS_EXTEND) && ENABLE_CANVAS_EXTEND void UITestCanvas::RM012globalAlpha001() { if (container_ == nullptr) { @@ -1991,4 +2004,5 @@ void UITestCanvas::RM012SaveOrRestore002() paint = canvas->Restore(); canvas->FillPath(paint); } +#endif } // namespace OHOS diff --git a/test/unittest/components/ui_canvas_unit_test.cpp b/test/unittest/components/ui_canvas_unit_test.cpp index df796eb43e9993f006c9ce92c714630872839531..e486d9b43ed3bd39b443d7c50f43ff9fd5b9c8c1 100644 --- a/test/unittest/components/ui_canvas_unit_test.cpp +++ b/test/unittest/components/ui_canvas_unit_test.cpp @@ -306,6 +306,7 @@ HWTEST_F(UICanvasTest, UICanvasDrawCurve_001, TestSize.Level0) viewGroup->Remove(canvas_); } +#if defined(ENABLE_CANVAS_EXTEND) && ENABLE_CANVAS_EXTEND /** * @tc.name: UICanvasBeginPath_001 * @tc.desc: Verify BeginPath function, equal. @@ -369,7 +370,7 @@ HWTEST_F(UICanvasTest, UICanvasLineTo_001, TestSize.Level0) EXPECT_EQ(end.x, LINE1_X); EXPECT_EQ(end.y, LINE1_Y); } - +#endif /** * @tc.name: UICanvasLineTo_002 * @tc.desc: Verify LineTo function, equal. @@ -400,6 +401,7 @@ HWTEST_F(UICanvasTest, UICanvasLineTo_002, TestSize.Level1) } #if defined(GRAPHIC_ENABLE_ARC_FLAG) && GRAPHIC_ENABLE_ARC_FLAG +#if defined(ENABLE_CANVAS_EXTEND) && ENABLE_CANVAS_EXTEND /** * @tc.name: UICanvasArcTo_001 * @tc.desc: Verify ArcTo function, equal. @@ -427,6 +429,7 @@ HWTEST_F(UICanvasTest, UICanvasArcTo_001, TestSize.Level0) EXPECT_EQ(end.x, int16_t(CENTER_X + sinma)); EXPECT_EQ(end.y, int16_t(CENTER_Y - cosma)); } +#endif /** * @tc.name: UICanvasArcTo_002 @@ -485,6 +488,7 @@ HWTEST_F(UICanvasTest, UICanvasArcTo_003, TestSize.Level1) } #endif +#if defined(ENABLE_CANVAS_EXTEND) && ENABLE_CANVAS_EXTEND /** * @tc.name: UICanvasAddRect_001 * @tc.desc: Verify AddRect function, equal. @@ -508,7 +512,7 @@ HWTEST_F(UICanvasTest, UICanvasAddRect_001, TestSize.Level0) EXPECT_EQ(end.x, 0); EXPECT_EQ(end.y, 0); } - +#endif /** * @tc.name: UICanvasAddRect_002 * @tc.desc: Verify AddRect function, equal. @@ -535,6 +539,7 @@ HWTEST_F(UICanvasTest, UICanvasAddRect_002, TestSize.Level1) EXPECT_EQ(end.y, 0); } +#if defined(ENABLE_CANVAS_EXTEND) && ENABLE_CANVAS_EXTEND /** * @tc.name: UICanvasClosePath_001 * @tc.desc: Verify ClosePath function, equal. @@ -560,7 +565,7 @@ HWTEST_F(UICanvasTest, UICanvasClosePath_001, TestSize.Level0) EXPECT_EQ(end.x, 0); EXPECT_EQ(end.y, 0); } - +#endif /** * @tc.name: UICanvasClosePath_002 * @tc.desc: Verify ClosePath function, equal. @@ -844,6 +849,7 @@ HWTEST_F(UICanvasTest, UICanvasSetLineDash_001, TestSize.Level0) EXPECT_EQ(paint_->IsLineDash(), 0); } #endif +#if defined(ENABLE_CANVAS_EXTEND) && ENABLE_CANVAS_EXTEND /** * @tc.name: UICanvasStrokeRect_001 * @tc.desc: Verify StrokeRect function, equal. @@ -987,7 +993,6 @@ HWTEST_F(UICanvasTest, UICanvasDrawImage_001, TestSize.Level1) EXPECT_EQ(canvas_->GetStartPosition().y, IMAGE_Y); viewGroup->Remove(canvas_); } - /** * @tc.name: UICanvasDrawImage_002 * @tc.desc: Verify DrawImage function, equal. @@ -1091,6 +1096,7 @@ HWTEST_F(UICanvasTest, UICanvasDrawImage_003, TestSize.Level1) viewGroup->Remove(canvas_); } #endif +#endif // ENABLE_CANVAS_EXTEND #if defined(GRAPHIC_ENABLE_DRAW_TEXT_FLAG) && GRAPHIC_ENABLE_DRAW_TEXT_FLAG /** @@ -1640,6 +1646,7 @@ HWTEST_F(UICanvasTest, UICanvasSetGlobalCompositeOperation_001, TestSize.Level0) EXPECT_EQ(paint_->GetGlobalCompositeOperation(), OHOS::COPY); } +#if defined(ENABLE_CANVAS_EXTEND) && ENABLE_CANVAS_EXTEND /** * @tc.name: UICanvasSetGlobalCompositeOperation_002 * @tc.desc: Verify SetGlobalCompositeOperation function, equal. @@ -1678,6 +1685,7 @@ HWTEST_F(UICanvasTest, UICanvasSetGlobalCompositeOperation_002, TestSize.Level1) EXPECT_EQ(paint_->GetGlobalCompositeOperation(), OHOS::COPY); } +#endif /** * @tc.name: UICanvasGetGlobalCompositeOperation_001 @@ -1700,6 +1708,7 @@ HWTEST_F(UICanvasTest, UICanvasGetGlobalCompositeOperation_001, TestSize.Level0) EXPECT_EQ(paint_->GetGlobalCompositeOperation(), OHOS::SOURCE_OVER); } +#if defined(ENABLE_CANVAS_EXTEND) && ENABLE_CANVAS_EXTEND /** * @tc.name: UICanvasGetGlobalCompositeOperation_002 * @tc.desc: Verify GetGlobalCompositeOperation function, equal. @@ -1738,6 +1747,7 @@ HWTEST_F(UICanvasTest, UICanvasGetGlobalCompositeOperation_002, TestSize.Level1) canvas_->FillPath(*paint_); EXPECT_EQ(paint_->GetGlobalCompositeOperation(), OHOS::SOURCE_OVER); } +#endif /** * @tc.name: UICanvasSave_001 diff --git a/tools/qt/simulator/libui/libui.pro b/tools/qt/simulator/libui/libui.pro index 014a29375670d2f0158aa4eba3168424c8bea844..71bd537d249e6c2dd7699306e40a942ebe0a4244 100644 --- a/tools/qt/simulator/libui/libui.pro +++ b/tools/qt/simulator/libui/libui.pro @@ -29,6 +29,7 @@ DEFINES += QT_DEPRECATED_WARNINGS \ "GRAPHIC_ENABLE_PATTERN_FILL_FLAG=1" \ "GRAPHIC_ENABLE_DRAW_IMAGE_FLAG=1" \ "GRAPHIC_ENABLE_DRAW_TEXT_FLAG=1" \ + "ENABLE_CANVAS_EXTEND=1" \ "DEFAULT_ANIMATION=1"