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 static std::vector<std::shared_ptr<Typeface>> GetSystemFonts(); 51 #ifdef RS_ENABLE_GPU 52 #ifdef RS_ENABLE_VK 53 static std::shared_ptr<Surface> MakeFromBackendRenderTarget(GPUContext* gpuContext, const TextureInfo& info, 54 TextureOrigin origin, ColorType colorType, std::shared_ptr<ColorSpace> colorSpace, 55 void (*deleteVkImage)(void *), void* cleanHelper); 56 #endif 57 static std::shared_ptr<Surface> MakeFromBackendTexture(GPUContext* gpuContext, const TextureInfo& info, 58 TextureOrigin origin, int sampleCnt, ColorType colorType, 59 std::shared_ptr<ColorSpace> colorSpace, void (*deleteVkImage)(void *), void* cleanHelper); 60 static std::shared_ptr<Surface> MakeRenderTarget(GPUContext* gpuContext, bool budgeted, const ImageInfo& imageInfo); 61 static std::shared_ptr<Image> MakeFromYUVAPixmaps(GPUContext& gpuContext, const YUVInfo& info, void* memory); 62 #endif 63 static std::shared_ptr<Surface> MakeRaster(const ImageInfo& imageInfo); 64 static std::shared_ptr<Surface> MakeRasterDirect(const ImageInfo& imageInfo, void* pixels, size_t rowBytes); 65 static std::shared_ptr<Surface> MakeRasterN32Premul(int32_t width, int32_t height); 66 static std::shared_ptr<Image> MakeFromRaster(const Pixmap& pixmap, 67 RasterReleaseProc rasterReleaseProc, ReleaseContext releaseContext); 68 static std::shared_ptr<Image> MakeRasterData(const ImageInfo& info, std::shared_ptr<Data> pixels, 69 size_t rowBytes); 70 static std::shared_ptr<TextBlob> DeserializeTextBlob(const void* data, size_t size, void* ctx); 71 static std::shared_ptr<Typeface> DeserializeTypeface(const void* data, size_t size); 72 static bool GetFillPath(const Pen& pen, const Path& src, Path& dst, const Rect* rect, const Matrix& matrix); 73 static bool CanComputeFastBounds(const Brush& brush); 74 static const Rect& ComputeFastBounds(const Brush& brush, const Rect& orig, Rect* storage); 75 static bool AsBlendMode(const Brush& brush); 76 static std::shared_ptr<Data> MakeDataFromFileName(const char path[]); 77 static void PathOutlineDecompose(const Path& path, std::vector<Path>& paths); 78 static void MultilayerPath(const std::vector<std::vector<size_t>>& multMap, 79 const std::vector<Path>& paths, std::vector<Path>& multPaths); 80 static void GetDrawingGlyphIDforTextBlob(const TextBlob* blob, std::vector<uint16_t>& glyphIds); 81 static Path GetDrawingPathforTextBlob(uint16_t glyphId, const TextBlob* blob); 82 static void GetDrawingPointsForTextBlob(const TextBlob* blob, std::vector<Point>& points); 83 static DrawingSymbolLayersGroups GetSymbolLayersGroups(uint16_t glyphId); 84 static std::vector<std::vector<DrawingPiecewiseParameter>> GetGroupParameters( 85 DrawingAnimationType type, uint16_t groupSum, uint16_t animationMode = 0, 86 DrawingCommonSubType commonSubType = DrawingCommonSubType::DOWN); 87 static std::shared_ptr<Blender> CreateWithBlendMode(BlendMode mode); 88 static void SetVmaCacheStatus(bool flag); 89 }; 90 } // namespace Drawing 91 } // namespace Rosen 92 } // namespace OHOS 93 #endif // STATIC_FACTORY_H