• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 RS_UI_CAPTURE_TASK_PARALLEL
17 #define RS_UI_CAPTURE_TASK_PARALLEL
18 #define EGL_EGLEXT_PROTOTYPES
19 #define GL_GLEXT_PROTOTYPES
20 
21 #include "drawable/rs_render_node_drawable.h"
22 #include "feature/capture/rs_surface_capture_task.h"
23 #include "pixel_map.h"
24 #include "system/rs_system_parameters.h"
25 
26 namespace OHOS {
27 namespace Rosen {
28 class RSUiCaptureTaskParallel {
29 public:
RSUiCaptureTaskParallel(NodeId nodeId,const RSSurfaceCaptureConfig & captureConfig)30     explicit RSUiCaptureTaskParallel(NodeId nodeId, const RSSurfaceCaptureConfig& captureConfig)
31         : nodeId_(nodeId), captureConfig_(captureConfig) {}
32     ~RSUiCaptureTaskParallel() = default;
33 
34     static void Capture(NodeId id, sptr<RSISurfaceCaptureCallback> callback,
35         const RSSurfaceCaptureConfig& captureConfig, const Drawing::Rect& specifiedAreaRect);
36 
37     bool CreateResources(const Drawing::Rect& specifiedAreaRect);
38     bool Run(sptr<RSISurfaceCaptureCallback> callback, const Drawing::Rect& specifiedAreaRect);
39 
40     static void ProcessUiCaptureCallback(sptr<RSISurfaceCaptureCallback> callback, NodeId id,
41         const RSSurfaceCaptureConfig& captureConfig, Media::PixelMap* pixelmap);
42 #ifdef RS_ENABLE_UNI_RENDER
43     static std::function<void()> CreateSurfaceSyncCopyTask(std::shared_ptr<Drawing::Surface> surface,
44         std::unique_ptr<Media::PixelMap> pixelMap, NodeId id, const RSSurfaceCaptureConfig& captureConfig,
45         sptr<RSISurfaceCaptureCallback> callback, int32_t rotation = 0);
46 #endif
47 
GetCaptureCount()48     static int32_t GetCaptureCount()
49     {
50         return captureCount_;
51     }
52 
53 private:
54     static bool IsRectValid(NodeId nodeId, const Drawing::Rect& specifiedAreaRect);
55     std::shared_ptr<Drawing::Surface> CreateSurface(const std::unique_ptr<Media::PixelMap>& pixelmap) const;
56     std::unique_ptr<Media::PixelMap> CreatePixelMapByNode(std::shared_ptr<RSRenderNode> node) const;
57     std::unique_ptr<Media::PixelMap> CreatePixelMapByRect(const Drawing::Rect& specifiedAreaRect) const;
58     std::unique_ptr<Media::PixelMap> pixelMap_ = nullptr;
59     std::shared_ptr<DrawableV2::RSRenderNodeDrawable> nodeDrawable_ = nullptr;
60     NodeId nodeId_ = INVALID_NODEID;
61     RSSurfaceCaptureConfig captureConfig_ = {};
62     static inline std::atomic<int32_t> captureCount_ = 0;
63 };
64 } // namespace Rosen
65 } // namespace OHOS
66 
67 #endif // RS_UI_CAPTURE_TASK_PARALLEL
68