Use is<>() / downcast<>() for Filter / FilterOperation subclasses
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 13 Oct 2014 18:28:25 +0000 (18:28 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 13 Oct 2014 18:28:25 +0000 (18:28 +0000)
https://bugs.webkit.org/show_bug.cgi?id=137644

Reviewed by Darin Adler.

Use is<>() / downcast<>() for Filter / FilterOperation subclasses.

Source/WebCore:

No new tests, no behavior change.

* css/CSSComputedStyleDeclaration.cpp:
(WebCore::ComputedStyleExtractor::valueForFilter):
* platform/graphics/ca/mac/PlatformCAFiltersMac.mm:
(PlatformCAFilters::filterValueForOperation):
(PlatformCAFilters::colorMatrixValueForFilter):
* platform/graphics/filters/Filter.h:
* platform/graphics/filters/FilterOperation.cpp:
(WebCore::DefaultFilterOperation::operator==):
(WebCore::ReferenceFilterOperation::operator==):
(WebCore::BasicColorMatrixFilterOperation::blend):
(WebCore::BasicColorMatrixFilterOperation::operator==):
(WebCore::BasicComponentTransferFilterOperation::blend):
(WebCore::BasicComponentTransferFilterOperation::operator==):
(WebCore::BlurFilterOperation::operator==):
(WebCore::BlurFilterOperation::blend):
(WebCore::DropShadowFilterOperation::operator==):
(WebCore::DropShadowFilterOperation::blend):
* platform/graphics/filters/FilterOperation.h:
* platform/graphics/filters/FilterOperations.cpp:
(WebCore::FilterOperations::outsets):
* rendering/FilterEffectRenderer.cpp:
(WebCore::FilterEffectRenderer::build):
* rendering/RenderLayerFilterInfo.cpp:
(WebCore::RenderLayer::FilterInfo::updateReferenceFilterClients):
* rendering/svg/RenderSVGResourceFilterPrimitive.cpp:
(WebCore::RenderSVGResourceFilterPrimitive::determineFilterPrimitiveSubregion):
* svg/graphics/filters/SVGFilter.h:
(isType):

Source/WebKit2:

* Shared/CoordinatedGraphics/CoordinatedGraphicsArgumentCoders.cpp:
(IPC::ArgumentCoder<WebCore::FilterOperations>::encode):
* Shared/WebCoreArgumentCoders.cpp:
(IPC::ArgumentCoder<FilterOperation>::encode):
* Shared/mac/RemoteLayerTreeTransaction.mm:
(WebKit::RemoteLayerTreeTextStream::operator<<):

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

17 files changed:
Source/WebCore/ChangeLog
Source/WebCore/css/CSSComputedStyleDeclaration.cpp
Source/WebCore/platform/graphics/ca/mac/PlatformCAFiltersMac.mm
Source/WebCore/platform/graphics/filters/Filter.h
Source/WebCore/platform/graphics/filters/FilterOperation.cpp
Source/WebCore/platform/graphics/filters/FilterOperation.h
Source/WebCore/platform/graphics/filters/FilterOperations.cpp
Source/WebCore/rendering/FilterEffectRenderer.cpp
Source/WebCore/rendering/RenderLayerFilterInfo.cpp
Source/WebCore/rendering/svg/RenderSVGResourceFilter.cpp
Source/WebCore/rendering/svg/RenderSVGResourceFilterPrimitive.cpp
Source/WebCore/rendering/svg/RenderSVGResourceFilterPrimitive.h
Source/WebCore/svg/graphics/filters/SVGFilter.h
Source/WebKit2/ChangeLog
Source/WebKit2/Shared/CoordinatedGraphics/CoordinatedGraphicsArgumentCoders.cpp
Source/WebKit2/Shared/WebCoreArgumentCoders.cpp
Source/WebKit2/Shared/mac/RemoteLayerTreeTransaction.mm

index 0bdfd20..1f0646e 100644 (file)
@@ -1,5 +1,45 @@
 2014-10-13  Chris Dumez  <cdumez@apple.com>
 
+        Use is<>() / downcast<>() for Filter / FilterOperation subclasses
+        https://bugs.webkit.org/show_bug.cgi?id=137644
+
+        Reviewed by Darin Adler.
+
+        Use is<>() / downcast<>() for Filter / FilterOperation subclasses.
+
+        No new tests, no behavior change.
+
+        * css/CSSComputedStyleDeclaration.cpp:
+        (WebCore::ComputedStyleExtractor::valueForFilter):
+        * platform/graphics/ca/mac/PlatformCAFiltersMac.mm:
+        (PlatformCAFilters::filterValueForOperation):
+        (PlatformCAFilters::colorMatrixValueForFilter):
+        * platform/graphics/filters/Filter.h:
+        * platform/graphics/filters/FilterOperation.cpp:
+        (WebCore::DefaultFilterOperation::operator==):
+        (WebCore::ReferenceFilterOperation::operator==):
+        (WebCore::BasicColorMatrixFilterOperation::blend):
+        (WebCore::BasicColorMatrixFilterOperation::operator==):
+        (WebCore::BasicComponentTransferFilterOperation::blend):
+        (WebCore::BasicComponentTransferFilterOperation::operator==):
+        (WebCore::BlurFilterOperation::operator==):
+        (WebCore::BlurFilterOperation::blend):
+        (WebCore::DropShadowFilterOperation::operator==):
+        (WebCore::DropShadowFilterOperation::blend):
+        * platform/graphics/filters/FilterOperation.h:
+        * platform/graphics/filters/FilterOperations.cpp:
+        (WebCore::FilterOperations::outsets):
+        * rendering/FilterEffectRenderer.cpp:
+        (WebCore::FilterEffectRenderer::build):
+        * rendering/RenderLayerFilterInfo.cpp:
+        (WebCore::RenderLayer::FilterInfo::updateReferenceFilterClients):
+        * rendering/svg/RenderSVGResourceFilterPrimitive.cpp:
+        (WebCore::RenderSVGResourceFilterPrimitive::determineFilterPrimitiveSubregion):
+        * svg/graphics/filters/SVGFilter.h:
+        (isType):
+
+2014-10-13  Chris Dumez  <cdumez@apple.com>
+
         Use is<>() / downcast<>() for Table render objects
         https://bugs.webkit.org/show_bug.cgi?id=137641
 
index f9c4ba5..6b7836b 100644 (file)
@@ -893,73 +893,73 @@ PassRef<CSSValue> ComputedStyleExtractor::valueForFilter(const RenderStyle* styl
 
     Vector<RefPtr<FilterOperation>>::const_iterator end = filterOperations.operations().end();
     for (Vector<RefPtr<FilterOperation>>::const_iterator it = filterOperations.operations().begin(); it != end; ++it) {
-        FilterOperation* filterOperation = (*it).get();
-        switch (filterOperation->type()) {
+        FilterOperation& filterOperation = **it;
+        switch (filterOperation.type()) {
         case FilterOperation::REFERENCE: {
-            ReferenceFilterOperation* referenceOperation = toReferenceFilterOperation(filterOperation);
+            ReferenceFilterOperation& referenceOperation = downcast<ReferenceFilterOperation>(filterOperation);
             filterValue = WebKitCSSFilterValue::create(WebKitCSSFilterValue::ReferenceFilterOperation);
-            filterValue->append(cssValuePool().createValue(referenceOperation->url(), CSSPrimitiveValue::CSS_URI));
+            filterValue->append(cssValuePool().createValue(referenceOperation.url(), CSSPrimitiveValue::CSS_URI));
             break;
         }
         case FilterOperation::GRAYSCALE: {
-            BasicColorMatrixFilterOperation* colorMatrixOperation = toBasicColorMatrixFilterOperation(filterOperation);
+            BasicColorMatrixFilterOperation& colorMatrixOperation = downcast<BasicColorMatrixFilterOperation>(filterOperation);
             filterValue = WebKitCSSFilterValue::create(WebKitCSSFilterValue::GrayscaleFilterOperation);
-            filterValue->append(cssValuePool().createValue(colorMatrixOperation->amount(), CSSPrimitiveValue::CSS_NUMBER));
+            filterValue->append(cssValuePool().createValue(colorMatrixOperation.amount(), CSSPrimitiveValue::CSS_NUMBER));
             break;
         }
         case FilterOperation::SEPIA: {
-            BasicColorMatrixFilterOperation* colorMatrixOperation = toBasicColorMatrixFilterOperation(filterOperation);
+            BasicColorMatrixFilterOperation& colorMatrixOperation = downcast<BasicColorMatrixFilterOperation>(filterOperation);
             filterValue = WebKitCSSFilterValue::create(WebKitCSSFilterValue::SepiaFilterOperation);
-            filterValue->append(cssValuePool().createValue(colorMatrixOperation->amount(), CSSPrimitiveValue::CSS_NUMBER));
+            filterValue->append(cssValuePool().createValue(colorMatrixOperation.amount(), CSSPrimitiveValue::CSS_NUMBER));
             break;
         }
         case FilterOperation::SATURATE: {
-            BasicColorMatrixFilterOperation* colorMatrixOperation = toBasicColorMatrixFilterOperation(filterOperation);
+            BasicColorMatrixFilterOperation& colorMatrixOperation = downcast<BasicColorMatrixFilterOperation>(filterOperation);
             filterValue = WebKitCSSFilterValue::create(WebKitCSSFilterValue::SaturateFilterOperation);
-            filterValue->append(cssValuePool().createValue(colorMatrixOperation->amount(), CSSPrimitiveValue::CSS_NUMBER));
+            filterValue->append(cssValuePool().createValue(colorMatrixOperation.amount(), CSSPrimitiveValue::CSS_NUMBER));
             break;
         }
         case FilterOperation::HUE_ROTATE: {
-            BasicColorMatrixFilterOperation* colorMatrixOperation = toBasicColorMatrixFilterOperation(filterOperation);
+            BasicColorMatrixFilterOperation& colorMatrixOperation = downcast<BasicColorMatrixFilterOperation>(filterOperation);
             filterValue = WebKitCSSFilterValue::create(WebKitCSSFilterValue::HueRotateFilterOperation);
-            filterValue->append(cssValuePool().createValue(colorMatrixOperation->amount(), CSSPrimitiveValue::CSS_DEG));
+            filterValue->append(cssValuePool().createValue(colorMatrixOperation.amount(), CSSPrimitiveValue::CSS_DEG));
             break;
         }
         case FilterOperation::INVERT: {
-            BasicComponentTransferFilterOperation* componentTransferOperation = toBasicComponentTransferFilterOperation(filterOperation);
+            BasicComponentTransferFilterOperation& componentTransferOperation = downcast<BasicComponentTransferFilterOperation>(filterOperation);
             filterValue = WebKitCSSFilterValue::create(WebKitCSSFilterValue::InvertFilterOperation);
-            filterValue->append(cssValuePool().createValue(componentTransferOperation->amount(), CSSPrimitiveValue::CSS_NUMBER));
+            filterValue->append(cssValuePool().createValue(componentTransferOperation.amount(), CSSPrimitiveValue::CSS_NUMBER));
             break;
         }
         case FilterOperation::OPACITY: {
-            BasicComponentTransferFilterOperation* componentTransferOperation = toBasicComponentTransferFilterOperation(filterOperation);
+            BasicComponentTransferFilterOperation& componentTransferOperation = downcast<BasicComponentTransferFilterOperation>(filterOperation);
             filterValue = WebKitCSSFilterValue::create(WebKitCSSFilterValue::OpacityFilterOperation);
-            filterValue->append(cssValuePool().createValue(componentTransferOperation->amount(), CSSPrimitiveValue::CSS_NUMBER));
+            filterValue->append(cssValuePool().createValue(componentTransferOperation.amount(), CSSPrimitiveValue::CSS_NUMBER));
             break;
         }
         case FilterOperation::BRIGHTNESS: {
-            BasicComponentTransferFilterOperation* brightnessOperation = toBasicComponentTransferFilterOperation(filterOperation);
+            BasicComponentTransferFilterOperation& brightnessOperation = downcast<BasicComponentTransferFilterOperation>(filterOperation);
             filterValue = WebKitCSSFilterValue::create(WebKitCSSFilterValue::BrightnessFilterOperation);
-            filterValue->append(cssValuePool().createValue(brightnessOperation->amount(), CSSPrimitiveValue::CSS_NUMBER));
+            filterValue->append(cssValuePool().createValue(brightnessOperation.amount(), CSSPrimitiveValue::CSS_NUMBER));
             break;
         }
         case FilterOperation::CONTRAST: {
-            BasicComponentTransferFilterOperation* contrastOperation = toBasicComponentTransferFilterOperation(filterOperation);
+            BasicComponentTransferFilterOperation& contrastOperation = downcast<BasicComponentTransferFilterOperation>(filterOperation);
             filterValue = WebKitCSSFilterValue::create(WebKitCSSFilterValue::ContrastFilterOperation);
-            filterValue->append(cssValuePool().createValue(contrastOperation->amount(), CSSPrimitiveValue::CSS_NUMBER));
+            filterValue->append(cssValuePool().createValue(contrastOperation.amount(), CSSPrimitiveValue::CSS_NUMBER));
             break;
         }
         case FilterOperation::BLUR: {
-            BlurFilterOperation* blurOperation = toBlurFilterOperation(filterOperation);
+            BlurFilterOperation& blurOperation = downcast<BlurFilterOperation>(filterOperation);
             filterValue = WebKitCSSFilterValue::create(WebKitCSSFilterValue::BlurFilterOperation);
-            filterValue->append(adjustLengthForZoom(blurOperation->stdDeviation(), style, adjust));
+            filterValue->append(adjustLengthForZoom(blurOperation.stdDeviation(), style, adjust));
             break;
         }
         case FilterOperation::DROP_SHADOW: {
-            DropShadowFilterOperation* dropShadowOperation = toDropShadowFilterOperation(filterOperation);
+            DropShadowFilterOperation& dropShadowOperation = downcast<DropShadowFilterOperation>(filterOperation);
             filterValue = WebKitCSSFilterValue::create(WebKitCSSFilterValue::DropShadowFilterOperation);
             // We want our computed style to look like that of a text shadow (has neither spread nor inset style).
-            ShadowData shadowData = ShadowData(dropShadowOperation->location(), dropShadowOperation->stdDeviation(), 0, Normal, false, dropShadowOperation->color());
+            ShadowData shadowData = ShadowData(dropShadowOperation.location(), dropShadowOperation.stdDeviation(), 0, Normal, false, dropShadowOperation.color());
             filterValue->append(valueForShadow(&shadowData, CSSPropertyTextShadow, style, adjust));
             break;
         }
index 248f9ed..4e225f4 100644 (file)
@@ -71,37 +71,37 @@ void PlatformCAFilters::setFiltersOnLayer(PlatformLayer* layer, const FilterOper
     
     for (unsigned i = 0; i < filters.size(); ++i) {
         String filterName = String::format("filter_%d", i);
-        const FilterOperation* filterOperation = filters.at(i);
-        switch (filterOperation->type()) {
+        const FilterOperation& filterOperation = *filters.at(i);
+        switch (filterOperation.type()) {
         case FilterOperation::DEFAULT:
             ASSERT_NOT_REACHED();
             break;
         case FilterOperation::DROP_SHADOW: {
             // FIXME: For now assume drop shadow is the last filter, put it on the layer.
             // <rdar://problem/10959969> Handle case where drop-shadow is not the last filter.
-            const DropShadowFilterOperation* op = toDropShadowFilterOperation(filterOperation);
-            [layer setShadowOffset:CGSizeMake(op->x(), op->y())];
+            const auto& dropShadowOperation = downcast<DropShadowFilterOperation>(filterOperation);
+            [layer setShadowOffset:CGSizeMake(dropShadowOperation.x(), dropShadowOperation.y())];
 
             CGFloat components[4];
-            op->color().getRGBA(components[0], components[1], components[2], components[3]);
+            dropShadowOperation.color().getRGBA(components[0], components[1], components[2], components[3]);
             RetainPtr<CGColorSpaceRef> colorSpace = adoptCF(CGColorSpaceCreateDeviceRGB());
             RetainPtr<CGColorRef> color = adoptCF(CGColorCreate(colorSpace.get(), components));
             [layer setShadowColor:color.get()];
-            [layer setShadowRadius:op->stdDeviation()];
+            [layer setShadowRadius:dropShadowOperation.stdDeviation()];
             [layer setShadowOpacity:1];
             break;
         }
 #if USE_CA_FILTERS
         case FilterOperation::GRAYSCALE: {
-            const BasicColorMatrixFilterOperation* op = toBasicColorMatrixFilterOperation(filterOperation);
+            const auto& colorMatrixOperation = downcast<BasicColorMatrixFilterOperation>(filterOperation);
             CAFilter *filter = [CAFilter filterWithType:kCAFilterColorMonochrome];
-            [filter setValue:[NSNumber numberWithFloat:op->amount()] forKey:@"inputAmount"];
+            [filter setValue:[NSNumber numberWithFloat:colorMatrixOperation.amount()] forKey:@"inputAmount"];
             [filter setName:filterName];
             [array.get() addObject:filter];
             break;
         }
         case FilterOperation::SEPIA: {
-            RetainPtr<NSValue> colorMatrixValue = PlatformCAFilters::colorMatrixValueForFilter(filterOperation->type(), filterOperation);
+            RetainPtr<NSValue> colorMatrixValue = PlatformCAFilters::colorMatrixValueForFilter(filterOperation.type(), &filterOperation);
             CAFilter *filter = [CAFilter filterWithType:kCAFilterColorMatrix];
             [filter setValue:colorMatrixValue.get() forKey:@"inputColorMatrix"];
             [filter setName:filterName];
@@ -109,24 +109,24 @@ void PlatformCAFilters::setFiltersOnLayer(PlatformLayer* layer, const FilterOper
             break;
         }
         case FilterOperation::SATURATE: {
-            const BasicColorMatrixFilterOperation* op = toBasicColorMatrixFilterOperation(filterOperation);
+            const auto& colorMatrixOperation = downcast<BasicColorMatrixFilterOperation>(filterOperation);
             CAFilter *filter = [CAFilter filterWithType:kCAFilterColorSaturate];
-            [filter setValue:[NSNumber numberWithFloat:op->amount()] forKey:@"inputAmount"];
+            [filter setValue:[NSNumber numberWithFloat:colorMatrixOperation.amount()] forKey:@"inputAmount"];
             [filter setName:filterName];
             [array.get() addObject:filter];
             break;
         }
         case FilterOperation::HUE_ROTATE: {
-            const BasicColorMatrixFilterOperation* op = toBasicColorMatrixFilterOperation(filterOperation);
+            const auto& colorMatrixOperation = downcast<BasicColorMatrixFilterOperation>(filterOperation);
             CAFilter *filter = [CAFilter filterWithType:kCAFilterColorHueRotate];
-            [filter setValue:[NSNumber numberWithFloat:deg2rad(op->amount())] forKey:@"inputAngle"];
+            [filter setValue:[NSNumber numberWithFloat:deg2rad(colorMatrixOperation.amount())] forKey:@"inputAngle"];
             [filter setName:@"hueRotate"];
             [filter setName:filterName];
             [array.get() addObject:filter];
             break;
         }
         case FilterOperation::INVERT: {
-            RetainPtr<NSValue> colorMatrixValue = PlatformCAFilters::colorMatrixValueForFilter(filterOperation->type(), filterOperation);
+            RetainPtr<NSValue> colorMatrixValue = PlatformCAFilters::colorMatrixValueForFilter(filterOperation.type(), &filterOperation);
             CAFilter *filter = [CAFilter filterWithType:kCAFilterColorMatrix];
             [filter setValue:colorMatrixValue.get() forKey:@"inputColorMatrix"];
             [filter setName:filterName];
@@ -134,7 +134,7 @@ void PlatformCAFilters::setFiltersOnLayer(PlatformLayer* layer, const FilterOper
             break;
         }
         case FilterOperation::OPACITY: {
-            RetainPtr<NSValue> colorMatrixValue = PlatformCAFilters::colorMatrixValueForFilter(filterOperation->type(), filterOperation);
+            RetainPtr<NSValue> colorMatrixValue = PlatformCAFilters::colorMatrixValueForFilter(filterOperation.type(), &filterOperation);
             CAFilter *filter = [CAFilter filterWithType:kCAFilterColorMatrix];
             [filter setValue:colorMatrixValue.get() forKey:@"inputColorMatrix"];
             [filter setName:filterName];
@@ -142,7 +142,7 @@ void PlatformCAFilters::setFiltersOnLayer(PlatformLayer* layer, const FilterOper
             break;
         }
         case FilterOperation::BRIGHTNESS: {
-            RetainPtr<NSValue> colorMatrixValue = PlatformCAFilters::colorMatrixValueForFilter(filterOperation->type(), filterOperation);
+            RetainPtr<NSValue> colorMatrixValue = PlatformCAFilters::colorMatrixValueForFilter(filterOperation.type(), &filterOperation);
             CAFilter *filter = [CAFilter filterWithType:kCAFilterColorMatrix];
             [filter setValue:colorMatrixValue.get() forKey:@"inputColorMatrix"];
             [filter setName:filterName];
@@ -150,7 +150,7 @@ void PlatformCAFilters::setFiltersOnLayer(PlatformLayer* layer, const FilterOper
             break;
         }
         case FilterOperation::CONTRAST: {
-            RetainPtr<NSValue> colorMatrixValue = PlatformCAFilters::colorMatrixValueForFilter(filterOperation->type(), filterOperation);
+            RetainPtr<NSValue> colorMatrixValue = PlatformCAFilters::colorMatrixValueForFilter(filterOperation.type(), &filterOperation);
             CAFilter *filter = [CAFilter filterWithType:kCAFilterColorMatrix];
             [filter setValue:colorMatrixValue.get() forKey:@"inputColorMatrix"];
             [filter setName:filterName];
@@ -158,30 +158,30 @@ void PlatformCAFilters::setFiltersOnLayer(PlatformLayer* layer, const FilterOper
             break;
         }
         case FilterOperation::BLUR: {
-            const BlurFilterOperation* op = toBlurFilterOperation(filterOperation);
+            const auto& blurOperation = downcast<BlurFilterOperation>(filterOperation);
             CAFilter *filter = [CAFilter filterWithType:kCAFilterGaussianBlur];
-            [filter setValue:[NSNumber numberWithFloat:floatValueForLength(op->stdDeviation(), 0)] forKey:@"inputRadius"];
+            [filter setValue:[NSNumber numberWithFloat:floatValueForLength(blurOperation.stdDeviation(), 0)] forKey:@"inputRadius"];
             [filter setName:filterName];
             [array.get() addObject:filter];
             break;
         }
 #else
         case FilterOperation::GRAYSCALE: {
-            const BasicColorMatrixFilterOperation* op = toBasicColorMatrixFilterOperation(filterOperation);
+            const auto& colorMatrixOperation = downcast<BasicColorMatrixFilterOperation>(filterOperation);
             CIFilter* filter = [CIFilter filterWithName:@"CIColorMonochrome"];
             [filter setDefaults];
-            [filter setValue:[NSNumber numberWithFloat:op->amount()] forKey:@"inputIntensity"];
+            [filter setValue:[NSNumber numberWithFloat:colorMatrixOperation.amount()] forKey:@"inputIntensity"];
             [filter setValue:[CIColor colorWithRed:0.67 green:0.67 blue:0.67] forKey:@"inputColor"]; // Color derived empirically to match zero saturation levels.
             [filter setName:filterName];
             [array.get() addObject:filter];
             break;
         }
         case FilterOperation::SEPIA: {
-            const BasicColorMatrixFilterOperation* op = toBasicColorMatrixFilterOperation(filterOperation);
+            const auto& colorMatrixOperation = downcast<BasicColorMatrixFilterOperation>(filterOperation);
             CIFilter* filter = [CIFilter filterWithName:@"CIColorMatrix"];
             [filter setDefaults];
 
-            double t = op->amount();
+            double t = colorMatrixOperation.amount();
             t = std::min(std::max(0.0, t), 1.0);
             // FIXME: results don't match the software filter.
             [filter setValue:[CIVector vectorWithX:WebCore::blend(sepiaNoneConstants[0][0], sepiaFullConstants[0][0], t)
@@ -198,30 +198,30 @@ void PlatformCAFilters::setFiltersOnLayer(PlatformLayer* layer, const FilterOper
             break;
         }
         case FilterOperation::SATURATE: {
-            const BasicColorMatrixFilterOperation* op = toBasicColorMatrixFilterOperation(filterOperation);
+            const auto& colorMatrixOperation = downcast<BasicColorMatrixFilterOperation>(filterOperation);
             CIFilter* filter = [CIFilter filterWithName:@"CIColorControls"];
             [filter setDefaults];
-            [filter setValue:[NSNumber numberWithFloat:op->amount()] forKey:@"inputSaturation"];
+            [filter setValue:[NSNumber numberWithFloat:colorMatrixOperation.amount()] forKey:@"inputSaturation"];
             [filter setName:filterName];
             [array.get() addObject:filter];
             break;
         }
         case FilterOperation::HUE_ROTATE: {
-            const BasicColorMatrixFilterOperation* op = toBasicColorMatrixFilterOperation(filterOperation);
+            const auto& colorMatrixOperation = downcast<BasicColorMatrixFilterOperation>(filterOperation);
             CIFilter* filter = [CIFilter filterWithName:@"CIHueAdjust"];
             [filter setDefaults];
 
-            [filter setValue:[NSNumber numberWithFloat:deg2rad(op->amount())] forKey:@"inputAngle"];
+            [filter setValue:[NSNumber numberWithFloat:deg2rad(colorMatrixOperation.amount())] forKey:@"inputAngle"];
             [filter setName:filterName];
             [array.get() addObject:filter];
             break;
         }
         case FilterOperation::INVERT: {
-            const BasicComponentTransferFilterOperation* op = toBasicComponentTransferFilterOperation(filterOperation);
+            const auto& componentTransferOperation = downcast<BasicComponentTransferFilterOperation>(filterOperation);
             CIFilter* filter = [CIFilter filterWithName:@"CIColorMatrix"];
             [filter setDefaults];
 
-            double multiplier = 1 - op->amount() * 2;
+            double multiplier = 1 - componentTransferOperation.amount() * 2;
 
             // FIXME: the results of this filter look wrong.
             [filter setValue:[CIVector vectorWithX:multiplier Y:0 Z:0 W:0] forKey:@"inputRVector"];
@@ -234,24 +234,24 @@ void PlatformCAFilters::setFiltersOnLayer(PlatformLayer* layer, const FilterOper
             break;
         }
         case FilterOperation::OPACITY: {
-            const BasicComponentTransferFilterOperation* op = toBasicComponentTransferFilterOperation(filterOperation);
+            const auto& componentTransferOperation = downcast<BasicComponentTransferFilterOperation>(filterOperation);
             CIFilter* filter = [CIFilter filterWithName:@"CIColorMatrix"];
             [filter setDefaults];
 
             [filter setValue:[CIVector vectorWithX:1 Y:0 Z:0 W:0] forKey:@"inputRVector"];
             [filter setValue:[CIVector vectorWithX:0 Y:1 Z:0 W:0] forKey:@"inputGVector"];
             [filter setValue:[CIVector vectorWithX:0 Y:0 Z:1 W:0] forKey:@"inputBVector"];
-            [filter setValue:[CIVector vectorWithX:0 Y:0 Z:0 W:op->amount()] forKey:@"inputAVector"];
+            [filter setValue:[CIVector vectorWithX:0 Y:0 Z:0 W:componentTransferOperation.amount()] forKey:@"inputAVector"];
             [filter setValue:[CIVector vectorWithX:0 Y:0 Z:0 W:0] forKey:@"inputBiasVector"];
             [filter setName:filterName];
             [array.get() addObject:filter];
             break;
         }
         case FilterOperation::BRIGHTNESS: {
-            const BasicComponentTransferFilterOperation* op = toBasicComponentTransferFilterOperation(filterOperation);
+            const auto& componentTransferOperation = downcast<BasicComponentTransferFilterOperation>(filterOperation);
             CIFilter* filter = [CIFilter filterWithName:@"CIColorMatrix"];
             [filter setDefaults];
-            double amount = op->amount();
+            double amount = componentTransferOperation.amount();
 
             [filter setValue:[CIVector vectorWithX:amount Y:0 Z:0 W:0] forKey:@"inputRVector"];
             [filter setValue:[CIVector vectorWithX:0 Y:amount Z:0 W:0] forKey:@"inputGVector"];
@@ -261,20 +261,20 @@ void PlatformCAFilters::setFiltersOnLayer(PlatformLayer* layer, const FilterOper
             break;
         }
         case FilterOperation::CONTRAST: {
-            const BasicComponentTransferFilterOperation* op = toBasicComponentTransferFilterOperation(filterOperation);
+            const auto& componentTransferOperation = downcast<BasicComponentTransferFilterOperation>(filterOperation);
             CIFilter* filter = [CIFilter filterWithName:@"CIColorControls"];
             [filter setDefaults];
-            [filter setValue:[NSNumber numberWithFloat:op->amount()] forKey:@"inputContrast"];
+            [filter setValue:[NSNumber numberWithFloat:componentTransferOperation.amount()] forKey:@"inputContrast"];
             [filter setName:filterName];
             [array.get() addObject:filter];
             break;
         }
         case FilterOperation::BLUR: {
             // FIXME: For now we ignore stdDeviationY.
-            const BlurFilterOperation* op = toBlurFilterOperation(filterOperation);
+            const auto& blurOperation = downcast<BlurFilterOperation>(filterOperation);
             CIFilter* filter = [CIFilter filterWithName:@"CIGaussianBlur"];
             [filter setDefaults];
-            [filter setValue:[NSNumber numberWithFloat:floatValueForLength(op->stdDeviation(), 0)] forKey:@"inputRadius"];
+            [filter setValue:[NSNumber numberWithFloat:floatValueForLength(blurOperation.stdDeviation(), 0)] forKey:@"inputRadius"];
             [filter setName:filterName];
             [array.get() addObject:filter];
             break;
@@ -302,8 +302,8 @@ RetainPtr<NSValue> PlatformCAFilters::filterValueForOperation(const FilterOperat
     FilterOperation::OperationType type = operation->type();
     RetainPtr<id> value;
     
-    if (type == FilterOperation::DEFAULT) {
-        type = toDefaultFilterOperation(operation)->representedType();
+    if (is<DefaultFilterOperation>(*operation)) {
+        type = downcast<DefaultFilterOperation>(*operation).representedType();
         operation = nullptr;
     }
     
@@ -316,7 +316,7 @@ RetainPtr<NSValue> PlatformCAFilters::filterValueForOperation(const FilterOperat
         // CAFilter: inputAmount
         double amount = 0;
         if (operation)
-            amount = toBasicColorMatrixFilterOperation(operation)->amount();
+            amount = downcast<BasicColorMatrixFilterOperation>(*operation).amount();
         
         value = [NSNumber numberWithDouble:amount];
         break;
@@ -328,12 +328,10 @@ RetainPtr<NSValue> PlatformCAFilters::filterValueForOperation(const FilterOperat
 #else
         // CIFilter: inputRVector, inputGVector, inputBVector
         double amount = 0;
-        if (operation) {
-            const BasicColorMatrixFilterOperation* op = toBasicColorMatrixFilterOperation(operation);
-            amount = op->amount();
-        }
+        if (operation)
+            amount = downcast<BasicColorMatrixFilterOperation>(*operation).amount();
 
-        CIVector* rowVector = 0;
+        CIVector* rowVector = nullptr;
         switch (internalFilterPropertyIndex) {
         case 0: rowVector = [[CIVector alloc] initWithX:WebCore::blend(sepiaNoneConstants[0][0], sepiaFullConstants[0][0], amount)
                                                       Y:WebCore::blend(sepiaNoneConstants[0][1], sepiaFullConstants[0][1], amount)
@@ -354,7 +352,7 @@ RetainPtr<NSValue> PlatformCAFilters::filterValueForOperation(const FilterOperat
         // CAFilter: inputAmount
         double amount = 1;
         if (operation)
-            amount = toBasicColorMatrixFilterOperation(operation)->amount();
+            amount = downcast<BasicColorMatrixFilterOperation>(*operation).amount();
         
         value = [NSNumber numberWithDouble:amount];
         break;
@@ -364,7 +362,7 @@ RetainPtr<NSValue> PlatformCAFilters::filterValueForOperation(const FilterOperat
         // Hue rotate CAFilter: inputAngle
         double amount = 0;
         if (operation)
-            amount = toBasicColorMatrixFilterOperation(operation)->amount();
+            amount = downcast<BasicColorMatrixFilterOperation>(*operation).amount();
         
         amount = deg2rad(amount);
         value = [NSNumber numberWithDouble:amount];
@@ -378,7 +376,7 @@ RetainPtr<NSValue> PlatformCAFilters::filterValueForOperation(const FilterOperat
         // CIFilter: inputRVector, inputGVector, inputBVector, inputBiasVector
         double amount = 0;
         if (operation)
-            amount = toBasicComponentTransferFilterOperation(operation)->amount();
+            amount = downcast<BasicComponentTransferFilterOperation>(*operation).amount();
         
         double multiplier = 1 - amount * 2;
 
@@ -404,7 +402,7 @@ RetainPtr<NSValue> PlatformCAFilters::filterValueForOperation(const FilterOperat
         // Opacity CIFilter: inputAVector
         double amount = 1;
         if (operation)
-            amount = toBasicComponentTransferFilterOperation(operation)->amount();
+            amount = downcast<BasicComponentTransferFilterOperation>(*operation).amount();
         
         value = adoptNS([[CIVector alloc] initWithX:0 Y:0 Z:0 W:amount]);
 #endif
@@ -419,9 +417,9 @@ RetainPtr<NSValue> PlatformCAFilters::filterValueForOperation(const FilterOperat
         // Brightness CIFilter: inputColorMatrix
         double amount = 1;
         if (operation)
-            amount = toBasicComponentTransferFilterOperation(operation)->amount();
+            amount = downcast<BasicComponentTransferFilterOperation>(*operation).amount();
         
-        CIVector* rowVector = 0;
+        CIVector* rowVector = nullptr;
         switch (internalFilterPropertyIndex) {
         case 0: rowVector = [[CIVector alloc] initWithX:amount Y:0 Z:0 W:0]; break; // inputRVector
         case 1: rowVector = [[CIVector alloc] initWithX:0 Y:amount Z:0 W:0]; break; // inputGVector
@@ -440,7 +438,7 @@ RetainPtr<NSValue> PlatformCAFilters::filterValueForOperation(const FilterOperat
         // Contrast CIFilter: inputContrast
         double amount = 1;
         if (operation)
-            amount = toBasicComponentTransferFilterOperation(operation)->amount();
+            amount = downcast<BasicComponentTransferFilterOperation>(*operation).amount();
         
         value = [NSNumber numberWithDouble:amount];
 #endif
@@ -451,7 +449,7 @@ RetainPtr<NSValue> PlatformCAFilters::filterValueForOperation(const FilterOperat
         // CAFilter: inputRadius
         double amount = 0;
         if (operation)
-            amount = floatValueForLength(toBlurFilterOperation(operation)->stdDeviation(), 0);
+            amount = floatValueForLength(downcast<BlurFilterOperation>(*operation).stdDeviation(), 0);
         
         value = [NSNumber numberWithDouble:amount];
         break;
@@ -468,7 +466,7 @@ RetainPtr<NSValue> PlatformCAFilters::colorMatrixValueForFilter(FilterOperation:
 {
     switch (type) {
     case FilterOperation::SEPIA: {
-        double t = filterOperation ? toBasicColorMatrixFilterOperation(filterOperation)->amount() : 0;
+        double t = filterOperation ? downcast<BasicColorMatrixFilterOperation>(*filterOperation).amount() : 0;
         t = std::min(std::max(0.0, t), 1.0);
         CAColorMatrix colorMatrix = {
             static_cast<float>(WebCore::blend(sepiaNoneConstants[0][0], sepiaFullConstants[0][0], t)),
@@ -487,7 +485,7 @@ RetainPtr<NSValue> PlatformCAFilters::colorMatrixValueForFilter(FilterOperation:
         return [NSValue valueWithCAColorMatrix:colorMatrix];
     }
     case FilterOperation::INVERT: {
-        float amount = filterOperation ? toBasicComponentTransferFilterOperation(filterOperation)->amount() : 0;
+        float amount = filterOperation ? downcast<BasicComponentTransferFilterOperation>(*filterOperation).amount() : 0;
         float multiplier = 1 - amount * 2;
         CAColorMatrix colorMatrix = {
             multiplier, 0, 0, 0, amount,
@@ -498,7 +496,7 @@ RetainPtr<NSValue> PlatformCAFilters::colorMatrixValueForFilter(FilterOperation:
         return [NSValue valueWithCAColorMatrix:colorMatrix];
     }
     case FilterOperation::OPACITY: {
-        float amount = filterOperation ? toBasicComponentTransferFilterOperation(filterOperation)->amount() : 1;
+        float amount = filterOperation ? downcast<BasicComponentTransferFilterOperation>(filterOperation)->amount() : 1;
         CAColorMatrix colorMatrix = {
             1, 0, 0, 0, 0,
             0, 1, 0, 0, 0,
@@ -508,7 +506,7 @@ RetainPtr<NSValue> PlatformCAFilters::colorMatrixValueForFilter(FilterOperation:
         return [NSValue valueWithCAColorMatrix:colorMatrix];
     }
     case FilterOperation::CONTRAST: {
-        float amount = filterOperation ? toBasicComponentTransferFilterOperation(filterOperation)->amount() : 1;
+        float amount = filterOperation ? downcast<BasicComponentTransferFilterOperation>(filterOperation)->amount() : 1;
         float intercept = -0.5 * amount + 0.5;
         CAColorMatrix colorMatrix = {
             amount, 0, 0, 0, intercept,
@@ -519,7 +517,7 @@ RetainPtr<NSValue> PlatformCAFilters::colorMatrixValueForFilter(FilterOperation:
         return [NSValue valueWithCAColorMatrix:colorMatrix];
     }
     case FilterOperation::BRIGHTNESS: {
-        float amount = filterOperation ? toBasicComponentTransferFilterOperation(filterOperation)->amount() : 1;
+        float amount = filterOperation ? downcast<BasicComponentTransferFilterOperation>(filterOperation)->amount() : 1;
         CAColorMatrix colorMatrix = {
             amount, 0, 0, 0, 0,
             0, amount, 0, 0, 0,
index 710ae63..dd512a3 100644 (file)
@@ -70,9 +70,6 @@ private:
     float m_filterScale;
 };
 
-#define FILTER_TYPE_CASTS(ToValueTypeName, predicate) \
-    TYPE_CASTS_BASE(ToValueTypeName, Filter, filter, filter->predicate, filter.predicate)
-
 } // namespace WebCore
 
 #endif // Filter_h
index f5ed732..b189e14 100644 (file)
 
 namespace WebCore {
     
-bool DefaultFilterOperation::operator==(const FilterOperation& o) const
+bool DefaultFilterOperation::operator==(const FilterOperation& operation) const
 {
-    if (!isSameType(o))
+    if (!isSameType(operation))
         return false;
     
-    return representedType() == toDefaultFilterOperation(o).representedType();
+    return representedType() == downcast<DefaultFilterOperation>(operation).representedType();
 }
 
 ReferenceFilterOperation::ReferenceFilterOperation(const String& url, const String& fragment)
@@ -50,12 +50,12 @@ ReferenceFilterOperation::~ReferenceFilterOperation()
 {
 }
     
-bool ReferenceFilterOperation::operator==(const FilterOperation& o) const
+bool ReferenceFilterOperation::operator==(const FilterOperation& operation) const
 {
-    if (!isSameType(o))
+    if (!isSameType(operation))
         return false;
     
-    return m_url == toReferenceFilterOperation(o).m_url;
+    return m_url == downcast<ReferenceFilterOperation>(operation).m_url;
 }
     
 CachedSVGDocumentReference* ReferenceFilterOperation::getOrCreateCachedSVGDocumentReference()
@@ -73,16 +73,16 @@ PassRefPtr<FilterOperation> BasicColorMatrixFilterOperation::blend(const FilterO
     if (blendToPassthrough)
         return BasicColorMatrixFilterOperation::create(WebCore::blend(m_amount, passthroughAmount(), progress), m_type);
         
-    const BasicColorMatrixFilterOperation* fromOp = toBasicColorMatrixFilterOperation(from);
-    double fromAmount = fromOp ? fromOp->amount() : passthroughAmount();
+    const BasicColorMatrixFilterOperation* fromOperation = downcast<BasicColorMatrixFilterOperation>(from);
+    double fromAmount = fromOperation ? fromOperation->amount() : passthroughAmount();
     return BasicColorMatrixFilterOperation::create(WebCore::blend(fromAmount, m_amount, progress), m_type);
 }
 
-inline bool BasicColorMatrixFilterOperation::operator==(const FilterOperation& o) const
+inline bool BasicColorMatrixFilterOperation::operator==(const FilterOperation& operation) const
 {
-    if (!isSameType(o))
+    if (!isSameType(operation))
         return false;
-    const BasicColorMatrixFilterOperation& other = toBasicColorMatrixFilterOperation(o);
+    const BasicColorMatrixFilterOperation& other = downcast<BasicColorMatrixFilterOperation>(operation);
     return m_amount == other.m_amount;
 }
 
@@ -109,16 +109,16 @@ PassRefPtr<FilterOperation> BasicComponentTransferFilterOperation::blend(const F
     if (blendToPassthrough)
         return BasicComponentTransferFilterOperation::create(WebCore::blend(m_amount, passthroughAmount(), progress), m_type);
         
-    const BasicComponentTransferFilterOperation* fromOp = toBasicComponentTransferFilterOperation(from);
-    double fromAmount = fromOp ? fromOp->amount() : passthroughAmount();
+    const BasicComponentTransferFilterOperation* fromOperation = downcast<BasicComponentTransferFilterOperation>(from);
+    double fromAmount = fromOperation ? fromOperation->amount() : passthroughAmount();
     return BasicComponentTransferFilterOperation::create(WebCore::blend(fromAmount, m_amount, progress), m_type);
 }
 
-inline bool BasicComponentTransferFilterOperation::operator==(const FilterOperation& o) const
+inline bool BasicComponentTransferFilterOperation::operator==(const FilterOperation& operation) const
 {
-    if (!isSameType(o))
+    if (!isSameType(operation))
         return false;
-    const BasicComponentTransferFilterOperation& other = toBasicComponentTransferFilterOperation(o);
+    const BasicComponentTransferFilterOperation& other = downcast<BasicComponentTransferFilterOperation>(operation);
     return m_amount == other.m_amount;
 }
 
@@ -139,12 +139,12 @@ double BasicComponentTransferFilterOperation::passthroughAmount() const
     }
 }
     
-bool BlurFilterOperation::operator==(const FilterOperation& o) const
+bool BlurFilterOperation::operator==(const FilterOperation& operation) const
 {
-    if (!isSameType(o))
+    if (!isSameType(operation))
         return false;
     
-    return m_stdDeviation == toBlurFilterOperation(o).stdDeviation();
+    return m_stdDeviation == downcast<BlurFilterOperation>(operation).stdDeviation();
 }
     
 PassRefPtr<FilterOperation> BlurFilterOperation::blend(const FilterOperation* from, double progress, bool blendToPassthrough)
@@ -157,16 +157,16 @@ PassRefPtr<FilterOperation> BlurFilterOperation::blend(const FilterOperation* fr
     if (blendToPassthrough)
         return BlurFilterOperation::create(Length(lengthType).blend(m_stdDeviation, progress));
 
-    const BlurFilterOperation* fromOp = toBlurFilterOperation(from);
-    Length fromLength = fromOp ? fromOp->m_stdDeviation : Length(lengthType);
+    const BlurFilterOperation* fromOperation = downcast<BlurFilterOperation>(from);
+    Length fromLength = fromOperation ? fromOperation->m_stdDeviation : Length(lengthType);
     return BlurFilterOperation::create(m_stdDeviation.blend(fromLength, progress));
 }
     
-bool DropShadowFilterOperation::operator==(const FilterOperation& o) const
+bool DropShadowFilterOperation::operator==(const FilterOperation& operation) const
 {
-    if (!isSameType(o))
+    if (!isSameType(operation))
         return false;
-    const DropShadowFilterOperation& other = toDropShadowFilterOperation(o);
+    const DropShadowFilterOperation& other = downcast<DropShadowFilterOperation>(operation);
     return m_location == other.m_location && m_stdDeviation == other.m_stdDeviation && m_color == other.m_color;
 }
     
@@ -181,10 +181,10 @@ PassRefPtr<FilterOperation> DropShadowFilterOperation::blend(const FilterOperati
             WebCore::blend(m_stdDeviation, 0, progress),
             WebCore::blend(m_color, Color(Color::transparent), progress));
 
-    const DropShadowFilterOperation* fromOp = toDropShadowFilterOperation(from);
-    IntPoint fromLocation = fromOp ? fromOp->location() : IntPoint();
-    int fromStdDeviation = fromOp ? fromOp->stdDeviation() : 0;
-    Color fromColor = fromOp ? fromOp->color() : Color(Color::transparent);
+    const DropShadowFilterOperation* fromOperation = downcast<DropShadowFilterOperation>(from);
+    IntPoint fromLocation = fromOperation ? fromOperation->location() : IntPoint();
+    int fromStdDeviation = fromOperation ? fromOperation->stdDeviation() : 0;
+    Color fromColor = fromOperation ? fromOperation->color() : Color(Color::transparent);
     
     return DropShadowFilterOperation::create(
         WebCore::blend(fromLocation, m_location, progress),
index a18d995..5fe2010 100644 (file)
@@ -33,6 +33,7 @@
 #include <wtf/OwnPtr.h>
 #include <wtf/PassOwnPtr.h>
 #include <wtf/RefCounted.h>
+#include <wtf/TypeCasts.h>
 #include <wtf/text/WTFString.h>
 
 // Annoyingly, wingdi.h #defines this.
@@ -114,9 +115,6 @@ protected:
     OperationType m_type;
 };
 
-#define FILTEROPERATION_TYPE_CASTS(ToValueTypeName, predicate) \
-    TYPE_CASTS_BASE(ToValueTypeName, WebCore::FilterOperation, value, value->predicate, value.predicate)
-
 class WEBCORE_EXPORT DefaultFilterOperation : public FilterOperation {
 public:
     static PassRefPtr<DefaultFilterOperation> create(OperationType representedType)
@@ -143,9 +141,6 @@ private:
     OperationType m_representedType;
 };
 
-FILTEROPERATION_TYPE_CASTS(DefaultFilterOperation, type() == FilterOperation::DEFAULT);
-
-
 class PassthroughFilterOperation : public FilterOperation {
 public:
     static PassRefPtr<PassthroughFilterOperation> create()
@@ -170,8 +165,6 @@ private:
     }
 };
 
-FILTEROPERATION_TYPE_CASTS(PassthroughFilterOperation, type() == FilterOperation::PASSTHROUGH);
-
 class ReferenceFilterOperation : public FilterOperation {
 public:
     static PassRefPtr<ReferenceFilterOperation> create(const String& url, const String& fragment)
@@ -210,8 +203,6 @@ private:
     RefPtr<FilterEffect> m_filterEffect;
 };
 
-FILTEROPERATION_TYPE_CASTS(ReferenceFilterOperation, type() == FilterOperation::REFERENCE);
-
 // GRAYSCALE, SEPIA, SATURATE and HUE_ROTATE are variations on a basic color matrix effect.
 // For HUE_ROTATE, the angle of rotation is stored in m_amount.
 class WEBCORE_EXPORT BasicColorMatrixFilterOperation : public FilterOperation {
@@ -244,8 +235,6 @@ private:
     double m_amount;
 };
 
-FILTEROPERATION_TYPE_CASTS(BasicColorMatrixFilterOperation, isBasicColorMatrixFilterOperation());
-
 // INVERT, BRIGHTNESS, CONTRAST and OPACITY are variations on a basic component transfer effect.
 class WEBCORE_EXPORT BasicComponentTransferFilterOperation : public FilterOperation {
 public:
@@ -279,8 +268,6 @@ private:
     double m_amount;
 };
 
-FILTEROPERATION_TYPE_CASTS(BasicComponentTransferFilterOperation, isBasicComponentTransferFilterOperation());
-
 class WEBCORE_EXPORT BlurFilterOperation : public FilterOperation {
 public:
     static PassRefPtr<BlurFilterOperation> create(Length stdDeviation)
@@ -312,8 +299,6 @@ private:
     Length m_stdDeviation;
 };
 
-FILTEROPERATION_TYPE_CASTS(BlurFilterOperation, type() == FilterOperation::BLUR);
-
 class WEBCORE_EXPORT DropShadowFilterOperation : public FilterOperation {
 public:
     static PassRefPtr<DropShadowFilterOperation> create(const IntPoint& location, int stdDeviation, Color color)
@@ -353,8 +338,19 @@ private:
     Color m_color;
 };
 
-FILTEROPERATION_TYPE_CASTS(DropShadowFilterOperation, type() == FilterOperation::DROP_SHADOW);
-
 } // namespace WebCore
 
+#define SPECIALIZE_TYPE_TRAITS_FILTEROPERATION(ToValueTypeName, predicate) \
+SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::ToValueTypeName) \
+    static bool isType(const WebCore::FilterOperation& operation) { return operation.predicate; } \
+SPECIALIZE_TYPE_TRAITS_END()
+
+SPECIALIZE_TYPE_TRAITS_FILTEROPERATION(DefaultFilterOperation, type() == WebCore::FilterOperation::DEFAULT)
+SPECIALIZE_TYPE_TRAITS_FILTEROPERATION(PassthroughFilterOperation, type() == WebCore::FilterOperation::PASSTHROUGH)
+SPECIALIZE_TYPE_TRAITS_FILTEROPERATION(ReferenceFilterOperation, type() == WebCore::FilterOperation::REFERENCE)
+SPECIALIZE_TYPE_TRAITS_FILTEROPERATION(BasicColorMatrixFilterOperation, isBasicColorMatrixFilterOperation())
+SPECIALIZE_TYPE_TRAITS_FILTEROPERATION(BasicComponentTransferFilterOperation, isBasicComponentTransferFilterOperation())
+SPECIALIZE_TYPE_TRAITS_FILTEROPERATION(BlurFilterOperation, type() == WebCore::FilterOperation::BLUR)
+SPECIALIZE_TYPE_TRAITS_FILTEROPERATION(DropShadowFilterOperation, type() == WebCore::FilterOperation::DROP_SHADOW)
+
 #endif // FilterOperation_h
index af82366..e1505dd 100644 (file)
@@ -106,24 +106,24 @@ FilterOutsets FilterOperations::outsets() const
 {
     FilterOutsets totalOutsets;
     for (size_t i = 0; i < m_operations.size(); ++i) {
-        const FilterOperation* filterOperation = m_operations.at(i).get();
-        switch (filterOperation->type()) {
+        const FilterOperation& filterOperation = *m_operations.at(i);
+        switch (filterOperation.type()) {
         case FilterOperation::BLUR: {
-            const BlurFilterOperation* blurOperation = toBlurFilterOperation(filterOperation);
-            float stdDeviation = floatValueForLength(blurOperation->stdDeviation(), 0);
+            const BlurFilterOperation& blurOperation = downcast<BlurFilterOperation>(filterOperation);
+            float stdDeviation = floatValueForLength(blurOperation.stdDeviation(), 0);
             IntSize outsetSize = outsetSizeForBlur(stdDeviation);
             FilterOutsets outsets(outsetSize.height(), outsetSize.width(), outsetSize.height(), outsetSize.width());
             totalOutsets += outsets;
             break;
         }
         case FilterOperation::DROP_SHADOW: {
-            const DropShadowFilterOperation* dropShadowOperation = toDropShadowFilterOperation(filterOperation);
-            IntSize outsetSize = outsetSizeForBlur(dropShadowOperation->stdDeviation());
+            const DropShadowFilterOperation& dropShadowOperation = downcast<DropShadowFilterOperation>(filterOperation);
+            IntSize outsetSize = outsetSizeForBlur(dropShadowOperation.stdDeviation());
             FilterOutsets outsets(
-                std::max(0, outsetSize.height() - dropShadowOperation->y()),
-                std::max(0, outsetSize.width() + dropShadowOperation->x()),
-                std::max(0, outsetSize.height() + dropShadowOperation->y()),
-                std::max(0, outsetSize.width() - dropShadowOperation->x())
+                std::max(0, outsetSize.height() - dropShadowOperation.y()),
+                std::max(0, outsetSize.width() + dropShadowOperation.x()),
+                std::max(0, outsetSize.height() + dropShadowOperation.y()),
+                std::max(0, outsetSize.width() - dropShadowOperation.x())
             );
             totalOutsets += outsets;
             break;
index aef902d..c55e7ac 100644 (file)
@@ -143,18 +143,18 @@ bool FilterEffectRenderer::build(RenderElement* renderer, const FilterOperations
     RefPtr<FilterEffect> previousEffect = m_sourceGraphic;
     for (size_t i = 0; i < operations.operations().size(); ++i) {
         RefPtr<FilterEffect> effect;
-        FilterOperation* filterOperation = operations.operations().at(i).get();
-        switch (filterOperation->type()) {
+        FilterOperation& filterOperation = *operations.operations().at(i);
+        switch (filterOperation.type()) {
         case FilterOperation::REFERENCE: {
-            ReferenceFilterOperation* referenceOperation = toReferenceFilterOperation(filterOperation);
-            effect = buildReferenceFilter(renderer, previousEffect, referenceOperation);
-            referenceOperation->setFilterEffect(effect);
+            ReferenceFilterOperation& referenceOperation = downcast<ReferenceFilterOperation>(filterOperation);
+            effect = buildReferenceFilter(renderer, previousEffect, &referenceOperation);
+            referenceOperation.setFilterEffect(effect);
             break;
         }
         case FilterOperation::GRAYSCALE: {
-            BasicColorMatrixFilterOperation* colorMatrixOperation = toBasicColorMatrixFilterOperation(filterOperation);
+            BasicColorMatrixFilterOperation& colorMatrixOperation = downcast<BasicColorMatrixFilterOperation>(filterOperation);
             Vector<float> inputParameters;
-            double oneMinusAmount = clampTo(1 - colorMatrixOperation->amount(), 0.0, 1.0);
+            double oneMinusAmount = clampTo(1 - colorMatrixOperation.amount(), 0.0, 1.0);
 
             // See https://dvcs.w3.org/hg/FXTF/raw-file/tip/filters/index.html#grayscaleEquivalent
             // for information on parameters.
@@ -180,9 +180,9 @@ bool FilterEffectRenderer::build(RenderElement* renderer, const FilterOperations
             break;
         }
         case FilterOperation::SEPIA: {
-            BasicColorMatrixFilterOperation* colorMatrixOperation = toBasicColorMatrixFilterOperation(filterOperation);
+            BasicColorMatrixFilterOperation& colorMatrixOperation = downcast<BasicColorMatrixFilterOperation>(filterOperation);
             Vector<float> inputParameters;
-            double oneMinusAmount = clampTo(1 - colorMatrixOperation->amount(), 0.0, 1.0);
+            double oneMinusAmount = clampTo(1 - colorMatrixOperation.amount(), 0.0, 1.0);
 
             // See https://dvcs.w3.org/hg/FXTF/raw-file/tip/filters/index.html#sepiaEquivalent
             // for information on parameters.
@@ -208,26 +208,26 @@ bool FilterEffectRenderer::build(RenderElement* renderer, const FilterOperations
             break;
         }
         case FilterOperation::SATURATE: {
-            BasicColorMatrixFilterOperation* colorMatrixOperation = toBasicColorMatrixFilterOperation(filterOperation);
+            BasicColorMatrixFilterOperation& colorMatrixOperation = downcast<BasicColorMatrixFilterOperation>(filterOperation);
             Vector<float> inputParameters;
-            inputParameters.append(narrowPrecisionToFloat(colorMatrixOperation->amount()));
+            inputParameters.append(narrowPrecisionToFloat(colorMatrixOperation.amount()));
             effect = FEColorMatrix::create(this, FECOLORMATRIX_TYPE_SATURATE, inputParameters);
             break;
         }
         case FilterOperation::HUE_ROTATE: {
-            BasicColorMatrixFilterOperation* colorMatrixOperation = toBasicColorMatrixFilterOperation(filterOperation);
+            BasicColorMatrixFilterOperation& colorMatrixOperation = downcast<BasicColorMatrixFilterOperation>(filterOperation);
             Vector<float> inputParameters;
-            inputParameters.append(narrowPrecisionToFloat(colorMatrixOperation->amount()));
+            inputParameters.append(narrowPrecisionToFloat(colorMatrixOperation.amount()));
             effect = FEColorMatrix::create(this, FECOLORMATRIX_TYPE_HUEROTATE, inputParameters);
             break;
         }
         case FilterOperation::INVERT: {
-            BasicComponentTransferFilterOperation* componentTransferOperation = toBasicComponentTransferFilterOperation(filterOperation);
+            BasicComponentTransferFilterOperation& componentTransferOperation = downcast<BasicComponentTransferFilterOperation>(filterOperation);
             ComponentTransferFunction transferFunction;
             transferFunction.type = FECOMPONENTTRANSFER_TYPE_TABLE;
             Vector<float> transferParameters;
-            transferParameters.append(narrowPrecisionToFloat(componentTransferOperation->amount()));
-            transferParameters.append(narrowPrecisionToFloat(1 - componentTransferOperation->amount()));
+            transferParameters.append(narrowPrecisionToFloat(componentTransferOperation.amount()));
+            transferParameters.append(narrowPrecisionToFloat(1 - componentTransferOperation.amount()));
             transferFunction.tableValues = transferParameters;
 
             ComponentTransferFunction nullFunction;
@@ -235,12 +235,12 @@ bool FilterEffectRenderer::build(RenderElement* renderer, const FilterOperations
             break;
         }
         case FilterOperation::OPACITY: {
-            BasicComponentTransferFilterOperation* componentTransferOperation = toBasicComponentTransferFilterOperation(filterOperation);
+            BasicComponentTransferFilterOperation& componentTransferOperation = downcast<BasicComponentTransferFilterOperation>(filterOperation);
             ComponentTransferFunction transferFunction;
             transferFunction.type = FECOMPONENTTRANSFER_TYPE_TABLE;
             Vector<float> transferParameters;
             transferParameters.append(0);
-            transferParameters.append(narrowPrecisionToFloat(componentTransferOperation->amount()));
+            transferParameters.append(narrowPrecisionToFloat(componentTransferOperation.amount()));
             transferFunction.tableValues = transferParameters;
 
             ComponentTransferFunction nullFunction;
@@ -248,10 +248,10 @@ bool FilterEffectRenderer::build(RenderElement* renderer, const FilterOperations
             break;
         }
         case FilterOperation::BRIGHTNESS: {
-            BasicComponentTransferFilterOperation* componentTransferOperation = toBasicComponentTransferFilterOperation(filterOperation);
+            BasicComponentTransferFilterOperation& componentTransferOperation = downcast<BasicComponentTransferFilterOperation>(filterOperation);
             ComponentTransferFunction transferFunction;
             transferFunction.type = FECOMPONENTTRANSFER_TYPE_LINEAR;
-            transferFunction.slope = narrowPrecisionToFloat(componentTransferOperation->amount());
+            transferFunction.slope = narrowPrecisionToFloat(componentTransferOperation.amount());
             transferFunction.intercept = 0;
 
             ComponentTransferFunction nullFunction;
@@ -259,10 +259,10 @@ bool FilterEffectRenderer::build(RenderElement* renderer, const FilterOperations
             break;
         }
         case FilterOperation::CONTRAST: {
-            BasicComponentTransferFilterOperation* componentTransferOperation = toBasicComponentTransferFilterOperation(filterOperation);
+            BasicComponentTransferFilterOperation& componentTransferOperation = downcast<BasicComponentTransferFilterOperation>(filterOperation);
             ComponentTransferFunction transferFunction;
             transferFunction.type = FECOMPONENTTRANSFER_TYPE_LINEAR;
-            float amount = narrowPrecisionToFloat(componentTransferOperation->amount());
+            float amount = narrowPrecisionToFloat(componentTransferOperation.amount());
             transferFunction.slope = amount;
             transferFunction.intercept = -0.5 * amount + 0.5;
             
@@ -271,15 +271,15 @@ bool FilterEffectRenderer::build(RenderElement* renderer, const FilterOperations
             break;
         }
         case FilterOperation::BLUR: {
-            BlurFilterOperation* blurOperation = toBlurFilterOperation(filterOperation);
-            float stdDeviation = floatValueForLength(blurOperation->stdDeviation(), 0);
+            BlurFilterOperation& blurOperation = downcast<BlurFilterOperation>(filterOperation);
+            float stdDeviation = floatValueForLength(blurOperation.stdDeviation(), 0);
             effect = FEGaussianBlur::create(this, stdDeviation, stdDeviation, consumer == FilterProperty ? EDGEMODE_NONE : EDGEMODE_DUPLICATE);
             break;
         }
         case FilterOperation::DROP_SHADOW: {
-            DropShadowFilterOperation* dropShadowOperation = toDropShadowFilterOperation(filterOperation);
-            effect = FEDropShadow::create(this, dropShadowOperation->stdDeviation(), dropShadowOperation->stdDeviation(),
-                                                dropShadowOperation->x(), dropShadowOperation->y(), dropShadowOperation->color(), 1);
+            DropShadowFilterOperation& dropShadowOperation = downcast<DropShadowFilterOperation>(filterOperation);
+            effect = FEDropShadow::create(this, dropShadowOperation.stdDeviation(), dropShadowOperation.stdDeviation(),
+                dropShadowOperation.x(), dropShadowOperation.y(), dropShadowOperation.color(), 1);
             break;
         }
         default:
@@ -292,7 +292,7 @@ bool FilterEffectRenderer::build(RenderElement* renderer, const FilterOperations
             effect->setClipsToBounds(consumer == FilterFunction);
             effect->setOperatingColorSpace(ColorSpaceDeviceRGB);
             
-            if (filterOperation->type() != FilterOperation::REFERENCE) {
+            if (filterOperation.type() != FilterOperation::REFERENCE) {
                 effect->inputEffects().append(previousEffect);
                 m_effects.append(effect);
             }
index 8fbb418..62e04bc 100644 (file)
@@ -99,12 +99,12 @@ void RenderLayer::FilterInfo::updateReferenceFilterClients(const FilterOperation
 {
     removeReferenceFilterClients();
     for (size_t i = 0, size = operations.size(); i < size; ++i) {
-        FilterOperation* filterOperation = operations.operations()[i].get();
-        if (filterOperation->type() != FilterOperation::REFERENCE)
+        FilterOperation& filterOperation = *operations.operations()[i];
+        if (!is<ReferenceFilterOperation>(filterOperation))
             continue;
-        ReferenceFilterOperation* referenceFilterOperation = toReferenceFilterOperation(filterOperation);
-        CachedSVGDocumentReference* documentReference = referenceFilterOperation->cachedSVGDocumentReference();
-        CachedSVGDocument* cachedSVGDocument = documentReference ? documentReference->document() : 0;
+        ReferenceFilterOperation& referenceFilterOperation = downcast<ReferenceFilterOperation>(filterOperation);
+        auto* documentReference = referenceFilterOperation.cachedSVGDocumentReference();
+        CachedSVGDocument* cachedSVGDocument = documentReference ? documentReference->document() : nullptr;
 
         if (cachedSVGDocument) {
             // Reference is external; wait for notifyFinished().
@@ -113,11 +113,11 @@ void RenderLayer::FilterInfo::updateReferenceFilterClients(const FilterOperation
         } else {
             // Reference is internal; add layer as a client so we can trigger
             // filter repaint on SVG attribute change.
-            Element* filter = m_layer.renderer().document().getElementById(referenceFilterOperation->fragment());
+            Element* filter = m_layer.renderer().document().getElementById(referenceFilterOperation.fragment());
 
-            if (!filter || !filter->renderer() || !filter->renderer()->isSVGResourceFilter())
+            if (!filter || !is<RenderSVGResourceFilter>(filter->renderer()))
                 continue;
-            toRenderSVGResourceContainer(*filter->renderer()).addClientRenderLayer(&m_layer);
+            downcast<RenderSVGResourceFilter>(*filter->renderer()).addClientRenderLayer(&m_layer);
             m_internalSVGReferences.append(filter);
         }
     }
index 2e71f15..ad5fcc3 100644 (file)
@@ -181,13 +181,13 @@ bool RenderSVGResourceFilter::applyResource(RenderElement& renderer, const Rende
     if (!lastEffect || lastEffect->totalNumberOfEffectInputs() > maxTotalOfEffectInputs)
         return false;
 
-    RenderSVGResourceFilterPrimitive::determineFilterPrimitiveSubregion(lastEffect);
+    RenderSVGResourceFilterPrimitive::determineFilterPrimitiveSubregion(*lastEffect);
     FloatRect subRegion = lastEffect->maxEffectRect();
     // At least one FilterEffect has a too big image size,
     // recalculate the effect sizes with new scale factors.
     if (!fitsInMaximumImageSize(subRegion.size(), scale)) {
         filterData->filter->setFilterResolution(scale);
-        RenderSVGResourceFilterPrimitive::determineFilterPrimitiveSubregion(lastEffect);
+        RenderSVGResourceFilterPrimitive::determineFilterPrimitiveSubregion(*lastEffect);
     }
 
     // If the drawingRegion is empty, we have something like <g filter=".."/>.
index 8d09417..54688c2 100644 (file)
@@ -70,46 +70,45 @@ void RenderSVGResourceFilterPrimitive::styleDidChange(StyleDifference diff, cons
     }
 }
 
-FloatRect RenderSVGResourceFilterPrimitive::determineFilterPrimitiveSubregion(FilterEffect* effect)
+FloatRect RenderSVGResourceFilterPrimitive::determineFilterPrimitiveSubregion(FilterEffect& effect)
 {
-    SVGFilter* filter = toSVGFilter(&(effect->filter()));
-    ASSERT(filter);
+    auto& filter = downcast<SVGFilter>(effect.filter());
 
     // FETile, FETurbulence, FEFlood don't have input effects, take the filter region as unite rect.
     FloatRect subregion;
-    if (unsigned numberOfInputEffects = effect->inputEffects().size()) {
-        subregion = determineFilterPrimitiveSubregion(effect->inputEffect(0));
+    if (unsigned numberOfInputEffects = effect.inputEffects().size()) {
+        subregion = determineFilterPrimitiveSubregion(*effect.inputEffect(0));
         for (unsigned i = 1; i < numberOfInputEffects; ++i)
-            subregion.unite(determineFilterPrimitiveSubregion(effect->inputEffect(i)));
+            subregion.unite(determineFilterPrimitiveSubregion(*effect.inputEffect(i)));
     } else
-        subregion = filter->filterRegionInUserSpace();
+        subregion = filter.filterRegionInUserSpace();
 
     // After calling determineFilterPrimitiveSubregion on the target effect, reset the subregion again for <feTile>.
-    if (effect->filterEffectType() == FilterEffectTypeTile)
-        subregion = filter->filterRegionInUserSpace();
+    if (effect.filterEffectType() == FilterEffectTypeTile)
+        subregion = filter.filterRegionInUserSpace();
 
-    FloatRect effectBoundaries = effect->effectBoundaries();
-    if (effect->hasX())
+    FloatRect effectBoundaries = effect.effectBoundaries();
+    if (effect.hasX())
         subregion.setX(effectBoundaries.x());
-    if (effect->hasY())
+    if (effect.hasY())
         subregion.setY(effectBoundaries.y());
-    if (effect->hasWidth())
+    if (effect.hasWidth())
         subregion.setWidth(effectBoundaries.width());
-    if (effect->hasHeight())
+    if (effect.hasHeight())
         subregion.setHeight(effectBoundaries.height());
 
-    effect->setFilterPrimitiveSubregion(subregion);
+    effect.setFilterPrimitiveSubregion(subregion);
 
-    FloatRect absoluteSubregion = filter->absoluteTransform().mapRect(subregion);
-    FloatSize filterResolution = filter->filterResolution();
+    FloatRect absoluteSubregion = filter.absoluteTransform().mapRect(subregion);
+    FloatSize filterResolution = filter.filterResolution();
     absoluteSubregion.scale(filterResolution.width(), filterResolution.height());
 
     // Clip every filter effect to the filter region.
-    FloatRect absoluteScaledFilterRegion = filter->filterRegion();
+    FloatRect absoluteScaledFilterRegion = filter.filterRegion();
     absoluteScaledFilterRegion.scale(filterResolution.width(), filterResolution.height());
     absoluteSubregion.intersect(absoluteScaledFilterRegion);
 
-    effect->setMaxEffectRect(absoluteSubregion);
+    effect.setMaxEffectRect(absoluteSubregion);
     return subregion;
 }
 
index 916e6e0..2f8da3a 100644 (file)
@@ -45,7 +45,7 @@ public:
     virtual bool isSVGResourceFilterPrimitive() const { return true; }
 
     // They depend on the RenderObject argument of RenderSVGResourceFilter::applyResource.
-    static FloatRect determineFilterPrimitiveSubregion(FilterEffect*);
+    static FloatRect determineFilterPrimitiveSubregion(FilterEffect&);
 
     inline void primitiveAttributeChanged(const QualifiedName& attribute)
     {
index 5765cba..587fa11 100644 (file)
@@ -30,6 +30,7 @@
 #include <wtf/PassRefPtr.h>
 #include <wtf/RefCounted.h>
 #include <wtf/RefPtr.h>
+#include <wtf/TypeCasts.h>
 
 namespace WebCore {
 
@@ -58,8 +59,10 @@ private:
     bool m_effectBBoxMode;
 };
 
-FILTER_TYPE_CASTS(SVGFilter, isSVGFilter())
-
 } // namespace WebCore
 
+SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::SVGFilter)
+    static bool isType(const WebCore::Filter& filter) { return filter.isSVGFilter(); }
+SPECIALIZE_TYPE_TRAITS_END()
+
 #endif // SVGFilter_h
index babf281..46dcd4f 100644 (file)
@@ -1,3 +1,19 @@
+2014-10-13  Chris Dumez  <cdumez@apple.com>
+
+        Use is<>() / downcast<>() for Filter / FilterOperation subclasses
+        https://bugs.webkit.org/show_bug.cgi?id=137644
+
+        Reviewed by Darin Adler.
+
+        Use is<>() / downcast<>() for Filter / FilterOperation subclasses.
+
+        * Shared/CoordinatedGraphics/CoordinatedGraphicsArgumentCoders.cpp:
+        (IPC::ArgumentCoder<WebCore::FilterOperations>::encode):
+        * Shared/WebCoreArgumentCoders.cpp:
+        (IPC::ArgumentCoder<FilterOperation>::encode):
+        * Shared/mac/RemoteLayerTreeTransaction.mm:
+        (WebKit::RemoteLayerTreeTextStream::operator<<):
+
 2014-10-12  Sergio Villar Senin  <svillar@igalia.com>
 
         [SOUP] [WK2] WebProcess and NetworkProcess initialization clears cache contents
index f729f5a..e3d2c4c 100644 (file)
@@ -64,30 +64,30 @@ void ArgumentCoder<WebCore::FilterOperations>::encode(ArgumentEncoder& encoder,
 {
     encoder << static_cast<uint32_t>(filters.size());
     for (size_t i = 0; i < filters.size(); ++i) {
-        const FilterOperation* filter = filters.at(i);
-        FilterOperation::OperationType type = filter->type();
+        const FilterOperation& filter = *filters.at(i);
+        FilterOperation::OperationType type = filter.type();
         encoder.encodeEnum(type);
         switch (type) {
         case FilterOperation::GRAYSCALE:
         case FilterOperation::SEPIA:
         case FilterOperation::SATURATE:
         case FilterOperation::HUE_ROTATE:
-            encoder << static_cast<double>(toBasicColorMatrixFilterOperation(filter)->amount());
+            encoder << static_cast<double>(downcast<BasicColorMatrixFilterOperation>(filter).amount());
             break;
         case FilterOperation::INVERT:
         case FilterOperation::BRIGHTNESS:
         case FilterOperation::CONTRAST:
         case FilterOperation::OPACITY:
-            encoder << static_cast<double>(toBasicComponentTransferFilterOperation(filter)->amount());
+            encoder << static_cast<double>(downcast<BasicComponentTransferFilterOperation>(filter).amount());
             break;
         case FilterOperation::BLUR:
-            ArgumentCoder<Length>::encode(encoder, toBlurFilterOperation(filter)->stdDeviation());
+            ArgumentCoder<Length>::encode(encoder, downcast<BlurFilterOperation>(filter).stdDeviation());
             break;
         case FilterOperation::DROP_SHADOW: {
-            const DropShadowFilterOperation* shadow = toDropShadowFilterOperation(filter);
-            ArgumentCoder<IntPoint>::encode(encoder, shadow->location());
-            encoder << static_cast<int32_t>(shadow->stdDeviation());
-            ArgumentCoder<Color>::encode(encoder, shadow->color());
+            const DropShadowFilterOperation& shadow = downcast<DropShadowFilterOperation>(filter);
+            ArgumentCoder<IntPoint>::encode(encoder, shadow.location());
+            encoder << static_cast<int32_t>(shadow.stdDeviation());
+            ArgumentCoder<Color>::encode(encoder, shadow.color());
             break;
         }
         case FilterOperation::REFERENCE:
index cdfa70f..a601ca8 100644 (file)
@@ -1538,26 +1538,26 @@ void ArgumentCoder<FilterOperation>::encode(ArgumentEncoder& encoder, const Filt
     case FilterOperation::SEPIA:
     case FilterOperation::SATURATE:
     case FilterOperation::HUE_ROTATE:
-        encoder << toBasicColorMatrixFilterOperation(filter).amount();
+        encoder << downcast<BasicColorMatrixFilterOperation>(filter).amount();
         break;
     case FilterOperation::INVERT:
     case FilterOperation::OPACITY:
     case FilterOperation::BRIGHTNESS:
     case FilterOperation::CONTRAST:
-        encoder << toBasicComponentTransferFilterOperation(filter).amount();
+        encoder << downcast<BasicComponentTransferFilterOperation>(filter).amount();
         break;
     case FilterOperation::BLUR:
-        encoder << toBlurFilterOperation(filter).stdDeviation();
+        encoder << downcast<BlurFilterOperation>(filter).stdDeviation();
         break;
     case FilterOperation::DROP_SHADOW: {
-        const auto& dropShadowFilter = toDropShadowFilterOperation(filter);
+        const auto& dropShadowFilter = downcast<DropShadowFilterOperation>(filter);
         encoder << dropShadowFilter.location();
         encoder << dropShadowFilter.stdDeviation();
         encoder << dropShadowFilter.color();
         break;
     }
     case FilterOperation::DEFAULT:
-        encoder.encodeEnum(toDefaultFilterOperation(filter).representedType());
+        encoder.encodeEnum(downcast<DefaultFilterOperation>(filter).representedType());
         break;
     case FilterOperation::PASSTHROUGH:
         break;
index 11276c3..7a7130b 100644 (file)
@@ -694,52 +694,52 @@ RemoteLayerTreeTextStream& RemoteLayerTreeTextStream::operator<<(const FilterOpe
         ts << "reference";
         break;
     case FilterOperation::GRAYSCALE: {
-        const BasicColorMatrixFilterOperation& colorMatrixFilter = toBasicColorMatrixFilterOperation(filter);
+        const auto& colorMatrixFilter = downcast<BasicColorMatrixFilterOperation>(filter);
         ts << "grayscale(" << colorMatrixFilter.amount() << ")";
         break;
     }
     case FilterOperation::SEPIA: {
-        const BasicColorMatrixFilterOperation& colorMatrixFilter = toBasicColorMatrixFilterOperation(filter);
+        const auto& colorMatrixFilter = downcast<BasicColorMatrixFilterOperation>(filter);
         ts << "sepia(" << colorMatrixFilter.amount() << ")";
         break;
     }
     case FilterOperation::SATURATE: {
-        const BasicColorMatrixFilterOperation& colorMatrixFilter = toBasicColorMatrixFilterOperation(filter);
+        const auto& colorMatrixFilter = downcast<BasicColorMatrixFilterOperation>(filter);
         ts << "saturate(" << colorMatrixFilter.amount() << ")";
         break;
     }
     case FilterOperation::HUE_ROTATE: {
-        const BasicColorMatrixFilterOperation& colorMatrixFilter = toBasicColorMatrixFilterOperation(filter);
+        const auto& colorMatrixFilter = downcast<BasicColorMatrixFilterOperation>(filter);
         ts << "hue-rotate(" << colorMatrixFilter.amount() << ")";
         break;
     }
     case FilterOperation::INVERT: {
-        const BasicComponentTransferFilterOperation& componentTransferFilter = toBasicComponentTransferFilterOperation(filter);
+        const auto& componentTransferFilter = downcast<BasicComponentTransferFilterOperation>(filter);
         ts << "invert(" << componentTransferFilter.amount() << ")";
         break;
     }
     case FilterOperation::OPACITY: {
-        const BasicComponentTransferFilterOperation& componentTransferFilter = toBasicComponentTransferFilterOperation(filter);
+        const auto& componentTransferFilter = downcast<BasicComponentTransferFilterOperation>(filter);
         ts << "opacity(" << componentTransferFilter.amount() << ")";
         break;
     }
     case FilterOperation::BRIGHTNESS: {
-        const BasicComponentTransferFilterOperation& componentTransferFilter = toBasicComponentTransferFilterOperation(filter);
+        const auto& componentTransferFilter = downcast<BasicComponentTransferFilterOperation>(filter);
         ts << "brightness(" << componentTransferFilter.amount() << ")";
         break;
     }
     case FilterOperation::CONTRAST: {
-        const BasicComponentTransferFilterOperation& componentTransferFilter = toBasicComponentTransferFilterOperation(filter);
+        const auto& componentTransferFilter = downcast<BasicComponentTransferFilterOperation>(filter);
         ts << "contrast(" << componentTransferFilter.amount() << ")";
         break;
     }
     case FilterOperation::BLUR: {
-        const BlurFilterOperation& blurFilter = toBlurFilterOperation(filter);
+        const auto& blurFilter = downcast<BlurFilterOperation>(filter);
         ts << "blur(" << floatValueForLength(blurFilter.stdDeviation(), 0) << ")";
         break;
     }
     case FilterOperation::DROP_SHADOW: {
-        const DropShadowFilterOperation& dropShadowFilter = toDropShadowFilterOperation(filter);
+        const auto& dropShadowFilter = downcast<DropShadowFilterOperation>(filter);
         ts << "drop-shadow(" << dropShadowFilter.x() << " " << dropShadowFilter.y() << " " << dropShadowFilter.location() << " ";
         ts << dropShadowFilter.color() << ")";
         break;
@@ -748,7 +748,7 @@ RemoteLayerTreeTextStream& RemoteLayerTreeTextStream::operator<<(const FilterOpe
         ts << "passthrough";
         break;
     case FilterOperation::DEFAULT: {
-        const DefaultFilterOperation& defaultFilter = toDefaultFilterOperation(filter);
+        const auto& defaultFilter = downcast<DefaultFilterOperation>(filter);
         ts << "default type=" << (int)defaultFilter.representedType();
         break;
     }