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

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

Issue 19305004: Move implementation of SkFilterShader into its source file. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 5 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 | « gyp/core.gypi ('k') | src/core/SkFilterShader.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 "SkColorFilter.h" 8 #include "SkColorFilter.h"
9 #include "SkFilterShader.h" 9
10 #include "SkFlattenableBuffers.h" 10 #include "SkFlattenableBuffers.h"
11 #include "SkShader.h" 11 #include "SkShader.h"
12 #include "SkUnPreMultiply.h" 12 #include "SkUnPreMultiply.h"
13 #include "SkString.h" 13 #include "SkString.h"
14 14
15 SK_DEFINE_INST_COUNT(SkColorFilter) 15 SK_DEFINE_INST_COUNT(SkColorFilter)
16 16
17 bool SkColorFilter::asColorMode(SkColor* color, SkXfermode::Mode* mode) const { 17 bool SkColorFilter::asColorMode(SkColor* color, SkXfermode::Mode* mode) const {
18 return false; 18 return false;
19 } 19 }
(...skipping 17 matching lines...) Expand all
37 37
38 SkColor SkColorFilter::filterColor(SkColor c) const { 38 SkColor SkColorFilter::filterColor(SkColor c) const {
39 SkPMColor dst, src = SkPreMultiplyColor(c); 39 SkPMColor dst, src = SkPreMultiplyColor(c);
40 this->filterSpan(&src, 1, &dst); 40 this->filterSpan(&src, 1, &dst);
41 return SkUnPreMultiply::PMColorToColor(dst); 41 return SkUnPreMultiply::PMColorToColor(dst);
42 } 42 }
43 43
44 GrEffectRef* SkColorFilter::asNewEffect(GrContext*) const { 44 GrEffectRef* SkColorFilter::asNewEffect(GrContext*) const {
45 return NULL; 45 return NULL;
46 } 46 }
47
48 ///////////////////////////////////////////////////////////////////////////////
49
50 SkFilterShader::SkFilterShader(SkShader* shader, SkColorFilter* filter) {
51 fShader = shader; shader->ref();
52 fFilter = filter; filter->ref();
53 }
54
55 SkFilterShader::SkFilterShader(SkFlattenableReadBuffer& buffer) :
56 INHERITED(buffer) {
57 fShader = buffer.readFlattenableT<SkShader>();
58 fFilter = buffer.readFlattenableT<SkColorFilter>();
59 }
60
61 SkFilterShader::~SkFilterShader() {
62 fFilter->unref();
63 fShader->unref();
64 }
65
66 void SkFilterShader::flatten(SkFlattenableWriteBuffer& buffer) const {
67 this->INHERITED::flatten(buffer);
68 buffer.writeFlattenable(fShader);
69 buffer.writeFlattenable(fFilter);
70 }
71
72 uint32_t SkFilterShader::getFlags() {
73 uint32_t shaderF = fShader->getFlags();
74 uint32_t filterF = fFilter->getFlags();
75
76 // if the filter doesn't support 16bit, clear the matching bit in the shader
77 if (!(filterF & SkColorFilter::kHasFilter16_Flag)) {
78 shaderF &= ~SkShader::kHasSpan16_Flag;
79 }
80 // if the filter might change alpha, clear the opaque flag in the shader
81 if (!(filterF & SkColorFilter::kAlphaUnchanged_Flag)) {
82 shaderF &= ~(SkShader::kOpaqueAlpha_Flag | SkShader::kHasSpan16_Flag);
83 }
84 return shaderF;
85 }
86
87 bool SkFilterShader::setContext(const SkBitmap& device,
88 const SkPaint& paint,
89 const SkMatrix& matrix) {
90 // we need to keep the setContext/endContext calls balanced. If we return
91 // false, our endContext() will not be called.
92
93 if (!this->INHERITED::setContext(device, paint, matrix)) {
94 return false;
95 }
96 if (!fShader->setContext(device, paint, matrix)) {
97 this->INHERITED::endContext();
98 return false;
99 }
100 return true;
101 }
102
103 void SkFilterShader::endContext() {
104 fShader->endContext();
105 this->INHERITED::endContext();
106 }
107
108 void SkFilterShader::shadeSpan(int x, int y, SkPMColor result[], int count) {
109 fShader->shadeSpan(x, y, result, count);
110 fFilter->filterSpan(result, count, result);
111 }
112
113 void SkFilterShader::shadeSpan16(int x, int y, uint16_t result[], int count) {
114 SkASSERT(fShader->getFlags() & SkShader::kHasSpan16_Flag);
115 SkASSERT(fFilter->getFlags() & SkColorFilter::kHasFilter16_Flag);
116
117 fShader->shadeSpan16(x, y, result, count);
118 fFilter->filterSpan16(result, count, result);
119 }
120
121 #ifdef SK_DEVELOPER
122 void SkFilterShader::toString(SkString* str) const {
123 str->append("SkFilterShader: (");
124
125 str->append("Shader: ");
126 fShader->toString(str);
127 str->append(" Filter: ");
128 // TODO: add "fFilter->toString(str);" once SkColorFilter::toString is added
129
130 this->INHERITED::toString(str);
131
132 str->append(")");
133 }
134 #endif
OLDNEW
« no previous file with comments | « gyp/core.gypi ('k') | src/core/SkFilterShader.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698