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