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