1 /*
2  * Copyright (c) 2021-2023 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 "skia_impl_factory.h"
17 
18 #include "skia_adapter/skia_bitmap.h"
19 #include "skia_adapter/skia_blender.h"
20 #include "skia_adapter/skia_pixmap.h"
21 #include "skia_adapter/skia_camera.h"
22 #include "skia_adapter/skia_canvas.h"
23 #include "skia_adapter/skia_color_filter.h"
24 #include "skia_adapter/skia_color_space.h"
25 #include "skia_adapter/skia_data.h"
26 #ifdef RS_ENABLE_GPU
27 #include "skia_adapter/skia_gpu_context.h"
28 #endif
29 #include "skia_adapter/skia_font.h"
30 #include "skia_adapter/skia_font_mgr.h"
31 #include "skia_adapter/skia_hm_symbol_config_ohos.h"
32 #include "skia_adapter/skia_image.h"
33 #include "skia_adapter/skia_image_filter.h"
34 #include "skia_adapter/skia_mask_filter.h"
35 #include "skia_adapter/skia_matrix.h"
36 #include "skia_adapter/skia_matrix44.h"
37 #include "skia_adapter/skia_path.h"
38 #include "skia_adapter/skia_path_effect.h"
39 #include "skia_adapter/skia_picture.h"
40 #include "skia_adapter/skia_region.h"
41 #include "skia_adapter/skia_resource_holder.h"
42 #include "skia_adapter/skia_shader_effect.h"
43 #include "skia_adapter/skia_runtime_blender_builder.h"
44 #include "skia_adapter/skia_runtime_effect.h"
45 #include "skia_adapter/skia_runtime_shader_builder.h"
46 #include "skia_adapter/skia_surface.h"
47 #include "skia_adapter/skia_text_blob_builder.h"
48 #include "skia_adapter/skia_trace_memory_dump.h"
49 #include "skia_adapter/skia_memory_stream.h"
50 #include "skia_adapter/skia_oplist_handle.h"
51 
52 namespace OHOS {
53 namespace Rosen {
54 namespace Drawing {
CreateCoreCanvas()55 std::unique_ptr<CoreCanvasImpl> SkiaImplFactory::CreateCoreCanvas()
56 {
57     return std::make_unique<SkiaCanvas>();
58 }
59 
CreateCoreCanvas(void * rawCanvas)60 std::unique_ptr<CoreCanvasImpl> SkiaImplFactory::CreateCoreCanvas(void* rawCanvas)
61 {
62     auto skCanvasPtr = reinterpret_cast<std::shared_ptr<SkCanvas>*>(rawCanvas);
63     return std::make_unique<SkiaCanvas>(*skCanvasPtr);
64 }
65 
CreateCoreCanvas(int32_t width,int32_t height)66 std::unique_ptr<CoreCanvasImpl> SkiaImplFactory::CreateCoreCanvas(int32_t width, int32_t height)
67 {
68     return std::make_unique<SkiaCanvas>(width, height);
69 }
70 
CreateData()71 std::unique_ptr<DataImpl> SkiaImplFactory::CreateData()
72 {
73     return std::make_unique<SkiaData>();
74 }
75 
76 #ifdef RS_ENABLE_GPU
CreateGPUContext()77 std::unique_ptr<GPUContextImpl> SkiaImplFactory::CreateGPUContext()
78 {
79     return std::make_unique<SkiaGPUContext>();
80 }
81 #endif
82 
CreateTraceMemoryDump(const char * categoryKey,bool itemizeType)83 std::unique_ptr<TraceMemoryDumpImpl> SkiaImplFactory::CreateTraceMemoryDump(const char* categoryKey, bool itemizeType)
84 {
85     return std::make_unique<SkiaTraceMemoryDump>(categoryKey, itemizeType);
86 }
87 
CreateBitmap()88 std::unique_ptr<BitmapImpl> SkiaImplFactory::CreateBitmap()
89 {
90     return std::make_unique<SkiaBitmap>();
91 }
92 
CreatePixmap()93 std::unique_ptr<PixmapImpl> SkiaImplFactory::CreatePixmap()
94 {
95     return std::make_unique<SkiaPixmap>();
96 }
97 
CreatePixmap(const ImageInfo & imageInfo,const void * addr,size_t rowBytes)98 std::unique_ptr<PixmapImpl> SkiaImplFactory::CreatePixmap(const ImageInfo& imageInfo, const void* addr, size_t rowBytes)
99 {
100     return std::make_unique<SkiaPixmap>(imageInfo, addr, rowBytes);
101 }
102 
CreateImage()103 std::unique_ptr<ImageImpl> SkiaImplFactory::CreateImage()
104 {
105     return std::make_unique<SkiaImage>();
106 }
107 
CreateImage(void * rawImg)108 std::unique_ptr<ImageImpl> SkiaImplFactory::CreateImage(void* rawImg)
109 {
110     auto skImg = reinterpret_cast<sk_sp<SkImage>*>(rawImg);
111     return std::make_unique<SkiaImage>(*skImg);
112 }
113 
CreatePicture()114 std::unique_ptr<PictureImpl> SkiaImplFactory::CreatePicture()
115 {
116     return std::make_unique<SkiaPicture>();
117 }
118 
CreatePath()119 std::unique_ptr<PathImpl> SkiaImplFactory::CreatePath()
120 {
121     return std::make_unique<SkiaPath>();
122 }
123 
CreateColorFilter()124 std::unique_ptr<ColorFilterImpl> SkiaImplFactory::CreateColorFilter()
125 {
126     return std::make_unique<SkiaColorFilter>();
127 }
128 
CreateMaskFilter()129 std::unique_ptr<MaskFilterImpl> SkiaImplFactory::CreateMaskFilter()
130 {
131     return std::make_unique<SkiaMaskFilter>();
132 }
133 
CreateImageFilter()134 std::unique_ptr<ImageFilterImpl> SkiaImplFactory::CreateImageFilter()
135 {
136     return std::make_unique<SkiaImageFilter>();
137 }
138 
CreateShaderEffect()139 std::unique_ptr<ShaderEffectImpl> SkiaImplFactory::CreateShaderEffect()
140 {
141     return std::make_unique<SkiaShaderEffect>();
142 }
143 
CreateBlender()144 std::unique_ptr<BlenderImpl> SkiaImplFactory::CreateBlender()
145 {
146     return std::make_unique<SkiaBlender>();
147 }
148 
CreateRuntimeEffect()149 std::unique_ptr<RuntimeEffectImpl> SkiaImplFactory::CreateRuntimeEffect()
150 {
151     return std::make_unique<SkiaRuntimeEffect>();
152 }
153 
CreateRuntimeShaderBuilder(std::shared_ptr<RuntimeEffect> runtimeEffect)154 std::unique_ptr<RuntimeShaderBuilderImpl> SkiaImplFactory::CreateRuntimeShaderBuilder(
155     std::shared_ptr<RuntimeEffect> runtimeEffect)
156 {
157     return std::make_unique<SkiaRuntimeShaderBuilder>(runtimeEffect);
158 }
159 
CreateRuntimeBlenderBuilder(std::shared_ptr<RuntimeEffect> runtimeEffect)160 std::unique_ptr<RuntimeBlenderBuilderImpl> SkiaImplFactory::CreateRuntimeBlenderBuilder(
161     std::shared_ptr<RuntimeEffect> runtimeEffect)
162 {
163     return std::make_unique<SkiaRuntimeBlenderBuilder>(runtimeEffect);
164 }
165 
CreateSurface()166 std::unique_ptr<SurfaceImpl> SkiaImplFactory::CreateSurface()
167 {
168     return std::make_unique<SkiaSurface>();
169 }
170 
CreateOplistHandle()171 std::unique_ptr<OpListHandleImpl> SkiaImplFactory::CreateOplistHandle()
172 {
173     return std::make_unique<SkiaOpListHandle>();
174 }
175 
CreatePathEffect()176 std::unique_ptr<PathEffectImpl> SkiaImplFactory::CreatePathEffect()
177 {
178     return std::make_unique<SkiaPathEffect>();
179 }
180 
CreateColorSpace()181 std::unique_ptr<ColorSpaceImpl> SkiaImplFactory::CreateColorSpace()
182 {
183     return std::make_unique<SkiaColorSpace>();
184 }
185 
CreateMatrix()186 std::unique_ptr<MatrixImpl> SkiaImplFactory::CreateMatrix()
187 {
188     return std::make_unique<SkiaMatrix>();
189 }
190 
CreateMatrix(const Matrix & other)191 std::unique_ptr<MatrixImpl> SkiaImplFactory::CreateMatrix(const Matrix& other)
192 {
193     return std::make_unique<SkiaMatrix>(other);
194 }
195 
CreateMatrix44()196 std::unique_ptr<Matrix44Impl> SkiaImplFactory::CreateMatrix44()
197 {
198     return std::make_unique<SkiaMatrix44>();
199 }
200 
CreateCamera()201 std::unique_ptr<CameraImpl> SkiaImplFactory::CreateCamera()
202 {
203     return std::make_unique<SkiaCamera>();
204 }
205 
CreateRegion()206 std::unique_ptr<RegionImpl> SkiaImplFactory::CreateRegion()
207 {
208     return std::make_unique<SkiaRegion>();
209 }
210 
CreateFont()211 std::unique_ptr<FontImpl> SkiaImplFactory::CreateFont()
212 {
213     return std::make_unique<SkiaFont>();
214 }
215 
CreateFont(std::shared_ptr<Typeface> typeface,scalar size,scalar scaleX,scalar skewX)216 std::unique_ptr<FontImpl> SkiaImplFactory::CreateFont(std::shared_ptr<Typeface> typeface,
217     scalar size, scalar scaleX, scalar skewX)
218 {
219     return std::make_unique<SkiaFont>(typeface, size, scaleX, skewX);
220 }
221 
CreateFont(const Font & font)222 std::unique_ptr<FontImpl> SkiaImplFactory::CreateFont(const Font& font)
223 {
224     return std::make_unique<SkiaFont>(font);
225 }
226 
CreateTextBlobBuilder()227 std::unique_ptr<TextBlobBuilderImpl> SkiaImplFactory::CreateTextBlobBuilder()
228 {
229     return std::make_unique<SkiaTextBlobBuilder>();
230 }
231 
CreateDefaultFontMgr()232 std::shared_ptr<FontMgrImpl> SkiaImplFactory::CreateDefaultFontMgr()
233 {
234     return SkiaFontMgr::CreateDefaultFontMgr();
235 }
236 
237 #ifndef USE_TEXGINE
CreateDynamicFontMgr()238 std::shared_ptr<FontMgrImpl> SkiaImplFactory::CreateDynamicFontMgr()
239 {
240     return SkiaFontMgr::CreateDynamicFontMgr();
241 }
242 #endif
243 
CreateVertices()244 std::unique_ptr<VerticesImpl> SkiaImplFactory::CreateVertices()
245 {
246     return std::make_unique<SkiaVertices>();
247 }
248 
CreateVerticesBuilder()249 std::unique_ptr<VerticesImpl::BuilderImpl> SkiaImplFactory::CreateVerticesBuilder()
250 {
251     return std::make_unique<SkiaVertices::SkiaBuilder>();
252 }
253 
CreateMemoryStream()254 std::shared_ptr<MemoryStreamImpl> SkiaImplFactory::CreateMemoryStream()
255 {
256     return std::make_shared<SkiaMemoryStream>();
257 }
258 
CreateMemoryStream(const void * data,size_t length,bool copyData)259 std::shared_ptr<MemoryStreamImpl> SkiaImplFactory::CreateMemoryStream(const void* data, size_t length, bool copyData)
260 {
261     return std::make_shared<SkiaMemoryStream>(data, length, copyData);
262 }
263 
CreateResourceHolder()264 std::shared_ptr<ResourceHolderImpl> SkiaImplFactory::CreateResourceHolder()
265 {
266     return std::make_shared<SkiaResourceHolder>();
267 }
268 } // namespace Drawing
269 } // namespace Rosen
270 } // namespace OHOS