• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 * Copyright (c) 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 #ifndef RENDER_SERVICE_CLIENT_CORE_UI_RS_CAPTURE_PIXELMAP_MANAGER_H
16 #define RENDER_SERVICE_CLIENT_CORE_UI_RS_CAPTURE_PIXELMAP_MANAGER_H
17 #include "pixel_map.h"
18 #include "common/rs_common_def.h"
19 #include "pipeline/rs_uni_render_judgement.h"
20 #include "image/image.h"
21 namespace OHOS {
22 namespace Rosen {
23 using CapturePixelMapMemFunHandle = std::unordered_map<int,
24     std::unordered_map<int, std::function<bool(const std::unique_ptr<Media::PixelMap>&, bool)>>>;
25 
26 using CapturePixelMapCheckFunHandle = std::unordered_map<int,
27      std::unordered_map<int, std::function<bool(const Drawing::Rect&, const RSSurfaceCaptureConfig&)>>>;
28 
29 class RSB_EXPORT RSCapturePixelMapManager {
30 public:
RSCapturePixelMapManager()31     RSCapturePixelMapManager(){};
~RSCapturePixelMapManager()32     ~RSCapturePixelMapManager(){};
33     static bool SetCapturePixelMapMem(const std::unique_ptr<Media::PixelMap>& pixelmap,
34         const SurfaceCaptureType& captureType, const UniRenderEnabledType& uniRenderEnabledType, bool useDma);
35     static std::unique_ptr<Media::PixelMap> CreatePixelMap(const Drawing::Rect& areaRect,
36         const RSSurfaceCaptureConfig& captureConfig);
37     // this func only use service
38     static bool CopyDataToPixelMap(std::shared_ptr<Drawing::Image> img,
39         const std::unique_ptr<Media::PixelMap>& pixelmap, std::shared_ptr<Drawing::ColorSpace> colorSpace = nullptr);
40 
41     static bool CopyDataToPixelMap(std::shared_ptr<Drawing::Image> img,
42         const std::unique_ptr<Media::PixelMap>& pixelmap);
43     static std::unique_ptr<Media::PixelMap> GetClientCapturePixelMap(const Drawing::Rect& nodeAreaRect,
44         const RSSurfaceCaptureConfig& captureConfig, const UniRenderEnabledType& uniRenderEnabledType,
45         const Drawing::Rect& specifiedAreaRect = {0.f, 0.f, 0.f, 0.f});
46 
47 private:
48     static CapturePixelMapMemFunHandle funcHandle_;
49     static CapturePixelMapCheckFunHandle checkHandle_;
50     static bool AttachCommMem(const std::unique_ptr<Media::PixelMap>& pixelMap, bool isUsedDma = false);
51     static bool AttachShareMem(const std::unique_ptr<Media::PixelMap>& pixelMap, bool isUsedDma = false);
52     static bool AttachHeapMem(const std::unique_ptr<Media::PixelMap>& pixelMap);
53     static bool AttachUniCommMem(const std::unique_ptr<Media::PixelMap>& pixelMap, bool isUsedDma = false);
54     static bool CheckCaptureConfig(const Drawing::Rect& areaRect, const RSSurfaceCaptureConfig& captureConfig,
55         const UniRenderEnabledType& uniRenderEnabledType);
56     static void LoadCheckFunc();
57     static void LoadSetMemFunc();
58     static std::unique_ptr<Media::PixelMap> GetCapturePixelMap(const Drawing::Rect& areaRect,
59         const RSSurfaceCaptureConfig& captureConfig, const UniRenderEnabledType& uniRenderEnabledType);
60 
61     static Drawing::Rect GetCaptureAreaRect(const Drawing::Rect& nodeAreaRect,
62         const Drawing::Rect& specifiedAreaRect = {0.f, 0.f, 0.f, 0.f},
63         const SurfaceCaptureType& captureType = SurfaceCaptureType::DEFAULT_CAPTURE);
64     static bool AttachDmaMem(const std::unique_ptr<Media::PixelMap>& pixelMap);
65     static constexpr uint32_t uint32UniRenderDisableType_ =
66         static_cast<uint32_t>(UniRenderEnabledType::UNI_RENDER_DISABLED);
67     static constexpr uint32_t uint32UniRenderEnableType_ =
68         static_cast<uint32_t>(UniRenderEnabledType::UNI_RENDER_ENABLED_FOR_ALL);
69     static constexpr uint32_t uint32DefaultCaptureType_ =
70         static_cast<uint32_t>(SurfaceCaptureType::DEFAULT_CAPTURE);
71     static constexpr uint32_t uint32UiCaptureType_ = static_cast<uint32_t>(SurfaceCaptureType::UICAPTURE);
72 
73 };
74 
75 class RSC_EXPORT RSCapturePixelMap {
76 public:
RSCapturePixelMap()77     RSCapturePixelMap(){};
~RSCapturePixelMap()78     ~RSCapturePixelMap(){};
SetCapturePixelMap(std::unique_ptr<Media::PixelMap> pixelmap)79     inline void SetCapturePixelMap(std::unique_ptr<Media::PixelMap> pixelmap) {
80         pixelMap_ = std::move(pixelmap);
81     }
82     std::unique_ptr<Media::PixelMap> pixelMap_ = nullptr;
GetPixelMap()83     const std::unique_ptr<Media::PixelMap>& GetPixelMap() {
84         return pixelMap_;
85     }
86 };
87 
88 } // Rosen
89 } // OHOS
90 
91 #endif