aboutsummaryrefslogtreecommitdiffstats
path: root/gm/strokerects.cpp
diff options
context:
space:
mode:
authorDerek Sollenberger <djsollen@google.com>2011-04-14 09:57:06 -0400
committerDerek Sollenberger <djsollen@google.com>2011-04-14 15:01:11 -0400
commit87b8e645865f9633f410c02252a0fd3feb18f09b (patch)
tree21e2521ed6f69bf466849f7c9579c37aa6b22b06 /gm/strokerects.cpp
parent7f10e10e25231b613ebb242fa14ad8c924ce694f (diff)
downloadexternal_skia-87b8e645865f9633f410c02252a0fd3feb18f09b.zip
external_skia-87b8e645865f9633f410c02252a0fd3feb18f09b.tar.gz
external_skia-87b8e645865f9633f410c02252a0fd3feb18f09b.tar.bz2
Skia Merge (revision 1116)
There is a companion change in external/webkit Change-Id: I1c4110e7520bbef3f4e5f9551adb7ec79ac1e3ed
Diffstat (limited to 'gm/strokerects.cpp')
-rw-r--r--gm/strokerects.cpp88
1 files changed, 88 insertions, 0 deletions
diff --git a/gm/strokerects.cpp b/gm/strokerects.cpp
new file mode 100644
index 0000000..b716407
--- /dev/null
+++ b/gm/strokerects.cpp
@@ -0,0 +1,88 @@
+/*
+ Copyright 2011 Google Inc.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ */
+
+
+#include "gm.h"
+#include "SkRandom.h"
+
+namespace skiagm {
+
+#define W 400
+#define H 400
+#define N 100
+
+static const SkScalar SW = SkIntToScalar(W);
+static const SkScalar SH = SkIntToScalar(H);
+
+class StrokeRectGM : public GM {
+public:
+ StrokeRectGM() {}
+
+protected:
+ virtual SkString onShortName() {
+ return SkString("strokerects");
+ }
+
+ virtual SkISize onISize() {
+ return make_isize(W*2, H*2);
+ }
+
+ static void rnd_rect(SkRect* r, SkRandom& rand) {
+ SkScalar x = rand.nextUScalar1() * W;
+ SkScalar y = rand.nextUScalar1() * H;
+ SkScalar w = rand.nextUScalar1() * (W >> 2);
+ SkScalar h = rand.nextUScalar1() * (H >> 2);
+
+ r->set(x, y, x + w, y + h);
+ r->offset(-w/2 + rand.nextSScalar1(), -h/2 + + rand.nextSScalar1());
+ }
+
+ virtual void onDraw(SkCanvas* canvas) {
+ canvas->drawColor(SK_ColorWHITE);
+
+ SkPaint paint;
+ paint.setStyle(SkPaint::kStroke_Style);
+
+ for (int y = 0; y < 2; y++) {
+ paint.setAntiAlias(!!y);
+ for (int x = 0; x < 2; x++) {
+ paint.setStrokeWidth(x * SkIntToScalar(3));
+
+ SkAutoCanvasRestore acr(canvas, true);
+ canvas->translate(SW * x, SH * y);
+ canvas->clipRect(SkRect::MakeLTRB(2, 2, SW - 2, SH - 2));
+
+ SkRandom rand;
+ for (int i = 0; i < N; i++) {
+ SkRect r;
+ rnd_rect(&r, rand);
+ canvas->drawRect(r, paint);
+ }
+ }
+ }
+ }
+
+private:
+ typedef GM INHERITED;
+};
+
+//////////////////////////////////////////////////////////////////////////////
+
+static GM* MyFactory(void*) { return new StrokeRectGM; }
+static GMRegistry reg(MyFactory);
+
+}
+