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); curOp()35 int curOp() const { return fCurOp; } 36 numOps()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 getPixels()44 void* getPixels() const { return fBM.getPixels(); } width()45 int width() const { return fBM.width(); } height()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 }; 58