junov@google.com | 869d6d9 | 2011-05-17 15:47:10 +0000 | [diff] [blame] | 1 | #include "SampleCode.h" |
| 2 | #include "SkCanvas.h" |
| 3 | |
| 4 | namespace { |
| 5 | SkBitmap make_bitmap() { |
| 6 | SkBitmap bm; |
| 7 | bm.setConfig(SkBitmap::kARGB_8888_Config , 10, 10); |
| 8 | bm.allocPixels(); |
| 9 | |
| 10 | for (int y = 0; y < bm.height(); y++) { |
| 11 | uint32_t* p = bm.getAddr32(0, y); |
| 12 | for (int x = 0; x < bm.width(); x++) { |
| 13 | p[x] = ((x + y) & 1) ? SK_ColorWHITE : SK_ColorBLACK; |
| 14 | } |
| 15 | } |
| 16 | bm.unlockPixels(); |
| 17 | return bm; |
| 18 | } |
| 19 | } // unnamed namespace |
| 20 | |
| 21 | class TextureDomainView : public SampleView { |
| 22 | SkBitmap fBM; |
| 23 | |
| 24 | public: |
| 25 | TextureDomainView(){ |
| 26 | fBM = make_bitmap(); |
| 27 | } |
| 28 | |
| 29 | protected: |
| 30 | // overrides from SkEventSink |
| 31 | virtual bool onQuery(SkEvent* evt) { |
| 32 | if (SampleCode::TitleQ(*evt)) { |
| 33 | SampleCode::TitleR(evt, "Texture Domian"); |
| 34 | return true; |
| 35 | } |
| 36 | return this->INHERITED::onQuery(evt); |
| 37 | } |
| 38 | |
| 39 | virtual void onDrawContent(SkCanvas* canvas) { |
| 40 | SkIRect srcRect; |
| 41 | SkRect dstRect; |
| 42 | SkPaint paint; |
| 43 | paint.setFilterBitmap(true); |
| 44 | srcRect.setXYWH(1, 1, 8, 8); |
| 45 | dstRect.setXYWH(10.0f, 10.0f, 810.0f, 810.0f); |
| 46 | canvas->drawBitmapRect(fBM, &srcRect, dstRect, &paint); |
| 47 | } |
| 48 | private: |
| 49 | typedef SkView INHERITED; |
| 50 | }; |
| 51 | |
| 52 | ////////////////////////////////////////////////////////////////////////////// |
| 53 | |
| 54 | static SkView* MyFactory() { return new TextureDomainView; } |
| 55 | static SkViewRegister reg(MyFactory); |
| 56 | |