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_SURFACE_CAPTURE_TASK_PARALLEL 17 #define RS_SURFACE_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 #if defined(ROSEN_OHOS) && defined(RS_ENABLE_VK) 29 class DmaMem { 30 public: 31 DmaMem() = default; 32 ~DmaMem(); 33 sptr<SurfaceBuffer> DmaMemAlloc(Drawing::ImageInfo &dstInfo, const std::unique_ptr<Media::PixelMap>& pixelMap); 34 std::shared_ptr<Drawing::Surface> GetSurfaceFromSurfaceBuffer(sptr<SurfaceBuffer> surfaceBuffer, 35 std::shared_ptr<Drawing::GPUContext> gpuContext); 36 void ReleaseDmaMemory(); 37 private: 38 OHNativeWindowBuffer* nativeWindowBuffer_ = nullptr; 39 }; 40 #endif 41 42 class RSSurfaceCaptureTaskParallel { 43 public: RSSurfaceCaptureTaskParallel(NodeId nodeId,const RSSurfaceCaptureConfig & captureConfig)44 explicit RSSurfaceCaptureTaskParallel(NodeId nodeId, const RSSurfaceCaptureConfig& captureConfig) 45 : nodeId_(nodeId), captureConfig_(captureConfig) {} 46 ~RSSurfaceCaptureTaskParallel() = default; 47 48 // Confirm whether the node is occlusive which should apply modifiers 49 static void CheckModifiers(NodeId id, bool useCurWindow); 50 // Do capture pipeline task 51 static void Capture(sptr<RSISurfaceCaptureCallback> callback, const RSSurfaceCaptureParam& captureParam); 52 53 #ifdef RS_ENABLE_UNI_RENDER 54 static std::function<void()> CreateSurfaceSyncCopyTask(std::shared_ptr<Drawing::Surface> surface, 55 std::unique_ptr<Media::PixelMap> pixelMap, NodeId id, const RSSurfaceCaptureConfig& captureConfig, 56 sptr<RSISurfaceCaptureCallback> callback, int32_t rotation = 0); 57 static std::function<void()> CreateSurfaceSyncCopyTaskWithDoublePixelMap( 58 std::shared_ptr<Drawing::Surface> surface, std::unique_ptr<Media::PixelMap> pixelMap, 59 std::shared_ptr<Drawing::Surface> surfaceHDR, std::unique_ptr<Media::PixelMap> pixelMapHDR, NodeId id, 60 const RSSurfaceCaptureConfig& captureConfig, sptr<RSISurfaceCaptureCallback> callback, int32_t rotation); 61 static bool PixelMapCopy(std::unique_ptr<Media::PixelMap>& pixelmap, 62 std::shared_ptr<Drawing::ColorSpace> colorSpace, const Drawing::BackendTexture& backendTexture, 63 Drawing::ColorType colorType, bool useDma, int32_t rotation); 64 #endif 65 66 bool CreateResources(); 67 68 bool Run(sptr<RSISurfaceCaptureCallback> callback, const RSSurfaceCaptureParam& captureParam); 69 bool RunHDR(sptr<RSISurfaceCaptureCallback> callback, const RSSurfaceCaptureParam& captureParam); 70 bool DrawHDRSurfaceContent( 71 std::shared_ptr<Drawing::Surface> surface, bool isOnHDR, const RSSurfaceCaptureParam& captureParam); UseScreenShotWithHDR()72 bool UseScreenShotWithHDR() const 73 { 74 return useScreenShotWithHDR_; 75 } 76 SetUseScreenShotWithHDR(bool enableHdrCapture)77 void SetUseScreenShotWithHDR(bool enableHdrCapture) 78 { 79 useScreenShotWithHDR_ = enableHdrCapture; 80 } 81 82 static void ClearCacheImageByFreeze(NodeId id); 83 84 private: 85 std::shared_ptr<Drawing::Surface> CreateSurface(const std::unique_ptr<Media::PixelMap>& pixelmap); 86 87 std::unique_ptr<Media::PixelMap> CreatePixelMapBySurfaceNode(std::shared_ptr<RSSurfaceRenderNode> node, 88 bool isF16Capture = false); 89 90 std::unique_ptr<Media::PixelMap> CreatePixelMapByDisplayNode(std::shared_ptr<RSLogicalDisplayRenderNode> node, 91 bool isHDRCapture = false); 92 93 bool CreateResourcesForClientPixelMap(const std::shared_ptr<RSRenderNode>& node); 94 95 void AddBlur(RSPaintFilterCanvas& canvas, const std::shared_ptr<Drawing::Surface>& surface, float blurRadius); 96 97 void SetupGpuContext(); 98 99 int32_t CalPixelMapRotation(); 100 101 void CaptureDisplayNode(DrawableV2::RSRenderNodeDrawable& displayNodeDrawable, RSPaintFilterCanvas& canvas, 102 const RSSurfaceCaptureParam& captureParam, RSPaintFilterCanvas::ScreenshotType type); 103 104 std::unique_ptr<Media::PixelMap> pixelMap_ = nullptr; 105 std::unique_ptr<Media::PixelMap> pixelMapHDR_ = nullptr; 106 std::shared_ptr<DrawableV2::RSRenderNodeDrawable> surfaceNodeDrawable_ = nullptr; 107 std::shared_ptr<DrawableV2::RSRenderNodeDrawable> displayNodeDrawable_ = nullptr; 108 std::shared_ptr<RSSurfaceRenderNode> surfaceNode_ = nullptr; 109 NodeId nodeId_; 110 ScreenId screenId_ = INVALID_SCREEN_ID; 111 bool useScreenShotWithHDR_ = false; 112 RSSurfaceCaptureConfig captureConfig_; 113 ScreenRotation screenCorrection_ = ScreenRotation::ROTATION_0; 114 ScreenRotation screenRotation_ = ScreenRotation::ROTATION_0; 115 float boundsX_ = 0; 116 float boundsY_ = 0; 117 int32_t finalRotationAngle_ = RS_ROTATION_0; 118 // only used for RSUniRenderThread 119 std::shared_ptr<Drawing::GPUContext> gpuContext_ = nullptr; 120 }; 121 122 } // namespace Rosen 123 } // namespace OHOS 124 125 #endif // RS_SURFACE_CAPTURE_TASK_PARALLEL 126