Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
TableBench.cpp
Go to the documentation of this file.
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
8#include "bench/Benchmark.h"
10#include "include/core/SkRect.h"
11
14
15// This bench draws a table in the manner of Google spreadsheet and sahadan.com.
16// ____________ ___
17// | 1 | 2 |
18// |____________|___|
19// | 3 | 4 |
20// |____________|___|
21//
22// Areas 1-4 are first all draw white. Areas 3&4 are then drawn grey. Areas
23// 2&4 are then drawn grey. Areas 2&3 are thus double drawn while area 4 is
24// triple drawn.
25// This trio of drawRects is then repeat for the next cell.
26class TableBench : public Benchmark {
27public:
28 static const int kNumRows = 48;
29 static const int kNumCols = 32;
30
31protected:
32 const char* onGetName() override {
33 return "tablebench";
34 }
35
36 void onDraw(int loops, SkCanvas* canvas) override {
37 SkPaint cellPaint;
38 cellPaint.setColor(0xFFFFFFF);
39
40 SkPaint borderPaint;
41 borderPaint.setColor(0xFFCCCCCC);
42
43 for (int i = 0; i < loops; ++i) {
44 for (int row = 0; row < kNumRows; ++row) {
45 for (int col = 0; col < kNumCols; ++col) {
47 row * kCellHeight,
48 (col+1) * kCellWidth,
49 (row+1) * kCellHeight);
50 canvas->drawRect(cell, cellPaint);
51
52 SkRect bottom = SkRect::MakeLTRB(col * kCellWidth,
54 (col+1) * kCellWidth,
55 (row+1) * kCellHeight);
56 canvas->drawRect(bottom, borderPaint);
57
59 row * kCellHeight,
60 (col+1) * kCellWidth,
61 (row+1) * kCellHeight);
62 canvas->drawRect(right, borderPaint);
63 }
64 }
65 }
66 }
67
68private:
69 using INHERITED = Benchmark;
70};
71
72DEF_BENCH( return new TableBench(); )
#define DEF_BENCH(code)
Definition Benchmark.h:20
static bool right(const SkPoint &p0, const SkPoint &p1)
#define SK_Scalar1
Definition SkScalar.h:18
#define SkIntToScalar(x)
Definition SkScalar.h:57
static const SkScalar kCellHeight
static const SkScalar kCellWidth
void drawRect(const SkRect &rect, const SkPaint &paint)
void setColor(SkColor color)
Definition SkPaint.cpp:119
void onDraw(int loops, SkCanvas *canvas) override
static const int kNumRows
static const int kNumCols
const char * onGetName() override
float SkScalar
Definition extension.cpp:12
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
Definition SkRect.h:646