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 DRAWING_SAMPLE_REPLAYER_H 17 #define DRAWING_SAMPLE_REPLAYER_H 18 19 #include "display_manager.h" 20 #include "ui/rs_surface_extractor.h" 21 #include "ui/rs_surface_node.h" 22 #include "render_context/render_context.h" 23 #include "transaction/rs_transaction.h" 24 25 #include "skia_adapter/skia_canvas.h" 26 27 #include "include/core/SkPictureRecorder.h" 28 #include "include/core/SkPicture.h" 29 #include "include/core/SkSerialProcs.h" 30 #include "include/utils/SkNWayCanvas.h" 31 32 namespace OHOS::Rosen { 33 34 enum CaptureMode { 35 RDC = 0, 36 SKP, 37 LAST, 38 }; 39 40 class EmptyAllocator : public DefaultAllocator { 41 public: 42 EmptyAllocator() = default; 43 ~EmptyAllocator() = default; Realloc(void * data,size_t newSize)44 void* Realloc(void *data, size_t newSize) override { return nullptr; } Alloc(size_t size)45 void* Alloc(size_t size) override { return nullptr; } Dealloc(void * data)46 void Dealloc(void *data) override { } 47 }; 48 49 class DrawingSampleReplayer { 50 public: 51 DrawingSampleReplayer() = default; 52 ~DrawingSampleReplayer(); 53 54 bool PrepareNativeEGLSetup(); 55 bool RenderLoop(); 56 void SetCaptureMode(CaptureMode mode); 57 private: 58 bool ReadCmds(const std::string path); 59 bool PrepareFrame(Drawing::Canvas* canvas); 60 61 bool InitCapturingSKP(Drawing::Canvas* canvas); 62 void FinilizeCapturingSKP(Drawing::Canvas* canvas); 63 64 enum CaptureMode captureMode_ = CaptureMode::RDC; 65 uint32_t width_ = 0; 66 uint32_t height_ = 0; 67 std::shared_ptr<RSSurfaceNode> surfaceNode_; 68 std::shared_ptr<RenderContext> renderContext_; 69 OHNativeWindow* nativeWindow_ = nullptr; 70 EGLSurface eglSurface_ = EGL_NO_SURFACE; 71 72 std::shared_ptr<Drawing::DrawCmdList> dcl_; 73 74 // for .skp 75 SkCanvas* pictureCanvas_ = nullptr; 76 SkCanvas* orgSkiaCanvas_ = nullptr; 77 std::unique_ptr<SkPictureRecorder> recorder_; 78 std::unique_ptr<SkNWayCanvas> nwayCanvas_; 79 80 const uint32_t maxRenderedFrames_ = 50; 81 const uint32_t defaultDisplayId_ = 0; 82 }; 83 84 } // namespace OHOS::Rosen 85 86 #endif // DRAWING_SAMPLE_REPLAYER_H