blob: 26b81847e07918ab373ae1cfceabfa4b07539dbe [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
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.com6acc9b32011-05-16 18:32:07 +00008#include "gm.h"
9
10namespace skiagm {
11
12class NoColorBleedGM : public GM {
13public:
bsalomon@google.com48dd1a22011-10-31 14:18:20 +000014 NoColorBleedGM() {
15 this->setBGColor(0xFFDDDDDD);
16 }
junov@google.com6acc9b32011-05-16 18:32:07 +000017
18protected:
19 virtual SkString onShortName() {
20 return SkString("nocolorbleed");
21 }
22
bungeman@google.com3c14d0f2011-05-20 14:05:03 +000023 virtual SkISize onISize() {
junov@google.com6acc9b32011-05-16 18:32:07 +000024 return make_isize(200, 200);
25 }
26
junov@google.com6acc9b32011-05-16 18:32:07 +000027 virtual void onDraw(SkCanvas* canvas) {
junov@google.com6acc9b32011-05-16 18:32:07 +000028 SkBitmap sprite;
29 sprite.setConfig(SkBitmap::kARGB_8888_Config, 4, 4, 4*sizeof(SkColor));
bungeman@google.com2ed67e82011-05-18 18:54:23 +000030 const SkColor spriteData[16] = {
junov@google.com6acc9b32011-05-16 18:32:07 +000031 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.com64f340c2011-05-26 14:35:41 +000036 sprite.allocPixels();
37 sprite.lockPixels();
38 SkPMColor* addr = sprite.getAddr32(0, 0);
bungeman@google.com2ed67e82011-05-18 18:54:23 +000039 for (size_t i = 0; i < SK_ARRAY_COUNT(spriteData); ++i) {
reed@google.com64f340c2011-05-26 14:35:41 +000040 addr[i] = SkPreMultiplyColor(spriteData[i]);
bungeman@google.com2ed67e82011-05-18 18:54:23 +000041 }
reed@google.com64f340c2011-05-26 14:35:41 +000042 sprite.unlockPixels();
junov@google.com6acc9b32011-05-16 18:32:07 +000043
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.com3c14d0f2011-05-20 14:05:03 +000053 dstRect.setXYWH(SkIntToScalar(0), SkIntToScalar(0)
54 , SkIntToScalar(100), SkIntToScalar(100));
junov@google.com6acc9b32011-05-16 18:32:07 +000055 canvas->drawBitmapRect(sprite, &srcRect, dstRect, &paint);
bungeman@google.com3c14d0f2011-05-20 14:05:03 +000056 dstRect.setXYWH(SkIntToScalar(100), SkIntToScalar(0)
57 , SkIntToScalar(100), SkIntToScalar(100));
junov@google.com6acc9b32011-05-16 18:32:07 +000058 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.com3c14d0f2011-05-20 14:05:03 +000061 dstRect.setXYWH(SkIntToScalar(25), SkIntToScalar(125)
62 , SkIntToScalar(50), SkIntToScalar(50));
junov@google.com6acc9b32011-05-16 18:32:07 +000063 canvas->drawBitmapRect(sprite, &srcRect, dstRect, &paint);
bungeman@google.com3c14d0f2011-05-20 14:05:03 +000064 dstRect.setXYWH(SkIntToScalar(125), SkIntToScalar(125)
65 , SkIntToScalar(50), SkIntToScalar(50));
junov@google.com6acc9b32011-05-16 18:32:07 +000066 canvas->drawBitmapRect(sprite, &srcRect, dstRect);
67 }
68
69private:
70 typedef GM INHERITED;
71};
72
73//////////////////////////////////////////////////////////////////////////////
74
75static GM* MyFactory(void*) { return new NoColorBleedGM; }
76static GMRegistry reg(MyFactory);
77
78}