xref: /third_party/skia/tools/mdbviz/Model.h (revision cb93a386)
1/*
2 * Copyright 2017 Google Inc.
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#include "include/core/SkBitmap.h"
9#include "include/private/SkTDArray.h"
10
11class DrawCommand;
12
13// This class encapsulates the both the in-memory representation of the draw ops
14// and the state of Skia/Ganesh's rendering. It should never have any Qt intrusions.
15class Model {
16public:
17    enum class ErrorCode {
18        kOK,
19        kCouldntOpenFile,
20        kCouldntDecodeSKP
21    };
22
23    Model();
24    ~Model();
25
26    static const char* ErrorString(ErrorCode);
27
28    // Replace the list of draw ops by reading the provided skp filename and
29    // reset the Skia draw state. It is up to the view portion to update itself
30    // after this call (i.e., rebuild the opsTask view).
31    ErrorCode load(const char* filename);
32
33    // Update the rendering state to the provided op
34    void setCurOp(int curOp);
35    int curOp() const { return fCurOp; }
36
37    int numOps() const { return fOps.count(); }
38    const char* getOpName(int index) const;
39
40    bool isHierarchyPush(int index) const;
41    bool isHierarchyPop(int index) const;
42
43    // Get the bits visually representing the current rendering state
44    void* getPixels() const { return fBM.getPixels(); }
45    int width() const { return fBM.width(); }
46    int height() const { return fBM.height(); }
47
48protected:
49    // draw the ops up to (and including) the index-th op
50    void drawTo(int index);
51    void resetOpsTask();
52
53private:
54    SkTDArray<DrawCommand*>   fOps;
55    int                       fCurOp;  // The current op the rendering state is at
56    SkBitmap                  fBM;
57};
58