2 * Copyright 2013 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
7 #include "include/core/SkCanvas.h"
8 #include "include/core/SkPaint.h"
9 #include "include/core/SkShader.h"
10 #include "include/utils/SkRandom.h"
11 #include "samplecode/Sample.h"
14 * Animated sample used to develop a predecessor of GrDrawOp combining.
16 class ManyRectsView : public Sample {
26 SkString name() override { return SkString("ManyRects"); }
28 void onDrawContent(SkCanvas* canvas) override {
29 SkISize dsize = canvas->getBaseLayerSize();
30 canvas->clear(0xFFF0E0F0);
32 for (int i = 0; i < N; ++i) {
33 SkRect rect = SkRect::MakeWH(SkIntToScalar(fRandom.nextRangeU(10, 100)),
34 SkIntToScalar(fRandom.nextRangeU(10, 100)));
35 int x = fRandom.nextRangeU(0, dsize.fWidth);
36 int y = fRandom.nextRangeU(0, dsize.fHeight);
39 canvas->translate(SkIntToScalar(x), SkIntToScalar(y));
40 // Uncomment to test rotated rect draw combining.
43 rotate.setRotate(fRandom.nextUScalar1() * 360,
44 SkIntToScalar(x) + SkScalarHalf(rect.fRight),
45 SkIntToScalar(y) + SkScalarHalf(rect.fBottom));
46 canvas->concat(rotate);
48 SkRect clipRect = rect;
49 // This clip will always contain the entire rect. It's here to give the GPU op combining
50 // code a little more challenge.
51 clipRect.outset(10, 10);
52 canvas->clipRect(clipRect);
54 paint.setColor(fRandom.nextU());
55 canvas->drawRect(rect, paint);
62 using INHERITED = Sample;
65 //////////////////////////////////////////////////////////////////////////////
67 DEF_SAMPLE( return new ManyRectsView(); )