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 */ 7 #include "Sample.h" 8 #include "SkBitmap.h" 9 #include "SkCanvas.h" 10 #include "SkCornerPathEffect.h" 11 #include "SkGradientShader.h" 12 #include "SkPath.h" 13 #include "SkRegion.h" 14 #include "SkShader.h" 15 #include "SkUTF.h" 16 17 static void create_bitmap(SkBitmap* bitmap) { 18 const int W = 100; 19 const int H = 100; 20 bitmap->allocN32Pixels(W, H); 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 29 class WritePixelsView : public Sample { 30 SkPath fPath; 31 public: 32 WritePixelsView() {} 33 34 protected: 35 virtual bool onQuery(Sample::Event* evt) { 36 if (Sample::TitleQ(*evt)) { 37 Sample::TitleR(evt, "WritePixels"); 38 return true; 39 } 40 return this->INHERITED::onQuery(evt); 41 } 42 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; 48 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 } 57 58 private: 59 typedef Sample INHERITED; 60 }; 61 62 ////////////////////////////////////////////////////////////////////////////// 63 64 DEF_SAMPLE( return new WritePixelsView(); ) 65