junov@google.com | 6acc9b3 | 2011-05-16 18:32:07 +0000 | [diff] [blame] | 1 | #include "gm.h" |
| 2 | |
| 3 | namespace skiagm { |
| 4 | |
| 5 | class NoColorBleedGM : public GM { |
| 6 | public: |
bungeman@google.com | 3c14d0f | 2011-05-20 14:05:03 +0000 | [diff] [blame^] | 7 | NoColorBleedGM() {} |
junov@google.com | 6acc9b3 | 2011-05-16 18:32:07 +0000 | [diff] [blame] | 8 | |
| 9 | protected: |
| 10 | virtual SkString onShortName() { |
| 11 | return SkString("nocolorbleed"); |
| 12 | } |
| 13 | |
bungeman@google.com | 3c14d0f | 2011-05-20 14:05:03 +0000 | [diff] [blame^] | 14 | virtual SkISize onISize() { |
junov@google.com | 6acc9b3 | 2011-05-16 18:32:07 +0000 | [diff] [blame] | 15 | return make_isize(200, 200); |
| 16 | } |
| 17 | |
| 18 | void drawBG(SkCanvas* canvas) { |
| 19 | canvas->drawColor(0xFFDDDDDD); |
| 20 | } |
| 21 | |
| 22 | virtual void onDraw(SkCanvas* canvas) { |
| 23 | drawBG(canvas); |
| 24 | |
| 25 | SkBitmap sprite; |
| 26 | sprite.setConfig(SkBitmap::kARGB_8888_Config, 4, 4, 4*sizeof(SkColor)); |
bungeman@google.com | 2ed67e8 | 2011-05-18 18:54:23 +0000 | [diff] [blame] | 27 | const SkColor spriteData[16] = { |
junov@google.com | 6acc9b3 | 2011-05-16 18:32:07 +0000 | [diff] [blame] | 28 | SK_ColorBLACK, SK_ColorCYAN, SK_ColorMAGENTA, SK_ColorYELLOW, |
| 29 | SK_ColorBLACK, SK_ColorWHITE, SK_ColorBLACK, SK_ColorRED, |
| 30 | SK_ColorGREEN, SK_ColorBLACK, SK_ColorWHITE, SK_ColorBLUE, |
| 31 | SK_ColorYELLOW, SK_ColorMAGENTA, SK_ColorCYAN, SK_ColorBLACK |
| 32 | }; |
bungeman@google.com | 2ed67e8 | 2011-05-18 18:54:23 +0000 | [diff] [blame] | 33 | SkPMColor spriteDataPM[16]; |
| 34 | for (size_t i = 0; i < SK_ARRAY_COUNT(spriteData); ++i) { |
| 35 | spriteDataPM[i] = SkPreMultiplyColor(spriteData[i]); |
| 36 | } |
| 37 | sprite.setPixels(spriteDataPM); |
junov@google.com | 6acc9b3 | 2011-05-16 18:32:07 +0000 | [diff] [blame] | 38 | |
| 39 | // We draw a magnified subrect of the sprite |
| 40 | // sample interpolation may cause color bleeding around edges |
| 41 | // the subrect is a pure white area |
| 42 | SkIRect srcRect; |
| 43 | SkRect dstRect; |
| 44 | SkPaint paint; |
| 45 | paint.setFilterBitmap(true); |
| 46 | //First row : full texture with and without filtering |
| 47 | srcRect.setXYWH(0, 0, 4, 4); |
bungeman@google.com | 3c14d0f | 2011-05-20 14:05:03 +0000 | [diff] [blame^] | 48 | dstRect.setXYWH(SkIntToScalar(0), SkIntToScalar(0) |
| 49 | , SkIntToScalar(100), SkIntToScalar(100)); |
junov@google.com | 6acc9b3 | 2011-05-16 18:32:07 +0000 | [diff] [blame] | 50 | canvas->drawBitmapRect(sprite, &srcRect, dstRect, &paint); |
bungeman@google.com | 3c14d0f | 2011-05-20 14:05:03 +0000 | [diff] [blame^] | 51 | dstRect.setXYWH(SkIntToScalar(100), SkIntToScalar(0) |
| 52 | , SkIntToScalar(100), SkIntToScalar(100)); |
junov@google.com | 6acc9b3 | 2011-05-16 18:32:07 +0000 | [diff] [blame] | 53 | canvas->drawBitmapRect(sprite, &srcRect, dstRect); |
| 54 | //Second row : sub rect of texture with and without filtering |
| 55 | srcRect.setXYWH(1, 1, 2, 2); |
bungeman@google.com | 3c14d0f | 2011-05-20 14:05:03 +0000 | [diff] [blame^] | 56 | dstRect.setXYWH(SkIntToScalar(25), SkIntToScalar(125) |
| 57 | , SkIntToScalar(50), SkIntToScalar(50)); |
junov@google.com | 6acc9b3 | 2011-05-16 18:32:07 +0000 | [diff] [blame] | 58 | canvas->drawBitmapRect(sprite, &srcRect, dstRect, &paint); |
bungeman@google.com | 3c14d0f | 2011-05-20 14:05:03 +0000 | [diff] [blame^] | 59 | dstRect.setXYWH(SkIntToScalar(125), SkIntToScalar(125) |
| 60 | , SkIntToScalar(50), SkIntToScalar(50)); |
junov@google.com | 6acc9b3 | 2011-05-16 18:32:07 +0000 | [diff] [blame] | 61 | canvas->drawBitmapRect(sprite, &srcRect, dstRect); |
| 62 | } |
| 63 | |
| 64 | private: |
| 65 | typedef GM INHERITED; |
| 66 | }; |
| 67 | |
| 68 | ////////////////////////////////////////////////////////////////////////////// |
| 69 | |
| 70 | static GM* MyFactory(void*) { return new NoColorBleedGM; } |
| 71 | static GMRegistry reg(MyFactory); |
| 72 | |
| 73 | } |