1a3e0fd82Sopenharmony_ci/* 2a3e0fd82Sopenharmony_ci * Copyright (c) 2020-2021 Huawei Device Co., Ltd. 3a3e0fd82Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4a3e0fd82Sopenharmony_ci * you may not use this file except in compliance with the License. 5a3e0fd82Sopenharmony_ci * You may obtain a copy of the License at 6a3e0fd82Sopenharmony_ci * 7a3e0fd82Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8a3e0fd82Sopenharmony_ci * 9a3e0fd82Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10a3e0fd82Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11a3e0fd82Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12a3e0fd82Sopenharmony_ci * See the License for the specific language governing permissions and 13a3e0fd82Sopenharmony_ci * limitations under the License. 14a3e0fd82Sopenharmony_ci */ 15a3e0fd82Sopenharmony_ci 16a3e0fd82Sopenharmony_ci#include "engines/gfx/soft_engine.h" 17a3e0fd82Sopenharmony_ci 18a3e0fd82Sopenharmony_ci#include <cstdlib> 19a3e0fd82Sopenharmony_ci 20a3e0fd82Sopenharmony_ci#include "draw/clip_utils.h" 21a3e0fd82Sopenharmony_ci#include "draw/draw_arc.h" 22a3e0fd82Sopenharmony_ci#include "draw/draw_canvas.h" 23a3e0fd82Sopenharmony_ci#include "draw/draw_curve.h" 24a3e0fd82Sopenharmony_ci#include "draw/draw_line.h" 25a3e0fd82Sopenharmony_ci#include "draw/draw_rect.h" 26a3e0fd82Sopenharmony_ci 27a3e0fd82Sopenharmony_cinamespace OHOS { 28a3e0fd82Sopenharmony_civoid SoftEngine::DrawArc(BufferInfo& dst, 29a3e0fd82Sopenharmony_ci ArcInfo& arcInfo, 30a3e0fd82Sopenharmony_ci const Rect& mask, 31a3e0fd82Sopenharmony_ci const Style& style, 32a3e0fd82Sopenharmony_ci OpacityType opacity, 33a3e0fd82Sopenharmony_ci uint8_t cap) 34a3e0fd82Sopenharmony_ci{ 35a3e0fd82Sopenharmony_ci DrawArc::GetInstance()->Draw(dst, arcInfo, mask, style, opacity, cap); 36a3e0fd82Sopenharmony_ci} 37a3e0fd82Sopenharmony_ci 38a3e0fd82Sopenharmony_civoid SoftEngine::DrawLine(BufferInfo& dst, 39a3e0fd82Sopenharmony_ci const Point& start, 40a3e0fd82Sopenharmony_ci const Point& end, 41a3e0fd82Sopenharmony_ci const Rect& mask, 42a3e0fd82Sopenharmony_ci int16_t width, 43a3e0fd82Sopenharmony_ci ColorType color, 44a3e0fd82Sopenharmony_ci OpacityType opacity) 45a3e0fd82Sopenharmony_ci{ 46a3e0fd82Sopenharmony_ci DrawLine::Draw(dst, start, end, mask, width, color, opacity); 47a3e0fd82Sopenharmony_ci} 48a3e0fd82Sopenharmony_ci 49a3e0fd82Sopenharmony_civoid SoftEngine::DrawLetter(BufferInfo& gfxDstBuffer, 50a3e0fd82Sopenharmony_ci const uint8_t* fontMap, 51a3e0fd82Sopenharmony_ci const Rect& fontRect, 52a3e0fd82Sopenharmony_ci const Rect& subRect, 53a3e0fd82Sopenharmony_ci const uint8_t fontWeight, 54a3e0fd82Sopenharmony_ci const ColorType& color, 55a3e0fd82Sopenharmony_ci const OpacityType opa) 56a3e0fd82Sopenharmony_ci{ 57a3e0fd82Sopenharmony_ci DrawUtils::GetInstance()->DrawLetter(gfxDstBuffer, fontMap, fontRect, subRect, fontWeight, color, opa); 58a3e0fd82Sopenharmony_ci} 59a3e0fd82Sopenharmony_ci 60a3e0fd82Sopenharmony_civoid SoftEngine::DrawCubicBezier(BufferInfo& dst, 61a3e0fd82Sopenharmony_ci const Point& start, 62a3e0fd82Sopenharmony_ci const Point& control1, 63a3e0fd82Sopenharmony_ci const Point& control2, 64a3e0fd82Sopenharmony_ci const Point& end, 65a3e0fd82Sopenharmony_ci const Rect& mask, 66a3e0fd82Sopenharmony_ci int16_t width, 67a3e0fd82Sopenharmony_ci ColorType color, 68a3e0fd82Sopenharmony_ci OpacityType opacity) 69a3e0fd82Sopenharmony_ci{ 70a3e0fd82Sopenharmony_ci DrawCurve::DrawCubicBezier(dst, start, control1, control2, end, mask, width, color, opacity); 71a3e0fd82Sopenharmony_ci} 72a3e0fd82Sopenharmony_ci 73a3e0fd82Sopenharmony_civoid SoftEngine::DrawRect(BufferInfo& dst, 74a3e0fd82Sopenharmony_ci const Rect& rect, 75a3e0fd82Sopenharmony_ci const Rect& dirtyRect, 76a3e0fd82Sopenharmony_ci const Style& style, 77a3e0fd82Sopenharmony_ci OpacityType opacity) 78a3e0fd82Sopenharmony_ci{ 79a3e0fd82Sopenharmony_ci DrawRect::Draw(dst, rect, dirtyRect, style, opacity); 80a3e0fd82Sopenharmony_ci} 81a3e0fd82Sopenharmony_ci 82a3e0fd82Sopenharmony_civoid SoftEngine::DrawTransform(BufferInfo& dst, 83a3e0fd82Sopenharmony_ci const Rect& mask, 84a3e0fd82Sopenharmony_ci const Point& position, 85a3e0fd82Sopenharmony_ci ColorType color, 86a3e0fd82Sopenharmony_ci OpacityType opacity, 87a3e0fd82Sopenharmony_ci const TransformMap& transMap, 88a3e0fd82Sopenharmony_ci const TransformDataInfo& dataInfo) 89a3e0fd82Sopenharmony_ci{ 90a3e0fd82Sopenharmony_ci DrawUtils::GetInstance()->DrawTransform(dst, mask, position, color, opacity, transMap, dataInfo); 91a3e0fd82Sopenharmony_ci} 92a3e0fd82Sopenharmony_ci 93a3e0fd82Sopenharmony_civoid SoftEngine::ClipCircle(const ImageInfo* info, float x, float y, float radius) 94a3e0fd82Sopenharmony_ci{ 95a3e0fd82Sopenharmony_ci ClipPath path; 96a3e0fd82Sopenharmony_ci path.Circle(PointF(x, y), radius); 97a3e0fd82Sopenharmony_ci ClipUtils clip; 98a3e0fd82Sopenharmony_ci clip.PerformScan(path, info); 99a3e0fd82Sopenharmony_ci} 100a3e0fd82Sopenharmony_ci 101a3e0fd82Sopenharmony_civoid SoftEngine::Blit(BufferInfo& dst, 102a3e0fd82Sopenharmony_ci const Point& dstPos, 103a3e0fd82Sopenharmony_ci const BufferInfo& src, 104a3e0fd82Sopenharmony_ci const Rect& subRect, 105a3e0fd82Sopenharmony_ci const BlendOption& blendOption) 106a3e0fd82Sopenharmony_ci{ 107a3e0fd82Sopenharmony_ci DrawUtils::GetInstance()->BlendWithSoftWare( 108a3e0fd82Sopenharmony_ci static_cast<uint8_t*>(src.virAddr), src.rect, src.stride, src.rect.GetHeight(), src.mode, src.color, 109a3e0fd82Sopenharmony_ci blendOption.opacity, static_cast<uint8_t*>(dst.virAddr), dst.stride, dst.mode, subRect.GetX(), subRect.GetY()); 110a3e0fd82Sopenharmony_ci} 111a3e0fd82Sopenharmony_ci 112a3e0fd82Sopenharmony_civoid SoftEngine::Fill(BufferInfo& dst, const Rect& fillArea, const ColorType color, const OpacityType opacity) 113a3e0fd82Sopenharmony_ci{ 114a3e0fd82Sopenharmony_ci DrawUtils::GetInstance()->FillAreaWithSoftWare(dst, fillArea, color, opacity); 115a3e0fd82Sopenharmony_ci} 116a3e0fd82Sopenharmony_ci 117a3e0fd82Sopenharmony_civoid SoftEngine::DrawPath(BufferInfo& dst, 118a3e0fd82Sopenharmony_ci void* param, 119a3e0fd82Sopenharmony_ci const Paint& paint, 120a3e0fd82Sopenharmony_ci const Rect& rect, 121a3e0fd82Sopenharmony_ci const Rect& invalidatedArea, 122a3e0fd82Sopenharmony_ci const Style& style) 123a3e0fd82Sopenharmony_ci{ 124a3e0fd82Sopenharmony_ci#if defined(ENABLE_CANVAS_EXTEND) && ENABLE_CANVAS_EXTEND 125a3e0fd82Sopenharmony_ci DrawCanvas::DoRender(dst, param, paint, rect, invalidatedArea, style, true); 126a3e0fd82Sopenharmony_ci#endif 127a3e0fd82Sopenharmony_ci} 128a3e0fd82Sopenharmony_ci 129a3e0fd82Sopenharmony_civoid SoftEngine::FillPath(BufferInfo& dst, 130a3e0fd82Sopenharmony_ci void* param, 131a3e0fd82Sopenharmony_ci const Paint& paint, 132a3e0fd82Sopenharmony_ci const Rect& rect, 133a3e0fd82Sopenharmony_ci const Rect& invalidatedArea, 134a3e0fd82Sopenharmony_ci const Style& style) 135a3e0fd82Sopenharmony_ci{ 136a3e0fd82Sopenharmony_ci#if defined(ENABLE_CANVAS_EXTEND) && ENABLE_CANVAS_EXTEND 137a3e0fd82Sopenharmony_ci DrawCanvas::DoRender(dst, param, paint, rect, invalidatedArea, style, false); 138a3e0fd82Sopenharmony_ci#endif 139a3e0fd82Sopenharmony_ci} 140a3e0fd82Sopenharmony_ci 141a3e0fd82Sopenharmony_ciuint8_t* SoftEngine::AllocBuffer(uint32_t size, uint32_t usage) 142a3e0fd82Sopenharmony_ci{ 143a3e0fd82Sopenharmony_ci return static_cast<uint8_t*>(malloc(size)); 144a3e0fd82Sopenharmony_ci} 145a3e0fd82Sopenharmony_ci 146a3e0fd82Sopenharmony_civoid SoftEngine::FreeBuffer(uint8_t* buffer, uint32_t usage) 147a3e0fd82Sopenharmony_ci{ 148a3e0fd82Sopenharmony_ci free(buffer); 149a3e0fd82Sopenharmony_ci} 150a3e0fd82Sopenharmony_ci} // namespace OHOS 151