diff --git a/BUILD.gn b/BUILD.gn index 6a592b699eeb7a112b96ac7a56e2db03259f9c6d..2954a93a9ce3f88ffa36afad1e2ff6da3daa6d45 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -185,6 +185,7 @@ lite_library("ui") { "frameworks/draw/draw_utils.cpp", "frameworks/engines/gfx/gfx_engine_manager.cpp", "frameworks/engines/gfx/hi3516/hi3516_engine.cpp", + "frameworks/engines/gfx/soft_engine.cpp", "frameworks/events/event.cpp", "frameworks/font/base_font.cpp", "frameworks/font/font_ram_allocator.cpp", diff --git a/frameworks/engines/gfx/gfx_engine_manager.cpp b/frameworks/engines/gfx/gfx_engine_manager.cpp index a97d0ec19ee91dc217bcc1848a9bc374411fa7f5..033d3d65bc23ac52aec8253217d6b661dd28a113 100644 --- a/frameworks/engines/gfx/gfx_engine_manager.cpp +++ b/frameworks/engines/gfx/gfx_engine_manager.cpp @@ -15,135 +15,6 @@ #include "engines/gfx/gfx_engine_manager.h" -#include - -#include "draw/clip_utils.h" -#include "draw/draw_arc.h" -#include "draw/draw_canvas.h" -#include "draw/draw_curve.h" -#include "draw/draw_line.h" -#include "draw/draw_rect.h" - - namespace OHOS { BaseGfxEngine* BaseGfxEngine::baseEngine_ = nullptr; -void BaseGfxEngine::DrawArc(BufferInfo& dst, - ArcInfo& arcInfo, - const Rect& mask, - const Style& style, - OpacityType opacity, - uint8_t cap) -{ - DrawArc::GetInstance()->Draw(dst, arcInfo, mask, style, opacity, cap); -} - -void BaseGfxEngine::DrawLine(BufferInfo& dst, - const Point& start, - const Point& end, - const Rect& mask, - int16_t width, - ColorType color, - OpacityType opacity) -{ - DrawLine::Draw(dst, start, end, mask, width, color, opacity); -} - -void BaseGfxEngine::DrawLetter(BufferInfo& gfxDstBuffer, - const uint8_t* fontMap, - const Rect& fontRect, - const Rect& subRect, - const uint8_t fontWeight, - const ColorType& color, - const OpacityType opa) -{ - DrawUtils::GetInstance()->DrawLetter(gfxDstBuffer, fontMap, fontRect, subRect, fontWeight, color, opa); -} - -void BaseGfxEngine::DrawCubicBezier(BufferInfo& dst, - const Point& start, - const Point& control1, - const Point& control2, - const Point& end, - const Rect& mask, - int16_t width, - ColorType color, - OpacityType opacity) -{ - DrawCurve::DrawCubicBezier(dst, start, control1, control2, end, mask, width, color, opacity); -} - -void BaseGfxEngine::DrawRect(BufferInfo& dst, - const Rect& rect, - const Rect& dirtyRect, - const Style& style, - OpacityType opacity) -{ - DrawRect::Draw(dst, rect, dirtyRect, style, opacity); -} - -void BaseGfxEngine::DrawTransform(BufferInfo& dst, - const Rect& mask, - const Point& position, - ColorType color, - OpacityType opacity, - const TransformMap& transMap, - const TransformDataInfo& dataInfo) -{ - DrawUtils::GetInstance()->DrawTransform(dst, mask, position, color, - opacity, transMap, dataInfo); -} - -void BaseGfxEngine::ClipCircle(const ImageInfo* info, float x, float y, float radius) -{ - ClipPath path; - path.Circle(PointF(x, y), radius); - ClipUtils clip; - clip.PerformScan(path, info); -} - -void BaseGfxEngine::Blit(BufferInfo& dst, - const Point& dstPos, - const BufferInfo& src, - const Rect& subRect, - const BlendOption& blendOption) -{ - DrawUtils::GetInstance()->BlendWithSoftWare(static_cast(src.virAddr), src.rect, src.stride, - src.rect.GetHeight(), src.mode, src.color, blendOption.opacity, static_cast(dst.virAddr), - dst.stride, dst.mode, subRect.GetX(), subRect.GetY()); -} - -void BaseGfxEngine::Fill(BufferInfo& dst, const Rect& fillArea, const ColorType color, const OpacityType opacity) -{ - DrawUtils::GetInstance()->FillAreaWithSoftWare(dst, fillArea, color, opacity); -} - -void BaseGfxEngine::DrawPath(BufferInfo& dst, - void* param, - const Paint& paint, - const Rect& rect, - const Rect& invalidatedArea, - const Style& style) -{ - DrawCanvas::DoRender(dst, param, paint, rect, invalidatedArea, style, true); -} - -void BaseGfxEngine::FillPath(BufferInfo& dst, - void* param, - const Paint& paint, - const Rect& rect, - const Rect& invalidatedArea, - const Style& style) -{ - DrawCanvas::DoRender(dst, param, paint, rect, invalidatedArea, style, false); -} - -uint8_t* BaseGfxEngine::AllocBuffer(uint32_t size, uint32_t usage) -{ - return static_cast(malloc(size)); -} - -void BaseGfxEngine::FreeBuffer(uint8_t* buffer, uint32_t usage) -{ - free(buffer); -} } diff --git a/frameworks/engines/gfx/hi3516/hi3516_engine.cpp b/frameworks/engines/gfx/hi3516/hi3516_engine.cpp index f0e737c42237bfb9bd83a3d2e5cbea113bb63451..a80b132f0f576b57c95326d52a7ae3cd21ec900c 100644 --- a/frameworks/engines/gfx/hi3516/hi3516_engine.cpp +++ b/frameworks/engines/gfx/hi3516/hi3516_engine.cpp @@ -44,6 +44,6 @@ void Hi3516GfxEngine::Fill(BufferInfo& dst, } } #endif - BaseGfxEngine::Fill(dst, fillArea, color, opacity); + SoftEngine::Fill(dst, fillArea, color, opacity); } } diff --git a/frameworks/engines/gfx/hi3516/hi3516_engine.h b/frameworks/engines/gfx/hi3516/hi3516_engine.h index e95509ea642137e6766395dcc4619740101dceca..d15be8310890247d18ce26e6601ba99e1bab173e 100644 --- a/frameworks/engines/gfx/hi3516/hi3516_engine.h +++ b/frameworks/engines/gfx/hi3516/hi3516_engine.h @@ -16,10 +16,10 @@ #ifndef GRAPHIC_LITE_HI3516_ENGINE_H #define GRAPHIC_LITE_HI3516_ENGINE_H -#include "engines/gfx/gfx_engine_manager.h" +#include "engines/gfx/soft_engine.h" namespace OHOS { -class Hi3516GfxEngine : public BaseGfxEngine { +class Hi3516GfxEngine : public SoftEngine { public: void Fill(BufferInfo& dst, const Rect& fillArea, diff --git a/frameworks/engines/gfx/soft_engine.cpp b/frameworks/engines/gfx/soft_engine.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7087a09dd03224b921a467659e3d582b442c6a61 --- /dev/null +++ b/frameworks/engines/gfx/soft_engine.cpp @@ -0,0 +1,146 @@ +/* + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "engines/gfx/soft_engine.h" + +#include + +#include "draw/clip_utils.h" +#include "draw/draw_arc.h" +#include "draw/draw_canvas.h" +#include "draw/draw_curve.h" +#include "draw/draw_line.h" +#include "draw/draw_rect.h" + +namespace OHOS { +void SoftEngine::DrawArc(BufferInfo& dst, + ArcInfo& arcInfo, + const Rect& mask, + const Style& style, + OpacityType opacity, + uint8_t cap) +{ + DrawArc::GetInstance()->Draw(dst, arcInfo, mask, style, opacity, cap); +} + +void SoftEngine::DrawLine(BufferInfo& dst, + const Point& start, + const Point& end, + const Rect& mask, + int16_t width, + ColorType color, + OpacityType opacity) +{ + DrawLine::Draw(dst, start, end, mask, width, color, opacity); +} + +void SoftEngine::DrawLetter(BufferInfo& gfxDstBuffer, + const uint8_t* fontMap, + const Rect& fontRect, + const Rect& subRect, + const uint8_t fontWeight, + const ColorType& color, + const OpacityType opa) +{ + DrawUtils::GetInstance()->DrawLetter(gfxDstBuffer, fontMap, fontRect, subRect, fontWeight, color, opa); +} + +void SoftEngine::DrawCubicBezier(BufferInfo& dst, + const Point& start, + const Point& control1, + const Point& control2, + const Point& end, + const Rect& mask, + int16_t width, + ColorType color, + OpacityType opacity) +{ + DrawCurve::DrawCubicBezier(dst, start, control1, control2, end, mask, width, color, opacity); +} + +void SoftEngine::DrawRect(BufferInfo& dst, + const Rect& rect, + const Rect& dirtyRect, + const Style& style, + OpacityType opacity) +{ + DrawRect::Draw(dst, rect, dirtyRect, style, opacity); +} + +void SoftEngine::DrawTransform(BufferInfo& dst, + const Rect& mask, + const Point& position, + ColorType color, + OpacityType opacity, + const TransformMap& transMap, + const TransformDataInfo& dataInfo) +{ + DrawUtils::GetInstance()->DrawTransform(dst, mask, position, color, opacity, transMap, dataInfo); +} + +void SoftEngine::ClipCircle(const ImageInfo* info, float x, float y, float radius) +{ + ClipPath path; + path.Circle(PointF(x, y), radius); + ClipUtils clip; + clip.PerformScan(path, info); +} + +void SoftEngine::Blit(BufferInfo& dst, + const Point& dstPos, + const BufferInfo& src, + const Rect& subRect, + const BlendOption& blendOption) +{ + DrawUtils::GetInstance()->BlendWithSoftWare( + static_cast(src.virAddr), src.rect, src.stride, src.rect.GetHeight(), src.mode, src.color, + blendOption.opacity, static_cast(dst.virAddr), dst.stride, dst.mode, subRect.GetX(), subRect.GetY()); +} + +void SoftEngine::Fill(BufferInfo& dst, const Rect& fillArea, const ColorType color, const OpacityType opacity) +{ + DrawUtils::GetInstance()->FillAreaWithSoftWare(dst, fillArea, color, opacity); +} + +void SoftEngine::DrawPath(BufferInfo& dst, + void* param, + const Paint& paint, + const Rect& rect, + const Rect& invalidatedArea, + const Style& style) +{ + DrawCanvas::DoRender(dst, param, paint, rect, invalidatedArea, style, true); +} + +void SoftEngine::FillPath(BufferInfo& dst, + void* param, + const Paint& paint, + const Rect& rect, + const Rect& invalidatedArea, + const Style& style) +{ + DrawCanvas::DoRender(dst, param, paint, rect, invalidatedArea, style, false); +} + +uint8_t* SoftEngine::AllocBuffer(uint32_t size, uint32_t usage) +{ + return static_cast(malloc(size)); +} + +void SoftEngine::FreeBuffer(uint8_t* buffer, uint32_t usage) +{ + free(buffer); +} +} // namespace OHOS diff --git a/interfaces/innerkits/engines/gfx/gfx_engine_manager.h b/interfaces/innerkits/engines/gfx/gfx_engine_manager.h index cbd16314442328af29aba7b47e7556d8ce795108..6cc637e2c949387963b77278eba2732222db17d3 100644 --- a/interfaces/innerkits/engines/gfx/gfx_engine_manager.h +++ b/interfaces/innerkits/engines/gfx/gfx_engine_manager.h @@ -16,12 +16,11 @@ #ifndef GRAPHIC_LITE_GFX_ENGINE_MANAGER_H #define GRAPHIC_LITE_GFX_ENGINE_MANAGER_H +#include "gfx_utils/color.h" #include "gfx_utils/diagram/common/paint.h" -#include "gfx_utils/geometry2d.h" #include "gfx_utils/graphic_buffer.h" -#include "gfx_utils/graphic_math.h" #include "gfx_utils/graphic_types.h" -#include "gfx_utils/heap_base.h" +#include "gfx_utils/image_info.h" #include "gfx_utils/style.h" #include "gfx_utils/transform.h" @@ -84,8 +83,8 @@ public: const Rect& mask, const Style& style, OpacityType opacity, - uint8_t cap); - + uint8_t cap) = 0; + virtual void MemoryBarrier() {} virtual void DrawLine(BufferInfo& dst, @@ -94,7 +93,7 @@ public: const Rect& mask, int16_t width, ColorType color, - OpacityType opacity); + OpacityType opacity) = 0; virtual void DrawLetter(BufferInfo& gfxDstBuffer, const uint8_t* fontMap, @@ -102,7 +101,7 @@ public: const Rect& subRect, const uint8_t fontWeight, const ColorType& color, - const OpacityType opa); + const OpacityType opa) = 0; virtual void DrawCubicBezier(BufferInfo& dst, const Point& start, @@ -112,10 +111,10 @@ public: const Rect& mask, int16_t width, ColorType color, - OpacityType opacity); + OpacityType opacity) = 0; virtual void - DrawRect(BufferInfo& dst, const Rect& rect, const Rect& dirtyRect, const Style& style, OpacityType opacity); + DrawRect(BufferInfo& dst, const Rect& rect, const Rect& dirtyRect, const Style& style, OpacityType opacity) = 0; virtual void DrawTransform(BufferInfo& dst, const Rect& mask, @@ -123,36 +122,36 @@ public: ColorType color, OpacityType opacity, const TransformMap& transMap, - const TransformDataInfo& dataInfo); + const TransformDataInfo& dataInfo) = 0; // x/y: center of a circle - virtual void ClipCircle(const ImageInfo* info, float x, float y, float radius); + virtual void ClipCircle(const ImageInfo* info, float x, float y, float radius) = 0; virtual void Blit(BufferInfo& dst, const Point& dstPos, const BufferInfo& src, const Rect& subRect, - const BlendOption& blendOption); + const BlendOption& blendOption) = 0; - virtual void Fill(BufferInfo& dst, const Rect& fillArea, const ColorType color, const OpacityType opacity); + virtual void Fill(BufferInfo& dst, const Rect& fillArea, const ColorType color, const OpacityType opacity) = 0; virtual void DrawPath(BufferInfo& dst, void* param, const Paint& paint, const Rect& rect, const Rect& invalidatedArea, - const Style& style); + const Style& style) = 0; virtual void FillPath(BufferInfo& dst, void* param, const Paint& paint, const Rect& rect, const Rect& invalidatedArea, - const Style& style); + const Style& style) = 0; - virtual uint8_t* AllocBuffer(uint32_t size, uint32_t usage); + virtual uint8_t* AllocBuffer(uint32_t size, uint32_t usage) = 0; - virtual void FreeBuffer(uint8_t* buffer, uint32_t usage); + virtual void FreeBuffer(uint8_t* buffer, uint32_t usage) = 0; virtual BufferInfo* GetFBBufferInfo() { @@ -188,13 +187,8 @@ public: return baseEngine_; } - static void InitGfxEngine(BaseGfxEngine* gfxEngine = nullptr) + static void InitGfxEngine(BaseGfxEngine* gfxEngine) { - if (gfxEngine == nullptr) { - static BaseGfxEngine localGfxEngine; - baseEngine_ = &localGfxEngine; - return; - } baseEngine_ = gfxEngine; } diff --git a/interfaces/innerkits/engines/gfx/soft_engine.h b/interfaces/innerkits/engines/gfx/soft_engine.h new file mode 100644 index 0000000000000000000000000000000000000000..57d96954bf957251dbaf8ddb28a1f6594f4e5e9b --- /dev/null +++ b/interfaces/innerkits/engines/gfx/soft_engine.h @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef GRAPHIC_LITE_SOFT_ENGINE_H +#define GRAPHIC_LITE_SOFT_ENGINE_H + +#include "engines/gfx/gfx_engine_manager.h" + +namespace OHOS { +class SoftEngine : public BaseGfxEngine { +public: + void DrawArc(BufferInfo& dst, + ArcInfo& arcInfo, + const Rect& mask, + const Style& style, + OpacityType opacity, + uint8_t cap) override; + + void DrawLine(BufferInfo& dst, + const Point& start, + const Point& end, + const Rect& mask, + int16_t width, + ColorType color, + OpacityType opacity) override; + + void DrawLetter(BufferInfo& gfxDstBuffer, + const uint8_t* fontMap, + const Rect& fontRect, + const Rect& subRect, + const uint8_t fontWeight, + const ColorType& color, + const OpacityType opa) override; + + void DrawCubicBezier(BufferInfo& dst, + const Point& start, + const Point& control1, + const Point& control2, + const Point& end, + const Rect& mask, + int16_t width, + ColorType color, + OpacityType opacity) override; + + void DrawRect(BufferInfo& dst, + const Rect& rect, + const Rect& dirtyRect, + const Style& style, + OpacityType opacity) override; + + void DrawTransform(BufferInfo& dst, + const Rect& mask, + const Point& position, + ColorType color, + OpacityType opacity, + const TransformMap& transMap, + const TransformDataInfo& dataInfo) override; + + // x/y: center of a circle + void ClipCircle(const ImageInfo* info, float x, float y, float radius) override; + + void Blit(BufferInfo& dst, + const Point& dstPos, + const BufferInfo& src, + const Rect& subRect, + const BlendOption& blendOption) override; + + void Fill(BufferInfo& dst, const Rect& fillArea, const ColorType color, const OpacityType opacity) override; + + void DrawPath(BufferInfo& dst, + void* param, + const Paint& paint, + const Rect& rect, + const Rect& invalidatedArea, + const Style& style) override; + + void FillPath(BufferInfo& dst, + void* param, + const Paint& paint, + const Rect& rect, + const Rect& invalidatedArea, + const Style& style) override; + + uint8_t* AllocBuffer(uint32_t size, uint32_t usage) override; + + void FreeBuffer(uint8_t* buffer, uint32_t usage) override; +}; +} // namespace OHOS +#endif diff --git a/tools/qt/simulator/drivers/display/monitor.h b/tools/qt/simulator/drivers/display/monitor.h index be6cee81f28d7b5768e04a4db296bb88c41bab72..80af87395390ffd79bd64a82e3eeeb3a72628cbd 100644 --- a/tools/qt/simulator/drivers/display/monitor.h +++ b/tools/qt/simulator/drivers/display/monitor.h @@ -18,11 +18,11 @@ #include -#include "engines/gfx/gfx_engine_manager.h" +#include "engines/gfx/soft_engine.h" #include "font/ui_font_header.h" namespace OHOS { -class Monitor : public QObject, public BaseGfxEngine { +class Monitor : public QObject, public SoftEngine { Q_OBJECT public: diff --git a/tools/qt/simulator/libui/libui.pro b/tools/qt/simulator/libui/libui.pro index 59d4849c87017ce7cad2fcded4a2682041fe4d8d..e9b187e172645ef38f89f1cf648b2a16b26febd2 100644 --- a/tools/qt/simulator/libui/libui.pro +++ b/tools/qt/simulator/libui/libui.pro @@ -125,6 +125,7 @@ SOURCES += \ ../../../../frameworks/dock/vibrator_manager.cpp \ ../../../../frameworks/dock/virtual_input_device.cpp \ ../../../../frameworks/engines/gfx/gfx_engine_manager.cpp \ + ../../../../frameworks/engines/gfx/soft_engine.cpp \ ../../../../frameworks/draw/clip_utils.cpp \ ../../../../frameworks/draw/draw_arc.cpp \ ../../../../frameworks/draw/draw_canvas.cpp \ @@ -252,6 +253,7 @@ HEADERS += \ ../../../../interfaces/innerkits/dock/vibrator_manager.h \ ../../../../interfaces/innerkits/font/ui_font_builder.h \ ../../../../interfaces/innerkits/engines/gfx/gfx_engine_manager.h \ + ../../../../interfaces/innerkits/engines/gfx/soft_engine.h \ ../../../../interfaces/kits/animator/animator.h \ ../../../../interfaces/kits/animator/easing_equation.h \ ../../../../interfaces/kits/animator/interpolation.h \ diff --git a/ui.gni b/ui.gni index 0f5271602437eaea58b767b9aef58a62aeeb47ec..ed51594ae118d5e19b5bab63ebb9d9f69146a0f0 100755 --- a/ui.gni +++ b/ui.gni @@ -98,6 +98,7 @@ graphic_ui_sources = [ "$GRAPHIC_UI_PATH/frameworks/draw/draw_triangle.cpp", "$GRAPHIC_UI_PATH/frameworks/draw/draw_utils.cpp", "$GRAPHIC_UI_PATH/frameworks/engines/gfx/gfx_engine_manager.cpp", + "$GRAPHIC_UI_PATH/frameworks/engines/gfx/soft_engine.cpp", "$GRAPHIC_UI_PATH/frameworks/events/event.cpp", "$GRAPHIC_UI_PATH/frameworks/font/base_font.cpp", "$GRAPHIC_UI_PATH/frameworks/font/font_ram_allocator.cpp",