Flutter Engine
The Flutter Engine
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) {
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,
42 SkIntToScalar(y) + SkScalarHalf(rect.fBottom));
43 canvas->concat(rotate);
44 }
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)
Definition: SkCanvas.cpp:1673
void clipRect(const SkRect &rect, SkClipOp op, bool doAntiAlias)
Definition: SkCanvas.cpp:1361
void restore()
Definition: SkCanvas.cpp:461
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
virtual SkISize getBaseLayerSize() const
Definition: SkCanvas.cpp:369
void clear(SkColor color)
Definition: SkCanvas.h:1199
int save()
Definition: SkCanvas.cpp:447
void concat(const SkMatrix &matrix)
Definition: SkCanvas.cpp:1318
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
Definition: color_source.cc:38
double y
double x
clipRect(r.rect, r.opAA.op(), r.opAA.aa())) template<> void Draw
sk_sp< SkBlender > blender SkRect rect
Definition: SkRecords.h:350
Definition: SkSize.h:16
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