| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
| 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 "SkFilterShader.h" | 8 #include "SkFilterShader.h" |
| 9 | 9 |
| 10 #include "SkColorFilter.h" | 10 #include "SkColorFilter.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 buffer.writeFlattenable(fShader); | 39 buffer.writeFlattenable(fShader); |
| 40 buffer.writeFlattenable(fFilter); | 40 buffer.writeFlattenable(fFilter); |
| 41 } | 41 } |
| 42 | 42 |
| 43 uint32_t SkFilterShader::FilterShaderContext::getFlags() const { | 43 uint32_t SkFilterShader::FilterShaderContext::getFlags() const { |
| 44 const SkFilterShader& filterShader = static_cast<const SkFilterShader&>(fSha
der); | 44 const SkFilterShader& filterShader = static_cast<const SkFilterShader&>(fSha
der); |
| 45 | 45 |
| 46 uint32_t shaderF = fShaderContext->getFlags(); | 46 uint32_t shaderF = fShaderContext->getFlags(); |
| 47 uint32_t filterF = filterShader.fFilter->getFlags(); | 47 uint32_t filterF = filterShader.fFilter->getFlags(); |
| 48 | 48 |
| 49 // filters don't support 16bit, so clear the matching bit in the shader | 49 // if the filter doesn't support 16bit, clear the matching bit in the shader |
| 50 shaderF &= ~SkShader::kHasSpan16_Flag; | 50 if (!(filterF & SkColorFilter::kHasFilter16_Flag)) { |
| 51 | 51 shaderF &= ~SkShader::kHasSpan16_Flag; |
| 52 } |
| 52 // if the filter might change alpha, clear the opaque flag in the shader | 53 // if the filter might change alpha, clear the opaque flag in the shader |
| 53 if (!(filterF & SkColorFilter::kAlphaUnchanged_Flag)) { | 54 if (!(filterF & SkColorFilter::kAlphaUnchanged_Flag)) { |
| 54 shaderF &= ~SkShader::kOpaqueAlpha_Flag; | 55 shaderF &= ~(SkShader::kOpaqueAlpha_Flag | SkShader::kHasSpan16_Flag); |
| 55 } | 56 } |
| 56 return shaderF; | 57 return shaderF; |
| 57 } | 58 } |
| 58 | 59 |
| 59 SkShader::Context* SkFilterShader::onCreateContext(const ContextRec& rec, void*
storage) const { | 60 SkShader::Context* SkFilterShader::onCreateContext(const ContextRec& rec, void*
storage) const { |
| 60 char* shaderContextStorage = (char*)storage + sizeof(FilterShaderContext); | 61 char* shaderContextStorage = (char*)storage + sizeof(FilterShaderContext); |
| 61 SkShader::Context* shaderContext = fShader->createContext(rec, shaderContext
Storage); | 62 SkShader::Context* shaderContext = fShader->createContext(rec, shaderContext
Storage); |
| 62 if (NULL == shaderContext) { | 63 if (NULL == shaderContext) { |
| 63 return NULL; | 64 return NULL; |
| 64 } | 65 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 79 fShaderContext->~Context(); | 80 fShaderContext->~Context(); |
| 80 } | 81 } |
| 81 | 82 |
| 82 void SkFilterShader::FilterShaderContext::shadeSpan(int x, int y, SkPMColor resu
lt[], int count) { | 83 void SkFilterShader::FilterShaderContext::shadeSpan(int x, int y, SkPMColor resu
lt[], int count) { |
| 83 const SkFilterShader& filterShader = static_cast<const SkFilterShader&>(fSha
der); | 84 const SkFilterShader& filterShader = static_cast<const SkFilterShader&>(fSha
der); |
| 84 | 85 |
| 85 fShaderContext->shadeSpan(x, y, result, count); | 86 fShaderContext->shadeSpan(x, y, result, count); |
| 86 filterShader.fFilter->filterSpan(result, count, result); | 87 filterShader.fFilter->filterSpan(result, count, result); |
| 87 } | 88 } |
| 88 | 89 |
| 90 void SkFilterShader::FilterShaderContext::shadeSpan16(int x, int y, uint16_t res
ult[], int count) { |
| 91 const SkFilterShader& filterShader = static_cast<const SkFilterShader&>(fSha
der); |
| 92 |
| 93 SkASSERT(fShaderContext->getFlags() & SkShader::kHasSpan16_Flag); |
| 94 SkASSERT(filterShader.fFilter->getFlags() & SkColorFilter::kHasFilter16_Flag
); |
| 95 |
| 96 fShaderContext->shadeSpan16(x, y, result, count); |
| 97 filterShader.fFilter->filterSpan16(result, count, result); |
| 98 } |
| 99 |
| 89 #ifndef SK_IGNORE_TO_STRING | 100 #ifndef SK_IGNORE_TO_STRING |
| 90 void SkFilterShader::toString(SkString* str) const { | 101 void SkFilterShader::toString(SkString* str) const { |
| 91 str->append("SkFilterShader: ("); | 102 str->append("SkFilterShader: ("); |
| 92 | 103 |
| 93 str->append("Shader: "); | 104 str->append("Shader: "); |
| 94 fShader->toString(str); | 105 fShader->toString(str); |
| 95 str->append(" Filter: "); | 106 str->append(" Filter: "); |
| 96 // TODO: add "fFilter->toString(str);" once SkColorFilter::toString is added | 107 // TODO: add "fFilter->toString(str);" once SkColorFilter::toString is added |
| 97 | 108 |
| 98 this->INHERITED::toString(str); | 109 this->INHERITED::toString(str); |
| 99 | 110 |
| 100 str->append(")"); | 111 str->append(")"); |
| 101 } | 112 } |
| 102 #endif | 113 #endif |
| OLD | NEW |