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/file_w_stream.h" 33 #include "utils/document.h" 34 #include "utils/perfevent.h" 35 #include "utils/rect.h" 36 #include "utils/serial_procs.h" 37 #include "utils/sharing_serial_context.h" 38 39 namespace OHOS { 40 namespace Rosen { 41 namespace Drawing { 42 class StaticFactory { 43 public: 44 static std::shared_ptr<TextBlob> MakeFromText(const void* text, size_t byteLength, 45 const Font& font, TextEncoding encoding); 46 static std::shared_ptr<TextBlob> MakeFromPosText(const void* text, size_t byteLength, 47 const Point pos[], const Font& font, TextEncoding encoding); 48 static std::shared_ptr<TextBlob> MakeFromRSXform(const void* text, size_t byteLength, 49 const RSXform xform[], const Font& font, TextEncoding encoding); 50 static std::shared_ptr<Typeface> MakeDefault(); 51 static std::shared_ptr<Typeface> MakeFromFile(const char path[], int index); 52 static std::shared_ptr<Typeface> MakeFromFile(const char path[], const FontArguments& fontArguments); 53 static std::shared_ptr<Typeface> MakeFromStream(std::unique_ptr<MemoryStream> memoryStream, int32_t index); 54 static std::shared_ptr<Typeface> MakeFromStream(std::unique_ptr<MemoryStream> memoryStream, 55 const FontArguments& fontArguments); 56 static std::shared_ptr<Typeface> MakeFromName(const char familyName[], FontStyle fontStyle); 57 static std::vector<std::shared_ptr<Typeface>> GetSystemFonts(); 58 #ifdef RS_ENABLE_GPU 59 #ifdef RS_ENABLE_VK 60 static std::shared_ptr<Surface> MakeFromBackendRenderTarget(GPUContext* gpuContext, const TextureInfo& info, 61 TextureOrigin origin, ColorType colorType, std::shared_ptr<ColorSpace> colorSpace, 62 void (*deleteVkImage)(void *), void* cleanHelper); 63 #endif 64 static std::shared_ptr<Surface> MakeFromBackendTexture(GPUContext* gpuContext, const TextureInfo& info, 65 TextureOrigin origin, int sampleCnt, ColorType colorType, 66 std::shared_ptr<ColorSpace> colorSpace, void (*deleteVkImage)(void *), void* cleanHelper); 67 static std::shared_ptr<Surface> MakeRenderTarget(GPUContext* gpuContext, bool budgeted, const ImageInfo& imageInfo); 68 static std::shared_ptr<Image> MakeFromYUVAPixmaps(GPUContext& gpuContext, const YUVInfo& info, void* memory); 69 #endif 70 static std::shared_ptr<Surface> MakeRaster(const ImageInfo& imageInfo); 71 static std::shared_ptr<Surface> MakeRasterDirect(const ImageInfo& imageInfo, void* pixels, size_t rowBytes); 72 static std::shared_ptr<Surface> MakeRasterN32Premul(int32_t width, int32_t height); 73 static std::shared_ptr<Image> MakeFromRaster(const Pixmap& pixmap, 74 RasterReleaseProc rasterReleaseProc, ReleaseContext releaseContext); 75 static std::shared_ptr<Document> MakeMultiPictureDocument(FileWStream* fileStream, 76 SerialProcs* procs, std::unique_ptr<SharingSerialContext>& serialContext); 77 static std::shared_ptr<Image> MakeRasterData(const ImageInfo& info, std::shared_ptr<Data> pixels, 78 size_t rowBytes); 79 static std::shared_ptr<TextBlob> DeserializeTextBlob(const void* data, size_t size, void* ctx); 80 static std::shared_ptr<Typeface> DeserializeTypeface(const void* data, size_t size); 81 static bool GetFillPath(const Pen& pen, const Path& src, Path& dst, const Rect* rect, const Matrix& matrix); 82 static bool CanComputeFastBounds(const Brush& brush); 83 static const Rect& ComputeFastBounds(const Brush& brush, const Rect& orig, Rect* storage); 84 static bool AsBlendMode(const Brush& brush); 85 static std::shared_ptr<Data> MakeDataFromFileName(const char path[]); 86 static void PathOutlineDecompose(const Path& path, std::vector<Path>& paths); 87 static void MultilayerPath(const std::vector<std::vector<size_t>>& multMap, 88 const std::vector<Path>& paths, std::vector<Path>& multPaths); 89 static void GetDrawingGlyphIDforTextBlob(const TextBlob* blob, std::vector<uint16_t>& glyphIds); 90 static Path GetDrawingPathforTextBlob(uint16_t glyphId, const TextBlob* blob); 91 static void GetDrawingPointsForTextBlob(const TextBlob* blob, std::vector<Point>& points); 92 static std::shared_ptr<Blender> CreateWithBlendMode(BlendMode mode); 93 static void SetVmaCacheStatus(bool flag); 94 static void ResetStatsData(); 95 static void ResetPerfEventData(); 96 static std::map<std::string, std::vector<uint16_t>> GetBlurStatsData(); 97 static std::map<std::string, RsBlurEvent> GetBlurPerfEventData(); 98 static std::map<std::string, std::vector<uint16_t>> GetTextureStatsData(); 99 static std::map<std::string, RsTextureEvent> GetTexturePerfEventData(); 100 static int16_t GetSplitRange(int64_t duration); 101 static bool IsOpenPerf(); 102 static int64_t GetCurrentTime(); 103 static void SetCurrentNodeId(uint64_t nodeId); 104 }; 105 } // namespace Drawing 106 } // namespace Rosen 107 } // namespace OHOS 108 #endif // STATIC_FACTORY_H 109