• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 ACE_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_resourece_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 
51 namespace OHOS {
52 namespace Rosen {
53 namespace Drawing {
CreateCoreCanvas()54 std::unique_ptr<CoreCanvasImpl> SkiaImplFactory::CreateCoreCanvas()
55 {
56     return std::make_unique<SkiaCanvas>();
57 }
58 
CreateCoreCanvas(void * rawCanvas)59 std::unique_ptr<CoreCanvasImpl> SkiaImplFactory::CreateCoreCanvas(void* rawCanvas)
60 {
61     auto skCanvasPtr = reinterpret_cast<std::shared_ptr<SkCanvas>*>(rawCanvas);
62     return std::make_unique<SkiaCanvas>(*skCanvasPtr);
63 }
64 
CreateCoreCanvas(int32_t width,int32_t height)65 std::unique_ptr<CoreCanvasImpl> SkiaImplFactory::CreateCoreCanvas(int32_t width, int32_t height)
66 {
67     return std::make_unique<SkiaCanvas>(width, height);
68 }
69 
CreateData()70 std::unique_ptr<DataImpl> SkiaImplFactory::CreateData()
71 {
72     return std::make_unique<SkiaData>();
73 }
74 
75 #ifdef ACE_ENABLE_GPU
CreateGPUContext()76 std::unique_ptr<GPUContextImpl> SkiaImplFactory::CreateGPUContext()
77 {
78     return std::make_unique<SkiaGPUContext>();
79 }
80 #endif
81 
CreateTraceMemoryDump(const char * categoryKey,bool itemizeType)82 std::unique_ptr<TraceMemoryDumpImpl> SkiaImplFactory::CreateTraceMemoryDump(const char* categoryKey, bool itemizeType)
83 {
84     return std::make_unique<SkiaTraceMemoryDump>(categoryKey, itemizeType);
85 }
86 
CreateBitmap()87 std::unique_ptr<BitmapImpl> SkiaImplFactory::CreateBitmap()
88 {
89     return std::make_unique<SkiaBitmap>();
90 }
91 
CreatePixmap()92 std::unique_ptr<PixmapImpl> SkiaImplFactory::CreatePixmap()
93 {
94     return std::make_unique<SkiaPixmap>();
95 }
96 
CreatePixmap(const ImageInfo & imageInfo,const void * addr,size_t rowBytes)97 std::unique_ptr<PixmapImpl> SkiaImplFactory::CreatePixmap(const ImageInfo& imageInfo, const void* addr, size_t rowBytes)
98 {
99     return std::make_unique<SkiaPixmap>(imageInfo, addr, rowBytes);
100 }
101 
CreateImage()102 std::unique_ptr<ImageImpl> SkiaImplFactory::CreateImage()
103 {
104     return std::make_unique<SkiaImage>();
105 }
106 
CreateImage(void * rawImg)107 std::unique_ptr<ImageImpl> SkiaImplFactory::CreateImage(void* rawImg)
108 {
109     auto skImg = reinterpret_cast<sk_sp<SkImage>*>(rawImg);
110     return std::make_unique<SkiaImage>(*skImg);
111 }
112 
CreatePicture()113 std::unique_ptr<PictureImpl> SkiaImplFactory::CreatePicture()
114 {
115     return std::make_unique<SkiaPicture>();
116 }
117 
CreatePath()118 std::unique_ptr<PathImpl> SkiaImplFactory::CreatePath()
119 {
120     return std::make_unique<SkiaPath>();
121 }
122 
CreateColorFilter()123 std::unique_ptr<ColorFilterImpl> SkiaImplFactory::CreateColorFilter()
124 {
125     return std::make_unique<SkiaColorFilter>();
126 }
127 
CreateMaskFilter()128 std::unique_ptr<MaskFilterImpl> SkiaImplFactory::CreateMaskFilter()
129 {
130     return std::make_unique<SkiaMaskFilter>();
131 }
132 
CreateImageFilter()133 std::unique_ptr<ImageFilterImpl> SkiaImplFactory::CreateImageFilter()
134 {
135     return std::make_unique<SkiaImageFilter>();
136 }
137 
CreateShaderEffect()138 std::unique_ptr<ShaderEffectImpl> SkiaImplFactory::CreateShaderEffect()
139 {
140     return std::make_unique<SkiaShaderEffect>();
141 }
142 
CreateBlender()143 std::unique_ptr<BlenderImpl> SkiaImplFactory::CreateBlender()
144 {
145     return std::make_unique<SkiaBlender>();
146 }
147 
CreateRuntimeEffect()148 std::unique_ptr<RuntimeEffectImpl> SkiaImplFactory::CreateRuntimeEffect()
149 {
150     return std::make_unique<SkiaRuntimeEffect>();
151 }
152 
CreateRuntimeShaderBuilder(std::shared_ptr<RuntimeEffect> runtimeEffect)153 std::unique_ptr<RuntimeShaderBuilderImpl> SkiaImplFactory::CreateRuntimeShaderBuilder(
154     std::shared_ptr<RuntimeEffect> runtimeEffect)
155 {
156     return std::make_unique<SkiaRuntimeShaderBuilder>(runtimeEffect);
157 }
158 
CreateRuntimeBlenderBuilder(std::shared_ptr<RuntimeEffect> runtimeEffect)159 std::unique_ptr<RuntimeBlenderBuilderImpl> SkiaImplFactory::CreateRuntimeBlenderBuilder(
160     std::shared_ptr<RuntimeEffect> runtimeEffect)
161 {
162     return std::make_unique<SkiaRuntimeBlenderBuilder>(runtimeEffect);
163 }
164 
CreateSurface()165 std::unique_ptr<SurfaceImpl> SkiaImplFactory::CreateSurface()
166 {
167     return std::make_unique<SkiaSurface>();
168 }
169 
CreatePathEffect()170 std::unique_ptr<PathEffectImpl> SkiaImplFactory::CreatePathEffect()
171 {
172     return std::make_unique<SkiaPathEffect>();
173 }
174 
CreateColorSpace()175 std::unique_ptr<ColorSpaceImpl> SkiaImplFactory::CreateColorSpace()
176 {
177     return std::make_unique<SkiaColorSpace>();
178 }
179 
CreateMatrix()180 std::unique_ptr<MatrixImpl> SkiaImplFactory::CreateMatrix()
181 {
182     return std::make_unique<SkiaMatrix>();
183 }
184 
CreateMatrix(const Matrix & other)185 std::unique_ptr<MatrixImpl> SkiaImplFactory::CreateMatrix(const Matrix& other)
186 {
187     return std::make_unique<SkiaMatrix>(other);
188 }
189 
CreateMatrix44()190 std::unique_ptr<Matrix44Impl> SkiaImplFactory::CreateMatrix44()
191 {
192     return std::make_unique<SkiaMatrix44>();
193 }
194 
CreateCamera()195 std::unique_ptr<CameraImpl> SkiaImplFactory::CreateCamera()
196 {
197     return std::make_unique<SkiaCamera>();
198 }
199 
CreateRegion()200 std::unique_ptr<RegionImpl> SkiaImplFactory::CreateRegion()
201 {
202     return std::make_unique<SkiaRegion>();
203 }
204 
CreateVertices()205 std::unique_ptr<VerticesImpl> SkiaImplFactory::CreateVertices()
206 {
207     return std::make_unique<SkiaVertices>();
208 }
209 
CreateVerticesBuilder()210 std::unique_ptr<VerticesImpl::BuilderImpl> SkiaImplFactory::CreateVerticesBuilder()
211 {
212     return std::make_unique<SkiaVertices::SkiaBuilder>();
213 }
214 
CreateFont()215 std::unique_ptr<FontImpl> SkiaImplFactory::CreateFont()
216 {
217     return std::make_unique<SkiaFont>();
218 }
219 
CreateFont(std::shared_ptr<Typeface> typeface,scalar size,scalar scaleX,scalar skewX)220 std::unique_ptr<FontImpl> SkiaImplFactory::CreateFont(std::shared_ptr<Typeface> typeface,
221     scalar size, scalar scaleX, scalar skewX)
222 {
223     return std::make_unique<SkiaFont>(typeface, size, scaleX, skewX);
224 }
225 
CreateTextBlobBuilder()226 std::unique_ptr<TextBlobBuilderImpl> SkiaImplFactory::CreateTextBlobBuilder()
227 {
228     return std::make_unique<SkiaTextBlobBuilder>();
229 }
230 
CreateDefaultFontMgr()231 std::shared_ptr<FontMgrImpl> SkiaImplFactory::CreateDefaultFontMgr()
232 {
233     return SkiaFontMgr::CreateDefaultFontMgr();
234 }
235 
236 #ifndef USE_TEXGINE
CreateDynamicFontMgr()237 std::shared_ptr<FontMgrImpl> SkiaImplFactory::CreateDynamicFontMgr()
238 {
239     return SkiaFontMgr::CreateDynamicFontMgr();
240 }
241 #endif
242 
CreateMemoryStream()243 std::shared_ptr<MemoryStreamImpl> SkiaImplFactory::CreateMemoryStream()
244 {
245     return std::make_shared<SkiaMemoryStream>();
246 }
247 
CreateMemoryStream(const void * data,size_t length,bool copyData)248 std::shared_ptr<MemoryStreamImpl> SkiaImplFactory::CreateMemoryStream(const void* data, size_t length, bool copyData)
249 {
250     return std::make_shared<SkiaMemoryStream>(data, length, copyData);
251 }
252 
CreateResourceHolder()253 std::shared_ptr<ResourceHolderImpl> SkiaImplFactory::CreateResourceHolder()
254 {
255     return std::make_shared<SkiaResourceHolder>();
256 }
257 } // namespace Drawing
258 } // namespace Rosen
259 } // namespace OHOS