2013-02-01 14:19:27 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 2013 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
#include "SampleCode.h"
|
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkDevice.h"
|
|
|
|
#include "SkPaint.h"
|
|
|
|
#include "SkRandom.h"
|
|
|
|
#include "SkShader.h"
|
|
|
|
#include "SkView.h"
|
|
|
|
|
|
|
|
/**
|
2015-07-28 16:58:39 +00:00
|
|
|
* Animated sample used to develop batched rect implementation in GrBufferedDrawTarget.
|
2013-02-01 14:19:27 +00:00
|
|
|
*/
|
|
|
|
class ManyRectsView : public SampleView {
|
|
|
|
private:
|
|
|
|
enum {
|
|
|
|
N = 1000,
|
|
|
|
};
|
|
|
|
|
|
|
|
public:
|
|
|
|
ManyRectsView() {}
|
|
|
|
|
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
bool onQuery(SkEvent* evt) override {
|
2013-02-01 14:19:27 +00:00
|
|
|
if (SampleCode::TitleQ(*evt)) {
|
|
|
|
SampleCode::TitleR(evt, "ManyRects");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return this->INHERITED::onQuery(evt);
|
|
|
|
}
|
|
|
|
|
2015-07-13 13:18:39 +00:00
|
|
|
void onDrawContent(SkCanvas* canvas) override {
|
2013-02-01 14:19:27 +00:00
|
|
|
SkISize dsize = canvas->getDeviceSize();
|
|
|
|
canvas->clear(0xFFF0E0F0);
|
|
|
|
|
|
|
|
for (int i = 0; i < N; ++i) {
|
|
|
|
SkRect rect = SkRect::MakeWH(SkIntToScalar(fRandom.nextRangeU(10, 100)),
|
|
|
|
SkIntToScalar(fRandom.nextRangeU(10, 100)));
|
|
|
|
int x = fRandom.nextRangeU(0, dsize.fWidth);
|
|
|
|
int y = fRandom.nextRangeU(0, dsize.fHeight);
|
|
|
|
canvas->save();
|
|
|
|
|
|
|
|
canvas->translate(SkIntToScalar(x), SkIntToScalar(y));
|
|
|
|
// Rotation messes up the GPU batching because of the clip below. We don't notice
|
|
|
|
// that the rect is inside the clip so the clip changes interrupt batching.
|
|
|
|
if (false) {
|
|
|
|
SkMatrix rotate;
|
|
|
|
rotate.setRotate(fRandom.nextUScalar1() * 360,
|
|
|
|
SkIntToScalar(x) + SkScalarHalf(rect.fRight),
|
|
|
|
SkIntToScalar(y) + SkScalarHalf(rect.fBottom));
|
|
|
|
canvas->concat(rotate);
|
|
|
|
}
|
|
|
|
SkRect clipRect = rect;
|
|
|
|
// This clip will always contain the entire rect. It's here to give the GPU batching
|
|
|
|
// code a little more challenge.
|
|
|
|
clipRect.outset(10, 10);
|
|
|
|
canvas->clipRect(clipRect);
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setColor(fRandom.nextU());
|
|
|
|
canvas->drawRect(rect, paint);
|
|
|
|
canvas->restore();
|
|
|
|
}
|
2015-08-27 14:41:13 +00:00
|
|
|
this->inval(nullptr);
|
2013-02-01 14:19:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2013-09-09 20:09:12 +00:00
|
|
|
SkRandom fRandom;
|
2013-02-01 14:19:27 +00:00
|
|
|
typedef SampleView INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
static SkView* MyFactory() { return new ManyRectsView; }
|
|
|
|
static SkViewRegister reg(MyFactory);
|