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

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: 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 | « no previous file | 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 unsigned alpha = this->getPaintAlpha();
2436 const int alphaScale = alpha + (alpha >> 7);
scroggo 2014/05/05 21:15:02 From the comments in SkColorPriv, it looks like th
reed1 2014/05/05 21:25:15 Done.
2437
2435 SkPoint src; 2438 SkPoint src;
2436 2439
2437 for (int i = 0; i < count; i++) { 2440 for (int i = 0; i < count; i++) {
2438 fDstToUnit.mapXY(SkIntToScalar(x), SkIntToScalar(y), &src); 2441 fDstToUnit.mapXY(SkIntToScalar(x), SkIntToScalar(y), &src);
2439 x += 1; 2442 x += 1;
2440 2443
2441 int scale1 = ScalarTo256(src.fX); 2444 int scale1 = ScalarTo256(src.fX);
2442 int scale2 = ScalarTo256(src.fY); 2445 int scale2 = ScalarTo256(src.fY);
2443 int scale0 = 256 - scale1 - scale2; 2446 int scale0 = 256 - scale1 - scale2;
2444 if (scale0 < 0) { 2447 if (scale0 < 0) {
2445 if (scale1 > scale2) { 2448 if (scale1 > scale2) {
2446 scale2 = 256 - scale1; 2449 scale2 = 256 - scale1;
2447 } else { 2450 } else {
2448 scale1 = 256 - scale2; 2451 scale1 = 256 - scale2;
2449 } 2452 }
2450 scale0 = 0; 2453 scale0 = 0;
2451 } 2454 }
2452 2455
2456 if (256 != alphaScale) {
2457 scale0 = (scale0 * alphaScale) >> 8;
scroggo 2014/05/05 21:15:02 Why not use SkAlphaMul?
reed1 2014/05/05 21:25:15 Done.
2458 scale1 = (scale1 * alphaScale) >> 8;
2459 scale2 = (scale2 * alphaScale) >> 8;
2460 }
2461
2453 dstC[i] = SkAlphaMulQ(fColors[0], scale0) + 2462 dstC[i] = SkAlphaMulQ(fColors[0], scale0) +
2454 SkAlphaMulQ(fColors[1], scale1) + 2463 SkAlphaMulQ(fColors[1], scale1) +
2455 SkAlphaMulQ(fColors[2], scale2); 2464 SkAlphaMulQ(fColors[2], scale2);
2456 } 2465 }
2457 } 2466 }
2458 2467
2459 #ifndef SK_IGNORE_TO_STRING 2468 #ifndef SK_IGNORE_TO_STRING
2460 void SkTriColorShader::toString(SkString* str) const { 2469 void SkTriColorShader::toString(SkString* str) const {
2461 str->append("SkTriColorShader: ("); 2470 str->append("SkTriColorShader: (");
2462 2471
2463 this->INHERITED::toString(str); 2472 this->INHERITED::toString(str);
2464 2473
2465 str->append(")"); 2474 str->append(")");
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
2824 mask->fImage = SkMask::AllocImage(size); 2833 mask->fImage = SkMask::AllocImage(size);
2825 memset(mask->fImage, 0, mask->computeImageSize()); 2834 memset(mask->fImage, 0, mask->computeImageSize());
2826 } 2835 }
2827 2836
2828 if (SkMask::kJustComputeBounds_CreateMode != mode) { 2837 if (SkMask::kJustComputeBounds_CreateMode != mode) {
2829 draw_into_mask(*mask, devPath, style); 2838 draw_into_mask(*mask, devPath, style);
2830 } 2839 }
2831 2840
2832 return true; 2841 return true;
2833 } 2842 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698