1 /* 2 * Copyright (c) 2021-2023 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 RENDER_SERVICE_CLIENT_CORE_PIPELINE_RS_RECORDING_CANVAS_H 17 #define RENDER_SERVICE_CLIENT_CORE_PIPELINE_RS_RECORDING_CANVAS_H 18 19 #include "recording/recording_canvas.h" 20 #include <mutex> 21 #include <queue> 22 #include "pipeline/rs_draw_cmd.h" 23 24 namespace OHOS { 25 namespace Media { 26 class PixelMap; 27 } 28 namespace Rosen { 29 class RSB_EXPORT ExtendRecordingCanvas : public Drawing::RecordingCanvas { 30 public: 31 ExtendRecordingCanvas(int32_t width, int32_t weight, bool addDrawOpImmediate = true); 32 ~ExtendRecordingCanvas() override = default; 33 static std::unique_ptr<ExtendRecordingCanvas> Obtain(int32_t width, int32_t height, 34 bool addDrawOpImmediate = true); 35 static void Recycle(std::unique_ptr<ExtendRecordingCanvas>& canvas); 36 void DrawImageWithParm(const std::shared_ptr<Drawing::Image>& image, const std::shared_ptr<Drawing::Data>& data, 37 const Drawing::AdaptiveImageInfo& rsImageInfo, const Drawing::SamplingOptions& sampling); 38 void DrawPixelMapWithParm(const std::shared_ptr<Media::PixelMap>& pixelMap, 39 const Drawing::AdaptiveImageInfo& rsImageInfo, const Drawing::SamplingOptions& sampling); 40 void DrawImageNineWithPixelMap(const std::shared_ptr<Media::PixelMap>& pixelmap, const Drawing::RectI& center, 41 const Drawing::Rect& dst, Drawing::FilterMode filter, const Drawing::Brush* brush); 42 void DrawPixelMapRect(const std::shared_ptr<Media::PixelMap>& pixelMap, const Drawing::Rect& src, 43 const Drawing::Rect& dst, const Drawing::SamplingOptions& sampling, 44 Drawing::SrcRectConstraint constraint = Drawing::SrcRectConstraint::STRICT_SRC_RECT_CONSTRAINT); 45 void DrawDrawFunc(Drawing::RecordingCanvas::DrawFunc&& drawFunc); 46 #ifdef ROSEN_OHOS 47 void DrawSurfaceBuffer(const DrawingSurfaceBufferInfo& surfaceBufferInfo); 48 #endif 49 private: 50 template<typename T, typename... Args> 51 void AddDrawOpImmediate(Args&&... args); 52 template<typename T, typename... Args> 53 void AddDrawOpDeferred(Args&&... args); 54 static constexpr int MAX_CANVAS_SIZE = 5; 55 static inline std::mutex canvasMutex_; 56 static inline std::queue<std::unique_ptr<ExtendRecordingCanvas>> canvasPool_; 57 }; 58 } // namespace Rosen 59 } // namespace OHOS 60 #endif // RENDER_SERVICE_CLIENT_CORE_PIPELINE_RS_RECORDING_CANVAS_H 61