chudy@google.com | 607357f | 2012-08-07 16:12:23 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2012 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
| 8 | |
| 9 | |
| 10 | #ifndef SKDEBUGGER_H_ |
| 11 | #define SKDEBUGGER_H_ |
| 12 | |
| 13 | #include "SkDebugCanvas.h" |
| 14 | #include "SkPicture.h" |
robertphillips@google.com | 8a1cdae | 2012-11-19 20:44:29 +0000 | [diff] [blame] | 15 | #include "SkTArray.h" |
chudy@google.com | 607357f | 2012-08-07 16:12:23 +0000 | [diff] [blame] | 16 | |
| 17 | class SkDebugger { |
| 18 | public: |
| 19 | SkDebugger(); |
| 20 | |
| 21 | ~SkDebugger(); |
| 22 | |
| 23 | void setIndex(int index) { |
| 24 | fIndex = index; |
| 25 | } |
| 26 | void draw(SkCanvas* canvas) { |
| 27 | if (fIndex > 0) { |
| 28 | fDebugCanvas->drawTo(canvas, fIndex); |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | void step(); |
| 33 | void stepBack(); |
| 34 | void play(); |
| 35 | void rewind(); |
| 36 | |
| 37 | bool isCommandVisible(int index) { |
| 38 | return fDebugCanvas->getDrawCommandVisibilityAt(index); |
| 39 | } |
| 40 | |
| 41 | void setCommandVisible(int index, bool isVisible) { |
| 42 | fDebugCanvas->toggleCommand(index, isVisible); |
| 43 | } |
| 44 | |
robertphillips@google.com | 8a1cdae | 2012-11-19 20:44:29 +0000 | [diff] [blame] | 45 | SkTArray<SkString>* getDrawCommandsAsStrings() { |
chudy@google.com | 607357f | 2012-08-07 16:12:23 +0000 | [diff] [blame] | 46 | return fDebugCanvas->getDrawCommandsAsStrings(); |
| 47 | } |
| 48 | |
robertphillips@google.com | 8a1cdae | 2012-11-19 20:44:29 +0000 | [diff] [blame] | 49 | const SkTDArray<SkDrawCommand*>& getDrawCommands() const { |
| 50 | return fDebugCanvas->getDrawCommands(); |
| 51 | } |
| 52 | |
chudy@google.com | 607357f | 2012-08-07 16:12:23 +0000 | [diff] [blame] | 53 | void highlightCurrentCommand(bool on) { |
| 54 | fDebugCanvas->toggleFilter(on); |
| 55 | } |
| 56 | |
| 57 | void resize(int width, int height) { |
| 58 | fDebugCanvas->setBounds(width, height); |
| 59 | } |
| 60 | |
| 61 | void loadPicture(SkPicture* picture); |
| 62 | |
| 63 | SkPicture* makePicture(); |
| 64 | |
| 65 | int getSize() { |
| 66 | return fDebugCanvas->getSize(); |
| 67 | } |
| 68 | |
bungeman@google.com | e8cc6e8 | 2013-01-17 16:30:56 +0000 | [diff] [blame^] | 69 | void setUserMatrix(SkMatrix userMatrix) { |
chudy@google.com | 607357f | 2012-08-07 16:12:23 +0000 | [diff] [blame] | 70 | // Should this live in debugger instead? |
bungeman@google.com | e8cc6e8 | 2013-01-17 16:30:56 +0000 | [diff] [blame^] | 71 | fDebugCanvas->setUserMatrix(userMatrix); |
chudy@google.com | 607357f | 2012-08-07 16:12:23 +0000 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | int getCommandAtPoint(int x, int y, int index) { |
| 75 | return fDebugCanvas->getCommandAtPoint(x, y, index); |
| 76 | } |
| 77 | |
chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 78 | SkTDArray<SkString*>* getCommandInfo(int index) { |
chudy@google.com | 607357f | 2012-08-07 16:12:23 +0000 | [diff] [blame] | 79 | return fDebugCanvas->getCommandInfo(index); |
| 80 | } |
| 81 | |
| 82 | const SkMatrix& getCurrentMatrix() { |
| 83 | return fDebugCanvas->getCurrentMatrix(); |
| 84 | } |
| 85 | |
| 86 | const SkIRect& getCurrentClip() { |
| 87 | return fDebugCanvas->getCurrentClip(); |
| 88 | } |
| 89 | |
| 90 | int pictureHeight() { |
| 91 | return fPictureHeight; |
| 92 | } |
| 93 | |
| 94 | int pictureWidth() { |
| 95 | return fPictureWidth; |
| 96 | } |
| 97 | |
| 98 | int index() { |
| 99 | return fIndex; |
| 100 | } |
| 101 | |
| 102 | private: |
| 103 | SkDebugCanvas* fDebugCanvas; |
| 104 | SkPicture* fPicture; |
| 105 | |
| 106 | int fPictureWidth; |
| 107 | int fPictureHeight; |
| 108 | int fIndex; |
| 109 | }; |
| 110 | |
| 111 | |
| 112 | #endif /* SKDEBUGGER_H_ */ |