aboutsummaryrefslogtreecommitdiffhomepage
path: root/gm/tablecolorfilter.cpp
diff options
context:
space:
mode:
authorGravatar cwallez <cwallez@google.com>2015-01-26 07:45:53 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2015-01-26 07:45:53 -0800
commitc12b74dc413ef024b13e0ed478491c4b1bafe6b1 (patch)
tree706b76c6b014f84ca982a58686720bb47f8cdeb2 /gm/tablecolorfilter.cpp
parent9ec0ffb77dfb2c7337daadd4d88736c3e1ebe28b (diff)
Collapse consecutive SkTableColorFilters
BUG=skia:1366 For the added bench, the collapsing makes the bench take: - 70% of the time for CPU rendering of 3 consecutive matrix filters - almost no change in the GPU rendering of the matrix filters - 50% of the time for CPU and GPU rendering of 3 consecutive table filters Review URL: https://codereview.chromium.org/776673002
Diffstat (limited to 'gm/tablecolorfilter.cpp')
-rw-r--r--gm/tablecolorfilter.cpp84
1 files changed, 69 insertions, 15 deletions
diff --git a/gm/tablecolorfilter.cpp b/gm/tablecolorfilter.cpp
index f806caad6a..a49859bf8f 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;
}
}