[CSS Shaders] Implement normal blend mode and source-atop compositing mode
https://bugs.webkit.org/show_bug.cgi?id=93869

Patch by Max Vujovic <mvujovic@adobe.com> on 2012-08-30
Reviewed by Dean Jackson.

Source/WebCore:

Instead of allowing direct texture access in an author's shader via u_texture, CSS
Shaders blends special symbols in the author's shader (css_MixColor and
css_ColorMatrix) with the DOM element texture.

The author specifies the blend mode and composite operator via the CSS mix
function like this:
-webkit-filter: custom(none mix(shader.fs normal source-atop));

This patch implements the normal blend mode and the source-atop composite
operator. The other blend modes and composite operators will come in later
patches.

This patch introduces a new class, CustomFilterValidatedProgram, which validates
the shader using ANGLE. If the shader uses blending and compositing,
CustomFilterValidatedProgram uses ANGLE's SH_CSS_SHADERS_SPEC flag. This allows
the author's shader to compile successfully with special symbols like
"css_MixColor". ANGLE also reserves the "css_" prefix. If the shader doesn't use
blending and compositing, CustomFilterValidatedProgram validates the shader using
ANGLE's SH_WEBGL_SPEC flag.

After validation, CustomFilterValidatedProgram adds blending, compositing, and
texture access shader code to the author's original shaders. The definitions for
css_MixColor and css_ColorMatrix are added before the author's fragment shader
code so that the author code can access them. The blending, compositing, and
texture access code is added after the author code and is thus inaccessible to the
author code. Since ANGLE reserves the "css_" prefix during the validation phase,
no collisions are possible between the author's code and the code that WebKit adds.

The CustomFilterGlobalContext now caches CustomFilterValidatedProgram instead
of CustomFilterCompiledProgram. CustomFilterValidatedProgram owns a
CustomFilterCompiledProgram. This way, we can use the platform-independent
CustomFilterValidatedProgram to validate and rewrite the shaders, regardless of
the platform representation of the program (e.g. CustomFilterCompiledProgram).

Tests: css3/filters/custom/custom-filter-color-matrix.html
       css3/filters/custom/custom-filter-composite-source-atop.html

* GNUmakefile.list.am:
* Target.pri:
* WebCore.gyp/WebCore.gyp:
* WebCore.gypi:
* WebCore.vcproj/WebCore.vcproj:
* WebCore.xcodeproj/project.pbxproj:
* platform/graphics/ANGLEWebKitBridge.cpp:
(WebCore::ANGLEWebKitBridge::ANGLEWebKitBridge):
    Add a shader spec parameter, since sometimes we want to validate the shader
    against the CSS Shaders spec and other times we want to validate the shader
    against the WebGL spec. Note that the CSS Shaders spec is treated as a subset
    of the WebGL spec in ANGLE.
(WebCore::ANGLEWebKitBridge::validateShaderSource):
* platform/graphics/ANGLEWebKitBridge.h:
(ANGLEWebKitBridge):
* platform/graphics/filters/CustomFilterCompiledProgram.cpp:
(WebCore::CustomFilterCompiledProgram::CustomFilterCompiledProgram):
(WebCore::CustomFilterCompiledProgram::compileShader):
(WebCore::CustomFilterCompiledProgram::initializeParameterLocations):
(WebCore::CustomFilterCompiledProgram::~CustomFilterCompiledProgram):
* platform/graphics/filters/CustomFilterCompiledProgram.h:
(WebCore):
* platform/graphics/filters/CustomFilterGlobalContext.cpp:
(WebCore::CustomFilterGlobalContext::~CustomFilterGlobalContext):
(WebCore::CustomFilterGlobalContext::webglShaderValidator):
(WebCore):
(WebCore::CustomFilterGlobalContext::mixShaderValidator):
(WebCore::CustomFilterGlobalContext::createShaderValidator):
(WebCore::CustomFilterGlobalContext::getValidatedProgram):
(WebCore::CustomFilterGlobalContext::removeValidatedProgram):
* platform/graphics/filters/CustomFilterGlobalContext.h:
(WebCore):
(CustomFilterGlobalContext):
* platform/graphics/filters/CustomFilterProgramInfo.h:
(WebCore::CustomFilterProgramInfo::mixSettings):
* platform/graphics/filters/CustomFilterValidatedProgram.cpp: Added.
(WebCore):
(WebCore::CustomFilterValidatedProgram::defaultVertexShaderString):
(WebCore::CustomFilterValidatedProgram::defaultFragmentShaderString):
(WebCore::CustomFilterValidatedProgram::CustomFilterValidatedProgram):
(WebCore::CustomFilterValidatedProgram::compiledProgram):
(WebCore::CustomFilterValidatedProgram::rewriteMixVertexShader):
(WebCore::CustomFilterValidatedProgram::rewriteMixFragmentShader):
(WebCore::CustomFilterValidatedProgram::blendFunctionString):
(WebCore::CustomFilterValidatedProgram::compositeFunctionString):
(WebCore::CustomFilterValidatedProgram::~CustomFilterValidatedProgram):
* platform/graphics/filters/CustomFilterValidatedProgram.h: Added.
(WebCore):
(CustomFilterValidatedProgram):
(WebCore::CustomFilterValidatedProgram::create):
(WebCore::CustomFilterValidatedProgram::programInfo):
(WebCore::CustomFilterValidatedProgram::isInitialized):
(WebCore::CustomFilterValidatedProgram::detachFromGlobalContext):
* platform/graphics/filters/FECustomFilter.cpp:
(WebCore::FECustomFilter::FECustomFilter):
    Accept a CustomFilterValidatedProgram instead of CustomFilterProgram.
(WebCore::FECustomFilter::create):
(WebCore::FECustomFilter::initializeContext):
(WebCore::FECustomFilter::bindVertexAttribute):
(WebCore::FECustomFilter::bindProgramAndBuffers):
* platform/graphics/filters/FECustomFilter.h:
(WebCore):
(FECustomFilter):
* rendering/FilterEffectRenderer.cpp:
(WebCore):
(WebCore::createCustomFilterEffect):
(WebCore::FilterEffectRenderer::build):
    Only create an FECustomFilter if the program validates.
* rendering/FilterEffectRenderer.h:
(WebCore):
(FilterEffectRenderer):

LayoutTests:

We've added two new special built-in symbols in CSS Shaders, css_MixColor and
css_ColorMatrix.

This change adds custom-filter-composite-source-atop.html, a new test that uses css_MixColor
in a shader with the normal blend mode and the source-atop compositing operator.

This change also adds custom-filter-color-matrix.html, a new test that uses css_ColorMatrix
in the shader.

Authors can read and write to these special built-ins in their shader code. WebKit will
premultiply the DOM element texture with css_ColorMatrix. Additionally, WebKit will blend
and composite css_MixColor with the DOM element texture, according to the blend mode and
compositing operator that the author specifies in CSS.

For example, the following line of CSS tells WebKit how to blend and composite the
css_MixColor from shader.fs:
-webkit-filter: custom(none mix(shader.fs normal source-atop));

* css3/filters/custom/custom-filter-color-matrix-expected.png: Added.
* css3/filters/custom/custom-filter-color-matrix-expected.txt: Added.
* css3/filters/custom/custom-filter-color-matrix.html: Added.
* css3/filters/custom/custom-filter-composite-source-atop-expected.png: Added.
* css3/filters/custom/custom-filter-composite-source-atop-expected.txt: Added.
* css3/filters/custom/custom-filter-composite-source-atop.html: Added.
* css3/filters/custom/custom-filter-shader-cache.html:
* css3/filters/custom/effect-color-check.html:
    Use pass-tex-coord.vs now. Since v_texCoord in not automatically passed in the default
    shaders anymore, we have to pass it in our own vertex shader. After we implement more
    blending and compositing modes, we will be able to convert most of the tests to use the
    CSS mix function. Then, we won't be sampling the DOM element texture directly, so we
    won't need a tex coord, so we won't need this shader anymore.
* css3/filters/custom/effect-custom.html:
    The default CSS value for <fragmentShader> needs to be specified explicitly until we
    change it from its current default. This will be fixed in:
    https://bugs.webkit.org/show_bug.cgi?id=94020
* css3/filters/custom/effect-custom-transform-parameters.html:
    Ditto.
* css3/filters/custom/filter-fallback-to-software.html:
    Ditto.
* css3/filters/custom/invalid-custom-filter-shader-expected.html:
    These tests will not attempt to apply a filter because the programs do not validate.
    This means we don't need to trigger FilterEffectRenderer with grayscale(0) in
    the reference file anymore.
* css3/filters/resources/composite.fs: Added.
* css3/filters/resources/empty-shader.fs: Added.
* css3/filters/resources/grayscale-color-matrix.fs: Added.
* css3/filters/resources/pass-tex-coord.vs: Added.
* platform/chromium/css3/filters/custom/custom-filter-color-matrix-expected.png: Added.
* platform/chromium/css3/filters/custom/custom-filter-composite-source-atop-expected.png: Added.
* platform/chromium/TestExpectations:
* platform/mac-snowleopard/css3/filters/custom/effect-custom-expected.png: Removed.
    We should use the generic expectation, because this expectation does not show the
    shaders applied.
* platform/mac-snowleopard/css3/filters/custom/effect-custom-parameters-expected.png: Removed.
    Ditto.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@127217 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Unreviewed Gardening. http/security/referrer tests fail. Unable to load resources over https.
https://bugs.webkit.org/show_bug.cgi?id=73913
        
* platform/win/Skipped:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@127218 268f45cc-cd09-0410-ab3c-d52691b4dbfc
~JSNPObject should call invalidate() if it hasn't been called already
https://bugs.webkit.org/show_bug.cgi?id=95497

Reviewed by Geoffrey Garen.

Finalization is no longer eager, just like destruction, so the original intent behind
this ASSERT in ~JSNPObject is no longer relevant. Therefore, we can just call invalidate()
ourselves in ~JSNPObject.

* WebProcess/Plugins/Netscape/JSNPObject.cpp:
(WebKit::JSNPObject::~JSNPObject):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@127219 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Make it possible to use CSS Variables inside Calc expressions.
https://bugs.webkit.org/show_bug.cgi?id=95284

Reviewed by Tony Chang.

Allows calc expressions to contain unevaluated variables, which are then resolved in StyleResolver.cpp when building the RenderStyle tree.

Tests:
fast/css/variables/calc.html

* css/CSSCalculationValue.cpp:
(WebCore::unitCategory):
(WebCore):
(WebCore::CSSCalcValue::customSerializeResolvingVariables):
Generates a CSS expression with variables resolved into their corresponding values.
(WebCore::CSSCalcValue::hasVariableReference):
Returns true if the calculation's expression tree refers to a variable (that needs to be resolved).
(CSSCalcPrimitiveValue):
(WebCore::CSSCalcPrimitiveValue::serializeResolvingVariables):
Resolves the variable using the underlying CSSPrimitiveValue's serializeResolvingVariables function.
(WebCore::CSSCalcPrimitiveValue::hasVariableReference):
(WebCore::CSSCalcPrimitiveValue::toCalcValue):
(WebCore::CSSCalcPrimitiveValue::doubleValue):
(WebCore::CSSCalcPrimitiveValue::computeLengthPx):
(WebCore::CSSCalcBinaryOperation::create):
(CSSCalcBinaryOperation):
(WebCore::CSSCalcBinaryOperation::serializeResolvingVariables):
Builds a CSS expression for contained subtrees.
(WebCore::CSSCalcBinaryOperation::hasVariableReference):
Returns true if either subtree contains a variable.
* css/CSSCalculationValue.h:
(CSSCalcExpressionNode):
(CSSCalcValue):
* css/CSSGrammar.y:
* css/CSSParser.cpp:
(WebCore::CSSParser::validCalculationUnit):
* css/CSSPrimitiveValue.cpp:
(WebCore::CSSPrimitiveValue::primitiveType):
(WebCore::CSSPrimitiveValue::customSerializeResolvingVariables):
* css/StyleResolver.cpp:
(WebCore::StyleResolver::collectMatchingRulesForList):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@127220 268f45cc-cd09-0410-ab3c-d52691b4dbfc
ASSERTION FAILURE in JSC::JSGlobalData::float32ArrayDescriptor when running fast/js/dfg-float64array.html
https://bugs.webkit.org/show_bug.cgi?id=95398

Reviewed by Mark Hahnenberg.

Source/JavaScriptCore:

Trying to get the build failure to be a bit more informative.

* runtime/JSGlobalData.h:
(JSGlobalData):

LayoutTests:

Temporarily unskipping tests to figure out what is going.

* platform/mac-wk2/Skipped:


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@127222 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Unreviewed gardening. fast/events/domactivate-sets-underlying-click-event-as-handled.html fails on Windows.
https://bugs.webkit.org/show_bug.cgi?id=87469

It looks like any test that involves popup windows of some sort confuses DRT. 
It doesn't know to continue the test when focus moves away from the main window.
This happens with select menu tests as well when focus is put on the select options popup.

* platform/win/Skipped:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@127223 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Replace more instances of += with StringBuilder
https://bugs.webkit.org/show_bug.cgi?id=95502

Reviewed by Darin Adler.

This patch removes many uses of WTF::String::operator+= in WebCore.
Many of these uses are inefficient because they cause us to allocate
and memcpy strings more times than necessary. In most cases, I've
replaced these inefficient patterns with StringBuilder.

This patch makes progress towards removing WTF::String::operator+= from
the project.

We can make cssText() more efficient by passing a single StringBuilder
instance along to the recursive calls, but I've left that for a later
patch.

* css/CSSBorderImageSliceValue.cpp:
(WebCore::CSSBorderImageSliceValue::customCssText):
* css/CSSFontFaceSrcValue.cpp:
(WebCore::CSSFontFaceSrcValue::customCssText):
* css/CSSFunctionValue.cpp:
(WebCore::CSSFunctionValue::customCssText):
* css/CSSGradientValue.cpp:
(WebCore::CSSLinearGradientValue::customCssText):
(WebCore::CSSRadialGradientValue::customCssText):
* css/CSSParser.cpp:
(WebCore::CSSParser::createKeyframe):
* css/CSSPrimitiveValue.cpp:
(WebCore::CSSPrimitiveValue::customCssText):
* css/CSSReflectValue.cpp:
(WebCore::CSSReflectValue::customCssText):
* css/CSSTimingFunctionValue.cpp:
(WebCore::CSSCubicBezierTimingFunctionValue::customCssText):
(WebCore::CSSStepsTimingFunctionValue::customCssText):
* css/StylePropertySet.cpp:
(WebCore::StylePropertySet::get4Values):
(WebCore::StylePropertySet::getLayeredShorthandValue):
(WebCore::StylePropertySet::getShorthandValue):
* fileapi/BlobURL.cpp:
(WebCore::BlobURL::createBlobURL):
* inspector/InspectorCSSAgent.cpp:
(WebCore::InspectorCSSAgent::SetPropertyTextAction::redo):
* inspector/InspectorClient.cpp:
(WebCore::InspectorClient::doDispatchMessageOnFrontendPage):
* inspector/InspectorConsoleAgent.cpp:
(WebCore::InspectorConsoleAgent::didFailLoading):
* inspector/InspectorFileSystemAgent.cpp:
(WebCore):
* inspector/InspectorPageAgent.cpp:
(WebCore::InspectorPageAgent::cachedResourceContent):
(WebCore::InspectorPageAgent::getCookies):
* inspector/InspectorStyleSheet.cpp:
(WebCore::InspectorStyleSheet::addRule):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@127224 268f45cc-cd09-0410-ab3c-d52691b4dbfc