1 /* 2 * Copyright (c) 2023 Huawei Device Co., Ltd.. All rights reserved. 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 #ifndef STATIC_FACTORY_H 17 #define STATIC_FACTORY_H 18 19 #include <cstdint> 20 #include <vector> 21 22 #include "draw/brush.h" 23 #include "draw/path.h" 24 #include "draw/surface.h" 25 #include "effect/blender.h" 26 #include "image/pixmap.h" 27 #include "image/yuv_info.h" 28 #include "text/font_style_set.h" 29 #include "text/text_blob.h" 30 #include "text/typeface.h" 31 #include "utils/data.h" 32 #include "utils/rect.h" 33 34 namespace OHOS { 35 namespace Rosen { 36 namespace Drawing { 37 class StaticFactory { 38 public: 39 static std::shared_ptr<TextBlob> MakeFromText(const void* text, size_t byteLength, 40 const Font& font, TextEncoding encoding); 41 static std::shared_ptr<TextBlob> MakeFromPosText(const void* text, size_t byteLength, 42 const Point pos[], const Font& font, TextEncoding encoding); 43 static std::shared_ptr<TextBlob> MakeFromRSXform(const void* text, size_t byteLength, 44 const RSXform xform[], const Font& font, TextEncoding encoding); 45 static std::shared_ptr<Typeface> MakeDefault(); 46 static std::shared_ptr<Typeface> MakeFromFile(const char path[], int index); 47 static std::shared_ptr<Typeface> MakeFromFile(const char path[], const FontArguments& fontArguments); 48 static std::shared_ptr<Typeface> MakeFromStream(std::unique_ptr<MemoryStream> memoryStream, int32_t index); 49 static std::shared_ptr<Typeface> MakeFromName(const char familyName[], FontStyle fontStyle); 50 #ifdef ACE_ENABLE_GPU 51 #ifdef RS_ENABLE_VK 52 static std::shared_ptr<Surface> MakeFromBackendRenderTarget(GPUContext* gpuContext, const TextureInfo& info, 53 TextureOrigin origin, ColorType colorType, std::shared_ptr<ColorSpace> colorSpace, 54 void (*deleteVkImage)(void *), void* cleanHelper); 55 #endif 56 static std::shared_ptr<Surface> MakeFromBackendTexture(GPUContext* gpuContext, const TextureInfo& info, 57 TextureOrigin origin, int sampleCnt, ColorType colorType, 58 std::shared_ptr<ColorSpace> colorSpace, void (*deleteVkImage)(void *), void* cleanHelper); 59 static std::shared_ptr<Surface> MakeRenderTarget(GPUContext* gpuContext, bool budgeted, const ImageInfo& imageInfo); 60 static std::shared_ptr<Image> MakeFromYUVAPixmaps(GPUContext& gpuContext, const YUVInfo& info, void* memory); 61 #endif 62 static std::shared_ptr<Surface> MakeRaster(const ImageInfo& imageInfo); 63 static std::shared_ptr<Surface> MakeRasterDirect(const ImageInfo& imageInfo, void* pixels, size_t rowBytes); 64 static std::shared_ptr<Surface> MakeRasterN32Premul(int32_t width, int32_t height); 65 static std::shared_ptr<Image> MakeFromRaster(const Pixmap& pixmap, 66 RasterReleaseProc rasterReleaseProc, ReleaseContext releaseContext); 67 static std::shared_ptr<Image> MakeRasterData(const ImageInfo& info, std::shared_ptr<Data> pixels, 68 size_t rowBytes); 69 static std::shared_ptr<TextBlob> DeserializeTextBlob(const void* data, size_t size, void* ctx); 70 static std::shared_ptr<Typeface> DeserializeTypeface(const void* data, size_t size); 71 static bool GetFillPath(const Pen& pen, const Path& src, Path& dst, const Rect* rect, const Matrix& matrix); 72 static bool CanComputeFastBounds(const Brush& brush); 73 static const Rect& ComputeFastBounds(const Brush& brush, const Rect& orig, Rect* storage); 74 static bool AsBlendMode(const Brush& brush); 75 static std::shared_ptr<Data> MakeDataFromFileName(const char path[]); 76 static void PathOutlineDecompose(const Path& path, std::vector<Path>& paths); 77 static void MultilayerPath(const std::vector<std::vector<size_t>>& multMap, 78 const std::vector<Path>& paths, std::vector<Path>& multPaths); 79 static void GetDrawingGlyphIDforTextBlob(const TextBlob* blob, std::vector<uint16_t>& glyphIds); 80 static Path GetDrawingPathforTextBlob(uint16_t glyphId, const TextBlob* blob); 81 static void GetDrawingPointsForTextBlob(const TextBlob* blob, std::vector<Point>& points); 82 static DrawingSymbolLayersGroups GetSymbolLayersGroups(uint16_t glyphId); 83 static std::vector<std::vector<DrawingPiecewiseParameter>> GetGroupParameters( 84 DrawingAnimationType type, uint16_t groupSum, uint16_t animationMode = 0, 85 DrawingCommonSubType commonSubType = DrawingCommonSubType::DOWN); 86 static std::shared_ptr<Blender> CreateWithBlendMode(BlendMode mode); 87 static void SetVmaCacheStatus(bool flag); 88 }; 89 } // namespace Drawing 90 } // namespace Rosen 91 } // namespace OHOS 92 #endif // STATIC_FACTORY_H