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

Side by Side Diff: src/core/SkDraw.cpp

Issue 270023002: fix TriColorShader to respect the paint's alpha (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: add Sk255To256 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 | « include/core/SkColorPriv.h ('k') | no next file » | 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 "SkDraw.h" 8 #include "SkDraw.h"
9 #include "SkBlitter.h" 9 #include "SkBlitter.h"
10 #include "SkBounder.h" 10 #include "SkBounder.h"
(...skipping 2414 matching lines...) Expand 10 before | Expand all | Expand 10 after
2425 SkTriColorShader::TriColorShaderContext::TriColorShaderContext(const SkTriColorS hader& shader, 2425 SkTriColorShader::TriColorShaderContext::TriColorShaderContext(const SkTriColorS hader& shader,
2426 const ContextRec& rec) 2426 const ContextRec& rec)
2427 : INHERITED(shader, rec) {} 2427 : INHERITED(shader, rec) {}
2428 2428
2429 SkTriColorShader::TriColorShaderContext::~TriColorShaderContext() {} 2429 SkTriColorShader::TriColorShaderContext::~TriColorShaderContext() {}
2430 2430
2431 size_t SkTriColorShader::contextSize() const { 2431 size_t SkTriColorShader::contextSize() const {
2432 return sizeof(TriColorShaderContext); 2432 return sizeof(TriColorShaderContext);
2433 } 2433 }
2434 void SkTriColorShader::TriColorShaderContext::shadeSpan(int x, int y, SkPMColor dstC[], int count) { 2434 void SkTriColorShader::TriColorShaderContext::shadeSpan(int x, int y, SkPMColor dstC[], int count) {
2435 const int alphaScale = Sk255To256(this->getPaintAlpha());
2436
2435 SkPoint src; 2437 SkPoint src;
2436 2438
2437 for (int i = 0; i < count; i++) { 2439 for (int i = 0; i < count; i++) {
2438 fDstToUnit.mapXY(SkIntToScalar(x), SkIntToScalar(y), &src); 2440 fDstToUnit.mapXY(SkIntToScalar(x), SkIntToScalar(y), &src);
2439 x += 1; 2441 x += 1;
2440 2442
2441 int scale1 = ScalarTo256(src.fX); 2443 int scale1 = ScalarTo256(src.fX);
2442 int scale2 = ScalarTo256(src.fY); 2444 int scale2 = ScalarTo256(src.fY);
2443 int scale0 = 256 - scale1 - scale2; 2445 int scale0 = 256 - scale1 - scale2;
2444 if (scale0 < 0) { 2446 if (scale0 < 0) {
2445 if (scale1 > scale2) { 2447 if (scale1 > scale2) {
2446 scale2 = 256 - scale1; 2448 scale2 = 256 - scale1;
2447 } else { 2449 } else {
2448 scale1 = 256 - scale2; 2450 scale1 = 256 - scale2;
2449 } 2451 }
2450 scale0 = 0; 2452 scale0 = 0;
2451 } 2453 }
2452 2454
2455 if (256 != alphaScale) {
2456 scale0 = SkAlphaMul(scale0, alphaScale);
2457 scale1 = SkAlphaMul(scale1, alphaScale);
2458 scale2 = SkAlphaMul(scale2, alphaScale);
2459 }
2460
2453 dstC[i] = SkAlphaMulQ(fColors[0], scale0) + 2461 dstC[i] = SkAlphaMulQ(fColors[0], scale0) +
2454 SkAlphaMulQ(fColors[1], scale1) + 2462 SkAlphaMulQ(fColors[1], scale1) +
2455 SkAlphaMulQ(fColors[2], scale2); 2463 SkAlphaMulQ(fColors[2], scale2);
2456 } 2464 }
2457 } 2465 }
2458 2466
2459 #ifndef SK_IGNORE_TO_STRING 2467 #ifndef SK_IGNORE_TO_STRING
2460 void SkTriColorShader::toString(SkString* str) const { 2468 void SkTriColorShader::toString(SkString* str) const {
2461 str->append("SkTriColorShader: ("); 2469 str->append("SkTriColorShader: (");
2462 2470
2463 this->INHERITED::toString(str); 2471 this->INHERITED::toString(str);
2464 2472
2465 str->append(")"); 2473 str->append(")");
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
2824 mask->fImage = SkMask::AllocImage(size); 2832 mask->fImage = SkMask::AllocImage(size);
2825 memset(mask->fImage, 0, mask->computeImageSize()); 2833 memset(mask->fImage, 0, mask->computeImageSize());
2826 } 2834 }
2827 2835
2828 if (SkMask::kJustComputeBounds_CreateMode != mode) { 2836 if (SkMask::kJustComputeBounds_CreateMode != mode) {
2829 draw_into_mask(*mask, devPath, style); 2837 draw_into_mask(*mask, devPath, style);
2830 } 2838 }
2831 2839
2832 return true; 2840 return true;
2833 } 2841 }
OLDNEW
« no previous file with comments | « include/core/SkColorPriv.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698