Chromium Code Reviews| Index: gm/tablecolorfilter.cpp |
| diff --git a/gm/tablecolorfilter.cpp b/gm/tablecolorfilter.cpp |
| index f806caad6ae850e68f2a521c7b2dca0bc4730ffb..6d75d5e23b4742fa5d9fd43b430a886064e99933 100644 |
| --- a/gm/tablecolorfilter.cpp |
| +++ b/gm/tablecolorfilter.cpp |
| @@ -7,6 +7,7 @@ |
| #include "gm.h" |
| #include "SkCanvas.h" |
| +#include "SkColorFilterImageFilter.h" |
| #include "SkGradientShader.h" |
| #include "SkTableColorFilter.h" |
| @@ -68,6 +69,10 @@ static void make_table2(uint8_t table[]) { |
| } |
| } |
| +static SkColorFilter* make_null_cf() { |
| + return NULL; |
| +} |
| + |
| static SkColorFilter* make_cf0() { |
| uint8_t table[256]; make_table0(table); |
| return SkTableColorFilter::Create(table); |
| @@ -97,7 +102,7 @@ protected: |
| } |
| virtual SkISize onISize() { |
| - return SkISize::Make(700, 300); |
| + return SkISize::Make(700, 1650); |
| } |
| virtual void onDraw(SkCanvas* canvas) { |
| @@ -106,25 +111,67 @@ protected: |
| SkScalar x = 0, y = 0; |
| - static void (*gMakers[])(SkBitmap*) = { make_bm0, make_bm1 }; |
| - for (size_t maker = 0; maker < SK_ARRAY_COUNT(gMakers); ++maker) { |
| + static SkColorFilter* (*gColorFilterMakers[])() = { make_null_cf, make_cf0, make_cf1, |
| + make_cf2, make_cf3 }; |
| + static void (*gBitmapMakers[])(SkBitmap*) = { make_bm0, make_bm1 }; |
| + |
| + // This test will be done once for each bitmap with the results stacked vertically. |
| + // For a single bitmap the resulting image will be the following: |
| + // - A first line with the original bitmap, followed by the image drawn once |
| + // with each of the N color filters |
| + // - N lines of the bitmap drawn N times, this will cover all N*N combinations of |
| + // pair of color filters in order to test the collpsing of consecutive table |
| + // color filters. |
| + // |
| + // Here is a graphical representation of the result for 2 bitmaps and 2 filters |
| + // with the number corresponding to the number of filters the bitmap goes through: |
| + // |
| + // --bitmap1 |
| + // 011 |
| + // 22 |
| + // 22 |
| + // --bitmap2 |
| + // 011 |
| + // 22 |
| + // 22 |
| + for (size_t bitmapMaker = 0; bitmapMaker < SK_ARRAY_COUNT(gBitmapMakers); ++bitmapMaker) { |
| SkBitmap bm; |
| - gMakers[maker](&bm); |
| + gBitmapMakers[bitmapMaker](&bm); |
| - SkPaint paint; |
| + SkScalar xOffset = bm.width() * 9 / 8; |
| + SkScalar yOffset = bm.height() * 9 / 8; |
| x = 0; |
| - canvas->drawBitmap(bm, x, y, &paint); |
| - paint.setColorFilter(make_cf0())->unref(); x += bm.width() * 9 / 8; |
| - canvas->drawBitmap(bm, x, y, &paint); |
| - paint.setColorFilter(make_cf1())->unref(); x += bm.width() * 9 / 8; |
| - canvas->drawBitmap(bm, x, y, &paint); |
| - paint.setColorFilter(make_cf2())->unref(); x += bm.width() * 9 / 8; |
| - canvas->drawBitmap(bm, x, y, &paint); |
| - paint.setColorFilter(make_cf3())->unref(); x += bm.width() * 9 / 8; |
| + |
| + SkPaint paint; |
| canvas->drawBitmap(bm, x, y, &paint); |
| - y += bm.height() * 9 / 8; |
| + for (unsigned i = 1; i < SK_ARRAY_COUNT(gColorFilterMakers); ++i) { |
| + paint.setColorFilter(gColorFilterMakers[i]())->unref(); |
| + x += xOffset; |
|
Justin Novosad
2015/01/21 16:50:32
The complex x/y positioning logic still needs to b
|
| + canvas->drawBitmap(bm, x, y, &paint); |
| + } |
| + |
| + y += yOffset; |
| + paint.setColorFilter(NULL); |
| + |
| + for (unsigned i = 0; i < SK_ARRAY_COUNT(gColorFilterMakers); ++i) { |
| + x = 0; |
| + SkAutoTUnref<SkColorFilter> colorFilter1(gColorFilterMakers[i]()); |
| + SkAutoTUnref<SkImageFilter> imageFilter1(SkColorFilterImageFilter::Create( |
| + colorFilter1, NULL, NULL, 0)); |
| + |
| + for (unsigned j = 1; j < SK_ARRAY_COUNT(gColorFilterMakers); ++j) { |
| + SkAutoTUnref<SkColorFilter> colorFilter2(gColorFilterMakers[j]()); |
| + SkAutoTUnref<SkImageFilter> imageFilter2(SkColorFilterImageFilter::Create( |
| + colorFilter2, imageFilter1, NULL, 0)); |
| + paint.setImageFilter(imageFilter2); |
| + canvas->drawBitmap(bm, x, y, &paint); |
| + x += xOffset; |
| + } |
| + y += yOffset; |
| + } |
| } |
| + |
| } |
| private: |