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