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

Side by Side Diff: tests/PathOpsSkpClipTest.cpp

Issue 1811613004: Change SkTime::GetMSecs to double; ensure values stored in SkMSec do not overflow. (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: Rebase. Created 4 years, 8 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
« no previous file with comments | « src/views/SkTouchGesture.cpp ('k') | tests/SkpSkGrTest.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 2013 Google Inc. 2 * Copyright 2013 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 "CrashHandler.h" 8 #include "CrashHandler.h"
9 // #include "OverwriteLine.h" 9 // #include "OverwriteLine.h"
10 #include "Resources.h" 10 #include "Resources.h"
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 strcpy(fFilename, filename.c_str()); 208 strcpy(fFilename, filename.c_str());
209 testOne(); 209 testOne();
210 } 210 }
211 211
212 void testOne(); 212 void testOne();
213 213
214 char fFilename[kMaxLength]; 214 char fFilename[kMaxLength];
215 TestStep fTestStep; 215 TestStep fTestStep;
216 int fDirNo; 216 int fDirNo;
217 int fPixelError; 217 int fPixelError;
218 int fTime; 218 SkMSec fTime;
219 int fScale; 219 int fScale;
220 }; 220 };
221 221
222 class SortByPixel : public TestResult { 222 class SortByPixel : public TestResult {
223 public: 223 public:
224 bool operator<(const SortByPixel& rh) const { 224 bool operator<(const SortByPixel& rh) const {
225 return fPixelError < rh.fPixelError; 225 return fPixelError < rh.fPixelError;
226 } 226 }
227 }; 227 };
228 228
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 int pixelError = testResult.fPixelError; 365 int pixelError = testResult.fPixelError;
366 if (pixelError > 0) { 366 if (pixelError > 0) {
367 for (int index = 0; index < worstCount; ++index) { 367 for (int index = 0; index < worstCount; ++index) {
368 if (pixelError > data->fPixelWorst[index].fPixelError) { 368 if (pixelError > data->fPixelWorst[index].fPixelError) {
369 data->fPixelWorst[index] = *(SortByPixel*) &testResult; 369 data->fPixelWorst[index] = *(SortByPixel*) &testResult;
370 return true; 370 return true;
371 } 371 }
372 } 372 }
373 } 373 }
374 int slowCount = data->fSlowest.count(); 374 int slowCount = data->fSlowest.count();
375 int time = testResult.fTime; 375 SkMSec time = testResult.fTime;
376 if (time > 0) { 376 if (time > 0) {
377 for (int index = 0; index < slowCount; ++index) { 377 for (int index = 0; index < slowCount; ++index) {
378 if (time > data->fSlowest[index].fTime) { 378 if (time > data->fSlowest[index].fTime) {
379 data->fSlowest[index] = *(SortByTime*) &testResult; 379 data->fSlowest[index] = *(SortByTime*) &testResult;
380 return true; 380 return true;
381 } 381 }
382 } 382 }
383 } 383 }
384 if (pixelError > 0 && worstCount < kMaxFiles) { 384 if (pixelError > 0 && worstCount < kMaxFiles) {
385 *data->fPixelWorst.append() = *(SortByPixel*) &testResult; 385 *data->fPixelWorst.append() = *(SortByPixel*) &testResult;
386 return true; 386 return true;
387 } 387 }
388 if (time > 0 && slowCount < kMaxFiles) { 388 if (time > 0 && slowCount < kMaxFiles) {
389 *data->fSlowest.append() = *(SortByTime*) &testResult; 389 *data->fSlowest.append() = *(SortByTime*) &testResult;
390 return true; 390 return true;
391 } 391 }
392 return false; 392 return false;
393 } 393 }
394 394
395 static SkMSec timePict(SkPicture* pic, SkCanvas* canvas) { 395 static SkMSec timePict(SkPicture* pic, SkCanvas* canvas) {
396 canvas->save(); 396 canvas->save();
397 SkScalar pWidth = pic->cullRect().width(); 397 SkScalar pWidth = pic->cullRect().width();
398 SkScalar pHeight = pic->cullRect().height(); 398 SkScalar pHeight = pic->cullRect().height();
399 const SkScalar maxDimension = 1000.0f; 399 const SkScalar maxDimension = 1000.0f;
400 const int slices = 3; 400 const int slices = 3;
401 SkScalar xInterval = SkTMax(pWidth - maxDimension, 0.0f) / (slices - 1); 401 SkScalar xInterval = SkTMax(pWidth - maxDimension, 0.0f) / (slices - 1);
402 SkScalar yInterval = SkTMax(pHeight - maxDimension, 0.0f) / (slices - 1); 402 SkScalar yInterval = SkTMax(pHeight - maxDimension, 0.0f) / (slices - 1);
403 SkRect rect = {0, 0, SkTMin(maxDimension, pWidth), SkTMin(maxDimension, pHei ght) }; 403 SkRect rect = {0, 0, SkTMin(maxDimension, pWidth), SkTMin(maxDimension, pHei ght) };
404 canvas->clipRect(rect); 404 canvas->clipRect(rect);
405 SkMSec start = SkTime::GetMSecs(); 405 double start = SkTime::GetMSecs();
406 for (int x = 0; x < slices; ++x) { 406 for (int x = 0; x < slices; ++x) {
407 for (int y = 0; y < slices; ++y) { 407 for (int y = 0; y < slices; ++y) {
408 pic->playback(canvas); 408 pic->playback(canvas);
409 canvas->translate(0, yInterval); 409 canvas->translate(0, yInterval);
410 } 410 }
411 canvas->translate(xInterval, -yInterval * slices); 411 canvas->translate(xInterval, -yInterval * slices);
412 } 412 }
413 SkMSec end = SkTime::GetMSecs(); 413 double end = SkTime::GetMSecs();
414 canvas->restore(); 414 canvas->restore();
415 return end - start; 415 return static_cast<SkMSec>(end - start);
416 } 416 }
417 417
418 static void drawPict(SkPicture* pic, SkCanvas* canvas, int scale) { 418 static void drawPict(SkPicture* pic, SkCanvas* canvas, int scale) {
419 canvas->clear(SK_ColorWHITE); 419 canvas->clear(SK_ColorWHITE);
420 if (scale != 1) { 420 if (scale != 1) {
421 canvas->save(); 421 canvas->save();
422 canvas->scale(1.0f / scale, 1.0f / scale); 422 canvas->scale(1.0f / scale, 1.0f / scale);
423 } 423 }
424 pic->playback(canvas); 424 pic->playback(canvas);
425 if (scale != 1) { 425 if (scale != 1) {
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 oldBitmap.eraseColor(SK_ColorWHITE); 495 oldBitmap.eraseColor(SK_ColorWHITE);
496 SkCanvas oldCanvas(oldBitmap); 496 SkCanvas oldCanvas(oldBitmap);
497 oldCanvas.setAllowSimplifyClip(false); 497 oldCanvas.setAllowSimplifyClip(false);
498 opBitmap.eraseColor(SK_ColorWHITE); 498 opBitmap.eraseColor(SK_ColorWHITE);
499 SkCanvas opCanvas(opBitmap); 499 SkCanvas opCanvas(opBitmap);
500 opCanvas.setAllowSimplifyClip(true); 500 opCanvas.setAllowSimplifyClip(true);
501 drawPict(pic.get(), &oldCanvas, fScale); 501 drawPict(pic.get(), &oldCanvas, fScale);
502 drawPict(pic.get(), &opCanvas, fScale); 502 drawPict(pic.get(), &opCanvas, fScale);
503 if (fTestStep == kCompareBits) { 503 if (fTestStep == kCompareBits) {
504 fPixelError = similarBits(oldBitmap, opBitmap); 504 fPixelError = similarBits(oldBitmap, opBitmap);
505 int oldTime = timePict(pic.get(), &oldCanvas); 505 SkMSec oldTime = timePict(pic.get(), &oldCanvas);
506 int opTime = timePict(pic.get(), &opCanvas); 506 SkMSec opTime = timePict(pic.get(), &opCanvas);
507 fTime = SkTMax(0, oldTime - opTime); 507 fTime = SkTMax(static_cast<SkMSec>(0), oldTime - opTime);
508 } else if (fTestStep == kEncodeFiles) { 508 } else if (fTestStep == kEncodeFiles) {
509 SkString pngStr = make_png_name(fFilename); 509 SkString pngStr = make_png_name(fFilename);
510 const char* pngName = pngStr.c_str(); 510 const char* pngName = pngStr.c_str();
511 writePict(oldBitmap, outOldDir, pngName); 511 writePict(oldBitmap, outOldDir, pngName);
512 writePict(opBitmap, outOpDir, pngName); 512 writePict(opBitmap, outOpDir, pngName);
513 } 513 }
514 } 514 }
515 } 515 }
516 516
517 DEFINE_string2(match, m, "PathOpsSkpClipThreaded", 517 DEFINE_string2(match, m, "PathOpsSkpClipThreaded",
(...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after
1093 } 1093 }
1094 } 1094 }
1095 return 0; 1095 return 0;
1096 } 1096 }
1097 1097
1098 #if !defined(SK_BUILD_FOR_IOS) 1098 #if !defined(SK_BUILD_FOR_IOS)
1099 int main(int argc, char * const argv[]) { 1099 int main(int argc, char * const argv[]) {
1100 return tool_main(argc, (char**) argv); 1100 return tool_main(argc, (char**) argv);
1101 } 1101 }
1102 #endif 1102 #endif
OLDNEW
« no previous file with comments | « src/views/SkTouchGesture.cpp ('k') | tests/SkpSkGrTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698