| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
| 3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com) | 3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com) |
| 4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com) | 4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com) |
| 5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc.
All rights reserved. | 5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc.
All rights reserved. |
| 6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> | 6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> |
| 7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org> | 7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org> |
| 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t
orchmobile.com/) | 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t
orchmobile.com/) |
| 9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved. | 9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved. |
| 10 * Copyright (C) Research In Motion Limited 2011. All rights reserved. | 10 * Copyright (C) Research In Motion Limited 2011. All rights reserved. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 * | 22 * |
| 23 * You should have received a copy of the GNU Library General Public License | 23 * You should have received a copy of the GNU Library General Public License |
| 24 * along with this library; see the file COPYING.LIB. If not, write to | 24 * along with this library; see the file COPYING.LIB. If not, write to |
| 25 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 25 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 26 * Boston, MA 02110-1301, USA. | 26 * Boston, MA 02110-1301, USA. |
| 27 */ | 27 */ |
| 28 | 28 |
| 29 #include "config.h" | 29 #include "config.h" |
| 30 #include "core/css/resolver/FilterOperationResolver.h" | 30 #include "core/css/resolver/FilterOperationResolver.h" |
| 31 | 31 |
| 32 #include "core/css/CSSMixFunctionValue.h" |
| 32 #include "core/css/CSSParser.h" | 33 #include "core/css/CSSParser.h" |
| 33 #include "core/css/CSSPrimitiveValueMappings.h" | 34 #include "core/css/CSSPrimitiveValueMappings.h" |
| 35 #include "core/css/CSSShaderValue.h" |
| 34 #include "core/css/ShadowValue.h" | 36 #include "core/css/ShadowValue.h" |
| 35 #include "core/css/WebKitCSSFilterValue.h" | 37 #include "core/css/WebKitCSSFilterValue.h" |
| 36 #include "core/css/WebKitCSSMixFunctionValue.h" | |
| 37 #include "core/css/WebKitCSSShaderValue.h" | |
| 38 #include "core/css/resolver/TransformBuilder.h" | 38 #include "core/css/resolver/TransformBuilder.h" |
| 39 #include "core/platform/graphics/filters/custom/CustomFilterArrayParameter.h" | 39 #include "core/platform/graphics/filters/custom/CustomFilterArrayParameter.h" |
| 40 #include "core/platform/graphics/filters/custom/CustomFilterConstants.h" | 40 #include "core/platform/graphics/filters/custom/CustomFilterConstants.h" |
| 41 #include "core/platform/graphics/filters/custom/CustomFilterNumberParameter.h" | 41 #include "core/platform/graphics/filters/custom/CustomFilterNumberParameter.h" |
| 42 #include "core/platform/graphics/filters/custom/CustomFilterOperation.h" | 42 #include "core/platform/graphics/filters/custom/CustomFilterOperation.h" |
| 43 #include "core/platform/graphics/filters/custom/CustomFilterParameter.h" | 43 #include "core/platform/graphics/filters/custom/CustomFilterParameter.h" |
| 44 #include "core/platform/graphics/filters/custom/CustomFilterProgramInfo.h" | 44 #include "core/platform/graphics/filters/custom/CustomFilterProgramInfo.h" |
| 45 #include "core/platform/graphics/filters/custom/CustomFilterTransformParameter.h
" | 45 #include "core/platform/graphics/filters/custom/CustomFilterTransformParameter.h
" |
| 46 #include "core/rendering/style/StyleCustomFilterProgram.h" | 46 #include "core/rendering/style/StyleCustomFilterProgram.h" |
| 47 #include "core/rendering/style/StyleCustomFilterProgramCache.h" | 47 #include "core/rendering/style/StyleCustomFilterProgramCache.h" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 return FilterOperation::NONE; | 87 return FilterOperation::NONE; |
| 88 } | 88 } |
| 89 return FilterOperation::NONE; | 89 return FilterOperation::NONE; |
| 90 } | 90 } |
| 91 | 91 |
| 92 static bool sortParametersByNameComparator(const RefPtr<CustomFilterParameter>&
a, const RefPtr<CustomFilterParameter>& b) | 92 static bool sortParametersByNameComparator(const RefPtr<CustomFilterParameter>&
a, const RefPtr<CustomFilterParameter>& b) |
| 93 { | 93 { |
| 94 return codePointCompareLessThan(a->name(), b->name()); | 94 return codePointCompareLessThan(a->name(), b->name()); |
| 95 } | 95 } |
| 96 | 96 |
| 97 static StyleShader* cachedOrPendingStyleShaderFromValue(WebKitCSSShaderValue* va
lue, StyleResolverState& state) | 97 static StyleShader* cachedOrPendingStyleShaderFromValue(CSSShaderValue* value, S
tyleResolverState& state) |
| 98 { | 98 { |
| 99 StyleShader* shader = value->cachedOrPendingShader(); | 99 StyleShader* shader = value->cachedOrPendingShader(); |
| 100 if (shader && shader->isPendingShader()) | 100 if (shader && shader->isPendingShader()) |
| 101 state.setHasPendingShaders(true); | 101 state.setHasPendingShaders(true); |
| 102 return shader; | 102 return shader; |
| 103 } | 103 } |
| 104 | 104 |
| 105 static StyleShader* styleShader(CSSValue* value, StyleResolverState& state) | 105 static StyleShader* styleShader(CSSValue* value, StyleResolverState& state) |
| 106 { | 106 { |
| 107 if (value->isWebKitCSSShaderValue()) | 107 if (value->isCSSShaderValue()) |
| 108 return cachedOrPendingStyleShaderFromValue(static_cast<WebKitCSSShaderVa
lue*>(value), state); | 108 return cachedOrPendingStyleShaderFromValue(static_cast<CSSShaderValue*>(
value), state); |
| 109 return 0; | 109 return 0; |
| 110 } | 110 } |
| 111 | 111 |
| 112 static PassRefPtr<CustomFilterParameter> parseCustomFilterArrayParameter(const S
tring& name, CSSValueList* values) | 112 static PassRefPtr<CustomFilterParameter> parseCustomFilterArrayParameter(const S
tring& name, CSSValueList* values) |
| 113 { | 113 { |
| 114 RefPtr<CustomFilterArrayParameter> arrayParameter = CustomFilterArrayParamet
er::create(name); | 114 RefPtr<CustomFilterArrayParameter> arrayParameter = CustomFilterArrayParamet
er::create(name); |
| 115 for (unsigned i = 0, length = values->length(); i < length; ++i) { | 115 for (unsigned i = 0, length = values->length(); i < length; ++i) { |
| 116 CSSValue* value = values->itemWithoutBoundsCheck(i); | 116 CSSValue* value = values->itemWithoutBoundsCheck(i); |
| 117 if (!value->isPrimitiveValue()) | 117 if (!value->isPrimitiveValue()) |
| 118 return 0; | 118 return 0; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 if (!values->length()) | 163 if (!values->length()) |
| 164 return 0; | 164 return 0; |
| 165 | 165 |
| 166 if (parameterValue->isWebKitCSSArrayFunctionValue()) | 166 if (parameterValue->isWebKitCSSArrayFunctionValue()) |
| 167 return parseCustomFilterArrayParameter(name, values); | 167 return parseCustomFilterArrayParameter(name, values); |
| 168 | 168 |
| 169 // If the first value of the list is a transform function, | 169 // If the first value of the list is a transform function, |
| 170 // then we could safely assume that all the remaining items | 170 // then we could safely assume that all the remaining items |
| 171 // are transforms. parseCustomFilterTransformParameter will | 171 // are transforms. parseCustomFilterTransformParameter will |
| 172 // return 0 if that assumption is incorrect. | 172 // return 0 if that assumption is incorrect. |
| 173 if (values->itemWithoutBoundsCheck(0)->isWebKitCSSTransformValue()) | 173 if (values->itemWithoutBoundsCheck(0)->isCSSTransformValue()) |
| 174 return parseCustomFilterTransformParameter(name, values, state); | 174 return parseCustomFilterTransformParameter(name, values, state); |
| 175 | 175 |
| 176 // We can have only arrays of booleans or numbers, so use the first value to
choose between those two. | 176 // We can have only arrays of booleans or numbers, so use the first value to
choose between those two. |
| 177 // We need up to 4 values (all booleans or all numbers). | 177 // We need up to 4 values (all booleans or all numbers). |
| 178 if (!values->itemWithoutBoundsCheck(0)->isPrimitiveValue() || values->length
() > 4) | 178 if (!values->itemWithoutBoundsCheck(0)->isPrimitiveValue() || values->length
() > 4) |
| 179 return 0; | 179 return 0; |
| 180 | 180 |
| 181 CSSPrimitiveValue* firstPrimitiveValue = toCSSPrimitiveValue(values->itemWit
houtBoundsCheck(0)); | 181 CSSPrimitiveValue* firstPrimitiveValue = toCSSPrimitiveValue(values->itemWit
houtBoundsCheck(0)); |
| 182 if (firstPrimitiveValue->primitiveType() == CSSPrimitiveValue::CSS_NUMBER) | 182 if (firstPrimitiveValue->primitiveType() == CSSPrimitiveValue::CSS_NUMBER) |
| 183 return parseCustomFilterNumberParameter(name, values); | 183 return parseCustomFilterNumberParameter(name, values); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 return true; | 225 return true; |
| 226 } | 226 } |
| 227 | 227 |
| 228 static PassRefPtr<CustomFilterOperation> createCustomFilterOperationWithAtRuleRe
ferenceSyntax(WebKitCSSFilterValue* filterValue) | 228 static PassRefPtr<CustomFilterOperation> createCustomFilterOperationWithAtRuleRe
ferenceSyntax(WebKitCSSFilterValue* filterValue) |
| 229 { | 229 { |
| 230 // FIXME: Implement style resolution for the custom filter at-rule reference
syntax. | 230 // FIXME: Implement style resolution for the custom filter at-rule reference
syntax. |
| 231 UNUSED_PARAM(filterValue); | 231 UNUSED_PARAM(filterValue); |
| 232 return 0; | 232 return 0; |
| 233 } | 233 } |
| 234 | 234 |
| 235 static PassRefPtr<CustomFilterProgram> lookupCustomFilterProgram(WebKitCSSShader
Value* vertexShader, WebKitCSSShaderValue* fragmentShader, | 235 static PassRefPtr<CustomFilterProgram> lookupCustomFilterProgram(CSSShaderValue*
vertexShader, CSSShaderValue* fragmentShader, |
| 236 CustomFilterProgramType programType, const CustomFilterProgramMixSettings& m
ixSettings, CustomFilterMeshType meshType, | 236 CustomFilterProgramType programType, const CustomFilterProgramMixSettings& m
ixSettings, CustomFilterMeshType meshType, |
| 237 StyleCustomFilterProgramCache* customFilterProgramCache, StyleResolverState&
state) | 237 StyleCustomFilterProgramCache* customFilterProgramCache, StyleResolverState&
state) |
| 238 { | 238 { |
| 239 CachedResourceLoader* cachedResourceLoader = state.document()->cachedResourc
eLoader(); | 239 CachedResourceLoader* cachedResourceLoader = state.document()->cachedResourc
eLoader(); |
| 240 KURL vertexShaderURL = vertexShader ? vertexShader->completeURL(cachedResour
ceLoader) : KURL(); | 240 KURL vertexShaderURL = vertexShader ? vertexShader->completeURL(cachedResour
ceLoader) : KURL(); |
| 241 KURL fragmentShaderURL = fragmentShader ? fragmentShader->completeURL(cached
ResourceLoader) : KURL(); | 241 KURL fragmentShaderURL = fragmentShader ? fragmentShader->completeURL(cached
ResourceLoader) : KURL(); |
| 242 RefPtr<StyleCustomFilterProgram> program; | 242 RefPtr<StyleCustomFilterProgram> program; |
| 243 if (customFilterProgramCache) | 243 if (customFilterProgramCache) |
| 244 program = customFilterProgramCache->lookup(CustomFilterProgramInfo(verte
xShaderURL.string(), fragmentShaderURL.string(), programType, mixSettings, meshT
ype)); | 244 program = customFilterProgramCache->lookup(CustomFilterProgramInfo(verte
xShaderURL.string(), fragmentShaderURL.string(), programType, mixSettings, meshT
ype)); |
| 245 if (!program) { | 245 if (!program) { |
| 246 // Create a new StyleCustomFilterProgram that will be resolved during th
e loadPendingShaders and added to the cache. | 246 // Create a new StyleCustomFilterProgram that will be resolved during th
e loadPendingShaders and added to the cache. |
| 247 program = StyleCustomFilterProgram::create(vertexShaderURL, vertexShader
? styleShader(vertexShader, state) : 0, | 247 program = StyleCustomFilterProgram::create(vertexShaderURL, vertexShader
? styleShader(vertexShader, state) : 0, |
| 248 fragmentShaderURL, fragmentShader ? styleShader(fragmentShader, stat
e) : 0, programType, mixSettings, meshType); | 248 fragmentShaderURL, fragmentShader ? styleShader(fragmentShader, stat
e) : 0, programType, mixSettings, meshType); |
| 249 // FIXME | 249 // FIXME |
| 250 } | 250 } |
| 251 return program.release(); | 251 return program.release(); |
| 252 } | 252 } |
| 253 | 253 |
| 254 static PassRefPtr<CustomFilterOperation> createCustomFilterOperationWithInlineSy
ntax(WebKitCSSFilterValue* filterValue, StyleCustomFilterProgramCache* customFil
terProgramCache, StyleResolverState& state) | 254 static PassRefPtr<CustomFilterOperation> createCustomFilterOperationWithInlineSy
ntax(WebKitCSSFilterValue* filterValue, StyleCustomFilterProgramCache* customFil
terProgramCache, StyleResolverState& state) |
| 255 { | 255 { |
| 256 CSSValue* shadersValue = filterValue->itemWithoutBoundsCheck(0); | 256 CSSValue* shadersValue = filterValue->itemWithoutBoundsCheck(0); |
| 257 ASSERT_WITH_SECURITY_IMPLICATION(shadersValue->isValueList()); | 257 ASSERT_WITH_SECURITY_IMPLICATION(shadersValue->isValueList()); |
| 258 CSSValueList* shadersList = toCSSValueList(shadersValue); | 258 CSSValueList* shadersList = toCSSValueList(shadersValue); |
| 259 | 259 |
| 260 unsigned shadersListLength = shadersList->length(); | 260 unsigned shadersListLength = shadersList->length(); |
| 261 ASSERT(shadersListLength); | 261 ASSERT(shadersListLength); |
| 262 | 262 |
| 263 WebKitCSSShaderValue* vertexShader = toWebKitCSSShaderValue(shadersList->ite
mWithoutBoundsCheck(0)); | 263 CSSShaderValue* vertexShader = toCSSShaderValue(shadersList->itemWithoutBoun
dsCheck(0)); |
| 264 WebKitCSSShaderValue* fragmentShader = 0; | 264 CSSShaderValue* fragmentShader = 0; |
| 265 CustomFilterProgramType programType = PROGRAM_TYPE_BLENDS_ELEMENT_TEXTURE; | 265 CustomFilterProgramType programType = PROGRAM_TYPE_BLENDS_ELEMENT_TEXTURE; |
| 266 CustomFilterProgramMixSettings mixSettings; | 266 CustomFilterProgramMixSettings mixSettings; |
| 267 | 267 |
| 268 if (shadersListLength > 1) { | 268 if (shadersListLength > 1) { |
| 269 CSSValue* fragmentShaderOrMixFunction = shadersList->itemWithoutBoundsCh
eck(1); | 269 CSSValue* fragmentShaderOrMixFunction = shadersList->itemWithoutBoundsCh
eck(1); |
| 270 if (fragmentShaderOrMixFunction->isWebKitCSSMixFunctionValue()) { | 270 if (fragmentShaderOrMixFunction->isCSSMixFunctionValue()) { |
| 271 WebKitCSSMixFunctionValue* mixFunction = static_cast<WebKitCSSMixFun
ctionValue*>(fragmentShaderOrMixFunction); | 271 CSSMixFunctionValue* mixFunction = static_cast<CSSMixFunctionValue*>
(fragmentShaderOrMixFunction); |
| 272 CSSValueListIterator iterator(mixFunction); | 272 CSSValueListIterator iterator(mixFunction); |
| 273 | 273 |
| 274 ASSERT(mixFunction->length()); | 274 ASSERT(mixFunction->length()); |
| 275 fragmentShader = toWebKitCSSShaderValue(iterator.value()); | 275 fragmentShader = toCSSShaderValue(iterator.value()); |
| 276 iterator.advance(); | 276 iterator.advance(); |
| 277 | 277 |
| 278 ASSERT(mixFunction->length() <= 3); | 278 ASSERT(mixFunction->length() <= 3); |
| 279 while (iterator.hasMore()) { | 279 while (iterator.hasMore()) { |
| 280 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(iterator
.value()); | 280 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(iterator
.value()); |
| 281 if (CSSParser::isBlendMode(primitiveValue->getIdent())) | 281 if (CSSParser::isBlendMode(primitiveValue->getIdent())) |
| 282 mixSettings.blendMode = *primitiveValue; | 282 mixSettings.blendMode = *primitiveValue; |
| 283 else if (CSSParser::isCompositeOperator(primitiveValue->getIdent
())) | 283 else if (CSSParser::isCompositeOperator(primitiveValue->getIdent
())) |
| 284 mixSettings.compositeOperator = *primitiveValue; | 284 mixSettings.compositeOperator = *primitiveValue; |
| 285 else | 285 else |
| 286 ASSERT_NOT_REACHED(); | 286 ASSERT_NOT_REACHED(); |
| 287 iterator.advance(); | 287 iterator.advance(); |
| 288 } | 288 } |
| 289 } else { | 289 } else { |
| 290 programType = PROGRAM_TYPE_NO_ELEMENT_TEXTURE; | 290 programType = PROGRAM_TYPE_NO_ELEMENT_TEXTURE; |
| 291 fragmentShader = toWebKitCSSShaderValue(fragmentShaderOrMixFunction)
; | 291 fragmentShader = toCSSShaderValue(fragmentShaderOrMixFunction); |
| 292 } | 292 } |
| 293 } | 293 } |
| 294 | 294 |
| 295 if (!vertexShader && !fragmentShader) | 295 if (!vertexShader && !fragmentShader) |
| 296 return 0; | 296 return 0; |
| 297 | 297 |
| 298 unsigned meshRows = 1; | 298 unsigned meshRows = 1; |
| 299 unsigned meshColumns = 1; | 299 unsigned meshColumns = 1; |
| 300 CustomFilterMeshType meshType = MeshTypeAttached; | 300 CustomFilterMeshType meshType = MeshTypeAttached; |
| 301 | 301 |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 return false; | 399 return false; |
| 400 | 400 |
| 401 operations.operations().append(operation); | 401 operations.operations().append(operation); |
| 402 continue; | 402 continue; |
| 403 } | 403 } |
| 404 if (operationType == FilterOperation::REFERENCE) { | 404 if (operationType == FilterOperation::REFERENCE) { |
| 405 if (filterValue->length() != 1) | 405 if (filterValue->length() != 1) |
| 406 continue; | 406 continue; |
| 407 CSSValue* argument = filterValue->itemWithoutBoundsCheck(0); | 407 CSSValue* argument = filterValue->itemWithoutBoundsCheck(0); |
| 408 | 408 |
| 409 if (!argument->isWebKitCSSSVGDocumentValue()) | 409 if (!argument->isCSSSVGDocumentValue()) |
| 410 continue; | 410 continue; |
| 411 | 411 |
| 412 WebKitCSSSVGDocumentValue* svgDocumentValue = static_cast<WebKitCSSS
VGDocumentValue*>(argument); | 412 CSSSVGDocumentValue* svgDocumentValue = static_cast<CSSSVGDocumentVa
lue*>(argument); |
| 413 KURL url = state.document()->completeURL(svgDocumentValue->url()); | 413 KURL url = state.document()->completeURL(svgDocumentValue->url()); |
| 414 | 414 |
| 415 RefPtr<ReferenceFilterOperation> operation = ReferenceFilterOperatio
n::create(svgDocumentValue->url(), url.fragmentIdentifier(), operationType); | 415 RefPtr<ReferenceFilterOperation> operation = ReferenceFilterOperatio
n::create(svgDocumentValue->url(), url.fragmentIdentifier(), operationType); |
| 416 if (SVGURIReference::isExternalURIReference(svgDocumentValue->url(),
state.document())) { | 416 if (SVGURIReference::isExternalURIReference(svgDocumentValue->url(),
state.document())) { |
| 417 if (!svgDocumentValue->loadRequested()) | 417 if (!svgDocumentValue->loadRequested()) |
| 418 state.pendingSVGDocuments().set(operation.get(), svgDocument
Value); | 418 state.pendingSVGDocuments().set(operation.get(), svgDocument
Value); |
| 419 else if (svgDocumentValue->cachedSVGDocument()) | 419 else if (svgDocumentValue->cachedSVGDocument()) |
| 420 operation->setCachedSVGDocumentReference(adoptPtr(new Cached
SVGDocumentReference(svgDocumentValue->cachedSVGDocument()))); | 420 operation->setCachedSVGDocumentReference(adoptPtr(new Cached
SVGDocumentReference(svgDocumentValue->cachedSVGDocument()))); |
| 421 } | 421 } |
| 422 operations.operations().append(operation); | 422 operations.operations().append(operation); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 507 ASSERT_NOT_REACHED(); | 507 ASSERT_NOT_REACHED(); |
| 508 break; | 508 break; |
| 509 } | 509 } |
| 510 } | 510 } |
| 511 | 511 |
| 512 outOperations = operations; | 512 outOperations = operations; |
| 513 return true; | 513 return true; |
| 514 } | 514 } |
| 515 | 515 |
| 516 } // namespace WebCore | 516 } // namespace WebCore |
| OLD | NEW |