Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(45)

Unified Diff: gm/tablecolorfilter.cpp

Issue 776673002: Collapse consecutive SkTableColorFilters (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix another msvc warning Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « bench/ImageFilterCollapse.cpp ('k') | gyp/bench.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gm/tablecolorfilter.cpp
diff --git a/gm/tablecolorfilter.cpp b/gm/tablecolorfilter.cpp
index f806caad6ae850e68f2a521c7b2dca0bc4730ffb..a49859bf8f0bfeb313ebc98f65705103d21d4c8d 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,33 +102,82 @@ protected:
}
virtual SkISize onISize() {
- return SkISize::Make(700, 300);
+ return SkISize::Make(700, 1650);
}
virtual void onDraw(SkCanvas* canvas) {
canvas->drawColor(0xFFDDDDDD);
canvas->translate(20, 20);
- 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
+
+ SkScalar x = 0, y = 0;
+ for (size_t bitmapMaker = 0; bitmapMaker < SK_ARRAY_COUNT(gBitmapMakers); ++bitmapMaker) {
SkBitmap bm;
- gMakers[maker](&bm);
+ gBitmapMakers[bitmapMaker](&bm);
- SkPaint paint;
+ SkScalar xOffset = SkScalar(bm.width() * 9 / 8);
+ SkScalar yOffset = SkScalar(bm.height() * 9 / 8);
+
+ // Draw the first element of the first line
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;
+ // Draws the rest of the first line for this bitmap
+ // each draw being at xOffset of the previous one
+ for (unsigned i = 1; i < SK_ARRAY_COUNT(gColorFilterMakers); ++i) {
+ x += xOffset;
+ paint.setColorFilter(gColorFilterMakers[i]())->unref();
+ canvas->drawBitmap(bm, x, y, &paint);
+ }
+
+ paint.setColorFilter(NULL);
+
+ for (unsigned i = 0; i < SK_ARRAY_COUNT(gColorFilterMakers); ++i) {
+ SkAutoTUnref<SkColorFilter> colorFilter1(gColorFilterMakers[i]());
+ SkAutoTUnref<SkImageFilter> imageFilter1(SkColorFilterImageFilter::Create(
+ colorFilter1, NULL, NULL, 0));
+
+ // Move down to the next line and draw it
+ // each draw being at xOffset of the previous one
+ y += yOffset;
+ x = 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;
+ }
+ }
+
+ // Move down one line to the beginning of the block for next bitmap
+ y += yOffset;
}
}
« no previous file with comments | « bench/ImageFilterCollapse.cpp ('k') | gyp/bench.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698