TableBench.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * Copyright 2012 Google Inc.
  3. *
  4. * Use of this source code is governed by a BSD-style license that can be
  5. * found in the LICENSE file.
  6. */
  7. #include "bench/Benchmark.h"
  8. #include "include/core/SkCanvas.h"
  9. #include "include/core/SkRect.h"
  10. static const SkScalar kCellWidth = SkIntToScalar(20);
  11. static const SkScalar kCellHeight = SkIntToScalar(10);
  12. // This bench draws a table in the manner of Google spreadsheet and sahadan.com.
  13. // ____________ ___
  14. // | 1 | 2 |
  15. // |____________|___|
  16. // | 3 | 4 |
  17. // |____________|___|
  18. //
  19. // Areas 1-4 are first all draw white. Areas 3&4 are then drawn grey. Areas
  20. // 2&4 are then drawn grey. Areas 2&3 are thus double drawn while area 4 is
  21. // triple drawn.
  22. // This trio of drawRects is then repeat for the next cell.
  23. class TableBench : public Benchmark {
  24. public:
  25. static const int kNumRows = 48;
  26. static const int kNumCols = 32;
  27. protected:
  28. virtual const char* onGetName() {
  29. return "tablebench";
  30. }
  31. virtual void onDraw(int loops, SkCanvas* canvas) {
  32. SkPaint cellPaint;
  33. cellPaint.setColor(0xFFFFFFF);
  34. SkPaint borderPaint;
  35. borderPaint.setColor(0xFFCCCCCC);
  36. for (int i = 0; i < loops; ++i) {
  37. for (int row = 0; row < kNumRows; ++row) {
  38. for (int col = 0; col < kNumCols; ++col) {
  39. SkRect cell = SkRect::MakeLTRB(col * kCellWidth,
  40. row * kCellHeight,
  41. (col+1) * kCellWidth,
  42. (row+1) * kCellHeight);
  43. canvas->drawRect(cell, cellPaint);
  44. SkRect bottom = SkRect::MakeLTRB(col * kCellWidth,
  45. row * kCellHeight + (kCellHeight-SK_Scalar1),
  46. (col+1) * kCellWidth,
  47. (row+1) * kCellHeight);
  48. canvas->drawRect(bottom, borderPaint);
  49. SkRect right = SkRect::MakeLTRB(col * kCellWidth + (kCellWidth-SK_Scalar1),
  50. row * kCellHeight,
  51. (col+1) * kCellWidth,
  52. (row+1) * kCellHeight);
  53. canvas->drawRect(right, borderPaint);
  54. }
  55. }
  56. }
  57. }
  58. private:
  59. typedef Benchmark INHERITED;
  60. };
  61. DEF_BENCH( return new TableBench(); )