Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkDebuggerGUI.h" | 8 #include "SkDebuggerGUI.h" |
| 9 #include "SkForceLinking.h" | 9 #include "SkForceLinking.h" |
| 10 #include "SkGraphics.h" | 10 #include "SkGraphics.h" |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 230 } | 230 } |
| 231 #endif | 231 #endif |
| 232 | 232 |
| 233 private: | 233 private: |
| 234 typedef SkPicturePlayback INHERITED; | 234 typedef SkPicturePlayback INHERITED; |
| 235 }; | 235 }; |
| 236 | 236 |
| 237 // Wrap SkPicture to allow installation of an SkTimedPicturePlayback object | 237 // Wrap SkPicture to allow installation of an SkTimedPicturePlayback object |
| 238 class SkTimedPicture : public SkPicture { | 238 class SkTimedPicture : public SkPicture { |
| 239 public: | 239 public: |
| 240 explicit SkTimedPicture(SkStream* stream, bool* success, SkPicture::InstallP ixelRefProc proc, | 240 static SkTimedPicture* CreateTimedPicture(SkStream* stream, |
| 241 const SkTDArray<bool>& deletedCommands) { | 241 SkPicture::InstallPixelRefProc pro c, |
| 242 if (success) { | 242 const SkTDArray<bool>& deletedComm ands) { |
| 243 *success = false; | |
| 244 } | |
| 245 fRecord = NULL; | |
| 246 fPlayback = NULL; | |
| 247 fWidth = fHeight = 0; | |
| 248 | |
| 249 SkPictInfo info; | 243 SkPictInfo info; |
| 250 | 244 if (!StreamIsSKP(stream, &info)) { |
| 251 if (!stream->read(&info, sizeof(info))) { | 245 return NULL; |
| 252 return; | |
| 253 } | |
| 254 if (SkPicture::PICTURE_VERSION != info.fVersion) { | |
| 255 return; | |
| 256 } | 246 } |
| 257 | 247 |
| 258 if (stream->readBool()) { | 248 SkPicturePlayback* playback = SkNEW_ARGS(SkTimedPicturePlayback, |
| 259 fPlayback = SkNEW_ARGS(SkTimedPicturePlayback, | 249 (stream, info, proc, deletedCom mands)); |
| 260 (stream, info, proc, deletedCommands)); | |
| 261 } | |
| 262 | 250 |
|
robertphillips
2013/06/24 17:22:09
Does it make sense for there to be a "(playback, w
scroggo
2013/06/24 18:22:19
Absolutely! Done.
| |
| 263 // do this at the end, so that they will be zero if we hit an error. | 251 SkTimedPicture* pic = SkNEW(SkTimedPicture); |
| 264 fWidth = info.fWidth; | 252 pic->fPlayback = playback; |
| 265 fHeight = info.fHeight; | 253 pic->fWidth = info.fWidth; |
| 266 if (success) { | 254 pic->fHeight = info.fHeight; |
| 267 *success = true; | 255 return pic; |
| 268 } | |
| 269 } | 256 } |
| 270 | 257 |
| 271 void resetTimes() { ((SkTimedPicturePlayback*) fPlayback)->resetTimes(); } | 258 void resetTimes() { ((SkTimedPicturePlayback*) fPlayback)->resetTimes(); } |
| 272 | 259 |
| 273 int count() const { return ((SkTimedPicturePlayback*) fPlayback)->count(); } | 260 int count() const { return ((SkTimedPicturePlayback*) fPlayback)->count(); } |
| 274 | 261 |
| 275 // return the fraction of the total time this command consumed | 262 // return the fraction of the total time this command consumed |
| 276 double time(int index) const { return ((SkTimedPicturePlayback*) fPlayback)- >time(index); } | 263 double time(int index) const { return ((SkTimedPicturePlayback*) fPlayback)- >time(index); } |
| 277 | 264 |
| 278 const SkTDArray<double>* typeTimes() const { return ((SkTimedPicturePlayback *) fPlayback)->typeTimes(); } | 265 const SkTDArray<double>* typeTimes() const { return ((SkTimedPicturePlayback *) fPlayback)->typeTimes(); } |
| 279 | 266 |
| 280 double totTime() const { return ((SkTimedPicturePlayback*) fPlayback)->totTi me(); } | 267 double totTime() const { return ((SkTimedPicturePlayback*) fPlayback)->totTi me(); } |
| 281 | 268 |
| 282 private: | 269 private: |
| 283 // disallow default ctor b.c. we don't have a good way to setup the fPlaybac k ptr | 270 // Default ctor is only used by CreateTimedPicture, which sets the necessary fields. |
| 284 SkTimedPicture(); | 271 SkTimedPicture() : INHERITED() {} |
| 285 // disallow the copy ctor - enabling would require copying code from SkPictu re | 272 // disallow the copy ctor - enabling would require copying code from SkPictu re |
| 286 SkTimedPicture(const SkTimedPicture& src); | 273 SkTimedPicture(const SkTimedPicture& src); |
| 287 | 274 |
| 288 typedef SkPicture INHERITED; | 275 typedef SkPicture INHERITED; |
| 289 }; | 276 }; |
| 290 | 277 |
| 291 // This is a simplification of PictureBenchmark's run with the addition of | 278 // This is a simplification of PictureBenchmark's run with the addition of |
| 292 // clearing of the times after the first pass (in resetTimes) | 279 // clearing of the times after the first pass (in resetTimes) |
| 293 void SkDebuggerGUI::run(SkTimedPicture* pict, | 280 void SkDebuggerGUI::run(SkTimedPicture* pict, |
| 294 sk_tools::PictureRenderer* renderer, | 281 sk_tools::PictureRenderer* renderer, |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 331 return; | 318 return; |
| 332 } | 319 } |
| 333 | 320 |
| 334 SkFILEStream inputStream; | 321 SkFILEStream inputStream; |
| 335 | 322 |
| 336 inputStream.setPath(fFileName.c_str()); | 323 inputStream.setPath(fFileName.c_str()); |
| 337 if (!inputStream.isValid()) { | 324 if (!inputStream.isValid()) { |
| 338 return; | 325 return; |
| 339 } | 326 } |
| 340 | 327 |
| 341 bool success = false; | 328 SkAutoTUnref<SkTimedPicture> picture(SkTimedPicture::CreateTimedPicture(&inp utStream, |
| 342 SkTimedPicture picture(&inputStream, &success, &SkImageDecoder::DecodeMemory , | 329 &SkImageDecoder::DecodeMemory, fSkipCom mands)); |
| 343 fSkipCommands); | 330 if (NULL == picture.get()) { |
| 344 if (!success) { | |
| 345 return; | 331 return; |
| 346 } | 332 } |
| 347 | 333 |
| 348 // For now this #if allows switching between tiled and simple rendering | 334 // For now this #if allows switching between tiled and simple rendering |
| 349 // modes. Eventually this will be accomplished via the GUI | 335 // modes. Eventually this will be accomplished via the GUI |
| 350 #if 0 | 336 #if 0 |
| 351 // With the current batch of SysTimers, profiling in tiled mode | 337 // With the current batch of SysTimers, profiling in tiled mode |
| 352 // gets swamped by the timing overhead: | 338 // gets swamped by the timing overhead: |
| 353 // | 339 // |
| 354 // tile mode simple mode | 340 // tile mode simple mode |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 370 #if SK_SUPPORT_GPU | 356 #if SK_SUPPORT_GPU |
| 371 if (Qt::Checked == fSettingsWidget.getGLCheckBox()->checkState()) { | 357 if (Qt::Checked == fSettingsWidget.getGLCheckBox()->checkState()) { |
| 372 renderer->setDeviceType(sk_tools::PictureRenderer::kGPU_DeviceType); | 358 renderer->setDeviceType(sk_tools::PictureRenderer::kGPU_DeviceType); |
| 373 } | 359 } |
| 374 #endif | 360 #endif |
| 375 | 361 |
| 376 #endif | 362 #endif |
| 377 | 363 |
| 378 static const int kNumRepeats = 10; | 364 static const int kNumRepeats = 10; |
| 379 | 365 |
| 380 run(&picture, renderer, kNumRepeats); | 366 run(picture.get(), renderer, kNumRepeats); |
| 381 | 367 |
| 382 SkASSERT(picture.count() == fListWidget.count()); | 368 SkASSERT(picture->count() == fListWidget.count()); |
| 383 | 369 |
| 384 // extract the individual command times from the SkTimedPlaybackPicture | 370 // extract the individual command times from the SkTimedPlaybackPicture |
| 385 for (int i = 0; i < picture.count(); ++i) { | 371 for (int i = 0; i < picture->count(); ++i) { |
| 386 double temp = picture.time(i); | 372 double temp = picture->time(i); |
| 387 | 373 |
| 388 QListWidgetItem* item = fListWidget.item(i); | 374 QListWidgetItem* item = fListWidget.item(i); |
| 389 | 375 |
| 390 item->setData(Qt::UserRole + 4, 100.0*temp); | 376 item->setData(Qt::UserRole + 4, 100.0*temp); |
| 391 } | 377 } |
| 392 | 378 |
| 393 setupOverviewText(picture.typeTimes(), picture.totTime(), kNumRepeats); | 379 setupOverviewText(picture->typeTimes(), picture->totTime(), kNumRepeats); |
| 394 } | 380 } |
| 395 | 381 |
| 396 void SkDebuggerGUI::actionCancel() { | 382 void SkDebuggerGUI::actionCancel() { |
| 397 for (int row = 0; row < fListWidget.count(); row++) { | 383 for (int row = 0; row < fListWidget.count(); row++) { |
| 398 fListWidget.item(row)->setHidden(false); | 384 fListWidget.item(row)->setHidden(false); |
| 399 } | 385 } |
| 400 } | 386 } |
| 401 | 387 |
| 402 void SkDebuggerGUI::actionClearBreakpoints() { | 388 void SkDebuggerGUI::actionClearBreakpoints() { |
| 403 for (int row = 0; row < fListWidget.count(); row++) { | 389 for (int row = 0; row < fListWidget.count(); row++) { |
| (...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 898 if (f.contains(r)) | 884 if (f.contains(r)) |
| 899 fDirectoryWidget.addItem(f); | 885 fDirectoryWidget.addItem(f); |
| 900 } | 886 } |
| 901 } | 887 } |
| 902 | 888 |
| 903 void SkDebuggerGUI::loadPicture(const SkString& fileName) { | 889 void SkDebuggerGUI::loadPicture(const SkString& fileName) { |
| 904 fFileName = fileName; | 890 fFileName = fileName; |
| 905 fLoading = true; | 891 fLoading = true; |
| 906 SkStream* stream = SkNEW_ARGS(SkFILEStream, (fileName.c_str())); | 892 SkStream* stream = SkNEW_ARGS(SkFILEStream, (fileName.c_str())); |
| 907 | 893 |
| 908 bool success = false; | 894 SkPicture* picture = SkPicture::CreateFromStream(stream); |
| 909 | 895 |
| 910 SkPicture* picture = SkNEW_ARGS(SkPicture, | 896 if (NULL == picture) { |
| 911 (stream, &success, &SkImageDecoder::DecodeMe mory)); | |
| 912 | |
| 913 if (!success) { | |
| 914 QMessageBox::critical(this, "Error loading file", "Couldn't read file, s orry."); | 897 QMessageBox::critical(this, "Error loading file", "Couldn't read file, s orry."); |
| 915 SkSafeUnref(stream); | 898 SkSafeUnref(stream); |
| 916 return; | 899 return; |
| 917 } | 900 } |
| 918 | 901 |
| 919 fCanvasWidget.resetWidgetTransform(); | 902 fCanvasWidget.resetWidgetTransform(); |
| 920 fDebugger.loadPicture(picture); | 903 fDebugger.loadPicture(picture); |
| 921 | 904 |
| 922 fSkipCommands.setCount(fDebugger.getSize()); | 905 fSkipCommands.setCount(fDebugger.getSize()); |
| 923 for (int i = 0; i < fSkipCommands.count(); ++i) { | 906 for (int i = 0; i < fSkipCommands.count(); ++i) { |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1004 } | 987 } |
| 1005 | 988 |
| 1006 // NOTE(chudy): Makes first item unselectable. | 989 // NOTE(chudy): Makes first item unselectable. |
| 1007 QStandardItemModel* model = qobject_cast<QStandardItemModel*>( | 990 QStandardItemModel* model = qobject_cast<QStandardItemModel*>( |
| 1008 fFilter.model()); | 991 fFilter.model()); |
| 1009 QModelIndex firstIndex = model->index(0, fFilter.modelColumn(), | 992 QModelIndex firstIndex = model->index(0, fFilter.modelColumn(), |
| 1010 fFilter.rootModelIndex()); | 993 fFilter.rootModelIndex()); |
| 1011 QStandardItem* firstItem = model->itemFromIndex(firstIndex); | 994 QStandardItem* firstItem = model->itemFromIndex(firstIndex); |
| 1012 firstItem->setSelectable(false); | 995 firstItem->setSelectable(false); |
| 1013 } | 996 } |
| OLD | NEW |