3 * Copyright 2013 Google Inc.
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
8 #include "SampleCode.h"
17 * Animated sample used to develop batched rect implementation in GrInOrderDrawBuffer.
19 class ManyRectsView : public SampleView {
29 bool onQuery(SkEvent* evt) override {
30 if (SampleCode::TitleQ(*evt)) {
31 SampleCode::TitleR(evt, "ManyRects");
34 return this->INHERITED::onQuery(evt);
37 virtual void onDrawContent(SkCanvas* canvas) {
38 SkISize dsize = canvas->getDeviceSize();
39 canvas->clear(0xFFF0E0F0);
41 for (int i = 0; i < N; ++i) {
42 SkRect rect = SkRect::MakeWH(SkIntToScalar(fRandom.nextRangeU(10, 100)),
43 SkIntToScalar(fRandom.nextRangeU(10, 100)));
44 int x = fRandom.nextRangeU(0, dsize.fWidth);
45 int y = fRandom.nextRangeU(0, dsize.fHeight);
48 canvas->translate(SkIntToScalar(x), SkIntToScalar(y));
49 // Rotation messes up the GPU batching because of the clip below. We don't notice
50 // that the rect is inside the clip so the clip changes interrupt batching.
53 rotate.setRotate(fRandom.nextUScalar1() * 360,
54 SkIntToScalar(x) + SkScalarHalf(rect.fRight),
55 SkIntToScalar(y) + SkScalarHalf(rect.fBottom));
56 canvas->concat(rotate);
58 SkRect clipRect = rect;
59 // This clip will always contain the entire rect. It's here to give the GPU batching
60 // code a little more challenge.
61 clipRect.outset(10, 10);
62 canvas->clipRect(clipRect);
64 paint.setColor(fRandom.nextU());
65 canvas->drawRect(rect, paint);
73 typedef SampleView INHERITED;
76 //////////////////////////////////////////////////////////////////////////////
78 static SkView* MyFactory() { return new ManyRectsView; }
79 static SkViewRegister reg(MyFactory);