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 | */ |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 7 | #include "include/core/SkBitmap.h" |
| 8 | #include "include/core/SkCanvas.h" |
| 9 | #include "include/core/SkPath.h" |
| 10 | #include "include/core/SkRegion.h" |
| 11 | #include "include/core/SkShader.h" |
| 12 | #include "include/effects/SkCornerPathEffect.h" |
| 13 | #include "include/effects/SkGradientShader.h" |
| 14 | #include "samplecode/Sample.h" |
| 15 | #include "src/utils/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: |
Hal Canary | 8a02731 | 2019-07-03 10:55:44 -0400 | [diff] [blame] | 35 | virtual SkString name() { return SkString("WritePixels"); } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 36 | |
reed@google.com | ceff287 | 2011-07-27 18:21:37 +0000 | [diff] [blame] | 37 | virtual void onDrawContent(SkCanvas* canvas) { |
| 38 | SkBitmap bitmap; |
| 39 | create_bitmap(&bitmap); |
| 40 | int x = bitmap.width() / 2; |
| 41 | int y = bitmap.height() / 2; |
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 | SkBitmap subset; |
| 44 | bitmap.extractSubset(&subset, SkIRect::MakeXYWH(x, y, x, y)); |
| 45 | |
| 46 | canvas->translate(SkIntToScalar(20), SkIntToScalar(20)); |
| 47 | |
| 48 | canvas->writePixels(bitmap, 0, 0); |
| 49 | canvas->writePixels(subset, 0, 0); |
| 50 | } |
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 | private: |
Ben Wagner | b2c4ea6 | 2018-08-08 11:36:17 -0400 | [diff] [blame] | 53 | typedef Sample INHERITED; |
reed@google.com | ceff287 | 2011-07-27 18:21:37 +0000 | [diff] [blame] | 54 | }; |
| 55 | |
| 56 | ////////////////////////////////////////////////////////////////////////////// |
| 57 | |
Ben Wagner | b2c4ea6 | 2018-08-08 11:36:17 -0400 | [diff] [blame] | 58 | DEF_SAMPLE( return new WritePixelsView(); ) |