1 /* 2 * Copyright (c) 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 SKIA_RECORDING_H 17 #define SKIA_RECORDING_H 18 19 #include <string> 20 21 #include "include/core/SkCanvas.h" 22 #include "include/core/SkStream.h" 23 #include "include/core/SkDocument.h" 24 #include "include/core/SkPictureRecorder.h" 25 #include "include/core/SkSerialProcs.h" 26 #include "include/utils/SkNWayCanvas.h" 27 #include "src/utils/SkMultiPictureDocument.h" 28 #include "tools/SkSharingProc.h" 29 30 namespace OHOS { 31 namespace Rosen { 32 class SkiaRecording { 33 public: 34 enum class SkiaCaptureMode { 35 SINGLE_FRAME, 36 MULTI_FRAME, 37 NONE, 38 }; 39 bool GetCaptureEnabled() const; 40 void InitConfigsFromParam(); 41 bool SetupMultiFrame(); 42 SkCanvas* BeginCapture(SkCanvas* canvas, int width, int height); 43 void EndCapture(); 44 static void SavePicture(const sk_sp<SkData>& data, const std::string& filename); 45 46 private: 47 bool captureEnabled_ = false; 48 int captureFrameNum_ = 0; 49 std::string captureFileName_ = ""; 50 SkiaCaptureMode captureMode_ = SkiaCaptureMode::NONE; 51 52 // Should be decleared before other serializing member 53 std::unique_ptr<SkSharingSerialContext> serialContext_; 54 std::unique_ptr<SkFILEWStream> openMultiPicStream_; 55 sk_sp<SkDocument> multiPic_; 56 SkCanvas* pictureCanvas_ = nullptr; 57 58 std::unique_ptr<SkPictureRecorder> recorder_; 59 std::unique_ptr<SkNWayCanvas> nwayCanvas_; 60 }; 61 } 62 } 63 64 #endif