skia2/samplecode/SampleManyRects.cpp
Ben Wagner b2c4ea6219 Move Views into Sample and Viewer.
What is left of the SkView system is used only by samples or viewer.
As a result, move it out of the Skia source tree and re-organize so it
is a bit easier to understand and use more shared code.

Move samplecode/ClockFaceView.cpp to samplecode/SampleTextEffects.cpp,
sice that's what's actually in it.

Move SkAnimTimer.h to tools/timer, since it's actually shared between gm
and samples.

Change-Id: I55dafd94c64e4f930ddbd19168e0f812af86c455
Reviewed-on: https://skia-review.googlesource.com/146161
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Ben Wagner <bungeman@google.com>
2018-08-09 15:25:32 +00:00

74 lines
2.2 KiB
C++

/*
* 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 "Sample.h"
#include "SkCanvas.h"
#include "SkPaint.h"
#include "SkRandom.h"
#include "SkShader.h"
/**
* Animated sample used to develop a predecessor of GrDrawOp combining.
*/
class ManyRectsView : public Sample {
private:
enum {
N = 1000,
};
public:
ManyRectsView() {}
protected:
bool onQuery(Sample::Event* evt) override {
if (Sample::TitleQ(*evt)) {
Sample::TitleR(evt, "ManyRects");
return true;
}
return this->INHERITED::onQuery(evt);
}
void onDrawContent(SkCanvas* canvas) override {
SkISize dsize = canvas->getBaseLayerSize();
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));
// Uncomment to test rotated rect draw combining.
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 op combining
// 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:
SkRandom fRandom;
typedef Sample INHERITED;
};
//////////////////////////////////////////////////////////////////////////////
DEF_SAMPLE( return new ManyRectsView(); )