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.
|
|
|
|
*/
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkPaint.h"
|
|
|
|
#include "include/core/SkShader.h"
|
|
|
|
#include "include/utils/SkRandom.h"
|
|
|
|
#include "samplecode/Sample.h"
|
2013-02-01 14:19:27 +00:00
|
|
|
|
|
|
|
/**
|
2016-12-21 16:14:46 +00:00
|
|
|
* Animated sample used to develop a predecessor of GrDrawOp combining.
|
2013-02-01 14:19:27 +00:00
|
|
|
*/
|
2018-08-08 15:36:17 +00:00
|
|
|
class ManyRectsView : public Sample {
|
2013-02-01 14:19:27 +00:00
|
|
|
private:
|
|
|
|
enum {
|
|
|
|
N = 1000,
|
|
|
|
};
|
|
|
|
|
|
|
|
public:
|
|
|
|
ManyRectsView() {}
|
|
|
|
|
|
|
|
protected:
|
2018-08-08 15:36:17 +00:00
|
|
|
bool onQuery(Sample::Event* evt) override {
|
|
|
|
if (Sample::TitleQ(*evt)) {
|
|
|
|
Sample::TitleR(evt, "ManyRects");
|
2013-02-01 14:19:27 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return this->INHERITED::onQuery(evt);
|
|
|
|
}
|
|
|
|
|
2015-07-13 13:18:39 +00:00
|
|
|
void onDrawContent(SkCanvas* canvas) override {
|
2017-02-22 18:21:42 +00:00
|
|
|
SkISize dsize = canvas->getBaseLayerSize();
|
2013-02-01 14:19:27 +00:00
|
|
|
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));
|
2016-12-21 16:14:46 +00:00
|
|
|
// Uncomment to test rotated rect draw combining.
|
2013-02-01 14:19:27 +00:00
|
|
|
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;
|
2016-12-21 16:14:46 +00:00
|
|
|
// This clip will always contain the entire rect. It's here to give the GPU op combining
|
2013-02-01 14:19:27 +00:00
|
|
|
// code a little more challenge.
|
|
|
|
clipRect.outset(10, 10);
|
|
|
|
canvas->clipRect(clipRect);
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setColor(fRandom.nextU());
|
|
|
|
canvas->drawRect(rect, paint);
|
|
|
|
canvas->restore();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2013-09-09 20:09:12 +00:00
|
|
|
SkRandom fRandom;
|
2018-08-08 15:36:17 +00:00
|
|
|
typedef Sample INHERITED;
|
2013-02-01 14:19:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2018-08-08 15:36:17 +00:00
|
|
|
DEF_SAMPLE( return new ManyRectsView(); )
|