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

Side by Side Diff: src/effects/gradients/SkGradientShader.cpp

Issue 296823008: Revert of Remove unused (by clients) SkUnitMapper (https://codereview.chromium.org/283273002/) (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 6 years, 7 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/core/SkValidatingReadBuffer.cpp ('k') | src/effects/gradients/SkGradientShaderPriv.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2006 The Android Open Source Project 2 * Copyright 2006 The Android Open Source Project
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 "SkGradientShaderPriv.h" 8 #include "SkGradientShaderPriv.h"
9 #include "SkLinearGradient.h" 9 #include "SkLinearGradient.h"
10 #include "SkRadialGradient.h" 10 #include "SkRadialGradient.h"
11 #include "SkTwoPointRadialGradient.h" 11 #include "SkTwoPointRadialGradient.h"
12 #include "SkTwoPointConicalGradient.h" 12 #include "SkTwoPointConicalGradient.h"
13 #include "SkSweepGradient.h" 13 #include "SkSweepGradient.h"
14 14
15 SkGradientShaderBase::SkGradientShaderBase(const Descriptor& desc, const SkMatri x* localMatrix) 15 SkGradientShaderBase::SkGradientShaderBase(const Descriptor& desc, const SkMatri x* localMatrix)
16 : INHERITED(localMatrix) 16 : INHERITED(localMatrix)
17 { 17 {
18 SkASSERT(desc.fCount > 1); 18 SkASSERT(desc.fCount > 1);
19 19
20 fMapper = desc.fMapper;
21 SkSafeRef(fMapper);
20 fGradFlags = SkToU8(desc.fGradFlags); 22 fGradFlags = SkToU8(desc.fGradFlags);
21 23
22 SkASSERT((unsigned)desc.fTileMode < SkShader::kTileModeCount); 24 SkASSERT((unsigned)desc.fTileMode < SkShader::kTileModeCount);
23 SkASSERT(SkShader::kTileModeCount == SK_ARRAY_COUNT(gTileProcs)); 25 SkASSERT(SkShader::kTileModeCount == SK_ARRAY_COUNT(gTileProcs));
24 fTileMode = desc.fTileMode; 26 fTileMode = desc.fTileMode;
25 fTileProc = gTileProcs[desc.fTileMode]; 27 fTileProc = gTileProcs[desc.fTileMode];
26 28
27 /* Note: we let the caller skip the first and/or last position. 29 /* Note: we let the caller skip the first and/or last position.
28 i.e. pos[0] = 0.3, pos[1] = 0.7 30 i.e. pos[0] = 0.3, pos[1] = 0.7
29 In these cases, we insert dummy entries to ensure that the final data 31 In these cases, we insert dummy entries to ensure that the final data
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 135
134 static SkShader::TileMode unpack_mode(uint32_t packed) { 136 static SkShader::TileMode unpack_mode(uint32_t packed) {
135 return (SkShader::TileMode)(packed & 0xF); 137 return (SkShader::TileMode)(packed & 0xF);
136 } 138 }
137 139
138 static uint32_t unpack_flags(uint32_t packed) { 140 static uint32_t unpack_flags(uint32_t packed) {
139 return packed >> 4; 141 return packed >> 4;
140 } 142 }
141 143
142 SkGradientShaderBase::SkGradientShaderBase(SkReadBuffer& buffer) : INHERITED(buf fer) { 144 SkGradientShaderBase::SkGradientShaderBase(SkReadBuffer& buffer) : INHERITED(buf fer) {
143 if (buffer.isVersionLT(SkReadBuffer::kNoUnitMappers_Version)) { 145 fMapper = buffer.readUnitMapper();
144 // skip the old SkUnitMapper slot
145 buffer.skipFlattenable();
146 }
147 146
148 int colorCount = fColorCount = buffer.getArrayCount(); 147 int colorCount = fColorCount = buffer.getArrayCount();
149 if (colorCount > kColorStorageCount) { 148 if (colorCount > kColorStorageCount) {
150 size_t allocSize = (sizeof(SkColor) + sizeof(SkPMColor) + sizeof(Rec)) * colorCount; 149 size_t allocSize = (sizeof(SkColor) + sizeof(SkPMColor) + sizeof(Rec)) * colorCount;
151 if (buffer.validateAvailable(allocSize)) { 150 if (buffer.validateAvailable(allocSize)) {
152 fOrigColors = reinterpret_cast<SkColor*>(sk_malloc_throw(allocSize)) ; 151 fOrigColors = reinterpret_cast<SkColor*>(sk_malloc_throw(allocSize)) ;
153 } else { 152 } else {
154 fOrigColors = NULL; 153 fOrigColors = NULL;
155 colorCount = fColorCount = 0; 154 colorCount = fColorCount = 0;
156 } 155 }
(...skipping 18 matching lines...) Expand all
175 } 174 }
176 } 175 }
177 buffer.readMatrix(&fPtsToUnit); 176 buffer.readMatrix(&fPtsToUnit);
178 this->initCommon(); 177 this->initCommon();
179 } 178 }
180 179
181 SkGradientShaderBase::~SkGradientShaderBase() { 180 SkGradientShaderBase::~SkGradientShaderBase() {
182 if (fOrigColors != fStorage) { 181 if (fOrigColors != fStorage) {
183 sk_free(fOrigColors); 182 sk_free(fOrigColors);
184 } 183 }
184 SkSafeUnref(fMapper);
185 } 185 }
186 186
187 void SkGradientShaderBase::initCommon() { 187 void SkGradientShaderBase::initCommon() {
188 unsigned colorAlpha = 0xFF; 188 unsigned colorAlpha = 0xFF;
189 for (int i = 0; i < fColorCount; i++) { 189 for (int i = 0; i < fColorCount; i++) {
190 colorAlpha &= SkColorGetA(fOrigColors[i]); 190 colorAlpha &= SkColorGetA(fOrigColors[i]);
191 } 191 }
192 fColorsAreOpaque = colorAlpha == 0xFF; 192 fColorsAreOpaque = colorAlpha == 0xFF;
193 } 193 }
194 194
195 void SkGradientShaderBase::flatten(SkWriteBuffer& buffer) const { 195 void SkGradientShaderBase::flatten(SkWriteBuffer& buffer) const {
196 this->INHERITED::flatten(buffer); 196 this->INHERITED::flatten(buffer);
197 buffer.writeFlattenable(fMapper);
197 buffer.writeColorArray(fOrigColors, fColorCount); 198 buffer.writeColorArray(fOrigColors, fColorCount);
198 buffer.writeUInt(pack_mode_flags(fTileMode, fGradFlags)); 199 buffer.writeUInt(pack_mode_flags(fTileMode, fGradFlags));
199 if (fColorCount > 2) { 200 if (fColorCount > 2) {
200 Rec* recs = fRecs; 201 Rec* recs = fRecs;
201 for (int i = 1; i < fColorCount; i++) { 202 for (int i = 1; i < fColorCount; i++) {
202 buffer.writeInt(recs[i].fPos); 203 buffer.writeInt(recs[i].fPos);
203 buffer.writeUInt(recs[i].fScale); 204 buffer.writeUInt(recs[i].fScale);
204 } 205 }
205 } 206 }
206 buffer.writeMatrix(fPtsToUnit); 207 buffer.writeMatrix(fPtsToUnit);
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
520 for (int i = 1; i < cache->fShader.fColorCount; i++) { 521 for (int i = 1; i < cache->fShader.fColorCount; i++) {
521 int nextIndex = SkFixedToFFFF(rec[i].fPos) >> kCache16Shift; 522 int nextIndex = SkFixedToFFFF(rec[i].fPos) >> kCache16Shift;
522 SkASSERT(nextIndex < kCache16Count); 523 SkASSERT(nextIndex < kCache16Count);
523 524
524 if (nextIndex > prevIndex) 525 if (nextIndex > prevIndex)
525 Build16bitCache(cache->fCache16 + prevIndex, cache->fShader.fOri gColors[i-1], 526 Build16bitCache(cache->fCache16 + prevIndex, cache->fShader.fOri gColors[i-1],
526 cache->fShader.fOrigColors[i], nextIndex - prevI ndex + 1); 527 cache->fShader.fOrigColors[i], nextIndex - prevI ndex + 1);
527 prevIndex = nextIndex; 528 prevIndex = nextIndex;
528 } 529 }
529 } 530 }
531
532 if (cache->fShader.fMapper) {
533 cache->fCache16Storage = (uint16_t*)sk_malloc_throw(allocSize);
534 uint16_t* linear = cache->fCache16; // just computed linear data
535 uint16_t* mapped = cache->fCache16Storage; // storage for mapped data
536 SkUnitMapper* map = cache->fShader.fMapper;
537 for (int i = 0; i < kCache16Count; i++) {
538 int index = map->mapUnit16(bitsTo16(i, kCache16Bits)) >> kCache16Shi ft;
539 mapped[i] = linear[index];
540 mapped[i + kCache16Count] = linear[index + kCache16Count];
541 }
542 sk_free(cache->fCache16);
543 cache->fCache16 = cache->fCache16Storage;
544 }
530 } 545 }
531 546
532 const SkPMColor* SkGradientShaderBase::GradientShaderCache::getCache32() { 547 const SkPMColor* SkGradientShaderBase::GradientShaderCache::getCache32() {
533 SkOnce(&fCache32Inited, &fCache32Mutex, SkGradientShaderBase::GradientShader Cache::initCache32, 548 SkOnce(&fCache32Inited, &fCache32Mutex, SkGradientShaderBase::GradientShader Cache::initCache32,
534 this); 549 this);
535 SkASSERT(fCache32); 550 SkASSERT(fCache32);
536 return fCache32; 551 return fCache32;
537 } 552 }
538 553
539 void SkGradientShaderBase::GradientShaderCache::initCache32(GradientShaderCache* cache) { 554 void SkGradientShaderBase::GradientShaderCache::initCache32(GradientShaderCache* cache) {
(...skipping 17 matching lines...) Expand all
557 int nextIndex = SkFixedToFFFF(rec[i].fPos) >> kCache32Shift; 572 int nextIndex = SkFixedToFFFF(rec[i].fPos) >> kCache32Shift;
558 SkASSERT(nextIndex < kCache32Count); 573 SkASSERT(nextIndex < kCache32Count);
559 574
560 if (nextIndex > prevIndex) 575 if (nextIndex > prevIndex)
561 Build32bitCache(cache->fCache32 + prevIndex, cache->fShader.fOri gColors[i-1], 576 Build32bitCache(cache->fCache32 + prevIndex, cache->fShader.fOri gColors[i-1],
562 cache->fShader.fOrigColors[i], nextIndex - prevI ndex + 1, 577 cache->fShader.fOrigColors[i], nextIndex - prevI ndex + 1,
563 cache->fCacheAlpha, cache->fShader.fGradFlags); 578 cache->fCacheAlpha, cache->fShader.fGradFlags);
564 prevIndex = nextIndex; 579 prevIndex = nextIndex;
565 } 580 }
566 } 581 }
582
583 if (cache->fShader.fMapper) {
584 SkMallocPixelRef* newPR = SkMallocPixelRef::NewAllocate(info, 0, NULL);
585 SkPMColor* linear = cache->fCache32; // just computed linear d ata
586 SkPMColor* mapped = (SkPMColor*)newPR->getAddr(); // storage for mapp ed data
587 SkUnitMapper* map = cache->fShader.fMapper;
588 for (int i = 0; i < kCache32Count; i++) {
589 int index = map->mapUnit16((i << 8) | i) >> 8;
590 mapped[i + kCache32Count*0] = linear[index + kCache32Count*0];
591 mapped[i + kCache32Count*1] = linear[index + kCache32Count*1];
592 mapped[i + kCache32Count*2] = linear[index + kCache32Count*2];
593 mapped[i + kCache32Count*3] = linear[index + kCache32Count*3];
594 }
595 cache->fCache32PixelRef->unref();
596 cache->fCache32PixelRef = newPR;
597 cache->fCache32 = (SkPMColor*)newPR->getAddr();
598 }
567 } 599 }
568 600
569 /* 601 /*
570 * The gradient holds a cache for the most recent value of alpha. Successive 602 * The gradient holds a cache for the most recent value of alpha. Successive
571 * callers with the same alpha value will share the same cache. 603 * callers with the same alpha value will share the same cache.
572 */ 604 */
573 SkGradientShaderBase::GradientShaderCache* SkGradientShaderBase::refCache(U8CPU alpha) const { 605 SkGradientShaderBase::GradientShaderCache* SkGradientShaderBase::refCache(U8CPU alpha) const {
574 SkAutoMutexAcquire ama(fCacheMutex); 606 SkAutoMutexAcquire ama(fCacheMutex);
575 if (!fCache || fCache->getAlpha() != alpha) { 607 if (!fCache || fCache->getAlpha() != alpha) {
576 fCache.reset(SkNEW_ARGS(GradientShaderCache, (alpha, *this))); 608 fCache.reset(SkNEW_ARGS(GradientShaderCache, (alpha, *this)));
(...skipping 11 matching lines...) Expand all
588 * allowing the client to utilize a cache of our bitmap (e.g. with a GPU). 620 * allowing the client to utilize a cache of our bitmap (e.g. with a GPU).
589 * To do that, we maintain a private cache of built-bitmaps, based on our 621 * To do that, we maintain a private cache of built-bitmaps, based on our
590 * colors and positions. Note: we don't try to flatten the fMapper, so if one 622 * colors and positions. Note: we don't try to flatten the fMapper, so if one
591 * is present, we skip the cache for now. 623 * is present, we skip the cache for now.
592 */ 624 */
593 void SkGradientShaderBase::getGradientTableBitmap(SkBitmap* bitmap) const { 625 void SkGradientShaderBase::getGradientTableBitmap(SkBitmap* bitmap) const {
594 // our caller assumes no external alpha, so we ensure that our cache is 626 // our caller assumes no external alpha, so we ensure that our cache is
595 // built with 0xFF 627 // built with 0xFF
596 SkAutoTUnref<GradientShaderCache> cache(this->refCache(0xFF)); 628 SkAutoTUnref<GradientShaderCache> cache(this->refCache(0xFF));
597 629
630 // don't have a way to put the mapper into our cache-key yet
631 if (fMapper) {
632 // force our cache32pixelref to be built
633 (void)cache->getCache32();
634 bitmap->setConfig(SkImageInfo::MakeN32Premul(kCache32Count, 1));
635 bitmap->setPixelRef(cache->getCache32PixelRef());
636 return;
637 }
638
598 // build our key: [numColors + colors[] + {positions[]} + flags ] 639 // build our key: [numColors + colors[] + {positions[]} + flags ]
599 int count = 1 + fColorCount + 1; 640 int count = 1 + fColorCount + 1;
600 if (fColorCount > 2) { 641 if (fColorCount > 2) {
601 count += fColorCount - 1; // fRecs[].fPos 642 count += fColorCount - 1; // fRecs[].fPos
602 } 643 }
603 644
604 SkAutoSTMalloc<16, int32_t> storage(count); 645 SkAutoSTMalloc<16, int32_t> storage(count);
605 int32_t* buffer = storage.get(); 646 int32_t* buffer = storage.get();
606 647
607 *buffer++ = fColorCount; 648 *buffer++ = fColorCount;
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
696 str->append(")"); 737 str->append(")");
697 } 738 }
698 739
699 static const char* gTileModeName[SkShader::kTileModeCount] = { 740 static const char* gTileModeName[SkShader::kTileModeCount] = {
700 "clamp", "repeat", "mirror" 741 "clamp", "repeat", "mirror"
701 }; 742 };
702 743
703 str->append(" "); 744 str->append(" ");
704 str->append(gTileModeName[fTileMode]); 745 str->append(gTileModeName[fTileMode]);
705 746
747 // TODO: add "fMapper->toString(str);" when SkUnitMapper::toString is added
748
706 this->INHERITED::toString(str); 749 this->INHERITED::toString(str);
707 } 750 }
708 #endif 751 #endif
709 752
710 /////////////////////////////////////////////////////////////////////////////// 753 ///////////////////////////////////////////////////////////////////////////////
711 /////////////////////////////////////////////////////////////////////////////// 754 ///////////////////////////////////////////////////////////////////////////////
712 755
713 #include "SkEmptyShader.h" 756 #include "SkEmptyShader.h"
714 757
715 // assumes colors is SkColor* and pos is SkScalar* 758 // assumes colors is SkColor* and pos is SkScalar*
716 #define EXPAND_1_COLOR(count) \ 759 #define EXPAND_1_COLOR(count) \
717 SkColor tmp[2]; \ 760 SkColor tmp[2]; \
718 do { \ 761 do { \
719 if (1 == count) { \ 762 if (1 == count) { \
720 tmp[0] = tmp[1] = colors[0]; \ 763 tmp[0] = tmp[1] = colors[0]; \
721 colors = tmp; \ 764 colors = tmp; \
722 pos = NULL; \ 765 pos = NULL; \
723 count = 2; \ 766 count = 2; \
724 } \ 767 } \
725 } while (0) 768 } while (0)
726 769
727 static void desc_init(SkGradientShaderBase::Descriptor* desc, 770 static void desc_init(SkGradientShaderBase::Descriptor* desc,
728 const SkColor colors[], 771 const SkColor colors[],
729 const SkScalar pos[], int colorCount, 772 const SkScalar pos[], int colorCount,
730 SkShader::TileMode mode, uint32_t flags) { 773 SkShader::TileMode mode,
774 SkUnitMapper* mapper, uint32_t flags) {
731 desc->fColors = colors; 775 desc->fColors = colors;
732 desc->fPos = pos; 776 desc->fPos = pos;
733 desc->fCount = colorCount; 777 desc->fCount = colorCount;
734 desc->fTileMode = mode; 778 desc->fTileMode = mode;
779 desc->fMapper = mapper;
735 desc->fGradFlags = flags; 780 desc->fGradFlags = flags;
736 } 781 }
737 782
738 SkShader* SkGradientShader::CreateLinear(const SkPoint pts[2], 783 SkShader* SkGradientShader::CreateLinear(const SkPoint pts[2],
739 const SkColor colors[], 784 const SkColor colors[],
740 const SkScalar pos[], int colorCount, 785 const SkScalar pos[], int colorCount,
741 SkShader::TileMode mode, 786 SkShader::TileMode mode,
787 SkUnitMapper* mapper,
742 uint32_t flags, 788 uint32_t flags,
743 const SkMatrix* localMatrix) { 789 const SkMatrix* localMatrix) {
744 if (NULL == pts || NULL == colors || colorCount < 1) { 790 if (NULL == pts || NULL == colors || colorCount < 1) {
745 return NULL; 791 return NULL;
746 } 792 }
747 EXPAND_1_COLOR(colorCount); 793 EXPAND_1_COLOR(colorCount);
748 794
749 SkGradientShaderBase::Descriptor desc; 795 SkGradientShaderBase::Descriptor desc;
750 desc_init(&desc, colors, pos, colorCount, mode, flags); 796 desc_init(&desc, colors, pos, colorCount, mode, mapper, flags);
751 return SkNEW_ARGS(SkLinearGradient, (pts, desc, localMatrix)); 797 return SkNEW_ARGS(SkLinearGradient, (pts, desc, localMatrix));
752 } 798 }
753 799
754 SkShader* SkGradientShader::CreateRadial(const SkPoint& center, SkScalar radius, 800 SkShader* SkGradientShader::CreateRadial(const SkPoint& center, SkScalar radius,
755 const SkColor colors[], 801 const SkColor colors[],
756 const SkScalar pos[], int colorCount, 802 const SkScalar pos[], int colorCount,
757 SkShader::TileMode mode, 803 SkShader::TileMode mode,
804 SkUnitMapper* mapper,
758 uint32_t flags, 805 uint32_t flags,
759 const SkMatrix* localMatrix) { 806 const SkMatrix* localMatrix) {
760 if (radius <= 0 || NULL == colors || colorCount < 1) { 807 if (radius <= 0 || NULL == colors || colorCount < 1) {
761 return NULL; 808 return NULL;
762 } 809 }
763 EXPAND_1_COLOR(colorCount); 810 EXPAND_1_COLOR(colorCount);
764 811
765 SkGradientShaderBase::Descriptor desc; 812 SkGradientShaderBase::Descriptor desc;
766 desc_init(&desc, colors, pos, colorCount, mode, flags); 813 desc_init(&desc, colors, pos, colorCount, mode, mapper, flags);
767 return SkNEW_ARGS(SkRadialGradient, (center, radius, desc, localMatrix)); 814 return SkNEW_ARGS(SkRadialGradient, (center, radius, desc, localMatrix));
768 } 815 }
769 816
770 SkShader* SkGradientShader::CreateTwoPointRadial(const SkPoint& start, 817 SkShader* SkGradientShader::CreateTwoPointRadial(const SkPoint& start,
771 SkScalar startRadius, 818 SkScalar startRadius,
772 const SkPoint& end, 819 const SkPoint& end,
773 SkScalar endRadius, 820 SkScalar endRadius,
774 const SkColor colors[], 821 const SkColor colors[],
775 const SkScalar pos[], 822 const SkScalar pos[],
776 int colorCount, 823 int colorCount,
777 SkShader::TileMode mode, 824 SkShader::TileMode mode,
825 SkUnitMapper* mapper,
778 uint32_t flags, 826 uint32_t flags,
779 const SkMatrix* localMatrix) { 827 const SkMatrix* localMatrix) {
780 if (startRadius < 0 || endRadius < 0 || NULL == colors || colorCount < 1) { 828 if (startRadius < 0 || endRadius < 0 || NULL == colors || colorCount < 1) {
781 return NULL; 829 return NULL;
782 } 830 }
783 EXPAND_1_COLOR(colorCount); 831 EXPAND_1_COLOR(colorCount);
784 832
785 SkGradientShaderBase::Descriptor desc; 833 SkGradientShaderBase::Descriptor desc;
786 desc_init(&desc, colors, pos, colorCount, mode, flags); 834 desc_init(&desc, colors, pos, colorCount, mode, mapper, flags);
787 return SkNEW_ARGS(SkTwoPointRadialGradient, 835 return SkNEW_ARGS(SkTwoPointRadialGradient,
788 (start, startRadius, end, endRadius, desc, localMatrix)); 836 (start, startRadius, end, endRadius, desc, localMatrix));
789 } 837 }
790 838
791 SkShader* SkGradientShader::CreateTwoPointConical(const SkPoint& start, 839 SkShader* SkGradientShader::CreateTwoPointConical(const SkPoint& start,
792 SkScalar startRadius, 840 SkScalar startRadius,
793 const SkPoint& end, 841 const SkPoint& end,
794 SkScalar endRadius, 842 SkScalar endRadius,
795 const SkColor colors[], 843 const SkColor colors[],
796 const SkScalar pos[], 844 const SkScalar pos[],
797 int colorCount, 845 int colorCount,
798 SkShader::TileMode mode, 846 SkShader::TileMode mode,
847 SkUnitMapper* mapper,
799 uint32_t flags, 848 uint32_t flags,
800 const SkMatrix* localMatrix) { 849 const SkMatrix* localMatrix) {
801 if (startRadius < 0 || endRadius < 0 || NULL == colors || colorCount < 1) { 850 if (startRadius < 0 || endRadius < 0 || NULL == colors || colorCount < 1) {
802 return NULL; 851 return NULL;
803 } 852 }
804 if (start == end && startRadius == endRadius) { 853 if (start == end && startRadius == endRadius) {
805 return SkNEW(SkEmptyShader); 854 return SkNEW(SkEmptyShader);
806 } 855 }
807 856
808 EXPAND_1_COLOR(colorCount); 857 EXPAND_1_COLOR(colorCount);
809 858
810 bool flipGradient = startRadius > endRadius; 859 bool flipGradient = startRadius > endRadius;
811 860
812 SkGradientShaderBase::Descriptor desc; 861 SkGradientShaderBase::Descriptor desc;
813 862
814 if (!flipGradient) { 863 if (!flipGradient) {
815 desc_init(&desc, colors, pos, colorCount, mode, flags); 864 desc_init(&desc, colors, pos, colorCount, mode, mapper, flags);
816 return SkNEW_ARGS(SkTwoPointConicalGradient, 865 return SkNEW_ARGS(SkTwoPointConicalGradient,
817 (start, startRadius, end, endRadius, flipGradient, des c, localMatrix)); 866 (start, startRadius, end, endRadius, flipGradient, des c, localMatrix));
818 } else { 867 } else {
819 SkAutoSTArray<8, SkColor> colorsNew(colorCount); 868 SkAutoSTArray<8, SkColor> colorsNew(colorCount);
820 SkAutoSTArray<8, SkScalar> posNew(colorCount); 869 SkAutoSTArray<8, SkScalar> posNew(colorCount);
821 for (int i = 0; i < colorCount; ++i) { 870 for (int i = 0; i < colorCount; ++i) {
822 colorsNew[i] = colors[colorCount - i - 1]; 871 colorsNew[i] = colors[colorCount - i - 1];
823 } 872 }
824 873
825 if (pos) { 874 if (pos) {
826 for (int i = 0; i < colorCount; ++i) { 875 for (int i = 0; i < colorCount; ++i) {
827 posNew[i] = 1 - pos[colorCount - i - 1]; 876 posNew[i] = 1 - pos[colorCount - i - 1];
828 } 877 }
829 desc_init(&desc, colorsNew.get(), posNew.get(), colorCount, mode, fl ags); 878 desc_init(&desc, colorsNew.get(), posNew.get(), colorCount, mode, ma pper, flags);
830 } else { 879 } else {
831 desc_init(&desc, colorsNew.get(), NULL, colorCount, mode, flags); 880 desc_init(&desc, colorsNew.get(), NULL, colorCount, mode, mapper, fl ags);
832 } 881 }
833 882
834 return SkNEW_ARGS(SkTwoPointConicalGradient, 883 return SkNEW_ARGS(SkTwoPointConicalGradient,
835 (end, endRadius, start, startRadius, flipGradient, des c, localMatrix)); 884 (end, endRadius, start, startRadius, flipGradient, des c, localMatrix));
836 } 885 }
837 } 886 }
838 887
839 SkShader* SkGradientShader::CreateSweep(SkScalar cx, SkScalar cy, 888 SkShader* SkGradientShader::CreateSweep(SkScalar cx, SkScalar cy,
840 const SkColor colors[], 889 const SkColor colors[],
841 const SkScalar pos[], 890 const SkScalar pos[],
842 int colorCount, 891 int colorCount, SkUnitMapper* mapper,
843 uint32_t flags, 892 uint32_t flags,
844 const SkMatrix* localMatrix) { 893 const SkMatrix* localMatrix) {
845 if (NULL == colors || colorCount < 1) { 894 if (NULL == colors || colorCount < 1) {
846 return NULL; 895 return NULL;
847 } 896 }
848 EXPAND_1_COLOR(colorCount); 897 EXPAND_1_COLOR(colorCount);
849 898
850 SkGradientShaderBase::Descriptor desc; 899 SkGradientShaderBase::Descriptor desc;
851 desc_init(&desc, colors, pos, colorCount, SkShader::kClamp_TileMode, flags); 900 desc_init(&desc, colors, pos, colorCount, SkShader::kClamp_TileMode, mapper, flags);
852 return SkNEW_ARGS(SkSweepGradient, (cx, cy, desc, localMatrix)); 901 return SkNEW_ARGS(SkSweepGradient, (cx, cy, desc, localMatrix));
853 } 902 }
854 903
855 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkGradientShader) 904 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkGradientShader)
856 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkLinearGradient) 905 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkLinearGradient)
857 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkRadialGradient) 906 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkRadialGradient)
858 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSweepGradient) 907 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSweepGradient)
859 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkTwoPointRadialGradient) 908 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkTwoPointRadialGradient)
860 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkTwoPointConicalGradient) 909 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkTwoPointConicalGradient)
861 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END 910 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
1161 (*stops)[i] = stop; 1210 (*stops)[i] = stop;
1162 stop = i < outColors - 1 ? stop + random->nextUScalar1() * (1.f - st op) : 1.f; 1211 stop = i < outColors - 1 ? stop + random->nextUScalar1() * (1.f - st op) : 1.f;
1163 } 1212 }
1164 } 1213 }
1165 *tm = static_cast<SkShader::TileMode>(random->nextULessThan(SkShader::kTileM odeCount)); 1214 *tm = static_cast<SkShader::TileMode>(random->nextULessThan(SkShader::kTileM odeCount));
1166 1215
1167 return outColors; 1216 return outColors;
1168 } 1217 }
1169 1218
1170 #endif 1219 #endif
OLDNEW
« no previous file with comments | « src/core/SkValidatingReadBuffer.cpp ('k') | src/effects/gradients/SkGradientShaderPriv.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698