| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "gm.h" | 8 #include "gm.h" |
| 9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
| 10 #include "SkColorFilterImageFilter.h" | 10 #include "SkColorFilterImageFilter.h" |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 table[i] = i * i / 255; | 66 table[i] = i * i / 255; |
| 67 } | 67 } |
| 68 } | 68 } |
| 69 static void make_table2(uint8_t table[]) { | 69 static void make_table2(uint8_t table[]) { |
| 70 for (int i = 0; i < 256; ++i) { | 70 for (int i = 0; i < 256; ++i) { |
| 71 float fi = i / 255.0f; | 71 float fi = i / 255.0f; |
| 72 table[i] = static_cast<uint8_t>(sqrtf(fi) * 255); | 72 table[i] = static_cast<uint8_t>(sqrtf(fi) * 255); |
| 73 } | 73 } |
| 74 } | 74 } |
| 75 | 75 |
| 76 static SkColorFilter* make_null_cf() { | 76 static sk_sp<SkColorFilter> make_null_cf() { |
| 77 return nullptr; | 77 return nullptr; |
| 78 } | 78 } |
| 79 | 79 |
| 80 static SkColorFilter* make_cf0() { | 80 static sk_sp<SkColorFilter> make_cf0() { |
| 81 uint8_t table[256]; make_table0(table); | 81 uint8_t table[256]; make_table0(table); |
| 82 return SkTableColorFilter::Create(table); | 82 return SkTableColorFilter::Make(table); |
| 83 } | 83 } |
| 84 static SkColorFilter* make_cf1() { | 84 static sk_sp<SkColorFilter> make_cf1() { |
| 85 uint8_t table[256]; make_table1(table); | 85 uint8_t table[256]; make_table1(table); |
| 86 return SkTableColorFilter::Create(table); | 86 return SkTableColorFilter::Make(table); |
| 87 } | 87 } |
| 88 static SkColorFilter* make_cf2() { | 88 static sk_sp<SkColorFilter> make_cf2() { |
| 89 uint8_t table[256]; make_table2(table); | 89 uint8_t table[256]; make_table2(table); |
| 90 return SkTableColorFilter::Create(table); | 90 return SkTableColorFilter::Make(table); |
| 91 } | 91 } |
| 92 static SkColorFilter* make_cf3() { | 92 static sk_sp<SkColorFilter> make_cf3() { |
| 93 uint8_t table0[256]; make_table0(table0); | 93 uint8_t table0[256]; make_table0(table0); |
| 94 uint8_t table1[256]; make_table1(table1); | 94 uint8_t table1[256]; make_table1(table1); |
| 95 uint8_t table2[256]; make_table2(table2); | 95 uint8_t table2[256]; make_table2(table2); |
| 96 return SkTableColorFilter::CreateARGB(nullptr, table0, table1, table2); | 96 return SkTableColorFilter::MakeARGB(nullptr, table0, table1, table2); |
| 97 } | 97 } |
| 98 | 98 |
| 99 class TableColorFilterGM : public skiagm::GM { | 99 class TableColorFilterGM : public skiagm::GM { |
| 100 public: | 100 public: |
| 101 TableColorFilterGM() {} | 101 TableColorFilterGM() {} |
| 102 | 102 |
| 103 protected: | 103 protected: |
| 104 virtual SkString onShortName() { | 104 virtual SkString onShortName() { |
| 105 return SkString("tablecolorfilter"); | 105 return SkString("tablecolorfilter"); |
| 106 } | 106 } |
| 107 | 107 |
| 108 virtual SkISize onISize() { | 108 virtual SkISize onISize() { |
| 109 return SkISize::Make(700, 1650); | 109 return SkISize::Make(700, 1650); |
| 110 } | 110 } |
| 111 | 111 |
| 112 virtual void onDraw(SkCanvas* canvas) { | 112 virtual void onDraw(SkCanvas* canvas) { |
| 113 canvas->drawColor(sk_tool_utils::color_to_565(0xFFDDDDDD)); | 113 canvas->drawColor(sk_tool_utils::color_to_565(0xFFDDDDDD)); |
| 114 canvas->translate(20, 20); | 114 canvas->translate(20, 20); |
| 115 | 115 |
| 116 | 116 |
| 117 static SkColorFilter* (*gColorFilterMakers[])() = { make_null_cf, make_c
f0, make_cf1, | 117 static sk_sp<SkColorFilter> (*gColorFilterMakers[])() = { |
| 118 make_cf2, make_cf3 }; | 118 make_null_cf, make_cf0, make_cf1, make_cf2, make_cf3 |
| 119 }; |
| 119 static void (*gBitmapMakers[])(SkBitmap*) = { make_bm0, make_bm1 }; | 120 static void (*gBitmapMakers[])(SkBitmap*) = { make_bm0, make_bm1 }; |
| 120 | 121 |
| 121 // This test will be done once for each bitmap with the results stacked
vertically. | 122 // This test will be done once for each bitmap with the results stacked
vertically. |
| 122 // For a single bitmap the resulting image will be the following: | 123 // For a single bitmap the resulting image will be the following: |
| 123 // - A first line with the original bitmap, followed by the image drawn
once | 124 // - A first line with the original bitmap, followed by the image drawn
once |
| 124 // with each of the N color filters | 125 // with each of the N color filters |
| 125 // - N lines of the bitmap drawn N times, this will cover all N*N combi
nations of | 126 // - N lines of the bitmap drawn N times, this will cover all N*N combi
nations of |
| 126 // pair of color filters in order to test the collpsing of consecutive
table | 127 // pair of color filters in order to test the collpsing of consecutive
table |
| 127 // color filters. | 128 // color filters. |
| 128 // | 129 // |
| (...skipping 19 matching lines...) Expand all Loading... |
| 148 | 149 |
| 149 // Draw the first element of the first line | 150 // Draw the first element of the first line |
| 150 x = 0; | 151 x = 0; |
| 151 SkPaint paint; | 152 SkPaint paint; |
| 152 canvas->drawBitmap(bm, x, y, &paint); | 153 canvas->drawBitmap(bm, x, y, &paint); |
| 153 | 154 |
| 154 // Draws the rest of the first line for this bitmap | 155 // Draws the rest of the first line for this bitmap |
| 155 // each draw being at xOffset of the previous one | 156 // each draw being at xOffset of the previous one |
| 156 for (unsigned i = 1; i < SK_ARRAY_COUNT(gColorFilterMakers); ++i) { | 157 for (unsigned i = 1; i < SK_ARRAY_COUNT(gColorFilterMakers); ++i) { |
| 157 x += xOffset; | 158 x += xOffset; |
| 158 paint.setColorFilter(gColorFilterMakers[i]())->unref(); | 159 paint.setColorFilter(gColorFilterMakers[i]()); |
| 159 canvas->drawBitmap(bm, x, y, &paint); | 160 canvas->drawBitmap(bm, x, y, &paint); |
| 160 } | 161 } |
| 161 | 162 |
| 162 paint.setColorFilter(nullptr); | 163 paint.setColorFilter(nullptr); |
| 163 | 164 |
| 164 for (unsigned i = 0; i < SK_ARRAY_COUNT(gColorFilterMakers); ++i) { | 165 for (unsigned i = 0; i < SK_ARRAY_COUNT(gColorFilterMakers); ++i) { |
| 165 SkAutoTUnref<SkColorFilter> colorFilter1(gColorFilterMakers[i]()
); | 166 auto colorFilter1(gColorFilterMakers[i]()); |
| 166 SkAutoTUnref<SkImageFilter> imageFilter1(SkColorFilterImageFilte
r::Create( | 167 SkAutoTUnref<SkImageFilter> imageFilter1(SkColorFilterImageFilte
r::Create( |
| 167 colorFilter1, nullptr, nullptr)); | 168 colorFilter1.get(), nullptr, nullptr)); |
| 168 | 169 |
| 169 // Move down to the next line and draw it | 170 // Move down to the next line and draw it |
| 170 // each draw being at xOffset of the previous one | 171 // each draw being at xOffset of the previous one |
| 171 y += yOffset; | 172 y += yOffset; |
| 172 x = 0; | 173 x = 0; |
| 173 for (unsigned j = 1; j < SK_ARRAY_COUNT(gColorFilterMakers); ++j
) { | 174 for (unsigned j = 1; j < SK_ARRAY_COUNT(gColorFilterMakers); ++j
) { |
| 174 SkAutoTUnref<SkColorFilter> colorFilter2(gColorFilterMakers[
j]()); | 175 auto colorFilter2(gColorFilterMakers[j]()); |
| 175 SkAutoTUnref<SkImageFilter> imageFilter2(SkColorFilterImageF
ilter::Create( | 176 SkAutoTUnref<SkImageFilter> imageFilter2(SkColorFilterImageF
ilter::Create( |
| 176 colorFilter2, imageFilter1, nullptr)); | 177 colorFilter2.get(), imageFilter1, nullptr)); |
| 177 paint.setImageFilter(imageFilter2); | 178 paint.setImageFilter(imageFilter2); |
| 178 canvas->drawBitmap(bm, x, y, &paint); | 179 canvas->drawBitmap(bm, x, y, &paint); |
| 179 x += xOffset; | 180 x += xOffset; |
| 180 } | 181 } |
| 181 } | 182 } |
| 182 | 183 |
| 183 // Move down one line to the beginning of the block for next bitmap | 184 // Move down one line to the beginning of the block for next bitmap |
| 184 y += yOffset; | 185 y += yOffset; |
| 185 } | 186 } |
| 186 } | 187 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 return SkISize::Make(790, 790); | 219 return SkISize::Make(790, 790); |
| 219 } | 220 } |
| 220 | 221 |
| 221 virtual void onDraw(SkCanvas* canvas) { | 222 virtual void onDraw(SkCanvas* canvas) { |
| 222 SkBitmap bm; | 223 SkBitmap bm; |
| 223 make_bm1(&bm); | 224 make_bm1(&bm); |
| 224 | 225 |
| 225 canvas->drawColor(sk_tool_utils::color_to_565(0xFFDDDDDD)); | 226 canvas->drawColor(sk_tool_utils::color_to_565(0xFFDDDDDD)); |
| 226 | 227 |
| 227 const int MODES = MODE_COUNT * COLOR_COUNT; | 228 const int MODES = MODE_COUNT * COLOR_COUNT; |
| 228 SkAutoTUnref<SkColorFilter> filters[MODES]; | 229 sk_sp<SkColorFilter> filters[MODES]; |
| 229 int index = 0; | 230 int index = 0; |
| 230 for (int i = 0; i < MODE_COUNT; ++i) { | 231 for (int i = 0; i < MODE_COUNT; ++i) { |
| 231 for (int j = 0; j < COLOR_COUNT; ++j) { | 232 for (int j = 0; j < COLOR_COUNT; ++j) { |
| 232 filters[index++].reset(SkColorFilter::CreateModeFilter(fColors[j
], fModes[i])); | 233 filters[index++] = SkColorFilter::MakeModeFilter(fColors[j], fMo
des[i]); |
| 233 } | 234 } |
| 234 } | 235 } |
| 235 | 236 |
| 236 SkPaint paint; | 237 SkPaint paint; |
| 237 paint.setShader(make_shader1(50, 50)); | 238 paint.setShader(make_shader1(50, 50)); |
| 238 SkRect r = SkRect::MakeWH(50, 50); | 239 SkRect r = SkRect::MakeWH(50, 50); |
| 239 const SkScalar spacer = 10; | 240 const SkScalar spacer = 10; |
| 240 | 241 |
| 241 canvas->translate(spacer, spacer); | 242 canvas->translate(spacer, spacer); |
| 242 | 243 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 254 canvas->translate(0, (i + 1) * (r.width() + spacer)); | 255 canvas->translate(0, (i + 1) * (r.width() + spacer)); |
| 255 canvas->drawRect(r, paint); | 256 canvas->drawRect(r, paint); |
| 256 canvas->restore(); | 257 canvas->restore(); |
| 257 } | 258 } |
| 258 | 259 |
| 259 canvas->translate(r.width() + spacer, r.width() + spacer); | 260 canvas->translate(r.width() + spacer, r.width() + spacer); |
| 260 | 261 |
| 261 for (int y = 0; y < MODES; ++y) { | 262 for (int y = 0; y < MODES; ++y) { |
| 262 canvas->save(); | 263 canvas->save(); |
| 263 for (int x = 0; x < MODES; ++x) { | 264 for (int x = 0; x < MODES; ++x) { |
| 264 SkAutoTUnref<SkColorFilter> compose(SkColorFilter::CreateCompose
Filter(filters[y], | 265 paint.setColorFilter(SkColorFilter::MakeComposeFilter(filters[y]
, filters[x])); |
| 265
filters[x])); | |
| 266 paint.setColorFilter(compose); | |
| 267 canvas->drawRect(r, paint); | 266 canvas->drawRect(r, paint); |
| 268 canvas->translate(r.width() + spacer, 0); | 267 canvas->translate(r.width() + spacer, 0); |
| 269 } | 268 } |
| 270 canvas->restore(); | 269 canvas->restore(); |
| 271 canvas->translate(0, r.height() + spacer); | 270 canvas->translate(0, r.height() + spacer); |
| 272 } | 271 } |
| 273 } | 272 } |
| 274 | 273 |
| 275 private: | 274 private: |
| 276 typedef GM INHERITED; | 275 typedef GM INHERITED; |
| 277 }; | 276 }; |
| 278 | 277 |
| 279 const SkColor gColors0[] = { SK_ColorCYAN, SK_ColorMAGENTA, SK_ColorYELLOW }; | 278 const SkColor gColors0[] = { SK_ColorCYAN, SK_ColorMAGENTA, SK_ColorYELLOW }; |
| 280 const SkXfermode::Mode gModes0[] = { | 279 const SkXfermode::Mode gModes0[] = { |
| 281 SkXfermode::kOverlay_Mode, | 280 SkXfermode::kOverlay_Mode, |
| 282 SkXfermode::kDarken_Mode, | 281 SkXfermode::kDarken_Mode, |
| 283 SkXfermode::kColorBurn_Mode, | 282 SkXfermode::kColorBurn_Mode, |
| 284 SkXfermode::kExclusion_Mode, | 283 SkXfermode::kExclusion_Mode, |
| 285 }; | 284 }; |
| 286 DEF_GM( return new ComposeColorFilterGM(gColors0, gModes0, "wacky"); ) | 285 DEF_GM( return new ComposeColorFilterGM(gColors0, gModes0, "wacky"); ) |
| 287 | 286 |
| 288 const SkColor gColors1[] = { 0x80FF0000, 0x8000FF00, 0x800000FF }; | 287 const SkColor gColors1[] = { 0x80FF0000, 0x8000FF00, 0x800000FF }; |
| 289 const SkXfermode::Mode gModes1[] = { | 288 const SkXfermode::Mode gModes1[] = { |
| 290 SkXfermode::kSrcOver_Mode, | 289 SkXfermode::kSrcOver_Mode, |
| 291 SkXfermode::kXor_Mode, | 290 SkXfermode::kXor_Mode, |
| 292 SkXfermode::kDstOut_Mode, | 291 SkXfermode::kDstOut_Mode, |
| 293 SkXfermode::kSrcATop_Mode, | 292 SkXfermode::kSrcATop_Mode, |
| 294 }; | 293 }; |
| 295 DEF_GM( return new ComposeColorFilterGM(gColors1, gModes1, "alpha"); ) | 294 DEF_GM( return new ComposeColorFilterGM(gColors1, gModes1, "alpha"); ) |
| OLD | NEW |