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 #endif 58 59 bool CreateResources(); 60 61 bool Run(sptr<RSISurfaceCaptureCallback> callback, const RSSurfaceCaptureParam& captureParam); 62 63 static void ClearCacheImageByFreeze(NodeId id); 64 65 private: 66 std::shared_ptr<Drawing::Surface> CreateSurface(const std::unique_ptr<Media::PixelMap>& pixelmap); 67 68 std::unique_ptr<Media::PixelMap> CreatePixelMapBySurfaceNode(std::shared_ptr<RSSurfaceRenderNode> node); 69 70 std::unique_ptr<Media::PixelMap> CreatePixelMapByDisplayNode(std::shared_ptr<RSDisplayRenderNode> node); 71 72 void AddBlur(RSPaintFilterCanvas& canvas, const std::shared_ptr<Drawing::Surface>& surface, float blurRadius); 73 74 void SetupGpuContext(); 75 76 int32_t CalPixelMapRotation(); 77 78 std::unique_ptr<Media::PixelMap> pixelMap_ = nullptr; 79 std::shared_ptr<DrawableV2::RSRenderNodeDrawable> surfaceNodeDrawable_ = nullptr; 80 std::shared_ptr<DrawableV2::RSRenderNodeDrawable> displayNodeDrawable_ = nullptr; 81 std::shared_ptr<RSSurfaceRenderNode> surfaceNode_ = nullptr; 82 NodeId nodeId_; 83 RSSurfaceCaptureConfig captureConfig_; 84 ScreenRotation screenCorrection_ = ScreenRotation::ROTATION_0; 85 ScreenRotation screenRotation_ = ScreenRotation::ROTATION_0; 86 int32_t finalRotationAngle_ = RS_ROTATION_0; 87 std::shared_ptr<Drawing::ColorSpace> colorSpace_ = nullptr; 88 89 // only used for RSUniRenderThread 90 std::shared_ptr<Drawing::GPUContext> gpuContext_ = nullptr; 91 }; 92 93 } // namespace Rosen 94 } // namespace OHOS 95 96 #endif // RS_SURFACE_CAPTURE_TASK_PARALLEL 97