• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2025 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 #ifndef SURFACE_DRAW_H
17 #define SURFACE_DRAW_H
18 
19 #include <ui/rs_surface_node.h>
20 
21 #include "draw/canvas.h"
22 #include "nocopyable.h"
23 #include "pixel_map.h"
24 #include "refbase.h"
25 #include "wm_common.h"
26 #include "ws_common.h"
27 
28 namespace OHOS {
29 namespace Rosen {
30 class SurfaceDraw {
31 public:
32     SurfaceDraw() = default;
33     ~SurfaceDraw() = default;
34     static bool DrawColor(std::shared_ptr<RSSurfaceNode> surfaceNode, int32_t bufferWidth,
35         int32_t bufferHeight, uint32_t color);
36     static bool DrawImage(std::shared_ptr<RSSurfaceNode> surfaceNode, int32_t bufferWidth,
37         int32_t bufferHeight, const std::string& imagePath);
38     static bool DrawImage(std::shared_ptr<RSSurfaceNode> surfaceNode, int32_t bufferWidth,
39         int32_t bufferHeight, std::shared_ptr<Media::PixelMap> pixelMap);
40     static bool DrawImageRect(std::shared_ptr<RSSurfaceNode> surfaceNode, Rect winRect,
41         std::shared_ptr<Media::PixelMap> pixelMap, uint32_t bkgColor, bool fillWindow = false);
42     static bool GetSurfaceSnapshot(const std::shared_ptr<RSSurfaceNode> surfaceNode,
43         std::shared_ptr<Media::PixelMap>& pixelMap, int32_t timeoutMs, float scaleW = 0.5, float scaleH = 0.5);
44     static bool DrawMasking(std::shared_ptr<RSSurfaceNode> surfaceNode, Rect screenRect,
45         Rect transparentRect);
46     static bool DrawCustomStartingWindow(const std::shared_ptr<RSSurfaceNode>& surfaceNode, const Rect& rect,
47         const std::shared_ptr<Rosen::StartingWindowPageDrawInfo>& info, const float ratio,
48         const std::array<uint32_t, size_t(StartWindowResType::Count)>& frameIndex);
49 private:
50     static bool DoDraw(uint8_t* addr, uint32_t width, uint32_t height, const std::string& imagePath);
51     static bool DoDraw(uint8_t* addr, uint32_t width, uint32_t height, uint32_t color);
52     static bool DoDraw(uint8_t* addr, uint32_t width, uint32_t height, std::shared_ptr<Media::PixelMap> pixelMap);
53     static sptr<OHOS::Surface> GetLayer(std::shared_ptr<RSSurfaceNode> surfaceNode);
54     static sptr<OHOS::SurfaceBuffer> GetSurfaceBuffer(sptr<OHOS::Surface> layer, int32_t bufferWidth,
55         int32_t bufferHeight);
56     static void DrawPixelmap(Drawing::Canvas& canvas, const std::string& imagePath);
57     static std::unique_ptr<OHOS::Media::PixelMap> DecodeImageToPixelMap(const std::string& imagePath);
58     static bool DoDrawImageRect(sptr<OHOS::SurfaceBuffer> buffer, const Rect& rect,
59         std::shared_ptr<Media::PixelMap> pixelMap, uint32_t color, bool fillWindow = false);
60     static bool DoDrawCustomStartingWindow(const sptr<OHOS::SurfaceBuffer>& buffer, const Rect& rect,
61         const std::shared_ptr<Rosen::StartingWindowPageDrawInfo>& info, const float ratio,
62         const std::array<uint32_t, size_t(StartWindowResType::Count)>& frameIndex);
63 };
64 } // Rosen
65 } // OHOS
66 #endif  // SURFACE_DRAW_H