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