blob: f3bc99dcaedb5fd238c63f6fab4a483e1104d94a [file] [log] [blame]
Robert Phillipsdeaf5682017-09-06 13:07:21 -04001/*
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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "include/core/SkBitmap.h"
9#include "include/private/SkTDArray.h"
Robert Phillipsdeaf5682017-09-06 13:07:21 -040010
Mike Klein8f4e2242019-03-20 11:59:00 -050011class DrawCommand;
Robert Phillipsdeaf5682017-09-06 13:07:21 -040012
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
Greg Danielf41b2bd2019-08-22 16:19:24 -040030 // after this call (i.e., rebuild the opsTask view).
Robert Phillipsdeaf5682017-09-06 13:07:21 -040031 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(); }
Robert Phillips276066b2017-09-06 17:17:44 -040038 const char* getOpName(int index) const;
39
40 bool isHierarchyPush(int index) const;
41 bool isHierarchyPop(int index) const;
Robert Phillipsdeaf5682017-09-06 13:07:21 -040042
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);
Greg Danielf41b2bd2019-08-22 16:19:24 -040051 void resetOpsTask();
Robert Phillipsdeaf5682017-09-06 13:07:21 -040052
53private:
Mike Klein8f4e2242019-03-20 11:59:00 -050054 SkTDArray<DrawCommand*> fOps;
Robert Phillipsdeaf5682017-09-06 13:07:21 -040055 int fCurOp; // The current op the rendering state is at
56 SkBitmap fBM;
57};