aboutsummaryrefslogtreecommitdiffhomepage
path: root/samplecode
diff options
context:
space:
mode:
authorGravatar reed@android.com <reed@android.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2009-07-16 01:13:14 +0000
committerGravatar reed@android.com <reed@android.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2009-07-16 01:13:14 +0000
commit7a99eb1c63d4327d352af09ea59f039f014e4028 (patch)
treeda87a81eb9d9b528603a20b24f4836305e751f76 /samplecode
parentb4f404ac4195e5b1f49e49c591bd69f98b246f9b (diff)
add shaderprocs for all-in-one special blits (matrix+sampler)
git-svn-id: http://skia.googlecode.com/svn/trunk@267 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'samplecode')
-rw-r--r--samplecode/SampleCircle.cpp88
1 files changed, 54 insertions, 34 deletions
diff --git a/samplecode/SampleCircle.cpp b/samplecode/SampleCircle.cpp
index 3f39dbd3fd..b250f298b9 100644
--- a/samplecode/SampleCircle.cpp
+++ b/samplecode/SampleCircle.cpp
@@ -26,6 +26,7 @@ public:
CircleView() {
fDX = fDY = fRAD = 0;
+ fN = 3;
}
protected:
@@ -71,56 +72,75 @@ protected:
const SkBitmap& bm = device->accessBitmap(false);
canvas->drawBitmapRect(bm, &src, dst, NULL);
}
+
+ static void make_poly(SkPath* path, int n) {
+ if (n <= 0) {
+ return;
+ }
+ path->incReserve(n + 1);
+ path->moveTo(SK_Scalar1, 0);
+ SkScalar step = SK_ScalarPI * 2 / n;
+ SkScalar angle = 0;
+ for (int i = 1; i < n; i++) {
+ angle += step;
+ SkScalar c, s = SkScalarSinCos(angle, &c);
+ path->lineTo(c, s);
+ }
+ path->close();
+ }
+
+ static void rotate(SkCanvas* canvas, SkScalar angle, SkScalar px, SkScalar py) {
+ canvas->translate(-px, -py);
+ canvas->rotate(angle);
+ canvas->translate(px, py);
+ }
virtual void onDraw(SkCanvas* canvas) {
this->drawBG(canvas);
- test_circlebounds(canvas);
+ SkPaint paint;
+ paint.setAntiAlias(true);
+ paint.setStyle(SkPaint::kStroke_Style);
+// canvas->drawCircle(250, 250, 220, paint);
+ SkMatrix matrix;
+ matrix.setScale(SkIntToScalar(100), SkIntToScalar(100));
+ matrix.postTranslate(SkIntToScalar(200), SkIntToScalar(200));
+ canvas->concat(matrix);
+ for (int n = 3; n < 20; n++) {
+ SkPath path;
+ make_poly(&path, n);
+ SkAutoCanvasRestore acr(canvas, true);
+ canvas->rotate(SkIntToScalar(10) * (n - 3));
+ canvas->translate(-SK_Scalar1, 0);
+ canvas->drawPath(path, paint);
+ }
if (false) {
- // canvas->translate(SK_ScalarHalf, SK_ScalarHalf);
-
- SkPaint paint;
- paint.setAntiAlias(true);
- paint.setStyle(SkPaint::kStroke_Style);
- canvas->drawCircle(SkIntToScalar(10), SkIntToScalar(10), SkIntToScalar(2), paint);
+ test_circlebounds(canvas);
- SkIRect r;
- r.set(7, 7, 13, 13);
- SkRect dst;
- dst.set(SkIntToScalar(100), SkIntToScalar(10), SkIntToScalar(200), SkIntToScalar(110));
- blowup(canvas, r, dst);
- return;
- }
-
- // test that degenerate rects do nothing
- if (true) {
- SkScalar x = SkIntToScalar(30);
- SkRect r;
- r.set(x, x, x, x);
- SkPaint p;
- canvas->drawRect(r, p);
- p.setAntiAlias(true);
- canvas->drawRect(r, p);
- }
-
- SkScalar dx = SkIntToScalar(32);
- SkScalar dy = SkIntToScalar(32);
-
- canvas->translate(dx + fDX, dy + fDY);
- drawSix(canvas, dx, dy);
+ SkScalar dx = SkIntToScalar(32);
+ SkScalar dy = SkIntToScalar(32);
+
+ canvas->translate(dx + fDX, dy + fDY);
+ drawSix(canvas, dx, dy);
- canvas->translate(dx, 0);
- canvas->translate(SK_ScalarHalf, SK_ScalarHalf);
- drawSix(canvas, dx, dy);
+ canvas->translate(dx, 0);
+ canvas->translate(SK_ScalarHalf, SK_ScalarHalf);
+ drawSix(canvas, dx, dy);
+ }
fDX += ANIM_DX;
fDY += ANIM_DY;
fRAD += ANIM_RAD;
+ fN += 1;
+ if (fN > 40) {
+ fN = 3;
+ }
this->inval(NULL);
}
private:
+ int fN;
typedef SkView INHERITED;
};