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 /** 35 * @brief Get component snapshot. 36 * @param id Indicates the NodeId of the RSNode. 37 * @param callback When the snapshot is compelete, the callback will be triggered. 38 * @param captureConfig Indicates the configuration of snapshot like scale, translation, rotation. 39 * @param specifiedAreaRect Indicates the range that user wants to clip the snapshot. 40 * @param rsCapturePixelMap Indicates the pixelmap that user wants to use. 41 */ 42 static void Capture(NodeId id, sptr<RSISurfaceCaptureCallback> callback, 43 const RSSurfaceCaptureConfig& captureConfig, const Drawing::Rect& specifiedAreaRect); 44 45 /** 46 * @brief Create resources for capture. 47 * @param specifiedAreaRect Indicates the range that user wants to clip the snapshot. 48 * @return Returns true if the resources are created successfully, otherwise returns false. 49 */ 50 bool CreateResources(const Drawing::Rect& specifiedAreaRect); 51 52 /** 53 * @brief Execute capture task. 54 * @param callback When the snapshot is compelete, the callback will be triggered. 55 * @param specifiedAreaRect Indicates the range that user wants to clip the snapshot. 56 * @return Returns true if the capture is run successfully, otherwise returns false. 57 */ 58 bool Run(sptr<RSISurfaceCaptureCallback> callback, const Drawing::Rect& specifiedAreaRect); 59 60 /** 61 * @brief Trigger callback to send pixelmap back to user. 62 * @param callback When the snapshot is compelete, the callback will be triggered. 63 * @param id Indicates the NodeId of the RSNode. 64 * @param captureConfig Indicates the configuration of snapshot like scale, translation, rotation. 65 * @param pixelmap Indicates the pixelmap that user wants to use. 66 */ 67 static void ProcessUiCaptureCallback(sptr<RSISurfaceCaptureCallback> callback, NodeId id, 68 const RSSurfaceCaptureConfig& captureConfig, Media::PixelMap* pixelmap); 69 #ifdef RS_ENABLE_UNI_RENDER 70 static std::function<void()> CreateSurfaceSyncCopyTask(std::shared_ptr<Drawing::Surface> surface, 71 std::unique_ptr<Media::PixelMap> pixelMap, NodeId id, const RSSurfaceCaptureConfig& captureConfig, 72 sptr<RSISurfaceCaptureCallback> callback, int32_t rotation = 0); 73 #endif 74 GetCaptureCount()75 static int32_t GetCaptureCount() 76 { 77 return captureCount_; 78 } 79 80 private: 81 static bool IsRectValid(NodeId nodeId, const Drawing::Rect& specifiedAreaRect); 82 bool IsStartEndSameNode(); 83 bool HasEndNodeRect() const; 84 bool UpdateStartAndEndNodeRect(); 85 std::shared_ptr<Drawing::Surface> CreateSurface(const std::unique_ptr<Media::PixelMap>& pixelmap) const; 86 std::unique_ptr<Media::PixelMap> CreatePixelMapByNode(std::shared_ptr<RSRenderNode> node) const; 87 std::unique_ptr<Media::PixelMap> CreatePixelMapByRect(const Drawing::Rect& specifiedAreaRect) const; 88 std::shared_ptr<DrawableV2::RSRenderNodeDrawable> nodeDrawable_ = nullptr; 89 std::shared_ptr<DrawableV2::RSRenderNodeDrawable> endNodeDrawable_ = nullptr; 90 std::unique_ptr<Media::PixelMap> pixelMap_ = nullptr; 91 NodeId nodeId_ = INVALID_NODEID; 92 NodeId endNodeId_ = INVALID_NODEID; 93 Drawing::Matrix startMatrix_; 94 Drawing::Matrix endMatrix_; 95 RSSurfaceCaptureConfig captureConfig_ = {}; 96 static inline std::atomic<int32_t> captureCount_ = 0; 97 RectI startRect_ = {}; 98 RectI endRect_ = {}; 99 bool isStartEndNodeSame_ = false; 100 }; 101 } // namespace Rosen 102 } // namespace OHOS 103 104 #endif // RS_UI_CAPTURE_TASK_PARALLEL 105