| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +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 | |
| robertphillips@google.com | f4741c1 | 2013-02-06 20:13:54 +0000 | [diff] [blame] | 10 | #include "SkColorPriv.h" |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 11 | #include "SkDebugCanvas.h" |
| 12 | #include "SkDrawCommand.h" |
| robertphillips@google.com | f4741c1 | 2013-02-06 20:13:54 +0000 | [diff] [blame] | 13 | #include "SkDrawFilter.h" |
| robertphillips@google.com | 6dec8fc | 2012-11-21 17:11:02 +0000 | [diff] [blame] | 14 | #include "SkDevice.h" |
| robertphillips@google.com | f4741c1 | 2013-02-06 20:13:54 +0000 | [diff] [blame] | 15 | #include "SkXfermode.h" |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 16 | |
| reed@google.com | 6ae24e0 | 2012-09-26 13:44:13 +0000 | [diff] [blame] | 17 | static SkBitmap make_noconfig_bm(int width, int height) { |
| 18 | SkBitmap bm; |
| 19 | bm.setConfig(SkBitmap::kNo_Config, width, height); |
| 20 | return bm; |
| 21 | } |
| 22 | |
| 23 | SkDebugCanvas::SkDebugCanvas(int width, int height) |
| tomhudson@google.com | 0699e02 | 2012-11-27 16:09:42 +0000 | [diff] [blame] | 24 | : INHERITED(make_noconfig_bm(width, height)) |
| robertphillips@google.com | f4741c1 | 2013-02-06 20:13:54 +0000 | [diff] [blame] | 25 | , fOverdrawViz(false) |
| scroggo@google.com | 06d6ac6 | 2013-02-08 21:16:19 +0000 | [diff] [blame] | 26 | , fOverdrawFilter(NULL) |
| robertphillips@google.com | 32bbcf8 | 2013-10-17 17:56:10 +0000 | [diff] [blame] | 27 | , fOverrideTexFiltering(false) |
| 28 | , fTexOverrideFilter(NULL) |
| scroggo@google.com | 06d6ac6 | 2013-02-08 21:16:19 +0000 | [diff] [blame] | 29 | , fOutstandingSaveCount(0) { |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 30 | // TODO(chudy): Free up memory from all draw commands in destructor. |
| chudy@google.com | 80a4a60 | 2012-07-30 18:54:07 +0000 | [diff] [blame] | 31 | fWidth = width; |
| 32 | fHeight = height; |
| reed@google.com | 6ae24e0 | 2012-09-26 13:44:13 +0000 | [diff] [blame] | 33 | // do we need fBm anywhere? |
| chudy@google.com | b9ddd4e | 2012-07-10 14:14:50 +0000 | [diff] [blame] | 34 | fBm.setConfig(SkBitmap::kNo_Config, fWidth, fHeight); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 35 | fFilter = false; |
| chudy@google.com | 830b879 | 2012-08-01 15:57:52 +0000 | [diff] [blame] | 36 | fIndex = 0; |
| bungeman@google.com | e8cc6e8 | 2013-01-17 16:30:56 +0000 | [diff] [blame] | 37 | fUserMatrix.reset(); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 38 | } |
| 39 | |
| chudy@google.com | 9cda6f7 | 2012-08-07 15:08:33 +0000 | [diff] [blame] | 40 | SkDebugCanvas::~SkDebugCanvas() { |
| robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 41 | fCommandVector.deleteAll(); |
| robertphillips@google.com | f4741c1 | 2013-02-06 20:13:54 +0000 | [diff] [blame] | 42 | SkSafeUnref(fOverdrawFilter); |
| chudy@google.com | 9cda6f7 | 2012-08-07 15:08:33 +0000 | [diff] [blame] | 43 | } |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 44 | |
| 45 | void SkDebugCanvas::addDrawCommand(SkDrawCommand* command) { |
| robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 46 | fCommandVector.push(command); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | void SkDebugCanvas::draw(SkCanvas* canvas) { |
| robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 50 | if(!fCommandVector.isEmpty()) { |
| 51 | for (int i = 0; i < fCommandVector.count(); i++) { |
| 52 | if (fCommandVector[i]->isVisible()) { |
| 53 | fCommandVector[i]->execute(canvas); |
| chudy@google.com | 0ab0339 | 2012-07-28 20:16:11 +0000 | [diff] [blame] | 54 | } |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 55 | } |
| 56 | } |
| robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 57 | fIndex = fCommandVector.count() - 1; |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 58 | } |
| 59 | |
| chudy@google.com | 830b879 | 2012-08-01 15:57:52 +0000 | [diff] [blame] | 60 | void SkDebugCanvas::applyUserTransform(SkCanvas* canvas) { |
| bungeman@google.com | e8cc6e8 | 2013-01-17 16:30:56 +0000 | [diff] [blame] | 61 | canvas->concat(fUserMatrix); |
| chudy@google.com | 830b879 | 2012-08-01 15:57:52 +0000 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | int SkDebugCanvas::getCommandAtPoint(int x, int y, int index) { |
| chudy@google.com | 0b5bbb0 | 2012-07-31 19:55:32 +0000 | [diff] [blame] | 65 | SkBitmap bitmap; |
| 66 | bitmap.setConfig(SkBitmap::kARGB_8888_Config, 1, 1); |
| 67 | bitmap.allocPixels(); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 68 | |
| chudy@google.com | 0b5bbb0 | 2012-07-31 19:55:32 +0000 | [diff] [blame] | 69 | SkCanvas canvas(bitmap); |
| robertphillips@google.com | 94acc70 | 2012-09-06 18:43:21 +0000 | [diff] [blame] | 70 | canvas.translate(SkIntToScalar(-x), SkIntToScalar(-y)); |
| chudy@google.com | 830b879 | 2012-08-01 15:57:52 +0000 | [diff] [blame] | 71 | applyUserTransform(&canvas); |
| chudy@google.com | 0b5bbb0 | 2012-07-31 19:55:32 +0000 | [diff] [blame] | 72 | |
| 73 | int layer = 0; |
| chudy@google.com | 751961d | 2012-07-31 20:07:42 +0000 | [diff] [blame] | 74 | SkColor prev = bitmap.getColor(0,0); |
| chudy@google.com | 0b5bbb0 | 2012-07-31 19:55:32 +0000 | [diff] [blame] | 75 | for (int i = 0; i < index; i++) { |
| robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 76 | if (fCommandVector[i]->isVisible()) { |
| 77 | fCommandVector[i]->execute(&canvas); |
| chudy@google.com | 0b5bbb0 | 2012-07-31 19:55:32 +0000 | [diff] [blame] | 78 | } |
| 79 | if (prev != bitmap.getColor(0,0)) { |
| 80 | layer = i; |
| 81 | } |
| 82 | prev = bitmap.getColor(0,0); |
| 83 | } |
| 84 | return layer; |
| 85 | } |
| 86 | |
| bsalomon@google.com | 383e234 | 2013-02-06 21:44:21 +0000 | [diff] [blame] | 87 | static SkPMColor OverdrawXferModeProc(SkPMColor src, SkPMColor dst) { |
| robertphillips@google.com | f4741c1 | 2013-02-06 20:13:54 +0000 | [diff] [blame] | 88 | // This table encodes the color progression of the overdraw visualization |
| 89 | static const SkPMColor gTable[] = { |
| 90 | SkPackARGB32(0x00, 0x00, 0x00, 0x00), |
| 91 | SkPackARGB32(0xFF, 128, 158, 255), |
| 92 | SkPackARGB32(0xFF, 170, 185, 212), |
| 93 | SkPackARGB32(0xFF, 213, 195, 170), |
| 94 | SkPackARGB32(0xFF, 255, 192, 127), |
| 95 | SkPackARGB32(0xFF, 255, 185, 85), |
| 96 | SkPackARGB32(0xFF, 255, 165, 42), |
| 97 | SkPackARGB32(0xFF, 255, 135, 0), |
| 98 | SkPackARGB32(0xFF, 255, 95, 0), |
| 99 | SkPackARGB32(0xFF, 255, 50, 0), |
| 100 | SkPackARGB32(0xFF, 255, 0, 0) |
| 101 | }; |
| 102 | |
| robertphillips@google.com | 0b256e1 | 2013-02-06 20:42:14 +0000 | [diff] [blame] | 103 | for (size_t i = 0; i < SK_ARRAY_COUNT(gTable)-1; ++i) { |
| robertphillips@google.com | f4741c1 | 2013-02-06 20:13:54 +0000 | [diff] [blame] | 104 | if (gTable[i] == dst) { |
| 105 | return gTable[i+1]; |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | return gTable[SK_ARRAY_COUNT(gTable)-1]; |
| 110 | } |
| 111 | |
| 112 | // The OverdrawFilter modifies every paint to use an SkProcXfermode which |
| 113 | // in turn invokes OverdrawXferModeProc |
| robertphillips@google.com | 32bbcf8 | 2013-10-17 17:56:10 +0000 | [diff] [blame] | 114 | class SkOverdrawFilter : public SkDrawFilter { |
| robertphillips@google.com | f4741c1 | 2013-02-06 20:13:54 +0000 | [diff] [blame] | 115 | public: |
| robertphillips@google.com | 32bbcf8 | 2013-10-17 17:56:10 +0000 | [diff] [blame] | 116 | SkOverdrawFilter() { |
| robertphillips@google.com | f4741c1 | 2013-02-06 20:13:54 +0000 | [diff] [blame] | 117 | fXferMode = new SkProcXfermode(OverdrawXferModeProc); |
| 118 | } |
| 119 | |
| robertphillips@google.com | 32bbcf8 | 2013-10-17 17:56:10 +0000 | [diff] [blame] | 120 | virtual ~SkOverdrawFilter() { |
| robertphillips@google.com | f4741c1 | 2013-02-06 20:13:54 +0000 | [diff] [blame] | 121 | delete fXferMode; |
| 122 | } |
| 123 | |
| 124 | virtual bool filter(SkPaint* p, Type) SK_OVERRIDE { |
| 125 | p->setXfermode(fXferMode); |
| 126 | return true; |
| 127 | } |
| 128 | |
| 129 | protected: |
| 130 | SkXfermode* fXferMode; |
| 131 | |
| 132 | private: |
| 133 | typedef SkDrawFilter INHERITED; |
| 134 | }; |
| 135 | |
| skia.committer@gmail.com | f84ad8f | 2013-10-18 07:01:59 +0000 | [diff] [blame] | 136 | // SkTexOverrideFilter modifies every paint to use the specified |
| robertphillips@google.com | 32bbcf8 | 2013-10-17 17:56:10 +0000 | [diff] [blame] | 137 | // texture filtering mode |
| 138 | class SkTexOverrideFilter : public SkDrawFilter { |
| 139 | public: |
| 140 | SkTexOverrideFilter() : fFilterLevel(SkPaint::kNone_FilterLevel) { |
| 141 | } |
| 142 | |
| 143 | void setFilterLevel(SkPaint::FilterLevel filterLevel) { |
| 144 | fFilterLevel = filterLevel; |
| 145 | } |
| 146 | |
| 147 | virtual bool filter(SkPaint* p, Type) SK_OVERRIDE { |
| 148 | p->setFilterLevel(fFilterLevel); |
| 149 | return true; |
| 150 | } |
| 151 | |
| 152 | protected: |
| 153 | SkPaint::FilterLevel fFilterLevel; |
| 154 | |
| 155 | private: |
| 156 | typedef SkDrawFilter INHERITED; |
| 157 | }; |
| 158 | |
| chudy@google.com | 0b5bbb0 | 2012-07-31 19:55:32 +0000 | [diff] [blame] | 159 | void SkDebugCanvas::drawTo(SkCanvas* canvas, int index) { |
| robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 160 | SkASSERT(!fCommandVector.isEmpty()); |
| 161 | SkASSERT(index < fCommandVector.count()); |
| chudy@google.com | 830b879 | 2012-08-01 15:57:52 +0000 | [diff] [blame] | 162 | int i; |
| 163 | |
| 164 | // This only works assuming the canvas and device are the same ones that |
| 165 | // were previously drawn into because they need to preserve all saves |
| 166 | // and restores. |
| 167 | if (fIndex < index) { |
| 168 | i = fIndex + 1; |
| 169 | } else { |
| tomhudson@google.com | 0699e02 | 2012-11-27 16:09:42 +0000 | [diff] [blame] | 170 | for (int j = 0; j < fOutstandingSaveCount; j++) { |
| 171 | canvas->restore(); |
| 172 | } |
| chudy@google.com | 830b879 | 2012-08-01 15:57:52 +0000 | [diff] [blame] | 173 | i = 0; |
| junov@google.com | dbfac8a | 2012-12-06 21:47:40 +0000 | [diff] [blame] | 174 | canvas->clear(SK_ColorTRANSPARENT); |
| chudy@google.com | 830b879 | 2012-08-01 15:57:52 +0000 | [diff] [blame] | 175 | canvas->resetMatrix(); |
| skia.committer@gmail.com | 04ba448 | 2012-09-07 02:01:30 +0000 | [diff] [blame] | 176 | SkRect rect = SkRect::MakeWH(SkIntToScalar(fWidth), |
| robertphillips@google.com | 94acc70 | 2012-09-06 18:43:21 +0000 | [diff] [blame] | 177 | SkIntToScalar(fHeight)); |
| chudy@google.com | 4c7962e | 2012-08-14 19:38:31 +0000 | [diff] [blame] | 178 | canvas->clipRect(rect, SkRegion::kReplace_Op ); |
| chudy@google.com | 830b879 | 2012-08-01 15:57:52 +0000 | [diff] [blame] | 179 | applyUserTransform(canvas); |
| tomhudson@google.com | 0699e02 | 2012-11-27 16:09:42 +0000 | [diff] [blame] | 180 | fOutstandingSaveCount = 0; |
| commit-bot@chromium.org | a27622c | 2013-08-05 16:31:27 +0000 | [diff] [blame] | 181 | } |
| robertphillips@google.com | f4741c1 | 2013-02-06 20:13:54 +0000 | [diff] [blame] | 182 | |
| commit-bot@chromium.org | a27622c | 2013-08-05 16:31:27 +0000 | [diff] [blame] | 183 | // The setting of the draw filter has to go here (rather than in |
| 184 | // SkRasterWidget) due to the canvas restores this class performs. |
| 185 | // Since the draw filter is stored in the layer stack if we |
| 186 | // call setDrawFilter on anything but the root layer odd things happen. |
| 187 | if (fOverdrawViz) { |
| 188 | if (NULL == fOverdrawFilter) { |
| robertphillips@google.com | 32bbcf8 | 2013-10-17 17:56:10 +0000 | [diff] [blame] | 189 | fOverdrawFilter = new SkOverdrawFilter; |
| robertphillips@google.com | f4741c1 | 2013-02-06 20:13:54 +0000 | [diff] [blame] | 190 | } |
| commit-bot@chromium.org | a27622c | 2013-08-05 16:31:27 +0000 | [diff] [blame] | 191 | |
| 192 | if (fOverdrawFilter != canvas->getDrawFilter()) { |
| 193 | canvas->setDrawFilter(fOverdrawFilter); |
| 194 | } |
| robertphillips@google.com | 32bbcf8 | 2013-10-17 17:56:10 +0000 | [diff] [blame] | 195 | } else if (fOverrideTexFiltering) { |
| 196 | if (NULL == fTexOverrideFilter) { |
| 197 | fTexOverrideFilter = new SkTexOverrideFilter; |
| 198 | } |
| 199 | |
| 200 | if (fTexOverrideFilter != canvas->getDrawFilter()) { |
| 201 | canvas->setDrawFilter(fTexOverrideFilter); |
| 202 | } |
| commit-bot@chromium.org | a27622c | 2013-08-05 16:31:27 +0000 | [diff] [blame] | 203 | } else { |
| 204 | canvas->setDrawFilter(NULL); |
| chudy@google.com | 830b879 | 2012-08-01 15:57:52 +0000 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | for (; i <= index; i++) { |
| chudy@google.com | 0b5bbb0 | 2012-07-31 19:55:32 +0000 | [diff] [blame] | 208 | if (i == index && fFilter) { |
| 209 | SkPaint p; |
| 210 | p.setColor(0xAAFFFFFF); |
| 211 | canvas->save(); |
| 212 | canvas->resetMatrix(); |
| 213 | SkRect mask; |
| 214 | mask.set(SkIntToScalar(0), SkIntToScalar(0), |
| 215 | SkIntToScalar(fWidth), SkIntToScalar(fHeight)); |
| 216 | canvas->clipRect(mask, SkRegion::kReplace_Op, false); |
| 217 | canvas->drawRectCoords(SkIntToScalar(0), SkIntToScalar(0), |
| 218 | SkIntToScalar(fWidth), SkIntToScalar(fHeight), p); |
| 219 | canvas->restore(); |
| 220 | } |
| 221 | |
| robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 222 | if (fCommandVector[i]->isVisible()) { |
| 223 | fCommandVector[i]->execute(canvas); |
| 224 | fCommandVector[i]->trackSaveState(&fOutstandingSaveCount); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 225 | } |
| 226 | } |
| chudy@google.com | a9e937c | 2012-08-03 17:32:05 +0000 | [diff] [blame] | 227 | fMatrix = canvas->getTotalMatrix(); |
| 228 | fClip = canvas->getTotalClip().getBounds(); |
| chudy@google.com | 830b879 | 2012-08-01 15:57:52 +0000 | [diff] [blame] | 229 | fIndex = index; |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 230 | } |
| 231 | |
| robertphillips@google.com | 50c84da | 2013-04-01 18:18:49 +0000 | [diff] [blame] | 232 | void SkDebugCanvas::deleteDrawCommandAt(int index) { |
| 233 | SkASSERT(index < fCommandVector.count()); |
| 234 | delete fCommandVector[index]; |
| 235 | fCommandVector.remove(index); |
| 236 | } |
| 237 | |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 238 | SkDrawCommand* SkDebugCanvas::getDrawCommandAt(int index) { |
| robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 239 | SkASSERT(index < fCommandVector.count()); |
| 240 | return fCommandVector[index]; |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 241 | } |
| 242 | |
| robertphillips@google.com | 50c84da | 2013-04-01 18:18:49 +0000 | [diff] [blame] | 243 | void SkDebugCanvas::setDrawCommandAt(int index, SkDrawCommand* command) { |
| 244 | SkASSERT(index < fCommandVector.count()); |
| 245 | delete fCommandVector[index]; |
| 246 | fCommandVector[index] = command; |
| 247 | } |
| 248 | |
| chudy@google.com | 97cee97 | 2012-08-07 20:41:37 +0000 | [diff] [blame] | 249 | SkTDArray<SkString*>* SkDebugCanvas::getCommandInfo(int index) { |
| robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 250 | SkASSERT(index < fCommandVector.count()); |
| 251 | return fCommandVector[index]->Info(); |
| chudy@google.com | 7e4cfbf | 2012-07-17 15:40:51 +0000 | [diff] [blame] | 252 | } |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 253 | |
| chudy@google.com | 7e4cfbf | 2012-07-17 15:40:51 +0000 | [diff] [blame] | 254 | bool SkDebugCanvas::getDrawCommandVisibilityAt(int index) { |
| robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 255 | SkASSERT(index < fCommandVector.count()); |
| 256 | return fCommandVector[index]->isVisible(); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 257 | } |
| 258 | |
| robertphillips@google.com | 8a1cdae | 2012-11-19 20:44:29 +0000 | [diff] [blame] | 259 | const SkTDArray <SkDrawCommand*>& SkDebugCanvas::getDrawCommands() const { |
| robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 260 | return fCommandVector; |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 261 | } |
| 262 | |
| robertphillips@google.com | febc0ec | 2013-03-11 22:53:11 +0000 | [diff] [blame] | 263 | SkTDArray <SkDrawCommand*>& SkDebugCanvas::getDrawCommands() { |
| 264 | return fCommandVector; |
| 265 | } |
| 266 | |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 267 | // TODO(chudy): Free command string memory. |
| robertphillips@google.com | 8a1cdae | 2012-11-19 20:44:29 +0000 | [diff] [blame] | 268 | SkTArray<SkString>* SkDebugCanvas::getDrawCommandsAsStrings() const { |
| robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 269 | SkTArray<SkString>* commandString = new SkTArray<SkString>(fCommandVector.count()); |
| 270 | if (!fCommandVector.isEmpty()) { |
| 271 | for (int i = 0; i < fCommandVector.count(); i ++) { |
| 272 | commandString->push_back() = fCommandVector[i]->toString(); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 273 | } |
| 274 | } |
| 275 | return commandString; |
| 276 | } |
| 277 | |
| 278 | void SkDebugCanvas::toggleFilter(bool toggle) { |
| 279 | fFilter = toggle; |
| 280 | } |
| 281 | |
| skia.committer@gmail.com | f84ad8f | 2013-10-18 07:01:59 +0000 | [diff] [blame] | 282 | void SkDebugCanvas::overrideTexFiltering(bool overrideTexFiltering, SkPaint::FilterLevel level) { |
| robertphillips@google.com | 32bbcf8 | 2013-10-17 17:56:10 +0000 | [diff] [blame] | 283 | if (NULL == fTexOverrideFilter) { |
| 284 | fTexOverrideFilter = new SkTexOverrideFilter; |
| 285 | } |
| 286 | |
| skia.committer@gmail.com | f84ad8f | 2013-10-18 07:01:59 +0000 | [diff] [blame] | 287 | fOverrideTexFiltering = overrideTexFiltering; |
| robertphillips@google.com | 32bbcf8 | 2013-10-17 17:56:10 +0000 | [diff] [blame] | 288 | fTexOverrideFilter->setFilterLevel(level); |
| 289 | } |
| 290 | |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 291 | void SkDebugCanvas::clear(SkColor color) { |
| commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 292 | addDrawCommand(new SkClearCommand(color)); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | bool SkDebugCanvas::clipPath(const SkPath& path, SkRegion::Op op, bool doAA) { |
| commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 296 | addDrawCommand(new SkClipPathCommand(path, op, doAA)); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 297 | return true; |
| 298 | } |
| 299 | |
| 300 | bool SkDebugCanvas::clipRect(const SkRect& rect, SkRegion::Op op, bool doAA) { |
| commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 301 | addDrawCommand(new SkClipRectCommand(rect, op, doAA)); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 302 | return true; |
| 303 | } |
| 304 | |
| robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 305 | bool SkDebugCanvas::clipRRect(const SkRRect& rrect, SkRegion::Op op, bool doAA) { |
| commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 306 | addDrawCommand(new SkClipRRectCommand(rrect, op, doAA)); |
| robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 307 | return true; |
| 308 | } |
| 309 | |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 310 | bool SkDebugCanvas::clipRegion(const SkRegion& region, SkRegion::Op op) { |
| commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 311 | addDrawCommand(new SkClipRegionCommand(region, op)); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 312 | return true; |
| 313 | } |
| 314 | |
| 315 | bool SkDebugCanvas::concat(const SkMatrix& matrix) { |
| commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 316 | addDrawCommand(new SkConcatCommand(matrix)); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 317 | return true; |
| 318 | } |
| 319 | |
| 320 | void SkDebugCanvas::drawBitmap(const SkBitmap& bitmap, SkScalar left, |
| commit-bot@chromium.org | eed779d | 2013-08-16 10:24:37 +0000 | [diff] [blame] | 321 | SkScalar top, const SkPaint* paint = NULL) { |
| commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 322 | addDrawCommand(new SkDrawBitmapCommand(bitmap, left, top, paint)); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 323 | } |
| 324 | |
| reed@google.com | 7112173 | 2012-09-18 15:14:33 +0000 | [diff] [blame] | 325 | void SkDebugCanvas::drawBitmapRectToRect(const SkBitmap& bitmap, |
| skia.committer@gmail.com | 7475811 | 2013-08-17 07:01:54 +0000 | [diff] [blame] | 326 | const SkRect* src, const SkRect& dst, |
| commit-bot@chromium.org | eed779d | 2013-08-16 10:24:37 +0000 | [diff] [blame] | 327 | const SkPaint* paint, |
| 328 | SkCanvas::DrawBitmapRectFlags flags) { |
| 329 | addDrawCommand(new SkDrawBitmapRectCommand(bitmap, src, dst, paint, flags)); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | void SkDebugCanvas::drawBitmapMatrix(const SkBitmap& bitmap, |
| commit-bot@chromium.org | eed779d | 2013-08-16 10:24:37 +0000 | [diff] [blame] | 333 | const SkMatrix& matrix, const SkPaint* paint) { |
| commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 334 | addDrawCommand(new SkDrawBitmapMatrixCommand(bitmap, matrix, paint)); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | void SkDebugCanvas::drawBitmapNine(const SkBitmap& bitmap, |
| 338 | const SkIRect& center, const SkRect& dst, const SkPaint* paint) { |
| commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 339 | addDrawCommand(new SkDrawBitmapNineCommand(bitmap, center, dst, paint)); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | void SkDebugCanvas::drawData(const void* data, size_t length) { |
| commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 343 | addDrawCommand(new SkDrawDataCommand(data, length)); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 344 | } |
| 345 | |
| robertphillips@google.com | 0a4805e | 2013-05-29 13:24:23 +0000 | [diff] [blame] | 346 | void SkDebugCanvas::beginCommentGroup(const char* description) { |
| commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 347 | addDrawCommand(new SkBeginCommentGroupCommand(description)); |
| robertphillips@google.com | 0a4805e | 2013-05-29 13:24:23 +0000 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | void SkDebugCanvas::addComment(const char* kywd, const char* value) { |
| commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 351 | addDrawCommand(new SkCommentCommand(kywd, value)); |
| robertphillips@google.com | 0a4805e | 2013-05-29 13:24:23 +0000 | [diff] [blame] | 352 | } |
| 353 | |
| 354 | void SkDebugCanvas::endCommentGroup() { |
| commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 355 | addDrawCommand(new SkEndCommentGroupCommand()); |
| robertphillips@google.com | 0a4805e | 2013-05-29 13:24:23 +0000 | [diff] [blame] | 356 | } |
| 357 | |
| robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 358 | void SkDebugCanvas::drawOval(const SkRect& oval, const SkPaint& paint) { |
| commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 359 | addDrawCommand(new SkDrawOvalCommand(oval, paint)); |
| robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 360 | } |
| 361 | |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 362 | void SkDebugCanvas::drawPaint(const SkPaint& paint) { |
| commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 363 | addDrawCommand(new SkDrawPaintCommand(paint)); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 364 | } |
| 365 | |
| bsalomon@google.com | 7ce564c | 2013-10-22 16:54:15 +0000 | [diff] [blame^] | 366 | void SkDebugCanvas::drawPath(const SkPath& path, const SkPaint& paint) { |
| commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 367 | addDrawCommand(new SkDrawPathCommand(path, paint)); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | void SkDebugCanvas::drawPicture(SkPicture& picture) { |
| commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 371 | addDrawCommand(new SkDrawPictureCommand(picture)); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | void SkDebugCanvas::drawPoints(PointMode mode, size_t count, |
| robertphillips@google.com | a3a09ab | 2013-03-22 12:25:30 +0000 | [diff] [blame] | 375 | const SkPoint pts[], const SkPaint& paint) { |
| commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 376 | addDrawCommand(new SkDrawPointsCommand(mode, count, pts, paint)); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | void SkDebugCanvas::drawPosText(const void* text, size_t byteLength, |
| 380 | const SkPoint pos[], const SkPaint& paint) { |
| commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 381 | addDrawCommand(new SkDrawPosTextCommand(text, byteLength, pos, paint)); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | void SkDebugCanvas::drawPosTextH(const void* text, size_t byteLength, |
| 385 | const SkScalar xpos[], SkScalar constY, const SkPaint& paint) { |
| commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 386 | addDrawCommand( |
| 387 | new SkDrawPosTextHCommand(text, byteLength, xpos, constY, paint)); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 388 | } |
| 389 | |
| bsalomon@google.com | 7ce564c | 2013-10-22 16:54:15 +0000 | [diff] [blame^] | 390 | void SkDebugCanvas::drawRect(const SkRect& rect, const SkPaint& paint) { |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 391 | // NOTE(chudy): Messing up when renamed to DrawRect... Why? |
| commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 392 | addDrawCommand(new SkDrawRectCommand(rect, paint)); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 393 | } |
| 394 | |
| robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 395 | void SkDebugCanvas::drawRRect(const SkRRect& rrect, const SkPaint& paint) { |
| commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 396 | addDrawCommand(new SkDrawRRectCommand(rrect, paint)); |
| robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 397 | } |
| 398 | |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 399 | void SkDebugCanvas::drawSprite(const SkBitmap& bitmap, int left, int top, |
| robertphillips@google.com | 6ede1fe | 2013-06-06 23:59:28 +0000 | [diff] [blame] | 400 | const SkPaint* paint = NULL) { |
| commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 401 | addDrawCommand(new SkDrawSpriteCommand(bitmap, left, top, paint)); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 402 | } |
| 403 | |
| 404 | void SkDebugCanvas::drawText(const void* text, size_t byteLength, SkScalar x, |
| 405 | SkScalar y, const SkPaint& paint) { |
| commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 406 | addDrawCommand(new SkDrawTextCommand(text, byteLength, x, y, paint)); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 407 | } |
| 408 | |
| 409 | void SkDebugCanvas::drawTextOnPath(const void* text, size_t byteLength, |
| 410 | const SkPath& path, const SkMatrix* matrix, const SkPaint& paint) { |
| commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 411 | addDrawCommand( |
| 412 | new SkDrawTextOnPathCommand(text, byteLength, path, matrix, paint)); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 413 | } |
| 414 | |
| 415 | void SkDebugCanvas::drawVertices(VertexMode vmode, int vertexCount, |
| 416 | const SkPoint vertices[], const SkPoint texs[], const SkColor colors[], |
| 417 | SkXfermode*, const uint16_t indices[], int indexCount, |
| 418 | const SkPaint& paint) { |
| commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 419 | addDrawCommand(new SkDrawVerticesCommand(vmode, vertexCount, vertices, |
| 420 | texs, colors, NULL, indices, indexCount, paint)); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | void SkDebugCanvas::restore() { |
| commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 424 | addDrawCommand(new SkRestoreCommand()); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 425 | } |
| 426 | |
| 427 | bool SkDebugCanvas::rotate(SkScalar degrees) { |
| commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 428 | addDrawCommand(new SkRotateCommand(degrees)); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 429 | return true; |
| 430 | } |
| 431 | |
| 432 | int SkDebugCanvas::save(SaveFlags flags) { |
| commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 433 | addDrawCommand(new SkSaveCommand(flags)); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 434 | return true; |
| 435 | } |
| 436 | |
| 437 | int SkDebugCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint, |
| 438 | SaveFlags flags) { |
| commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 439 | addDrawCommand(new SkSaveLayerCommand(bounds, paint, flags)); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 440 | return true; |
| 441 | } |
| 442 | |
| 443 | bool SkDebugCanvas::scale(SkScalar sx, SkScalar sy) { |
| commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 444 | addDrawCommand(new SkScaleCommand(sx, sy)); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 445 | return true; |
| 446 | } |
| 447 | |
| 448 | void SkDebugCanvas::setMatrix(const SkMatrix& matrix) { |
| commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 449 | addDrawCommand(new SkSetMatrixCommand(matrix)); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 450 | } |
| 451 | |
| 452 | bool SkDebugCanvas::skew(SkScalar sx, SkScalar sy) { |
| commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 453 | addDrawCommand(new SkSkewCommand(sx, sy)); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 454 | return true; |
| 455 | } |
| 456 | |
| 457 | bool SkDebugCanvas::translate(SkScalar dx, SkScalar dy) { |
| commit-bot@chromium.org | 7a11591 | 2013-06-18 20:20:55 +0000 | [diff] [blame] | 458 | addDrawCommand(new SkTranslateCommand(dx, dy)); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 459 | return true; |
| 460 | } |
| 461 | |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 462 | void SkDebugCanvas::toggleCommand(int index, bool toggle) { |
| robertphillips@google.com | 67baba4 | 2013-01-02 20:20:31 +0000 | [diff] [blame] | 463 | SkASSERT(index < fCommandVector.count()); |
| 464 | fCommandVector[index]->setVisible(toggle); |
| chudy@google.com | 902ebe5 | 2012-06-29 14:21:22 +0000 | [diff] [blame] | 465 | } |