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

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

Powered by Google App Engine
This is Rietveld 408576698