epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2011 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
reed@google.com | ceff287 | 2011-07-27 18:21:37 +0000 | [diff] [blame] | 8 | #include "SampleCode.h" |
| 9 | #include "SkView.h" |
| 10 | #include "SkCanvas.h" |
| 11 | #include "SkCornerPathEffect.h" |
| 12 | #include "SkCullPoints.h" |
| 13 | #include "SkGradientShader.h" |
| 14 | #include "SkPath.h" |
| 15 | #include "SkRegion.h" |
| 16 | #include "SkShader.h" |
| 17 | #include "SkUtils.h" |
| 18 | |
| 19 | static void create_bitmap(SkBitmap* bitmap) { |
| 20 | const int W = 100; |
| 21 | const int H = 100; |
commit-bot@chromium.org | a8c1831 | 2014-02-17 02:55:57 +0000 | [diff] [blame] | 22 | bitmap->allocN32Pixels(W, H); |
reed@google.com | ceff287 | 2011-07-27 18:21:37 +0000 | [diff] [blame] | 23 | |
| 24 | SkCanvas canvas(*bitmap); |
| 25 | canvas.drawColor(SK_ColorRED); |
| 26 | SkPaint paint; |
| 27 | paint.setColor(SK_ColorBLUE); |
| 28 | canvas.drawCircle(SkIntToScalar(W)/2, SkIntToScalar(H)/2, SkIntToScalar(W)/2, paint); |
| 29 | } |
| 30 | |
| 31 | class WritePixelsView : public SampleView { |
| 32 | SkPath fPath; |
| 33 | public: |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 34 | WritePixelsView() {} |
| 35 | |
reed@google.com | ceff287 | 2011-07-27 18:21:37 +0000 | [diff] [blame] | 36 | protected: |
| 37 | // overrides from SkEventSink |
| 38 | virtual bool onQuery(SkEvent* evt) { |
| 39 | if (SampleCode::TitleQ(*evt)) { |
| 40 | SampleCode::TitleR(evt, "WritePixels"); |
| 41 | return true; |
| 42 | } |
| 43 | return this->INHERITED::onQuery(evt); |
| 44 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 45 | |
reed@google.com | ceff287 | 2011-07-27 18:21:37 +0000 | [diff] [blame] | 46 | virtual void onDrawContent(SkCanvas* canvas) { |
| 47 | SkBitmap bitmap; |
| 48 | create_bitmap(&bitmap); |
| 49 | int x = bitmap.width() / 2; |
| 50 | int y = bitmap.height() / 2; |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 51 | |
reed@google.com | ceff287 | 2011-07-27 18:21:37 +0000 | [diff] [blame] | 52 | SkBitmap subset; |
| 53 | bitmap.extractSubset(&subset, SkIRect::MakeXYWH(x, y, x, y)); |
| 54 | |
| 55 | canvas->translate(SkIntToScalar(20), SkIntToScalar(20)); |
| 56 | |
| 57 | canvas->writePixels(bitmap, 0, 0); |
| 58 | canvas->writePixels(subset, 0, 0); |
| 59 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 60 | |
reed@google.com | ceff287 | 2011-07-27 18:21:37 +0000 | [diff] [blame] | 61 | private: |
| 62 | typedef SampleView INHERITED; |
| 63 | }; |
| 64 | |
| 65 | ////////////////////////////////////////////////////////////////////////////// |
| 66 | |
| 67 | static SkView* MyFactory() { return new WritePixelsView; } |
| 68 | static SkViewRegister reg(MyFactory); |