1607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com
2607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com/*
3607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com * Copyright 2012 Google Inc.
4607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com *
5607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com * Use of this source code is governed by a BSD-style license that can be
6607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com * found in the LICENSE file.
7607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com */
8607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com
9607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com
10607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com#ifndef SKDEBUGGER_H_
11607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com#define SKDEBUGGER_H_
12607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com
13607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com#include "SkDebugCanvas.h"
14607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com#include "SkPicture.h"
158a1cdaece7e1d009befb84f21bb82370025bf4d6robertphillips@google.com#include "SkTArray.h"
16607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com
172d9dbd4f78314b4b36f67d6ebbf3e0f2d9a163e3borenet@google.comclass SkString;
182d9dbd4f78314b4b36f67d6ebbf3e0f2d9a163e3borenet@google.com
19607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.comclass SkDebugger {
20607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.compublic:
21607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com    SkDebugger();
22607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com
23607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com    ~SkDebugger();
24607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com
25607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com    void setIndex(int index) {
26607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com        fIndex = index;
27607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com    }
28607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com    void draw(SkCanvas* canvas) {
29607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com        if (fIndex > 0) {
30607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com            fDebugCanvas->drawTo(canvas, fIndex);
31607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com        }
32607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com    }
33607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com
34607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com    void step();
35607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com    void stepBack();
36607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com    void play();
37607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com    void rewind();
38607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com
39607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com    bool isCommandVisible(int index) {
40607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com        return fDebugCanvas->getDrawCommandVisibilityAt(index);
41607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com    }
42607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com
43607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com    void setCommandVisible(int index, bool isVisible) {
44607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com        fDebugCanvas->toggleCommand(index, isVisible);
45607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com    }
46607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com
478a1cdaece7e1d009befb84f21bb82370025bf4d6robertphillips@google.com    SkTArray<SkString>* getDrawCommandsAsStrings() {
48607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com        return fDebugCanvas->getDrawCommandsAsStrings();
49607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com    }
50607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com
5157f74e0aa931e7784d47cba3ecc83020aa8e72b2commit-bot@chromium.org    SkTDArray<size_t>* getDrawCommandOffsets() {
5257f74e0aa931e7784d47cba3ecc83020aa8e72b2commit-bot@chromium.org        return fDebugCanvas->getDrawCommandOffsets();
5357f74e0aa931e7784d47cba3ecc83020aa8e72b2commit-bot@chromium.org    }
5457f74e0aa931e7784d47cba3ecc83020aa8e72b2commit-bot@chromium.org
558a1cdaece7e1d009befb84f21bb82370025bf4d6robertphillips@google.com    const SkTDArray<SkDrawCommand*>& getDrawCommands() const {
568a1cdaece7e1d009befb84f21bb82370025bf4d6robertphillips@google.com        return fDebugCanvas->getDrawCommands();
578a1cdaece7e1d009befb84f21bb82370025bf4d6robertphillips@google.com    }
588a1cdaece7e1d009befb84f21bb82370025bf4d6robertphillips@google.com
59607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com    void highlightCurrentCommand(bool on) {
60607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com        fDebugCanvas->toggleFilter(on);
61607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com    }
62607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com
63a8d7f0b13cd4c6d773fcf055fe17db75d260fa05robertphillips    void setWindowSize(int width, int height) { fDebugCanvas->setWindowSize(width, height); }
64607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com
65607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com    void loadPicture(SkPicture* picture);
66607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com
6725bc2f86c2b94ee1f0921d90e6629d8cb22f69b7robertphillips@google.com    SkPicture* copyPicture();
68607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com
69607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com    int getSize() {
70607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com        return fDebugCanvas->getSize();
71607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com    }
72607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com
73e8cc6e8071935339a06548b13a0668b56a7540f5bungeman@google.com    void setUserMatrix(SkMatrix userMatrix) {
74607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com        // Should this live in debugger instead?
75e8cc6e8071935339a06548b13a0668b56a7540f5bungeman@google.com        fDebugCanvas->setUserMatrix(userMatrix);
76607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com    }
77607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com
78607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com    int getCommandAtPoint(int x, int y, int index) {
79607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com        return fDebugCanvas->getCommandAtPoint(x, y, index);
80607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com    }
81607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com
8297cee9735350cb472249ce1a827ba1aa6b2a5f59chudy@google.com    SkTDArray<SkString*>* getCommandInfo(int index) {
83607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com        return fDebugCanvas->getCommandInfo(index);
84607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com    }
85607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com
86607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com    const SkMatrix& getCurrentMatrix() {
87607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com        return fDebugCanvas->getCurrentMatrix();
88607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com    }
89607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com
90607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com    const SkIRect& getCurrentClip() {
91607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com        return fDebugCanvas->getCurrentClip();
92607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com    }
93607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com
94a8d7f0b13cd4c6d773fcf055fe17db75d260fa05robertphillips    SkRect pictureCull() const   {
95a8d7f0b13cd4c6d773fcf055fe17db75d260fa05robertphillips        return NULL == fPicture ? SkRect::MakeEmpty() : fPicture->cullRect();
96607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com    }
97607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com
98607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com    int index() {
99607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com        return fIndex;
100607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com    }
101607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com
102f4741c1322944e194ca34a8f5cf8188fe2c0efe2robertphillips@google.com    void setOverdrawViz(bool overDrawViz) {
10349f085dddff10473b6ebf832a974288300224e60bsalomon        if (fDebugCanvas) {
104f4741c1322944e194ca34a8f5cf8188fe2c0efe2robertphillips@google.com            fDebugCanvas->setOverdrawViz(overDrawViz);
105f4741c1322944e194ca34a8f5cf8188fe2c0efe2robertphillips@google.com        }
106f4741c1322944e194ca34a8f5cf8188fe2c0efe2robertphillips@google.com    }
107f4741c1322944e194ca34a8f5cf8188fe2c0efe2robertphillips@google.com
1082a67e123a3e559774a16a58cbe5106bc0fb86740commit-bot@chromium.org    void setPathOps(bool pathOps) {
10949f085dddff10473b6ebf832a974288300224e60bsalomon        if (fDebugCanvas) {
1102a67e123a3e559774a16a58cbe5106bc0fb86740commit-bot@chromium.org            fDebugCanvas->setAllowSimplifyClip(pathOps);
1112a67e123a3e559774a16a58cbe5106bc0fb86740commit-bot@chromium.org        }
1122a67e123a3e559774a16a58cbe5106bc0fb86740commit-bot@chromium.org    }
1132a67e123a3e559774a16a58cbe5106bc0fb86740commit-bot@chromium.org
114768ac85655017d4106444bf3ad044680a575ccaacommit-bot@chromium.org    void setMegaViz(bool megaViz) {
11549f085dddff10473b6ebf832a974288300224e60bsalomon        if (fDebugCanvas) {
116768ac85655017d4106444bf3ad044680a575ccaacommit-bot@chromium.org            fDebugCanvas->setMegaVizMode(megaViz);
117768ac85655017d4106444bf3ad044680a575ccaacommit-bot@chromium.org        }
118768ac85655017d4106444bf3ad044680a575ccaacommit-bot@chromium.org    }
119768ac85655017d4106444bf3ad044680a575ccaacommit-bot@chromium.org
12032bbcf828d66ad244fa25b468bc3a229e531491frobertphillips@google.com    void setTexFilterOverride(bool texFilterOverride, SkPaint::FilterLevel level) {
12149f085dddff10473b6ebf832a974288300224e60bsalomon        if (fDebugCanvas) {
12232bbcf828d66ad244fa25b468bc3a229e531491frobertphillips@google.com            fDebugCanvas->overrideTexFiltering(texFilterOverride, level);
12332bbcf828d66ad244fa25b468bc3a229e531491frobertphillips@google.com        }
12432bbcf828d66ad244fa25b468bc3a229e531491frobertphillips@google.com    }
12532bbcf828d66ad244fa25b468bc3a229e531491frobertphillips@google.com
12691274b99722d9be62e077ab979c630c23cdd04b1skia.committer@gmail.com    void getOverviewText(const SkTDArray<double>* typeTimes, double totTime,
127e428f9b1132c12299c204a333192495d7e748511robertphillips@google.com                         SkString* overview, int numRuns);
128f4741c1322944e194ca34a8f5cf8188fe2c0efe2robertphillips@google.com
1292a67e123a3e559774a16a58cbe5106bc0fb86740commit-bot@chromium.org    void getClipStackText(SkString* clipStack);
1302a67e123a3e559774a16a58cbe5106bc0fb86740commit-bot@chromium.org
131607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.comprivate:
132607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com    SkDebugCanvas* fDebugCanvas;
133607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com    SkPicture* fPicture;
134607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com
135607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com    int fIndex;
136607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com};
137607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com
138607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com
139607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com#endif /* SKDEBUGGER_H_ */
140