| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2012 Google Inc. | 3 * Copyright 2012 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 | 9 |
| 10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
| 11 #include "SkDebugCanvas.h" | 11 #include "SkDebugCanvas.h" |
| 12 #include "SkDrawCommand.h" | 12 #include "SkDrawCommand.h" |
| 13 #include "SkDrawFilter.h" | 13 #include "SkDrawFilter.h" |
| 14 #include "SkDevice.h" | 14 #include "SkDevice.h" |
| 15 #include "SkXfermode.h" | 15 #include "SkXfermode.h" |
| 16 | 16 |
| 17 SkDebugCanvas::SkDebugCanvas(int width, int height) | 17 SkDebugCanvas::SkDebugCanvas(int width, int height) |
| 18 : INHERITED(width, height) | 18 : INHERITED(width, height) |
| 19 , fWidth(width) | 19 , fWidth(width) |
| 20 , fHeight(height) | 20 , fHeight(height) |
| 21 , fFilter(false) | 21 , fFilter(false) |
| 22 , fMegaVizMode(false) |
| 22 , fIndex(0) | 23 , fIndex(0) |
| 23 , fOverdrawViz(false) | 24 , fOverdrawViz(false) |
| 24 , fOverdrawFilter(NULL) | 25 , fOverdrawFilter(NULL) |
| 25 , fOverrideTexFiltering(false) | 26 , fOverrideTexFiltering(false) |
| 26 , fTexOverrideFilter(NULL) | 27 , fTexOverrideFilter(NULL) |
| 27 , fOutstandingSaveCount(0) { | 28 , fOutstandingSaveCount(0) { |
| 28 fUserMatrix.reset(); | 29 fUserMatrix.reset(); |
| 29 | 30 |
| 30 // SkPicturePlayback uses the base-class' quickReject calls to cull clipped | 31 // SkPicturePlayback uses the base-class' quickReject calls to cull clipped |
| 31 // operations. This can lead to problems in the debugger which expects all | 32 // operations. This can lead to problems in the debugger which expects all |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 return true; | 155 return true; |
| 155 } | 156 } |
| 156 | 157 |
| 157 protected: | 158 protected: |
| 158 SkPaint::FilterLevel fFilterLevel; | 159 SkPaint::FilterLevel fFilterLevel; |
| 159 | 160 |
| 160 private: | 161 private: |
| 161 typedef SkDrawFilter INHERITED; | 162 typedef SkDrawFilter INHERITED; |
| 162 }; | 163 }; |
| 163 | 164 |
| 165 class SkDebugClipVisitor : public SkCanvas::ClipVisitor { |
| 166 public: |
| 167 SkDebugClipVisitor(SkCanvas* canvas) : fCanvas(canvas) {} |
| 168 |
| 169 virtual void clipRect(const SkRect& r, SkRegion::Op, bool doAA) SK_OVERRIDE
{ |
| 170 SkPaint p; |
| 171 p.setColor(SK_ColorRED); |
| 172 p.setStyle(SkPaint::kStroke_Style); |
| 173 p.setAntiAlias(doAA); |
| 174 fCanvas->drawRect(r, p); |
| 175 } |
| 176 virtual void clipRRect(const SkRRect& rr, SkRegion::Op, bool doAA) SK_OVERRI
DE { |
| 177 SkPaint p; |
| 178 p.setColor(SK_ColorGREEN); |
| 179 p.setStyle(SkPaint::kStroke_Style); |
| 180 p.setAntiAlias(doAA); |
| 181 fCanvas->drawRRect(rr, p); |
| 182 } |
| 183 virtual void clipPath(const SkPath& path, SkRegion::Op, bool doAA) SK_OVERRI
DE { |
| 184 SkPaint p; |
| 185 p.setColor(SK_ColorBLUE); |
| 186 p.setStyle(SkPaint::kStroke_Style); |
| 187 p.setAntiAlias(doAA); |
| 188 fCanvas->drawPath(path, p); |
| 189 } |
| 190 |
| 191 protected: |
| 192 SkCanvas* fCanvas; |
| 193 |
| 194 private: |
| 195 typedef SkCanvas::ClipVisitor INHERITED; |
| 196 }; |
| 197 |
| 198 // set up the saveLayer commands so that the active ones |
| 199 // return true in their 'active' method |
| 200 void SkDebugCanvas::markActiveSaveLayers(int index) { |
| 201 SkTDArray<SkDrawCommand*> activeLayers; |
| 202 |
| 203 for (int i = 0; i < fCommandVector.count(); ++i) { |
| 204 fCommandVector[i]->setActive(false); |
| 205 } |
| 206 |
| 207 for (int i = 0; i < index; ++i) { |
| 208 SkDrawCommand::Action result = fCommandVector[i]->action(); |
| 209 if (SkDrawCommand::kPush_Action == result) { |
| 210 activeLayers.push(fCommandVector[i]); |
| 211 } else if (SkDrawCommand::kPop_Action == result) { |
| 212 activeLayers.pop(); |
| 213 } |
| 214 } |
| 215 |
| 216 for (int i = 0; i < activeLayers.count(); ++i) { |
| 217 activeLayers[i]->setActive(true); |
| 218 } |
| 219 } |
| 220 |
| 164 void SkDebugCanvas::drawTo(SkCanvas* canvas, int index) { | 221 void SkDebugCanvas::drawTo(SkCanvas* canvas, int index) { |
| 165 SkASSERT(!fCommandVector.isEmpty()); | 222 SkASSERT(!fCommandVector.isEmpty()); |
| 166 SkASSERT(index < fCommandVector.count()); | 223 SkASSERT(index < fCommandVector.count()); |
| 167 int i = 0; | 224 int i = 0; |
| 168 | 225 |
| 169 // This only works assuming the canvas and device are the same ones that | 226 // This only works assuming the canvas and device are the same ones that |
| 170 // were previously drawn into because they need to preserve all saves | 227 // were previously drawn into because they need to preserve all saves |
| 171 // and restores. | 228 // and restores. |
| 172 // The visibility filter also requires a full re-draw - otherwise we can | 229 // The visibility filter also requires a full re-draw - otherwise we can |
| 173 // end up drawing the filter repeatedly. | 230 // end up drawing the filter repeatedly. |
| 174 if (fIndex < index && !fFilter) { | 231 if (fIndex < index && !fFilter && !fMegaVizMode) { |
| 175 i = fIndex + 1; | 232 i = fIndex + 1; |
| 176 } else { | 233 } else { |
| 177 for (int j = 0; j < fOutstandingSaveCount; j++) { | 234 for (int j = 0; j < fOutstandingSaveCount; j++) { |
| 178 canvas->restore(); | 235 canvas->restore(); |
| 179 } | 236 } |
| 180 canvas->clear(SK_ColorTRANSPARENT); | 237 canvas->clear(SK_ColorTRANSPARENT); |
| 181 canvas->resetMatrix(); | 238 canvas->resetMatrix(); |
| 182 SkRect rect = SkRect::MakeWH(SkIntToScalar(fWidth), | 239 SkRect rect = SkRect::MakeWH(SkIntToScalar(fWidth), |
| 183 SkIntToScalar(fHeight)); | 240 SkIntToScalar(fHeight)); |
| 184 canvas->clipRect(rect, SkRegion::kReplace_Op ); | 241 canvas->clipRect(rect, SkRegion::kReplace_Op ); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 203 fTexOverrideFilter = new SkTexOverrideFilter; | 260 fTexOverrideFilter = new SkTexOverrideFilter; |
| 204 } | 261 } |
| 205 | 262 |
| 206 if (fTexOverrideFilter != canvas->getDrawFilter()) { | 263 if (fTexOverrideFilter != canvas->getDrawFilter()) { |
| 207 canvas->setDrawFilter(fTexOverrideFilter); | 264 canvas->setDrawFilter(fTexOverrideFilter); |
| 208 } | 265 } |
| 209 } else { | 266 } else { |
| 210 canvas->setDrawFilter(NULL); | 267 canvas->setDrawFilter(NULL); |
| 211 } | 268 } |
| 212 | 269 |
| 270 if (fMegaVizMode) { |
| 271 this->markActiveSaveLayers(index); |
| 272 } |
| 273 |
| 213 for (; i <= index; i++) { | 274 for (; i <= index; i++) { |
| 214 if (i == index && fFilter) { | 275 if (i == index && fFilter) { |
| 215 SkPaint p; | 276 SkPaint p; |
| 216 p.setColor(0xAAFFFFFF); | 277 p.setColor(0xAAFFFFFF); |
| 217 canvas->save(); | 278 canvas->save(); |
| 218 canvas->resetMatrix(); | 279 canvas->resetMatrix(); |
| 219 SkRect mask; | 280 SkRect mask; |
| 220 mask.set(SkIntToScalar(0), SkIntToScalar(0), | 281 mask.set(SkIntToScalar(0), SkIntToScalar(0), |
| 221 SkIntToScalar(fWidth), SkIntToScalar(fHeight)); | 282 SkIntToScalar(fWidth), SkIntToScalar(fHeight)); |
| 222 canvas->clipRect(mask, SkRegion::kReplace_Op, false); | 283 canvas->clipRect(mask, SkRegion::kReplace_Op, false); |
| 223 canvas->drawRectCoords(SkIntToScalar(0), SkIntToScalar(0), | 284 canvas->drawRectCoords(SkIntToScalar(0), SkIntToScalar(0), |
| 224 SkIntToScalar(fWidth), SkIntToScalar(fHeight), p); | 285 SkIntToScalar(fWidth), SkIntToScalar(fHeight), p); |
| 225 canvas->restore(); | 286 canvas->restore(); |
| 226 } | 287 } |
| 227 | 288 |
| 228 if (fCommandVector[i]->isVisible()) { | 289 if (fCommandVector[i]->isVisible()) { |
| 229 fCommandVector[i]->execute(canvas); | 290 if (fMegaVizMode && fCommandVector[i]->active()) { |
| 230 fCommandVector[i]->trackSaveState(&fOutstandingSaveCount); | 291 // All active saveLayers get replaced with saves so all draws go
to the |
| 292 // visible canvas |
| 293 canvas->save(); |
| 294 ++fOutstandingSaveCount; |
| 295 } else { |
| 296 fCommandVector[i]->execute(canvas); |
| 297 fCommandVector[i]->trackSaveState(&fOutstandingSaveCount); |
| 298 } |
| 231 } | 299 } |
| 232 } | 300 } |
| 301 |
| 302 if (fMegaVizMode) { |
| 303 SkRect r = SkRect::MakeWH(SkIntToScalar(fWidth), SkIntToScalar(fHeight))
; |
| 304 r.outset(SK_Scalar1, SK_Scalar1); |
| 305 |
| 306 canvas->save(); |
| 307 // nuke the CTM |
| 308 canvas->setMatrix(SkMatrix::I()); |
| 309 // turn off clipping |
| 310 canvas->clipRect(r, SkRegion::kReplace_Op); |
| 311 |
| 312 // visualize existing clips |
| 313 SkDebugClipVisitor visitor(canvas); |
| 314 |
| 315 canvas->replayClips(&visitor); |
| 316 |
| 317 canvas->restore(); |
| 318 } |
| 233 fMatrix = canvas->getTotalMatrix(); | 319 fMatrix = canvas->getTotalMatrix(); |
| 234 fClip = canvas->getTotalClip().getBounds(); | 320 fClip = canvas->getTotalClip().getBounds(); |
| 235 fIndex = index; | 321 fIndex = index; |
| 236 } | 322 } |
| 237 | 323 |
| 238 void SkDebugCanvas::deleteDrawCommandAt(int index) { | 324 void SkDebugCanvas::deleteDrawCommandAt(int index) { |
| 239 SkASSERT(index < fCommandVector.count()); | 325 SkASSERT(index < fCommandVector.count()); |
| 240 delete fCommandVector[index]; | 326 delete fCommandVector[index]; |
| 241 fCommandVector.remove(index); | 327 fCommandVector.remove(index); |
| 242 } | 328 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 SkTArray<SkString>* SkDebugCanvas::getDrawCommandsAsStrings() const { | 360 SkTArray<SkString>* SkDebugCanvas::getDrawCommandsAsStrings() const { |
| 275 SkTArray<SkString>* commandString = new SkTArray<SkString>(fCommandVector.co
unt()); | 361 SkTArray<SkString>* commandString = new SkTArray<SkString>(fCommandVector.co
unt()); |
| 276 if (!fCommandVector.isEmpty()) { | 362 if (!fCommandVector.isEmpty()) { |
| 277 for (int i = 0; i < fCommandVector.count(); i ++) { | 363 for (int i = 0; i < fCommandVector.count(); i ++) { |
| 278 commandString->push_back() = fCommandVector[i]->toString(); | 364 commandString->push_back() = fCommandVector[i]->toString(); |
| 279 } | 365 } |
| 280 } | 366 } |
| 281 return commandString; | 367 return commandString; |
| 282 } | 368 } |
| 283 | 369 |
| 284 void SkDebugCanvas::toggleFilter(bool toggle) { | |
| 285 fFilter = toggle; | |
| 286 } | |
| 287 | |
| 288 void SkDebugCanvas::overrideTexFiltering(bool overrideTexFiltering, SkPaint::Fil
terLevel level) { | 370 void SkDebugCanvas::overrideTexFiltering(bool overrideTexFiltering, SkPaint::Fil
terLevel level) { |
| 289 if (NULL == fTexOverrideFilter) { | 371 if (NULL == fTexOverrideFilter) { |
| 290 fTexOverrideFilter = new SkTexOverrideFilter; | 372 fTexOverrideFilter = new SkTexOverrideFilter; |
| 291 } | 373 } |
| 292 | 374 |
| 293 fOverrideTexFiltering = overrideTexFiltering; | 375 fOverrideTexFiltering = overrideTexFiltering; |
| 294 fTexOverrideFilter->setFilterLevel(level); | 376 fTexOverrideFilter->setFilterLevel(level); |
| 295 } | 377 } |
| 296 | 378 |
| 297 void SkDebugCanvas::clear(SkColor color) { | 379 void SkDebugCanvas::clear(SkColor color) { |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 471 | 553 |
| 472 bool SkDebugCanvas::translate(SkScalar dx, SkScalar dy) { | 554 bool SkDebugCanvas::translate(SkScalar dx, SkScalar dy) { |
| 473 addDrawCommand(new SkTranslateCommand(dx, dy)); | 555 addDrawCommand(new SkTranslateCommand(dx, dy)); |
| 474 return true; | 556 return true; |
| 475 } | 557 } |
| 476 | 558 |
| 477 void SkDebugCanvas::toggleCommand(int index, bool toggle) { | 559 void SkDebugCanvas::toggleCommand(int index, bool toggle) { |
| 478 SkASSERT(index < fCommandVector.count()); | 560 SkASSERT(index < fCommandVector.count()); |
| 479 fCommandVector[index]->setVisible(toggle); | 561 fCommandVector[index]->setVisible(toggle); |
| 480 } | 562 } |
| OLD | NEW |