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

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

Issue 111323005: Remvoe duplicate impl for SkImageInfo flattening (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years 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/SkPixelRef.cpp ('k') | src/gpu/GrSurface.cpp » ('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"
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 } 506 }
507 sk_free(fCache16); 507 sk_free(fCache16);
508 fCache16 = fCache16Storage; 508 fCache16 = fCache16Storage;
509 } 509 }
510 } 510 }
511 return fCache16; 511 return fCache16;
512 } 512 }
513 513
514 const SkPMColor* SkGradientShaderBase::getCache32() const { 514 const SkPMColor* SkGradientShaderBase::getCache32() const {
515 if (fCache32 == NULL) { 515 if (fCache32 == NULL) {
516 // double the count for dither entries 516 SkImageInfo info;
517 const int entryCount = kCache32Count * 4; 517 info.fWidth = kCache32Count;
518 const size_t allocSize = sizeof(SkPMColor) * entryCount; 518 info.fHeight = 4; // for our 4 dither rows
519 info.fAlphaType = kPremul_SkAlphaType;
520 info.fColorType = kPMColor_SkColorType;
519 521
520 if (NULL == fCache32PixelRef) { 522 if (NULL == fCache32PixelRef) {
521 fCache32PixelRef = SkNEW_ARGS(SkMallocPixelRef, 523 fCache32PixelRef = SkMallocPixelRef::NewAllocate(info, 0, NULL);
522 (NULL, allocSize, NULL));
523 } 524 }
524 fCache32 = (SkPMColor*)fCache32PixelRef->getAddr(); 525 fCache32 = (SkPMColor*)fCache32PixelRef->getAddr();
525 if (fColorCount == 2) { 526 if (fColorCount == 2) {
526 Build32bitCache(fCache32, fOrigColors[0], fOrigColors[1], 527 Build32bitCache(fCache32, fOrigColors[0], fOrigColors[1],
527 kCache32Count, fCacheAlpha, fGradFlags); 528 kCache32Count, fCacheAlpha, fGradFlags);
528 } else { 529 } else {
529 Rec* rec = fRecs; 530 Rec* rec = fRecs;
530 int prevIndex = 0; 531 int prevIndex = 0;
531 for (int i = 1; i < fColorCount; i++) { 532 for (int i = 1; i < fColorCount; i++) {
532 int nextIndex = SkFixedToFFFF(rec[i].fPos) >> kCache32Shift; 533 int nextIndex = SkFixedToFFFF(rec[i].fPos) >> kCache32Shift;
533 SkASSERT(nextIndex < kCache32Count); 534 SkASSERT(nextIndex < kCache32Count);
534 535
535 if (nextIndex > prevIndex) 536 if (nextIndex > prevIndex)
536 Build32bitCache(fCache32 + prevIndex, fOrigColors[i-1], 537 Build32bitCache(fCache32 + prevIndex, fOrigColors[i-1],
537 fOrigColors[i], nextIndex - prevIndex + 1, 538 fOrigColors[i], nextIndex - prevIndex + 1,
538 fCacheAlpha, fGradFlags); 539 fCacheAlpha, fGradFlags);
539 prevIndex = nextIndex; 540 prevIndex = nextIndex;
540 } 541 }
541 } 542 }
542 543
543 if (fMapper) { 544 if (fMapper) {
544 SkMallocPixelRef* newPR = SkNEW_ARGS(SkMallocPixelRef, 545 SkMallocPixelRef* newPR = SkMallocPixelRef::NewAllocate(info, 0, NUL L);
545 (NULL, allocSize, NULL));
546 SkPMColor* linear = fCache32; // just computed linear data 546 SkPMColor* linear = fCache32; // just computed linear data
547 SkPMColor* mapped = (SkPMColor*)newPR->getAddr(); // storage for mapped data 547 SkPMColor* mapped = (SkPMColor*)newPR->getAddr(); // storage for mapped data
548 SkUnitMapper* map = fMapper; 548 SkUnitMapper* map = fMapper;
549 for (int i = 0; i < kCache32Count; i++) { 549 for (int i = 0; i < kCache32Count; i++) {
550 int index = map->mapUnit16((i << 8) | i) >> 8; 550 int index = map->mapUnit16((i << 8) | i) >> 8;
551 mapped[i + kCache32Count*0] = linear[index + kCache32Count*0]; 551 mapped[i + kCache32Count*0] = linear[index + kCache32Count*0];
552 mapped[i + kCache32Count*1] = linear[index + kCache32Count*1]; 552 mapped[i + kCache32Count*1] = linear[index + kCache32Count*1];
553 mapped[i + kCache32Count*2] = linear[index + kCache32Count*2]; 553 mapped[i + kCache32Count*2] = linear[index + kCache32Count*2];
554 mapped[i + kCache32Count*3] = linear[index + kCache32Count*3]; 554 mapped[i + kCache32Count*3] = linear[index + kCache32Count*3];
555 } 555 }
(...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after
1133 (*stops)[i] = stop; 1133 (*stops)[i] = stop;
1134 stop = i < outColors - 1 ? stop + random->nextUScalar1() * (1.f - st op) : 1.f; 1134 stop = i < outColors - 1 ? stop + random->nextUScalar1() * (1.f - st op) : 1.f;
1135 } 1135 }
1136 } 1136 }
1137 *tm = static_cast<SkShader::TileMode>(random->nextULessThan(SkShader::kTileM odeCount)); 1137 *tm = static_cast<SkShader::TileMode>(random->nextULessThan(SkShader::kTileM odeCount));
1138 1138
1139 return outColors; 1139 return outColors;
1140 } 1140 }
1141 1141
1142 #endif 1142 #endif
OLDNEW
« no previous file with comments | « src/core/SkPixelRef.cpp ('k') | src/gpu/GrSurface.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698