Robert Phillips | deaf568 | 2017-09-06 13:07:21 -0400 | [diff] [blame] | 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 "SkBitmap.h" |
| 9 | #include "SkTDArray.h" |
| 10 | |
| 11 | class SkDrawCommand; |
| 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. |
| 15 | class Model { |
| 16 | public: |
| 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 opList 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(); } |
Robert Phillips | 276066b | 2017-09-06 17:17:44 -0400 | [diff] [blame] | 38 | const char* getOpName(int index) const; |
| 39 | |
| 40 | bool isHierarchyPush(int index) const; |
| 41 | bool isHierarchyPop(int index) const; |
Robert Phillips | deaf568 | 2017-09-06 13:07:21 -0400 | [diff] [blame] | 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 | |
| 48 | protected: |
| 49 | // draw the ops up to (and including) the index-th op |
| 50 | void drawTo(int index); |
| 51 | void resetOpList(); |
| 52 | |
| 53 | private: |
| 54 | SkTDArray<SkDrawCommand*> fOps; |
| 55 | int fCurOp; // The current op the rendering state is at |
| 56 | SkBitmap fBM; |
| 57 | }; |