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_PROFILER_CAPTURE_RECORDER_H 17 #define RS_PROFILER_CAPTURE_RECORDER_H 18 19 #ifdef RS_PROFILER_ENABLED 20 21 #include "include/core/SkRefCnt.h" 22 23 class SkDocument; 24 class SkPicture; 25 class SkPictureRecorder; 26 class SkFILEWStream; 27 struct SkSharingSerialContext; 28 29 namespace OHOS::Rosen::Drawing { 30 class Canvas; 31 } // namespace OHOS::Rosen::Drawing 32 33 namespace OHOS::Rosen { 34 35 class ExtendRecordingCanvas; 36 37 class RSCaptureRecorder final { 38 public: GetInstance()39 static RSCaptureRecorder& GetInstance() 40 { 41 static RSCaptureRecorder instance; 42 return instance; 43 } 44 45 Drawing::Canvas* TryInstantCapture(float width, float height); 46 void EndInstantCapture(); 47 48 // to check if .rdc is recorded and send the filename to client 49 static bool PullAndSendRdc(); 50 static std::pair<uint32_t, uint32_t> GetDirtyRect(uint32_t displayWidth, uint32_t displayHeight); 51 static bool IsRecordingEnabled(); 52 53 private: 54 RSCaptureRecorder(); 55 ~RSCaptureRecorder(); 56 57 void InitMSKP(); 58 ExtendRecordingCanvas* TryInstantCaptureDrawing(float width, float height); 59 void EndInstantCaptureDrawing(); 60 Drawing::Canvas* TryInstantCaptureSKP(float width, float height); 61 void EndInstantCaptureSKP(); 62 Drawing::Canvas* TryCaptureMSKP(float width, float height); 63 void EndCaptureMSKP(); 64 65 // used for .rdc capturing 66 std::unique_ptr<ExtendRecordingCanvas> recordingCanvas_; 67 // used for .skp capturing 68 std::unique_ptr<SkPictureRecorder> skRecorder_; 69 std::shared_ptr<Drawing::Canvas> recordingSkpCanvas_; 70 // to make sure the capture start/finish happen for the same frame / thread 71 bool recordingTriggered_ = false; 72 73 sk_sp<SkPicture> picture_; 74 75 std::unique_ptr<SkSharingSerialContext> serialContext_; 76 std::unique_ptr<SkFILEWStream> openMultiPicStream_; 77 78 sk_sp<SkDocument> multiPic_; 79 int32_t mskpMaxLocal_ = 0; 80 int32_t mskpIdxCurrent_ = -1; 81 int32_t mskpIdxNext_ = -1; 82 bool isPageActive_ = false; 83 }; 84 85 } // namespace OHOS::Rosen 86 87 #endif // RS_PROFILER_ENABLED 88 89 #endif // RS_PROFILER_CAPTURE_RECORDER_H