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

Side by Side Diff: bench/RectBench.cpp

Issue 2136343002: Revert of try to speed-up maprect + round2i + contains (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 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
« no previous file with comments | « no previous file | gyp/core.gypi » ('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 2011 Google Inc. 2 * Copyright 2011 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 #include "Benchmark.h" 7 #include "Benchmark.h"
8 #include "SkCanvas.h" 8 #include "SkCanvas.h"
9 #include "SkCommandLineFlags.h" 9 #include "SkCommandLineFlags.h"
10 #include "SkPaint.h" 10 #include "SkPaint.h"
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 "maskopaque");) 295 "maskopaque");)
296 DEF_BENCH(return new BlitMaskBench(SkCanvas::kPoints_PointMode, 296 DEF_BENCH(return new BlitMaskBench(SkCanvas::kPoints_PointMode,
297 BlitMaskBench::kMaskBlack, 297 BlitMaskBench::kMaskBlack,
298 "maskblack");) 298 "maskblack");)
299 DEF_BENCH(return new BlitMaskBench(SkCanvas::kPoints_PointMode, 299 DEF_BENCH(return new BlitMaskBench(SkCanvas::kPoints_PointMode,
300 BlitMaskBench::kMaskColor, 300 BlitMaskBench::kMaskColor,
301 "maskcolor");) 301 "maskcolor");)
302 DEF_BENCH(return new BlitMaskBench(SkCanvas::kPoints_PointMode, 302 DEF_BENCH(return new BlitMaskBench(SkCanvas::kPoints_PointMode,
303 BlitMaskBench::KMaskShader, 303 BlitMaskBench::KMaskShader,
304 "maskshader");) 304 "maskshader");)
305
306 //////////////////////////////////////////////////////////////////////////////// ///////////////////
307
308 typedef int (*RectMathProc)(const SkMatrix&, const SkRect[], const SkIRect[], in t count);
309
310 class RectMathBench : public Benchmark {
311 SkString fName;
312 SkRandom fRand;
313 SkString fSuffix;
314 RectMathProc fProc;
315
316 public:
317 enum {
318 N = 300,
319 OUTER = 10000,
320 };
321 SkRect fRects[N];
322 SkIRect fIRects[N];
323 volatile int fCounter;
324
325 RectMathBench(RectMathProc proc, const char* suffix) {
326 fProc = proc;
327 fSuffix.set(suffix);
328 SkRandom rand;
329 for (int i = 0; i < N; ++i) {
330 fRects[i].setXYWH(rand.nextUScalar1() * 100, rand.nextUScalar1() * 1 00,
331 rand.nextUScalar1() * 100, rand.nextUScalar1() * 1 00);
332 fIRects[i].setXYWH(i, i, 10, 10);
333 }
334 }
335
336 bool isVisual() override { return false; }
337
338 protected:
339 const char* onGetName() override {
340 fName.printf("rect_math_%s", fSuffix.c_str());
341 return fName.c_str();
342 }
343
344 void onDraw(int loops, SkCanvas* canvas) override {
345 SkMatrix mat;
346 for (int j = 0; j < OUTER; ++j) {
347 mat.setScaleTranslate(fRand.nextUScalar1(), fRand.nextUScalar1(),
348 fRand.nextUScalar1(), fRand.nextUScalar1());
349 fCounter += fProc(mat, fRects, fIRects, N);
350 }
351 }
352
353 private:
354 typedef Benchmark INHERITED;
355 };
356
357 static int rectmath0(const SkMatrix& mat, const SkRect rr[], const SkIRect ir[], int count) {
358 int counter = 0;
359 for (int i = 0; i < count; ++i) {
360 SkRect dst;
361 mat.mapRectScaleTranslate(&dst, rr[i]);
362 counter += dst.round().contains(ir[i]);
363 }
364 return counter;
365 }
366
367 static int rectmath1(const SkMatrix& mat, const SkRect rr[], const SkIRect ir[], int count) {
368 int counter = 0;
369 for (int i = 0; i < count; ++i) {
370 SkRect dst;
371 mat.mapRectScaleTranslate(&dst, rr[i]);
372 counter += dst.round2i().contains(ir[i]);
373 }
374 return counter;
375 }
376
377 #if 0
378 static bool contains(SkIRect outer, SkIRect inner) {
379 Sk4i le(outer.fLeft, outer.fTop, inner.fRight, inner.fBottom);
380 Sk4i ge(inner.fLeft, inner.fTop, outer.fRight, outer.fBottom);
381 return (le <= ge).allTrue();
382 }
383
384 static int rectmath3(const SkMatrix& mat, const SkRect rr[], const SkIRect ir[], int count) {
385 int counter = 0;
386 for (int i = 0; i < count; ++i) {
387 counter += contains(mat.mapRectScaleTranslate(rr[i]).round2i(), ir[i]);
388 }
389 return counter;
390 }
391 #endif
392
393 DEF_BENCH(return new RectMathBench(rectmath0, "0");)
394 DEF_BENCH(return new RectMathBench(rectmath1, "1");)
OLDNEW
« no previous file with comments | « no previous file | gyp/core.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698