Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(225)

Side by Side Diff: debugger/QT/SkDebuggerGUI.cpp

Issue 17113004: Replace SkPicture(SkStream) constructors with a factory. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Remove a change in behavior Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | gm/gmmain.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
248 SkTimedPicturePlayback* playback;
249 // Check to see if there is a playback to recreate.
258 if (stream->readBool()) { 250 if (stream->readBool()) {
259 fPlayback = SkNEW_ARGS(SkTimedPicturePlayback, 251 playback = SkNEW_ARGS(SkTimedPicturePlayback,
260 (stream, info, proc, deletedCommands)); 252 (stream, info, proc, deletedCommands));
253 } else {
254 playback = NULL;
261 } 255 }
262 256
263 // do this at the end, so that they will be zero if we hit an error. 257 return SkNEW_ARGS(SkTimedPicture, (playback, info.fWidth, info.fHeight)) ;
264 fWidth = info.fWidth;
265 fHeight = info.fHeight;
266 if (success) {
267 *success = true;
268 }
269 } 258 }
270 259
271 void resetTimes() { ((SkTimedPicturePlayback*) fPlayback)->resetTimes(); } 260 void resetTimes() { ((SkTimedPicturePlayback*) fPlayback)->resetTimes(); }
272 261
273 int count() const { return ((SkTimedPicturePlayback*) fPlayback)->count(); } 262 int count() const { return ((SkTimedPicturePlayback*) fPlayback)->count(); }
274 263
275 // return the fraction of the total time this command consumed 264 // return the fraction of the total time this command consumed
276 double time(int index) const { return ((SkTimedPicturePlayback*) fPlayback)- >time(index); } 265 double time(int index) const { return ((SkTimedPicturePlayback*) fPlayback)- >time(index); }
277 266
278 const SkTDArray<double>* typeTimes() const { return ((SkTimedPicturePlayback *) fPlayback)->typeTimes(); } 267 const SkTDArray<double>* typeTimes() const { return ((SkTimedPicturePlayback *) fPlayback)->typeTimes(); }
279 268
280 double totTime() const { return ((SkTimedPicturePlayback*) fPlayback)->totTi me(); } 269 double totTime() const { return ((SkTimedPicturePlayback*) fPlayback)->totTi me(); }
281 270
282 private: 271 private:
283 // disallow default ctor b.c. we don't have a good way to setup the fPlaybac k ptr 272 // disallow default ctor b.c. we don't have a good way to setup the fPlaybac k ptr
284 SkTimedPicture(); 273 SkTimedPicture();
274 // Private ctor only used by CreateTimedPicture, which has created the playb ack.
275 SkTimedPicture(SkTimedPicturePlayback* playback, int width, int height)
276 : INHERITED(playback, width, height) {}
285 // disallow the copy ctor - enabling would require copying code from SkPictu re 277 // disallow the copy ctor - enabling would require copying code from SkPictu re
286 SkTimedPicture(const SkTimedPicture& src); 278 SkTimedPicture(const SkTimedPicture& src);
287 279
288 typedef SkPicture INHERITED; 280 typedef SkPicture INHERITED;
289 }; 281 };
290 282
291 // This is a simplification of PictureBenchmark's run with the addition of 283 // This is a simplification of PictureBenchmark's run with the addition of
292 // clearing of the times after the first pass (in resetTimes) 284 // clearing of the times after the first pass (in resetTimes)
293 void SkDebuggerGUI::run(SkTimedPicture* pict, 285 void SkDebuggerGUI::run(SkTimedPicture* pict,
294 sk_tools::PictureRenderer* renderer, 286 sk_tools::PictureRenderer* renderer,
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 return; 323 return;
332 } 324 }
333 325
334 SkFILEStream inputStream; 326 SkFILEStream inputStream;
335 327
336 inputStream.setPath(fFileName.c_str()); 328 inputStream.setPath(fFileName.c_str());
337 if (!inputStream.isValid()) { 329 if (!inputStream.isValid()) {
338 return; 330 return;
339 } 331 }
340 332
341 bool success = false; 333 SkAutoTUnref<SkTimedPicture> picture(SkTimedPicture::CreateTimedPicture(&inp utStream,
342 SkTimedPicture picture(&inputStream, &success, &SkImageDecoder::DecodeMemory , 334 &SkImageDecoder::DecodeMemory, fSkipCom mands));
343 fSkipCommands); 335 if (NULL == picture.get()) {
344 if (!success) {
345 return; 336 return;
346 } 337 }
347 338
348 // For now this #if allows switching between tiled and simple rendering 339 // For now this #if allows switching between tiled and simple rendering
349 // modes. Eventually this will be accomplished via the GUI 340 // modes. Eventually this will be accomplished via the GUI
350 #if 0 341 #if 0
351 // With the current batch of SysTimers, profiling in tiled mode 342 // With the current batch of SysTimers, profiling in tiled mode
352 // gets swamped by the timing overhead: 343 // gets swamped by the timing overhead:
353 // 344 //
354 // tile mode simple mode 345 // tile mode simple mode
(...skipping 15 matching lines...) Expand all
370 #if SK_SUPPORT_GPU 361 #if SK_SUPPORT_GPU
371 if (Qt::Checked == fSettingsWidget.getGLCheckBox()->checkState()) { 362 if (Qt::Checked == fSettingsWidget.getGLCheckBox()->checkState()) {
372 renderer->setDeviceType(sk_tools::PictureRenderer::kGPU_DeviceType); 363 renderer->setDeviceType(sk_tools::PictureRenderer::kGPU_DeviceType);
373 } 364 }
374 #endif 365 #endif
375 366
376 #endif 367 #endif
377 368
378 static const int kNumRepeats = 10; 369 static const int kNumRepeats = 10;
379 370
380 run(&picture, renderer, kNumRepeats); 371 run(picture.get(), renderer, kNumRepeats);
381 372
382 SkASSERT(picture.count() == fListWidget.count()); 373 SkASSERT(picture->count() == fListWidget.count());
383 374
384 // extract the individual command times from the SkTimedPlaybackPicture 375 // extract the individual command times from the SkTimedPlaybackPicture
385 for (int i = 0; i < picture.count(); ++i) { 376 for (int i = 0; i < picture->count(); ++i) {
386 double temp = picture.time(i); 377 double temp = picture->time(i);
387 378
388 QListWidgetItem* item = fListWidget.item(i); 379 QListWidgetItem* item = fListWidget.item(i);
389 380
390 item->setData(Qt::UserRole + 4, 100.0*temp); 381 item->setData(Qt::UserRole + 4, 100.0*temp);
391 } 382 }
392 383
393 setupOverviewText(picture.typeTimes(), picture.totTime(), kNumRepeats); 384 setupOverviewText(picture->typeTimes(), picture->totTime(), kNumRepeats);
394 } 385 }
395 386
396 void SkDebuggerGUI::actionCancel() { 387 void SkDebuggerGUI::actionCancel() {
397 for (int row = 0; row < fListWidget.count(); row++) { 388 for (int row = 0; row < fListWidget.count(); row++) {
398 fListWidget.item(row)->setHidden(false); 389 fListWidget.item(row)->setHidden(false);
399 } 390 }
400 } 391 }
401 392
402 void SkDebuggerGUI::actionClearBreakpoints() { 393 void SkDebuggerGUI::actionClearBreakpoints() {
403 for (int row = 0; row < fListWidget.count(); row++) { 394 for (int row = 0; row < fListWidget.count(); row++) {
(...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after
898 if (f.contains(r)) 889 if (f.contains(r))
899 fDirectoryWidget.addItem(f); 890 fDirectoryWidget.addItem(f);
900 } 891 }
901 } 892 }
902 893
903 void SkDebuggerGUI::loadPicture(const SkString& fileName) { 894 void SkDebuggerGUI::loadPicture(const SkString& fileName) {
904 fFileName = fileName; 895 fFileName = fileName;
905 fLoading = true; 896 fLoading = true;
906 SkStream* stream = SkNEW_ARGS(SkFILEStream, (fileName.c_str())); 897 SkStream* stream = SkNEW_ARGS(SkFILEStream, (fileName.c_str()));
907 898
908 bool success = false; 899 SkPicture* picture = SkPicture::CreateFromStream(stream);
909 900
910 SkPicture* picture = SkNEW_ARGS(SkPicture, 901 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."); 902 QMessageBox::critical(this, "Error loading file", "Couldn't read file, s orry.");
915 SkSafeUnref(stream); 903 SkSafeUnref(stream);
916 return; 904 return;
917 } 905 }
918 906
919 fCanvasWidget.resetWidgetTransform(); 907 fCanvasWidget.resetWidgetTransform();
920 fDebugger.loadPicture(picture); 908 fDebugger.loadPicture(picture);
921 909
922 fSkipCommands.setCount(fDebugger.getSize()); 910 fSkipCommands.setCount(fDebugger.getSize());
923 for (int i = 0; i < fSkipCommands.count(); ++i) { 911 for (int i = 0; i < fSkipCommands.count(); ++i) {
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
1004 } 992 }
1005 993
1006 // NOTE(chudy): Makes first item unselectable. 994 // NOTE(chudy): Makes first item unselectable.
1007 QStandardItemModel* model = qobject_cast<QStandardItemModel*>( 995 QStandardItemModel* model = qobject_cast<QStandardItemModel*>(
1008 fFilter.model()); 996 fFilter.model());
1009 QModelIndex firstIndex = model->index(0, fFilter.modelColumn(), 997 QModelIndex firstIndex = model->index(0, fFilter.modelColumn(),
1010 fFilter.rootModelIndex()); 998 fFilter.rootModelIndex());
1011 QStandardItem* firstItem = model->itemFromIndex(firstIndex); 999 QStandardItem* firstItem = model->itemFromIndex(firstIndex);
1012 firstItem->setSelectable(false); 1000 firstItem->setSelectable(false);
1013 } 1001 }
OLDNEW
« no previous file with comments | « no previous file | gm/gmmain.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698