Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
ManyRectsSlide.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2013 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 */
10#include "src/base/SkRandom.h"
11#include "tools/viewer/Slide.h"
12
13/**
14 * Animated sample used to develop a predecessor of GrDrawOp combining.
15 */
16class ManyRectsSlide : public Slide {
17private:
18 enum {
19 N = 1000,
20 };
21
22public:
23 ManyRectsSlide() { fName = "ManyRects"; }
24
25 void draw(SkCanvas* canvas) override {
26 SkISize dsize = canvas->getBaseLayerSize();
27 canvas->clear(0xFFF0E0F0);
28
29 for (int i = 0; i < N; ++i) {
30 SkRect rect = SkRect::MakeWH(SkIntToScalar(fRandom.nextRangeU(10, 100)),
31 SkIntToScalar(fRandom.nextRangeU(10, 100)));
32 int x = fRandom.nextRangeU(0, dsize.fWidth);
33 int y = fRandom.nextRangeU(0, dsize.fHeight);
34 canvas->save();
35
37 // Uncomment to test rotated rect draw combining.
38 if ((false)) {
40 rotate.setRotate(fRandom.nextUScalar1() * 360,
41 SkIntToScalar(x) + SkScalarHalf(rect.fRight),
42 SkIntToScalar(y) + SkScalarHalf(rect.fBottom));
43 canvas->concat(rotate);
44 }
45 SkRect clipRect = rect;
46 // This clip will always contain the entire rect. It's here to give the GPU op combining
47 // code a little more challenge.
48 clipRect.outset(10, 10);
49 canvas->clipRect(clipRect);
51 paint.setColor(fRandom.nextU());
52 canvas->drawRect(rect, paint);
53 canvas->restore();
54 }
55 }
56
57private:
58 SkRandom fRandom;
59};
60
61//////////////////////////////////////////////////////////////////////////////
62
63DEF_SLIDE(return new ManyRectsSlide();)
static bool rotate(const SkDCubic &cubic, int zero, int index, SkDCubic &rotPath)
#define SkScalarHalf(a)
Definition SkScalar.h:75
#define SkIntToScalar(x)
Definition SkScalar.h:57
#define DEF_SLIDE(code)
Definition Slide.h:25
void draw(SkCanvas *canvas) override
void drawRect(const SkRect &rect, const SkPaint &paint)
void clipRect(const SkRect &rect, SkClipOp op, bool doAntiAlias)
void restore()
Definition SkCanvas.cpp:465
void translate(SkScalar dx, SkScalar dy)
virtual SkISize getBaseLayerSize() const
Definition SkCanvas.cpp:373
void clear(SkColor color)
Definition SkCanvas.h:1199
int save()
Definition SkCanvas.cpp:451
void concat(const SkMatrix &matrix)
SkMatrix & setRotate(SkScalar degrees, SkScalar px, SkScalar py)
Definition SkMatrix.cpp:452
uint32_t nextU()
Definition SkRandom.h:42
SkScalar nextUScalar1()
Definition SkRandom.h:101
uint32_t nextRangeU(uint32_t min, uint32_t max)
Definition SkRandom.h:80
Definition Slide.h:29
SkString fName
Definition Slide.h:54
const Paint & paint
double y
double x
int32_t fHeight
Definition SkSize.h:18
int32_t fWidth
Definition SkSize.h:17
static constexpr SkRect MakeWH(float w, float h)
Definition SkRect.h:609