OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 "SkTableColorFilter.h" | 8 #include "SkTableColorFilter.h" |
9 | 9 |
10 #include "SkBitmap.h" | 10 #include "SkBitmap.h" |
(...skipping 28 matching lines...) Expand all Loading... |
39 } | 39 } |
40 if (tableB) { | 40 if (tableB) { |
41 memcpy(dst, tableB, 256); | 41 memcpy(dst, tableB, 256); |
42 fFlags |= kB_Flag; | 42 fFlags |= kB_Flag; |
43 } | 43 } |
44 } | 44 } |
45 | 45 |
46 virtual ~SkTable_ColorFilter() { delete fBitmap; } | 46 virtual ~SkTable_ColorFilter() { delete fBitmap; } |
47 | 47 |
48 bool asComponentTable(SkBitmap* table) const override; | 48 bool asComponentTable(SkBitmap* table) const override; |
49 SkColorFilter* newComposed(const SkColorFilter* inner) const override; | 49 sk_sp<SkColorFilter> makeComposed(sk_sp<SkColorFilter> inner) const override
; |
50 | 50 |
51 #if SK_SUPPORT_GPU | 51 #if SK_SUPPORT_GPU |
52 const GrFragmentProcessor* asFragmentProcessor(GrContext*) const override; | 52 const GrFragmentProcessor* asFragmentProcessor(GrContext*) const override; |
53 #endif | 53 #endif |
54 | 54 |
55 void filterSpan(const SkPMColor src[], int count, SkPMColor dst[]) const ove
rride; | 55 void filterSpan(const SkPMColor src[], int count, SkPMColor dst[]) const ove
rride; |
56 | 56 |
57 SK_TO_STRING_OVERRIDE() | 57 SK_TO_STRING_OVERRIDE() |
58 | 58 |
59 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkTable_ColorFilter) | 59 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkTable_ColorFilter) |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 ptr += 256; | 244 ptr += 256; |
245 } | 245 } |
246 if (flags & kG_Flag) { | 246 if (flags & kG_Flag) { |
247 g = ptr; | 247 g = ptr; |
248 ptr += 256; | 248 ptr += 256; |
249 } | 249 } |
250 if (flags & kB_Flag) { | 250 if (flags & kB_Flag) { |
251 b = ptr; | 251 b = ptr; |
252 ptr += 256; | 252 ptr += 256; |
253 } | 253 } |
254 return SkTableColorFilter::CreateARGB(a, r, g, b); | 254 return SkTableColorFilter::MakeARGB(a, r, g, b).release(); |
255 } | 255 } |
256 | 256 |
257 bool SkTable_ColorFilter::asComponentTable(SkBitmap* table) const { | 257 bool SkTable_ColorFilter::asComponentTable(SkBitmap* table) const { |
258 if (table) { | 258 if (table) { |
259 if (nullptr == fBitmap) { | 259 if (nullptr == fBitmap) { |
260 SkBitmap* bmp = new SkBitmap; | 260 SkBitmap* bmp = new SkBitmap; |
261 bmp->allocPixels(SkImageInfo::MakeA8(256, 4)); | 261 bmp->allocPixels(SkImageInfo::MakeA8(256, 4)); |
262 uint8_t* bitmapPixels = bmp->getAddr8(0, 0); | 262 uint8_t* bitmapPixels = bmp->getAddr8(0, 0); |
263 int offset = 0; | 263 int offset = 0; |
264 static const unsigned kFlags[] = { kA_Flag, kR_Flag, kG_Flag, kB_Fla
g }; | 264 static const unsigned kFlags[] = { kA_Flag, kR_Flag, kG_Flag, kB_Fla
g }; |
(...skipping 15 matching lines...) Expand all Loading... |
280 } | 280 } |
281 | 281 |
282 // Combines the two lookup tables so that making a lookup using res[] has | 282 // Combines the two lookup tables so that making a lookup using res[] has |
283 // the same effect as making a lookup through inner[] then outer[]. | 283 // the same effect as making a lookup through inner[] then outer[]. |
284 static void combine_tables(uint8_t res[256], const uint8_t outer[256], const uin
t8_t inner[256]) { | 284 static void combine_tables(uint8_t res[256], const uint8_t outer[256], const uin
t8_t inner[256]) { |
285 for (int i = 0; i < 256; i++) { | 285 for (int i = 0; i < 256; i++) { |
286 res[i] = outer[inner[i]]; | 286 res[i] = outer[inner[i]]; |
287 } | 287 } |
288 } | 288 } |
289 | 289 |
290 SkColorFilter* SkTable_ColorFilter::newComposed(const SkColorFilter* innerFilter
) const { | 290 sk_sp<SkColorFilter> SkTable_ColorFilter::makeComposed(sk_sp<SkColorFilter> inne
rFilter) const { |
291 SkBitmap innerBM; | 291 SkBitmap innerBM; |
292 if (!innerFilter->asComponentTable(&innerBM)) { | 292 if (!innerFilter->asComponentTable(&innerBM)) { |
293 return nullptr; | 293 return nullptr; |
294 } | 294 } |
295 | 295 |
296 innerBM.lockPixels(); | 296 innerBM.lockPixels(); |
297 if (nullptr == innerBM.getPixels()) { | 297 if (nullptr == innerBM.getPixels()) { |
298 return nullptr; | 298 return nullptr; |
299 } | 299 } |
300 | 300 |
(...skipping 18 matching lines...) Expand all Loading... |
319 uint8_t concatA[256]; | 319 uint8_t concatA[256]; |
320 uint8_t concatR[256]; | 320 uint8_t concatR[256]; |
321 uint8_t concatG[256]; | 321 uint8_t concatG[256]; |
322 uint8_t concatB[256]; | 322 uint8_t concatB[256]; |
323 | 323 |
324 combine_tables(concatA, tableA, innerBM.getAddr8(0, 0)); | 324 combine_tables(concatA, tableA, innerBM.getAddr8(0, 0)); |
325 combine_tables(concatR, tableR, innerBM.getAddr8(0, 1)); | 325 combine_tables(concatR, tableR, innerBM.getAddr8(0, 1)); |
326 combine_tables(concatG, tableG, innerBM.getAddr8(0, 2)); | 326 combine_tables(concatG, tableG, innerBM.getAddr8(0, 2)); |
327 combine_tables(concatB, tableB, innerBM.getAddr8(0, 3)); | 327 combine_tables(concatB, tableB, innerBM.getAddr8(0, 3)); |
328 | 328 |
329 return SkTableColorFilter::CreateARGB(concatA, concatR, concatG, concatB); | 329 return SkTableColorFilter::MakeARGB(concatA, concatR, concatG, concatB); |
330 } | 330 } |
331 | 331 |
332 #if SK_SUPPORT_GPU | 332 #if SK_SUPPORT_GPU |
333 | 333 |
334 #include "GrContext.h" | 334 #include "GrContext.h" |
335 #include "GrFragmentProcessor.h" | 335 #include "GrFragmentProcessor.h" |
336 #include "GrInvariantOutput.h" | 336 #include "GrInvariantOutput.h" |
337 #include "SkGr.h" | 337 #include "SkGr.h" |
338 #include "effects/GrTextureStripAtlas.h" | 338 #include "effects/GrTextureStripAtlas.h" |
339 #include "glsl/GrGLSLFragmentProcessor.h" | 339 #include "glsl/GrGLSLFragmentProcessor.h" |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
547 flags |= d->fRandom->nextBool() ? (1 << i): 0; | 547 flags |= d->fRandom->nextBool() ? (1 << i): 0; |
548 } | 548 } |
549 } while (!flags); | 549 } while (!flags); |
550 for (int i = 0; i < 4; ++i) { | 550 for (int i = 0; i < 4; ++i) { |
551 if (flags & (1 << i)) { | 551 if (flags & (1 << i)) { |
552 for (int j = 0; j < 256; ++j) { | 552 for (int j = 0; j < 256; ++j) { |
553 luts[j][i] = SkToU8(d->fRandom->nextBits(8)); | 553 luts[j][i] = SkToU8(d->fRandom->nextBits(8)); |
554 } | 554 } |
555 } | 555 } |
556 } | 556 } |
557 SkAutoTUnref<SkColorFilter> filter(SkTableColorFilter::CreateARGB( | 557 auto filter(SkTableColorFilter::MakeARGB( |
558 (flags & (1 << 0)) ? luts[0] : nullptr, | 558 (flags & (1 << 0)) ? luts[0] : nullptr, |
559 (flags & (1 << 1)) ? luts[1] : nullptr, | 559 (flags & (1 << 1)) ? luts[1] : nullptr, |
560 (flags & (1 << 2)) ? luts[2] : nullptr, | 560 (flags & (1 << 2)) ? luts[2] : nullptr, |
561 (flags & (1 << 3)) ? luts[3] : nullptr | 561 (flags & (1 << 3)) ? luts[3] : nullptr |
562 )); | 562 )); |
563 | 563 |
564 const GrFragmentProcessor* fp = filter->asFragmentProcessor(d->fContext); | 564 const GrFragmentProcessor* fp = filter->asFragmentProcessor(d->fContext); |
565 SkASSERT(fp); | 565 SkASSERT(fp); |
566 return fp; | 566 return fp; |
567 } | 567 } |
(...skipping 12 matching lines...) Expand all Loading... |
580 #ifdef SK_CPU_BENDIAN | 580 #ifdef SK_CPU_BENDIAN |
581 #else | 581 #else |
582 #define SK_A32_INDEX (3 - (SK_A32_SHIFT >> 3)) | 582 #define SK_A32_INDEX (3 - (SK_A32_SHIFT >> 3)) |
583 #define SK_R32_INDEX (3 - (SK_R32_SHIFT >> 3)) | 583 #define SK_R32_INDEX (3 - (SK_R32_SHIFT >> 3)) |
584 #define SK_G32_INDEX (3 - (SK_G32_SHIFT >> 3)) | 584 #define SK_G32_INDEX (3 - (SK_G32_SHIFT >> 3)) |
585 #define SK_B32_INDEX (3 - (SK_B32_SHIFT >> 3)) | 585 #define SK_B32_INDEX (3 - (SK_B32_SHIFT >> 3)) |
586 #endif | 586 #endif |
587 | 587 |
588 /////////////////////////////////////////////////////////////////////////////// | 588 /////////////////////////////////////////////////////////////////////////////// |
589 | 589 |
590 SkColorFilter* SkTableColorFilter::Create(const uint8_t table[256]) { | 590 sk_sp<SkColorFilter> SkTableColorFilter::Make(const uint8_t table[256]) { |
591 return new SkTable_ColorFilter(table, table, table, table); | 591 return sk_make_sp<SkTable_ColorFilter>(table, table, table, table); |
592 } | 592 } |
593 | 593 |
594 SkColorFilter* SkTableColorFilter::CreateARGB(const uint8_t tableA[256], | 594 sk_sp<SkColorFilter> SkTableColorFilter::MakeARGB(const uint8_t tableA[256], |
595 const uint8_t tableR[256], | 595 const uint8_t tableR[256], |
596 const uint8_t tableG[256], | 596 const uint8_t tableG[256], |
597 const uint8_t tableB[256]) { | 597 const uint8_t tableB[256]) { |
598 return new SkTable_ColorFilter(tableA, tableR, tableG, tableB); | 598 return sk_make_sp<SkTable_ColorFilter>(tableA, tableR, tableG, tableB); |
599 } | 599 } |
600 | 600 |
601 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkTableColorFilter) | 601 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkTableColorFilter) |
602 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkTable_ColorFilter) | 602 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkTable_ColorFilter) |
603 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 603 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
OLD | NEW |