Model.h 1.6 KB

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