xref: /aosp_15_r20/external/skia/tools/viewer/MSKPSlide.h (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1 /*
2  * Copyright 2021 Google LLC
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #ifndef MSKPSlide_DEFINED
9 #define MSKPSlide_DEFINED
10 
11 #include "include/core/SkScalar.h"
12 #include "include/core/SkSize.h"
13 #include "include/core/SkStream.h"
14 #include "include/core/SkString.h"
15 #include "tools/MSKPPlayer.h"
16 #include "tools/viewer/Slide.h"
17 
18 #include <memory>
19 #include <vector>
20 
21 class SkCanvas;
22 
23 class MSKPSlide : public Slide {
24 public:
25     MSKPSlide(const SkString& name, const SkString& path);
26     MSKPSlide(const SkString& name, std::unique_ptr<SkStreamSeekable>);
27 
28     SkISize getDimensions() const override;
29 
30     void draw(SkCanvas* canvas) override;
31     bool animate(double nanos) override;
32     void load(SkScalar winWidth, SkScalar winHeight) override;
33     void unload() override;
34     void gpuTeardown() override;
35 
36 private:
37     // Call if layers need to be redrawn because we've looped playback or UI interaction.
38     void redrawLayers();
39 
40     std::unique_ptr<SkStreamSeekable> fStream;
41     std::unique_ptr<MSKPPlayer>       fPlayer;
42 
43     int    fFrame         = 0;
44     int    fFPS           = 15;
45     bool   fPaused        = false;
46     double fLastFrameTime = -1;
47 
48     bool fShowFrameBounds = false;
49 
50     // Default to transparent black, which is correct for Android MSKPS.
51     float fBackgroundColor[4] = {0, 0, 0, 0};
52 
53     std::vector<int>              fAllLayerIDs;
54     std::vector<std::vector<int>> fFrameLayerIDs;
55     std::vector<SkString>         fLayerIDStrings;
56     int                           fDrawLayerID = -1;  // -1 means just draw the root layer
57     bool                          fListAllLayers = true;
58 };
59 
60 #endif
61