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 DRAWING_PLAYBACK_H
17  #define DRAWING_PLAYBACK_H
18  
19  #include <chrono>
20  #include <unistd.h>
21  #include <sys/stat.h>
22  #include <sys/mman.h>
23  
24  #include <message_parcel.h>
25  #include "pipeline/rs_draw_cmd_list.h"
26  
27  #include "benchmark.h"
28  #include "drawing_command.h"
29  #include "skia_recording.h"
30  #include "include/core/SkBBHFactory.h"
31  #include "include/core/SkBitmap.h"
32  #include "include/core/SkCanvas.h"
33  #include "include/core/SkData.h"
34  #include "include/core/SkPicture.h"
35  #include "src/utils/SkMultiPictureDocument.h"
36  #include "tools/flags/CommonFlagsConfig.h"
37  #include "tools/gpu/MemoryCache.h"
38  #include "src/utils/SkOSPath.h"
39  
40  namespace OHOS {
41  namespace Rosen {
42  class MSKPSrc {
43  public:
44      explicit MSKPSrc(const std::string& path);
45  
46      bool Draw(SkCanvas* c) const;
47      bool NextFrame();
Name()48      SkString Name() const { return SkOSPath::Basename(fPath_.c_str()); }
GetCurFrameNum()49      int GetCurFrameNum() const { return curFrameNum_; }
50  private:
51      uint16_t curFrameNum_ = 0;
52      std::string fPath_;
53      mutable SkTArray<SkDocumentPage> fPages_;
54  };
55  
56  class DrawingDCL : public BenchMark {
57  public:
DrawingDCL()58      DrawingDCL() { std::cout << "DrawingDCL" << std::endl; }
59      DrawingDCL(int32_t argc, char* argv[]);
60      ~DrawingDCL();
61      bool GetDirectionAndStep(std::string command, bool &isMoreOps);
62      bool IterateFrame(int &curLoop, int &frame);
63      bool ReplayMSKP(SkCanvas *skiaCanvas);
64      void ReplaySKP(SkCanvas *skiaCanvas);
65      bool PlayBackByFrame(Drawing::Canvas* canvas, bool isDumpPictures = false);
66      bool PlayBackByOpItem(SkCanvas *skiaCanvas, bool isMoreOps = true);
67      void UpdateParameters(bool notNeeded);
68      void UpdateParametersFromDCLCommand(const DCLCommand& dclCommand);
69      void PrintDurationTime(const std::string &description, std::chrono::time_point<std::chrono::system_clock> start);
Start()70      void Start() override {};
Stop()71      void Stop() override {};
72      void Test(Drawing::Canvas* canvas, int width, int height) override;
73      void Output() override;
74      int LoadDrawCmdList(const std::string& dclFile);
75      std::string GetRealPathStr(const std::string& filePath);
76      bool IsValidFile(const std::string& realPathStr);
77  
78  private:
79      friend class DCLCommand;
80      const static size_t recordingParcelMaxCapcity_ = 234 * 1000 * 1024;
81      inline const static std::string dclFileDir_ = "/data/";
82      std::shared_ptr<Drawing::DrawCmdList> dcl_ = nullptr;
83      IterateType iterateType_ = IterateType::ITERATE_FRAME;
84      int beginFrame_ = 0;
85      int endFrame_ = 100;
86      int curFrameNo_ = beginFrame_;
87      int loop_ = 1;
88      double opItemStep_ = 4;
89      std::string inputFilePath_ = "/data/lkx/";
90      std::string outputFilePath_ = "/data/lkx/";
91      SkiaRecording skiaRecording;
92      SkCanvas* orgSkiaCanvas_ = nullptr;
93      SkCanvas* skiaCanvas_ = nullptr;
94      std::unique_ptr<MSKPSrc> mskpPtr;
95      sk_sp<SkPicture> skpPtr;
96  };
97  }
98  }
99  
100  #endif