Title: [264805] trunk/Source/WebCore
Revision
264805
Author
commit-qu...@webkit.org
Date
2020-07-23 16:42:42 -0700 (Thu, 23 Jul 2020)

Log Message

Infrastructure Work for Integrating CoreImage for Accelerated CSS/SVG Filter Rendering
https://bugs.webkit.org/show_bug.cgi?id=213672

Patch by Guowei Yang <guowei_y...@apple.com> on 2020-07-23
Reviewed by Simon Fraser.

This patch is the infrastructure work to enable filter rendering using
CoreImage. The design of this code is as follows:

0) changing WebCore configuration for using CoreImage framework from
   iOS/mac only to unconditional, so watchOS and tvOS could also use
   CoreImage

1) adding a new API to obtain the IOSurface from an AcceleratedImageBuffer
   since CoreImage needs to render to an IOSurface

2) Instead of applying the filters inside FilterEffect, a new class,
   FilterEffectRendererCoreImage is designed to handle the rendering. We hide
   the implementation details by subclassing from a generic FilterEffectRenderer class.
   This also has the benefit of organizing CoreImage obj-c calls in one place. This class
   owns a FilterEffect node, that is the last FilterEffect of a given filter graph.
   The filter graph will be traversed backwards and filter parameters is gathered
   along the way. Then CIFilters will be created and connected to a larger CIFilter
   graph. The output of the CIFilter graph will be rendered to the IOSurface of
   a newly created AcceleratedImageBuffer. This image buffer will be returned
   to RenderLayerFilters and rendered to the screen

3) Inside CSSFilter::build, we first try to create a FilterEffectRenderer by passing in
   a renderer setting. A valid pointer will be returned only when the following two conditions
   are met:
       . CoreImage rendering is enabled in settings
       . All the filters inside the filter graph is implemented using CIFilters

No new tests are required as this is the
infrastructure code for integrating CoreImage
This patch should pass all the existing css3/filters tests

* Configurations/WebCore.xcconfig: modified flag definition
   so that CoreImage is used on all Apple Platforms, not only iPhone.
* Sources.txt: Added the generic FilterEffectRenderer class file
* SourcesCocoa.txt: added FilterEffectRendererCoreImage.mm
* WebCore.xcodeproj/project.pbxproj: Reflecting newly added files,
   with some ordering changes
* platform/graphics/ConcreteImageBuffer.h: overrides isAccelerated()
   function that returns true only if the backend is IOSurface
* platform/graphics/ImageBuffer.h: defined virtual function isAccelerated()
* platform/graphics/ImageBufferBackend.h: defined virtual function
  isAccelerated() that returns false in the base class
(WebCore::ImageBufferBackend::isAccelerated const): returns false for the base class
* platform/graphics/PlatformImageBuffer.h: added SPECIALIZE_TYPE_TRAITS to check
  what type of ImageBufferBackend is
* platform/graphics/PlatformImageBuffer.h: Added API to obtain
  IOSurface from IOSurfaceBackend; added SPECIALIZE_TYPE_TRAITS
(WebCore::AcceleratedImageBuffer::surface): Obtain the IOSurface pointer
  from ImageBufferIOSurfaceBackend
(isType): check if a given ImageBuffer is type AcceleratedImageBuffer
* platform/graphics/cg/ImageBufferIOSurfaceBackend.cpp:
(WebCore::ImageBufferIOSurfaceBackend::surface): added an API to get the
   IOSurface pointer
(WebCore::ImageBufferIOSurfaceBackend::isAccelerated const): returns true
   because it is an accelerated image buffer
* platform/graphics/cg/ImageBufferIOSurfaceBackend.h: added function surface()
   and isAccelerated()
* platform/graphics/coreimage/FilterEffectRendererCoreImage.h: Added.
* platform/graphics/coreimage/FilterEffectRendererCoreImage.mm: Added.
(WebCore::FilterEffectRendererCoreImage::tryCreate): creates a FilterEffectRendererCoreImage
  unique pointer. If the filters inside the graph are not all implemented,
  we return nullptr
(WebCore::FilterEffectRendererCoreImage::supportsCoreImageRendering):
  a function that takes in FilterEffect& and returns true if its a filter effect
  type that is implemented in CoreImage, false otherwise
(WebCore::FilterEffectRendererCoreImage::applyEffects): takes in a FilterEffect pointer,
   calls FilterEffectRendererCoreImage::connectCIFilters to create the final output CIImage
(WebCore::FilterEffectRendererCoreImage::connectCIFilters): recursive
   helper function that traverses the FilterEffect graph backwards,
   creates CIFilter graph based on the subclass type of current processing
   FilterEffect node. It will cache the CIFilter in a hashmap, whose key
   is the corresponding FilterEffect pointer.
(WebCore::FilterEffectRendererCoreImage::canRenderUsingCIFilters): unction
   that takes in the last FilterEffect node and determines whether
   all of the filters inside the filter graph is already implemented using
   CIFilters. It returns false as long as there is one filter that hasn't
   been implemented. The rendering procedure will fallback to software mode
   if this function returns false
(WebCore::FilterEffectRendererCoreImage::output const): returns the ImageBuffer
   that contains the data of the final output image
(WebCore::FilterEffectRendererCoreImage::renderToImageBuffer): r
   enders CIImage* to an ImageBuffer
(WebCore::FilterEffectRendererCoreImage::destRect const): calculates the destination
   bounding box
(WebCore::FilterEffectRendererCoreImage::clearResult): clears all the saved results
(WebCore::FilterEffectRendererCoreImage::FilterEffectRendererCoreImage): constructor
* platform/graphics/filters/FEBlend.cpp:
(WebCore::FEBlend::FEBlend): Pass an additional FilterEffect::Type argument
  to base class constructor
* platform/graphics/filters/FEColorMatrix.cpp:
(WebCore::FEColorMatrix::FEColorMatrix): ditto
* platform/graphics/filters/FEComponentTransfer.cpp:
(WebCore::FEComponentTransfer::FEComponentTransfer): ditto
* platform/graphics/filters/FEComposite.cpp:
(WebCore::FEComposite::FEComposite): ditto
* platform/graphics/filters/FEConvolveMatrix.cpp:
(WebCore::FEConvolveMatrix::FEConvolveMatrix): ditto
* platform/graphics/filters/FEDiffuseLighting.cpp:
(WebCore::FEDiffuseLighting::FEDiffuseLighting):ditto
* platform/graphics/filters/FEDisplacementMap.cpp:
(WebCore::FEDisplacementMap::FEDisplacementMap):ditto
* platform/graphics/filters/FEDisplacementMap.h:
* platform/graphics/filters/FEDropShadow.cpp:
(WebCore::FEDropShadow::FEDropShadow):ditto
* platform/graphics/filters/FEFlood.cpp:
(WebCore::FEFlood::FEFlood):ditto
* platform/graphics/filters/FEGaussianBlur.cpp:
(WebCore::FEGaussianBlur::FEGaussianBlur):ditto
* platform/graphics/filters/FELighting.cpp:
(WebCore::FELighting::FELighting):ditto
* platform/graphics/filters/FELighting.h:
* platform/graphics/filters/FEMerge.cpp:
(WebCore::FEMerge::FEMerge): ditto
* platform/graphics/filters/FEMorphology.cpp:
(WebCore::FEMorphology::FEMorphology): ditto
* platform/graphics/filters/FEOffset.cpp:
(WebCore::FEOffset::FEOffset): ditto
* platform/graphics/filters/FESpecularLighting.cpp:
(WebCore::FESpecularLighting::FESpecularLighting): ditto
* platform/graphics/filters/FETile.cpp:
(WebCore::FETile::FETile): ditto
* platform/graphics/filters/FETurbulence.cpp:
(WebCore::FETurbulence::FETurbulence): ditto
* platform/graphics/filters/FilterEffect.cpp:
(WebCore::FilterEffect::FilterEffect): ditto
* platform/graphics/filters/FilterEffect.h: added a const member,
  m_filterEffectType
(WebCore::FilterEffect::filterEffectClassType): returns the FilterEffect
  class type
* platform/graphics/filters/FilterEffectRenderer.cpp: Added.
(WebCore::FilterEffectRenderer::tryCreate): tries creates a new FilterEffectRenderer
   unique pointer. Here, we check whether the renderer setting has
   CoreImage accelerated filter rendering enabled; we also check if all the
   filters in the given FilterEffect graph is already implemented using
   CoreImage. If both conditions are satisfied, create a FilterEffectRendererCoreImage
   otherwise returns nullptr.
* platform/graphics/filters/FilterEffectRenderer.h: Added.
* platform/graphics/filters/SourceAlpha.cpp:
(WebCore::SourceAlpha::SourceAlpha): Pass an additional FilterEffect::Type argument
  to base class constructor
* platform/graphics/filters/SourceAlpha.h:
* platform/graphics/filters/SourceGraphic.h:
(WebCore::SourceGraphic::SourceGraphic): ditto
* rendering/CSSFilter.cpp:
(WebCore::CSSFilter::build): we try to create a FilterEffectRenderer here by passing
   in the state of the CoreImage Accelerated Rendering feature switch
(WebCore::CSSFilter::apply): If we have a valid m_filterRenderer pointer, that means
   we can render the result image using CoreImage path, thus we don't call effect.apply()
   fall back to software mode if hasResult() returns false.
(WebCore::CSSFilter::output const): if we have a valid m_filterRenderer, then we will
   obtain the ImageBuffer result from it, not FilterEffect
(WebCore::CSSFilter::outputRect const): if we have a valid m_filterRenderer, then we will
   obtain the ImageBuffer result from it, not FilterEffect
* rendering/CSSFilter.h:
* svg/graphics/filters/SVGFEImage.cpp:
(WebCore::FEImage::FEImage):  Pass an additional FilterEffect::Type argument
  to base class constructor

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (264804 => 264805)


--- trunk/Source/WebCore/ChangeLog	2020-07-23 23:08:19 UTC (rev 264804)
+++ trunk/Source/WebCore/ChangeLog	2020-07-23 23:42:42 UTC (rev 264805)
@@ -1,3 +1,168 @@
+2020-07-23  Guowei Yang  <guowei_y...@apple.com>
+
+        Infrastructure Work for Integrating CoreImage for Accelerated CSS/SVG Filter Rendering
+        https://bugs.webkit.org/show_bug.cgi?id=213672
+
+        Reviewed by Simon Fraser.
+
+        This patch is the infrastructure work to enable filter rendering using 
+        CoreImage. The design of this code is as follows:
+
+        0) changing WebCore configuration for using CoreImage framework from
+           iOS/mac only to unconditional, so watchOS and tvOS could also use
+           CoreImage
+
+        1) adding a new API to obtain the IOSurface from an AcceleratedImageBuffer 
+           since CoreImage needs to render to an IOSurface
+
+        2) Instead of applying the filters inside FilterEffect, a new class,
+           FilterEffectRendererCoreImage is designed to handle the rendering. We hide
+           the implementation details by subclassing from a generic FilterEffectRenderer class.
+           This also has the benefit of organizing CoreImage obj-c calls in one place. This class
+           owns a FilterEffect node, that is the last FilterEffect of a given filter graph.
+           The filter graph will be traversed backwards and filter parameters is gathered 
+           along the way. Then CIFilters will be created and connected to a larger CIFilter 
+           graph. The output of the CIFilter graph will be rendered to the IOSurface of 
+           a newly created AcceleratedImageBuffer. This image buffer will be returned 
+           to RenderLayerFilters and rendered to the screen
+
+        3) Inside CSSFilter::build, we first try to create a FilterEffectRenderer by passing in
+           a renderer setting. A valid pointer will be returned only when the following two conditions
+           are met:
+               . CoreImage rendering is enabled in settings
+               . All the filters inside the filter graph is implemented using CIFilters
+
+        No new tests are required as this is the 
+        infrastructure code for integrating CoreImage
+        This patch should pass all the existing css3/filters tests
+
+        * Configurations/WebCore.xcconfig: modified flag definition 
+           so that CoreImage is used on all Apple Platforms, not only iPhone.
+        * Sources.txt: Added the generic FilterEffectRenderer class file
+        * SourcesCocoa.txt: added FilterEffectRendererCoreImage.mm
+        * WebCore.xcodeproj/project.pbxproj: Reflecting newly added files,
+           with some ordering changes 
+        * platform/graphics/ConcreteImageBuffer.h: overrides isAccelerated()
+           function that returns true only if the backend is IOSurface
+        * platform/graphics/ImageBuffer.h: defined virtual function isAccelerated()
+        * platform/graphics/ImageBufferBackend.h: defined virtual function 
+          isAccelerated() that returns false in the base class
+        (WebCore::ImageBufferBackend::isAccelerated const): returns false for the base class
+        * platform/graphics/PlatformImageBuffer.h: added SPECIALIZE_TYPE_TRAITS to check 
+          what type of ImageBufferBackend is
+        * platform/graphics/PlatformImageBuffer.h: Added API to obtain 
+          IOSurface from IOSurfaceBackend; added SPECIALIZE_TYPE_TRAITS
+        (WebCore::AcceleratedImageBuffer::surface): Obtain the IOSurface pointer
+          from ImageBufferIOSurfaceBackend
+        (isType): check if a given ImageBuffer is type AcceleratedImageBuffer
+        * platform/graphics/cg/ImageBufferIOSurfaceBackend.cpp:
+        (WebCore::ImageBufferIOSurfaceBackend::surface): added an API to get the 
+           IOSurface pointer
+        (WebCore::ImageBufferIOSurfaceBackend::isAccelerated const): returns true
+           because it is an accelerated image buffer
+        * platform/graphics/cg/ImageBufferIOSurfaceBackend.h: added function surface()
+           and isAccelerated()
+        * platform/graphics/coreimage/FilterEffectRendererCoreImage.h: Added.
+        * platform/graphics/coreimage/FilterEffectRendererCoreImage.mm: Added.
+        (WebCore::FilterEffectRendererCoreImage::tryCreate): creates a FilterEffectRendererCoreImage
+          unique pointer. If the filters inside the graph are not all implemented,
+          we return nullptr
+        (WebCore::FilterEffectRendererCoreImage::supportsCoreImageRendering): 
+          a function that takes in FilterEffect& and returns true if its a filter effect 
+          type that is implemented in CoreImage, false otherwise
+        (WebCore::FilterEffectRendererCoreImage::applyEffects): takes in a FilterEffect pointer,
+           calls FilterEffectRendererCoreImage::connectCIFilters to create the final output CIImage
+        (WebCore::FilterEffectRendererCoreImage::connectCIFilters): recursive 
+           helper function that traverses the FilterEffect graph backwards, 
+           creates CIFilter graph based on the subclass type of current processing 
+           FilterEffect node. It will cache the CIFilter in a hashmap, whose key
+           is the corresponding FilterEffect pointer. 
+        (WebCore::FilterEffectRendererCoreImage::canRenderUsingCIFilters): unction 
+           that takes in the last FilterEffect node and determines whether
+           all of the filters inside the filter graph is already implemented using 
+           CIFilters. It returns false as long as there is one filter that hasn't 
+           been implemented. The rendering procedure will fallback to software mode
+           if this function returns false
+        (WebCore::FilterEffectRendererCoreImage::output const): returns the ImageBuffer
+           that contains the data of the final output image
+        (WebCore::FilterEffectRendererCoreImage::renderToImageBuffer): r
+           enders CIImage* to an ImageBuffer
+        (WebCore::FilterEffectRendererCoreImage::destRect const): calculates the destination
+           bounding box
+        (WebCore::FilterEffectRendererCoreImage::clearResult): clears all the saved results
+        (WebCore::FilterEffectRendererCoreImage::FilterEffectRendererCoreImage): constructor
+        * platform/graphics/filters/FEBlend.cpp:
+        (WebCore::FEBlend::FEBlend): Pass an additional FilterEffect::Type argument
+          to base class constructor
+        * platform/graphics/filters/FEColorMatrix.cpp:
+        (WebCore::FEColorMatrix::FEColorMatrix): ditto
+        * platform/graphics/filters/FEComponentTransfer.cpp:
+        (WebCore::FEComponentTransfer::FEComponentTransfer): ditto
+        * platform/graphics/filters/FEComposite.cpp:
+        (WebCore::FEComposite::FEComposite): ditto
+        * platform/graphics/filters/FEConvolveMatrix.cpp:
+        (WebCore::FEConvolveMatrix::FEConvolveMatrix): ditto
+        * platform/graphics/filters/FEDiffuseLighting.cpp:
+        (WebCore::FEDiffuseLighting::FEDiffuseLighting):ditto
+        * platform/graphics/filters/FEDisplacementMap.cpp:
+        (WebCore::FEDisplacementMap::FEDisplacementMap):ditto
+        * platform/graphics/filters/FEDisplacementMap.h:
+        * platform/graphics/filters/FEDropShadow.cpp:
+        (WebCore::FEDropShadow::FEDropShadow):ditto
+        * platform/graphics/filters/FEFlood.cpp:
+        (WebCore::FEFlood::FEFlood):ditto
+        * platform/graphics/filters/FEGaussianBlur.cpp:
+        (WebCore::FEGaussianBlur::FEGaussianBlur):ditto
+        * platform/graphics/filters/FELighting.cpp:
+        (WebCore::FELighting::FELighting):ditto
+        * platform/graphics/filters/FELighting.h:
+        * platform/graphics/filters/FEMerge.cpp:
+        (WebCore::FEMerge::FEMerge): ditto
+        * platform/graphics/filters/FEMorphology.cpp:
+        (WebCore::FEMorphology::FEMorphology): ditto
+        * platform/graphics/filters/FEOffset.cpp:
+        (WebCore::FEOffset::FEOffset): ditto
+        * platform/graphics/filters/FESpecularLighting.cpp:
+        (WebCore::FESpecularLighting::FESpecularLighting): ditto
+        * platform/graphics/filters/FETile.cpp:
+        (WebCore::FETile::FETile): ditto
+        * platform/graphics/filters/FETurbulence.cpp:
+        (WebCore::FETurbulence::FETurbulence): ditto
+        * platform/graphics/filters/FilterEffect.cpp:
+        (WebCore::FilterEffect::FilterEffect): ditto
+        * platform/graphics/filters/FilterEffect.h: added a const member, 
+          m_filterEffectType
+        (WebCore::FilterEffect::filterEffectClassType): returns the FilterEffect
+          class type
+        * platform/graphics/filters/FilterEffectRenderer.cpp: Added.
+        (WebCore::FilterEffectRenderer::tryCreate): tries creates a new FilterEffectRenderer 
+           unique pointer. Here, we check whether the renderer setting has 
+           CoreImage accelerated filter rendering enabled; we also check if all the 
+           filters in the given FilterEffect graph is already implemented using 
+           CoreImage. If both conditions are satisfied, create a FilterEffectRendererCoreImage
+           otherwise returns nullptr.
+        * platform/graphics/filters/FilterEffectRenderer.h: Added.
+        * platform/graphics/filters/SourceAlpha.cpp:
+        (WebCore::SourceAlpha::SourceAlpha): Pass an additional FilterEffect::Type argument
+          to base class constructor
+        * platform/graphics/filters/SourceAlpha.h:
+        * platform/graphics/filters/SourceGraphic.h:
+        (WebCore::SourceGraphic::SourceGraphic): ditto
+        * rendering/CSSFilter.cpp:
+        (WebCore::CSSFilter::build): we try to create a FilterEffectRenderer here by passing 
+           in the state of the CoreImage Accelerated Rendering feature switch
+        (WebCore::CSSFilter::apply): If we have a valid m_filterRenderer pointer, that means 
+           we can render the result image using CoreImage path, thus we don't call effect.apply()
+           fall back to software mode if hasResult() returns false.
+        (WebCore::CSSFilter::output const): if we have a valid m_filterRenderer, then we will 
+           obtain the ImageBuffer result from it, not FilterEffect
+        (WebCore::CSSFilter::outputRect const): if we have a valid m_filterRenderer, then we will 
+           obtain the ImageBuffer result from it, not FilterEffect
+        * rendering/CSSFilter.h:
+        * svg/graphics/filters/SVGFEImage.cpp:
+        (WebCore::FEImage::FEImage):  Pass an additional FilterEffect::Type argument
+          to base class constructor
+
 2020-07-23  Yusuke Suzuki  <ysuz...@apple.com>
 
         We should have exception check after promise operation

Modified: trunk/Source/WebCore/Configurations/WebCore.xcconfig (264804 => 264805)


--- trunk/Source/WebCore/Configurations/WebCore.xcconfig	2020-07-23 23:08:19 UTC (rev 264804)
+++ trunk/Source/WebCore/Configurations/WebCore.xcconfig	2020-07-23 23:42:42 UTC (rev 264805)
@@ -118,15 +118,13 @@
 WK_SYSTEM_CONFIGURATION_LDFLAGS = $(WK_SYSTEM_CONFIGURATION_LDFLAGS_$(WK_PLATFORM_NAME));
 WK_SYSTEM_CONFIGURATION_LDFLAGS_macosx = -framework SystemConfiguration;
 
-WK_SYSTEM_PREVIEW_LDFLAGS = $(WK_SYSTEM_PREVIEW_LDFLAGS_$(WK_PLATFORM_NAME));
-WK_SYSTEM_PREVIEW_LDFLAGS_iphoneos = -framework CoreImage;
-WK_SYSTEM_PREVIEW_LDFLAGS_iphonesimulator = -framework CoreImage;
+WK_CORE_IMAGE_LDFLAGS = -framework CoreImage;
 
 WK_URL_FORMATTING_LDFLAGS = $(WK_URL_FORMATTING_LDFLAGS_$(WK_HAVE_URL_FORMATTING));
 WK_URL_FORMATTING_LDFLAGS_YES = -framework URLFormatting;
 
 // FIXME: Reduce the number of allowable_clients <rdar://problem/31823969>
-OTHER_LDFLAGS = $(inherited) $(WK_RELOCATABLE_FRAMEWORK_LDFLAGS) $(WK_UNDEFINED_SYMBOLS_LDFLAGS) -lsqlite3 -lobjc -lANGLE -allowable_client WebCoreTestSupport -allowable_client WebKitLegacy -force_load $(BUILT_PRODUCTS_DIR)/libPAL.a -framework CFNetwork -framework CoreAudio -framework CoreGraphics -framework CoreText -framework Foundation -framework IOSurface -framework ImageIO -framework Metal $(OTHER_LDFLAGS_PLATFORM_$(WK_COCOA_TOUCH)) $(OTHER_LDFLAGS_PLATFORM_$(WK_PLATFORM_NAME)) $(WK_APPKIT_LDFLAGS) $(WK_APPSUPPORT_LDFLAGS) $(WK_AUDIO_UNIT_LDFLAGS) $(WK_CARBON_LDFLAGS) $(WK_CORE_UI_LDFLAGS) $(WK_DATA_DETECTORS_CORE_LDFLAGS) $(WK_GRAPHICS_SERVICES_LDFLAGS) $(WK_IOSURFACE_ACCELERATOR_LDFLAGS) $(WK_LIBWEBRTC_LDFLAGS) $(WK_MOBILE_CORE_SERVICES_LDFLAGS) $(WK_MOBILE_GESTALT_LDFLAGS) $(WK_OPENGL_LDFLAGS) $(WK_SYSTEM_CONFIGURATION_LDFLAGS) $(WK_SYSTEM_PREVIEW_LDFLAGS) $(WK_URL_FORMATTING_LDFLAGS);
+OTHER_LDFLAGS = $(inherited) $(WK_RELOCATABLE_FRAMEWORK_LDFLAGS) $(WK_UNDEFINED_SYMBOLS_LDFLAGS) -lsqlite3 -lobjc -lANGLE -allowable_client WebCoreTestSupport -allowable_client WebKitLegacy -force_load $(BUILT_PRODUCTS_DIR)/libPAL.a -framework CFNetwork -framework CoreAudio -framework CoreGraphics -framework CoreText -framework Foundation -framework IOSurface -framework ImageIO -framework Metal $(OTHER_LDFLAGS_PLATFORM_$(WK_COCOA_TOUCH)) $(OTHER_LDFLAGS_PLATFORM_$(WK_PLATFORM_NAME)) $(WK_APPKIT_LDFLAGS) $(WK_APPSUPPORT_LDFLAGS) $(WK_AUDIO_UNIT_LDFLAGS) $(WK_CARBON_LDFLAGS) $(WK_CORE_UI_LDFLAGS) $(WK_DATA_DETECTORS_CORE_LDFLAGS) $(WK_GRAPHICS_SERVICES_LDFLAGS) $(WK_IOSURFACE_ACCELERATOR_LDFLAGS) $(WK_LIBWEBRTC_LDFLAGS) $(WK_MOBILE_CORE_SERVICES_LDFLAGS) $(WK_MOBILE_GESTALT_LDFLAGS) $(WK_OPENGL_LDFLAGS) $(WK_SYSTEM_CONFIGURATION_LDFLAGS) $(WK_CORE_IMAGE_LDFLAGS) $(WK_URL_FORMATTING_LDFLAGS);
 
 OTHER_LDFLAGS_PLATFORM_cocoatouch = -allowable_client WebKit -allowable_client iTunesU -allowable_client Casablanca -allowable_client Remote -allowable_client TVBooks -allowable_client DumpRenderTree -allowable_client WebKitTestRunner -allowable_client TestWebKitAPI;
 OTHER_LDFLAGS_PLATFORM_macosx = -sub_library libobjc -umbrella WebKit;

Modified: trunk/Source/WebCore/Sources.txt (264804 => 264805)


--- trunk/Source/WebCore/Sources.txt	2020-07-23 23:08:19 UTC (rev 264804)
+++ trunk/Source/WebCore/Sources.txt	2020-07-23 23:42:42 UTC (rev 264805)
@@ -1920,6 +1920,7 @@
 platform/graphics/filters/FETile.cpp
 platform/graphics/filters/FETurbulence.cpp
 platform/graphics/filters/FilterEffect.cpp
+platform/graphics/filters/FilterEffectRenderer.cpp
 platform/graphics/filters/FilterOperation.cpp
 platform/graphics/filters/FilterOperations.cpp
 platform/graphics/filters/PointLightSource.cpp

Modified: trunk/Source/WebCore/SourcesCocoa.txt (264804 => 264805)


--- trunk/Source/WebCore/SourcesCocoa.txt	2020-07-23 23:08:19 UTC (rev 264804)
+++ trunk/Source/WebCore/SourcesCocoa.txt	2020-07-23 23:42:42 UTC (rev 264805)
@@ -367,6 +367,7 @@
 platform/graphics/cv/PixelBufferConformerCV.cpp
 platform/graphics/cv/TextureCacheCV.mm
 platform/graphics/cv/VideoTextureCopierCV.cpp
+platform/graphics/coreimage/FilterEffectRendererCoreImage.mm
 platform/graphics/gpu/Texture.cpp
 platform/graphics/gpu/TilingData.cpp
 platform/graphics/gpu/cocoa/GPUBindGroupAllocatorMetal.mm

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (264804 => 264805)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2020-07-23 23:08:19 UTC (rev 264804)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2020-07-23 23:42:42 UTC (rev 264805)
@@ -709,6 +709,8 @@
 		29FAF4B6195AB08900A522DC /* TextUndoInsertionMarkupMac.h in Headers */ = {isa = PBXBuildFile; fileRef = 29FAF4B5195AB08900A522DC /* TextUndoInsertionMarkupMac.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		2B365C841525119E0091D27B /* RenderSVGEllipse.h in Headers */ = {isa = PBXBuildFile; fileRef = 2B4235A015250F6000DBBCD8 /* RenderSVGEllipse.h */; };
 		2BE8E2C712A589EC00FAD550 /* HTMLMetaCharsetParser.h in Headers */ = {isa = PBXBuildFile; fileRef = 2BE8E2C612A589EC00FAD550 /* HTMLMetaCharsetParser.h */; };
+		2C85653424C0F73C00A37673 /* FilterEffectRenderer.h in Headers */ = {isa = PBXBuildFile; fileRef = 2C85653324C0F73C00A37673 /* FilterEffectRenderer.h */; };
+		2CAA4A3A24BE18B7009DEE70 /* FilterEffectRendererCoreImage.h in Headers */ = {isa = PBXBuildFile; fileRef = 2CAA4A3924BE18B7009DEE70 /* FilterEffectRendererCoreImage.h */; };
 		2D0621441DA639B600A7FB26 /* WebKitMediaKeyMessageEvent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2D0621421DA6398800A7FB26 /* WebKitMediaKeyMessageEvent.cpp */; };
 		2D0621451DA639BA00A7FB26 /* WebKitMediaKeyMessageEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D0621431DA6398800A7FB26 /* WebKitMediaKeyMessageEvent.h */; };
 		2D06214D1DA63A8B00A7FB26 /* WebKitMediaKeys.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2D0621491DA63A7900A7FB26 /* WebKitMediaKeys.cpp */; };
@@ -6828,6 +6830,10 @@
 		2B4235A015250F6000DBBCD8 /* RenderSVGEllipse.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RenderSVGEllipse.h; sourceTree = "<group>"; };
 		2BE8E2C612A589EC00FAD550 /* HTMLMetaCharsetParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HTMLMetaCharsetParser.h; sourceTree = "<group>"; };
 		2BE8E2C812A58A0100FAD550 /* HTMLMetaCharsetParser.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HTMLMetaCharsetParser.cpp; sourceTree = "<group>"; };
+		2C85653324C0F73C00A37673 /* FilterEffectRenderer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FilterEffectRenderer.h; sourceTree = "<group>"; };
+		2C85653824C10B0B00A37673 /* FilterEffectRenderer.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = FilterEffectRenderer.cpp; sourceTree = "<group>"; };
+		2CAA4A3724BE18A1009DEE70 /* FilterEffectRendererCoreImage.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = FilterEffectRendererCoreImage.mm; sourceTree = "<group>"; };
+		2CAA4A3924BE18B7009DEE70 /* FilterEffectRendererCoreImage.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FilterEffectRendererCoreImage.h; sourceTree = "<group>"; };
 		2D0621421DA6398800A7FB26 /* WebKitMediaKeyMessageEvent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebKitMediaKeyMessageEvent.cpp; sourceTree = "<group>"; };
 		2D0621431DA6398800A7FB26 /* WebKitMediaKeyMessageEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebKitMediaKeyMessageEvent.h; sourceTree = "<group>"; };
 		2D0621471DA63A7900A7FB26 /* WebKitMediaKeyNeededEvent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebKitMediaKeyNeededEvent.cpp; sourceTree = "<group>"; };
@@ -18329,6 +18335,15 @@
 			path = isolatedtree;
 			sourceTree = "<group>";
 		};
+		2CE1189824C2402C003770E9 /* coreimage */ = {
+			isa = PBXGroup;
+			children = (
+				2CAA4A3924BE18B7009DEE70 /* FilterEffectRendererCoreImage.h */,
+				2CAA4A3724BE18A1009DEE70 /* FilterEffectRendererCoreImage.mm */,
+			);
+			path = coreimage;
+			sourceTree = "<group>";
+		};
 		2D0621461DA639EC00A7FB26 /* legacy */ = {
 			isa = PBXGroup;
 			children = (
@@ -23740,6 +23755,8 @@
 				845E72F70FD261EE00A87D79 /* Filter.h */,
 				08C925170FCC7C4A00480DEC /* FilterEffect.cpp */,
 				08C925180FCC7C4A00480DEC /* FilterEffect.h */,
+				2C85653824C10B0B00A37673 /* FilterEffectRenderer.cpp */,
+				2C85653324C0F73C00A37673 /* FilterEffectRenderer.h */,
 				49ECEB631499790D00CDD3A4 /* FilterOperation.cpp */,
 				49ECEB641499790D00CDD3A4 /* FilterOperation.h */,
 				49ECEB651499790D00CDD3A4 /* FilterOperations.cpp */,
@@ -25552,6 +25569,7 @@
 				499B3EC0128CCC1800E726C2 /* ca */,
 				B27535290B053814002CE64F /* cg */,
 				B5320D68122A24E9002D1440 /* cocoa */,
+				2CE1189824C2402C003770E9 /* coreimage */,
 				9332AB3B16515D7700D827EC /* cpu */,
 				CD9D827C1C7BB2ED006FF066 /* cv */,
 				0FE5FBC91C3DD5060007A2CA /* displaylists */,
@@ -30825,6 +30843,8 @@
 				712BE4831FE865DD002031CC /* FillMode.h in Headers */,
 				845E72F80FD261EE00A87D79 /* Filter.h in Headers */,
 				08C9251A0FCC7C4A00480DEC /* FilterEffect.h in Headers */,
+				2C85653424C0F73C00A37673 /* FilterEffectRenderer.h in Headers */,
+				2CAA4A3A24BE18B7009DEE70 /* FilterEffectRendererCoreImage.h in Headers */,
 				49ECEB6E1499790D00CDD3A4 /* FilterOperation.h in Headers */,
 				49ECEB701499790D00CDD3A4 /* FilterOperations.h in Headers */,
 				372C00D9129619F8005C9575 /* FindOptions.h in Headers */,

Modified: trunk/Source/WebCore/platform/graphics/ConcreteImageBuffer.h (264804 => 264805)


--- trunk/Source/WebCore/platform/graphics/ConcreteImageBuffer.h	2020-07-23 23:08:19 UTC (rev 264804)
+++ trunk/Source/WebCore/platform/graphics/ConcreteImageBuffer.h	2020-07-23 23:42:42 UTC (rev 264805)
@@ -50,6 +50,13 @@
             return nullptr;
         return std::unique_ptr<ImageBufferType>(new ImageBufferType(WTFMove(backend), std::forward<Arguments>(arguments)...));
     }
+    
+    bool isAccelerated() const override
+    {
+        if (auto* backend = ensureBackendCreated())
+            return backend->isAccelerated();
+        return false;
+    }
 
 protected:
     ConcreteImageBuffer(std::unique_ptr<BackendType>&& backend)

Modified: trunk/Source/WebCore/platform/graphics/ImageBuffer.h (264804 => 264805)


--- trunk/Source/WebCore/platform/graphics/ImageBuffer.h	2020-07-23 23:08:19 UTC (rev 264804)
+++ trunk/Source/WebCore/platform/graphics/ImageBuffer.h	2020-07-23 23:42:42 UTC (rev 264805)
@@ -101,6 +101,8 @@
     // with textures that are RGB or RGBA format, and UNSIGNED_BYTE type.
     virtual bool copyToPlatformTexture(GraphicsContextGLOpenGL&, GCGLenum, PlatformGLObject, GCGLenum, bool, bool) const = 0;
     virtual PlatformLayer* platformLayer() const = 0;
+    
+    virtual bool isAccelerated() const = 0;
 
 protected:
     ImageBuffer() = default;

Modified: trunk/Source/WebCore/platform/graphics/ImageBufferBackend.h (264804 => 264805)


--- trunk/Source/WebCore/platform/graphics/ImageBufferBackend.h	2020-07-23 23:08:19 UTC (rev 264804)
+++ trunk/Source/WebCore/platform/graphics/ImageBufferBackend.h	2020-07-23 23:42:42 UTC (rev 264805)
@@ -98,6 +98,8 @@
 
     virtual PlatformLayer* platformLayer() const { return nullptr; }
     virtual bool copyToPlatformTexture(GraphicsContextGLOpenGL&, GCGLenum, PlatformGLObject, GCGLenum, bool, bool) const { return false; }
+    
+    virtual bool isAccelerated() const { return false; }
 
 protected:
     WEBCORE_EXPORT ImageBufferBackend(const FloatSize& logicalSize, const IntSize& backendSize, float resolutionScale, ColorSpace);

Modified: trunk/Source/WebCore/platform/graphics/PlatformImageBuffer.h (264804 => 264805)


--- trunk/Source/WebCore/platform/graphics/PlatformImageBuffer.h	2020-07-23 23:08:19 UTC (rev 264804)
+++ trunk/Source/WebCore/platform/graphics/PlatformImageBuffer.h	2020-07-23 23:42:42 UTC (rev 264805)
@@ -61,8 +61,23 @@
 #endif
 
 using UnacceleratedImageBuffer = ConcreteImageBuffer<UnacceleratedImageBufferBackend>;
+
+#if HAVE(IOSURFACE)
+class AcceleratedImageBuffer : public ConcreteImageBuffer<ImageBufferIOSurfaceBackend> {
+    using Base = ConcreteImageBuffer<AcceleratedImageBufferBackend>;
+    using Base::Base;
+public:
+    IOSurface& surface() { return *m_backend->surface(); }
+};
+#else
 using AcceleratedImageBuffer = ConcreteImageBuffer<AcceleratedImageBufferBackend>;
+#endif
+
 using DisplayListUnacceleratedImageBuffer = DisplayList::ImageBuffer<UnacceleratedImageBufferBackend>;
 using DisplayListAcceleratedImageBuffer = DisplayList::ImageBuffer<AcceleratedImageBufferBackend>;
 
 } // namespace WebCore
+
+SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::AcceleratedImageBuffer)
+    static bool isType(const WebCore::ImageBuffer& buffer) { return buffer.isAccelerated(); }
+SPECIALIZE_TYPE_TRAITS_END()

Modified: trunk/Source/WebCore/platform/graphics/cg/ImageBufferIOSurfaceBackend.cpp (264804 => 264805)


--- trunk/Source/WebCore/platform/graphics/cg/ImageBufferIOSurfaceBackend.cpp	2020-07-23 23:08:19 UTC (rev 264804)
+++ trunk/Source/WebCore/platform/graphics/cg/ImageBufferIOSurfaceBackend.cpp	2020-07-23 23:42:42 UTC (rev 264805)
@@ -184,6 +184,17 @@
     m_requiresDrawAfterPutImageData = true;
 }
 
+IOSurface* ImageBufferIOSurfaceBackend::surface()
+{
+    flushContext();
+    return m_surface.get();
+}
+
+bool ImageBufferIOSurfaceBackend::isAccelerated() const
+{
+    return true;
+}
+
 } // namespace WebCore
 
 #endif // HAVE(IOSURFACE)

Modified: trunk/Source/WebCore/platform/graphics/cg/ImageBufferIOSurfaceBackend.h (264804 => 264805)


--- trunk/Source/WebCore/platform/graphics/cg/ImageBufferIOSurfaceBackend.h	2020-07-23 23:08:19 UTC (rev 264804)
+++ trunk/Source/WebCore/platform/graphics/cg/ImageBufferIOSurfaceBackend.h	2020-07-23 23:42:42 UTC (rev 264805)
@@ -61,6 +61,8 @@
 
     RefPtr<ImageData> getImageData(AlphaPremultiplication outputFormat, const IntRect&) const override;
     void putImageData(AlphaPremultiplication inputFormat, const ImageData&, const IntRect& srcRect, const IntPoint& destPoint) override;
+    IOSurface* surface();
+    bool isAccelerated() const override;
 
 protected:
     static RetainPtr<CGColorSpaceRef> contextColorSpace(const GraphicsContext&);

Added: trunk/Source/WebCore/platform/graphics/coreimage/FilterEffectRendererCoreImage.h (0 => 264805)


--- trunk/Source/WebCore/platform/graphics/coreimage/FilterEffectRendererCoreImage.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/coreimage/FilterEffectRendererCoreImage.h	2020-07-23 23:42:42 UTC (rev 264805)
@@ -0,0 +1,68 @@
+/*
+* Copyright (C) 2020 Apple Inc. All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions
+* are met:
+* 1. Redistributions of source code must retain the above copyright
+*    notice, this list of conditions and the following disclaimer.
+* 2. Redistributions in binary form must reproduce the above copyright
+*    notice, this list of conditions and the following disclaimer in the
+*    documentation and/or other materials provided with the distribution.
+*
+* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+* PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#pragma once
+
+#if USE(CORE_IMAGE)
+
+#import "FilterEffectRenderer.h"
+#import <wtf/HashMap.h>
+#import <wtf/Vector.h>
+
+OBJC_CLASS CIImage;
+OBJC_CLASS CIFilter;
+OBJC_CLASS CIContext;
+
+namespace WebCore {
+
+class FilterEffectRendererCoreImage : public FilterEffectRenderer {
+    WTF_MAKE_FAST_ALLOCATED;
+    
+public:
+    static std::unique_ptr<FilterEffectRendererCoreImage> tryCreate(FilterEffect&);
+    
+    void applyEffects(FilterEffect&) final;
+    bool hasResult() const final { return m_outputImage; }
+    ImageBuffer* output() const final;
+    FloatRect destRect(const FilterEffect&) const final;
+    void clearResult() final;
+    
+    FilterEffectRendererCoreImage();
+    
+private:
+    CIImage* connectCIFilters(FilterEffect&);
+    void renderToImageBuffer(FilterEffect&) final;
+    static bool supportsCoreImageRendering(FilterEffect&);
+    static bool canRenderUsingCIFilters(FilterEffect&);
+    
+    std::unique_ptr<ImageBuffer> m_outputImageBuffer;
+    HashMap<Ref<FilterEffect>, Vector<RetainPtr<CIFilter>>> m_ciFilterStorageMap;
+    RetainPtr<CIImage> m_outputImage;
+    RetainPtr<CIContext> m_context;
+};
+
+} // namespace WebCore
+
+#endif

Added: trunk/Source/WebCore/platform/graphics/coreimage/FilterEffectRendererCoreImage.mm (0 => 264805)


--- trunk/Source/WebCore/platform/graphics/coreimage/FilterEffectRendererCoreImage.mm	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/coreimage/FilterEffectRendererCoreImage.mm	2020-07-23 23:42:42 UTC (rev 264805)
@@ -0,0 +1,192 @@
+/*
+* Copyright (C) 2020 Apple Inc. All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions
+* are met:
+* 1. Redistributions of source code must retain the above copyright
+*    notice, this list of conditions and the following disclaimer.
+* 2. Redistributions in binary form must reproduce the above copyright
+*    notice, this list of conditions and the following disclaimer in the
+*    documentation and/or other materials provided with the distribution.
+*
+* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+* PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#import "config.h"
+#import "FilterEffectRendererCoreImage.h"
+
+#if USE(CORE_IMAGE)
+
+#import "Filter.h"
+#import "FilterEffect.h"
+#import "GraphicsContextCG.h"
+#import "ImageBuffer.h"
+#import "PlatformImageBuffer.h"
+#import <CoreImage/CIContext.h>
+#import <CoreImage/CIFilter.h>
+#import <CoreImage/CoreImage.h>
+
+namespace WebCore {
+
+std::unique_ptr<FilterEffectRendererCoreImage> FilterEffectRendererCoreImage::tryCreate(FilterEffect& lastEffect)
+{
+    if (canRenderUsingCIFilters(lastEffect))
+        return makeUnique<FilterEffectRendererCoreImage>();
+    return nullptr;
+}
+
+bool FilterEffectRendererCoreImage::supportsCoreImageRendering(FilterEffect& effect)
+{
+    // FIXME: change return value to true once they are implemented
+    switch (effect.filterEffectClassType()) {
+    case FilterEffect::Type::Blend:
+    case FilterEffect::Type::ColorMatrix:
+    case FilterEffect::Type::ComponentTransfer:
+    case FilterEffect::Type::Composite:
+    case FilterEffect::Type::ConvolveMatrix:
+    case FilterEffect::Type::DiffuseLighting:
+    case FilterEffect::Type::DisplacementMap:
+    case FilterEffect::Type::DropShadow:
+    case FilterEffect::Type::Flood:
+    case FilterEffect::Type::GaussianBlur:
+    case FilterEffect::Type::Image:
+    case FilterEffect::Type::Lighting:
+    case FilterEffect::Type::Merge:
+    case FilterEffect::Type::Morphology:
+    case FilterEffect::Type::Offset:
+    case FilterEffect::Type::SpecularLighting:
+    case FilterEffect::Type::Tile:
+    case FilterEffect::Type::Turbulence:
+    case FilterEffect::Type::SourceAlpha:
+    case FilterEffect::Type::SourceGraphic:
+        return false;
+    }
+    return false;
+}
+
+void FilterEffectRendererCoreImage::applyEffects(FilterEffect& lastEffect)
+{
+    m_outputImage = connectCIFilters(lastEffect);
+    if (!m_outputImage)
+        return;
+    renderToImageBuffer(lastEffect);
+}
+
+CIImage* FilterEffectRendererCoreImage::connectCIFilters(FilterEffect& effect)
+{
+    Vector<CIImage*> inputImages;
+    
+    for (auto in : effect.inputEffects()) {
+        CIImage* inputImage = connectCIFilters(*in);
+        if (!inputImage)
+            return nullptr;
+        inputImages.append(inputImage);
+    }
+    effect.determineAbsolutePaintRect();
+    effect.setResultColorSpace(effect.operatingColorSpace());
+    
+    if (effect.absolutePaintRect().isEmpty() || ImageBuffer::sizeNeedsClamping(effect.absolutePaintRect().size()))
+        return nullptr;
+    
+    // FIXME: Implement those filters using CIFilter so that the function returns a valid CIImage
+    switch (effect.filterEffectClassType()) {
+    case FilterEffect::Type::Blend:
+    case FilterEffect::Type::ColorMatrix:
+    case FilterEffect::Type::ComponentTransfer:
+    case FilterEffect::Type::Composite:
+    case FilterEffect::Type::ConvolveMatrix:
+    case FilterEffect::Type::DiffuseLighting:
+    case FilterEffect::Type::DisplacementMap:
+    case FilterEffect::Type::DropShadow:
+    case FilterEffect::Type::Flood:
+    case FilterEffect::Type::GaussianBlur:
+    case FilterEffect::Type::Image:
+    case FilterEffect::Type::Lighting:
+    case FilterEffect::Type::Merge:
+    case FilterEffect::Type::Morphology:
+    case FilterEffect::Type::Offset:
+    case FilterEffect::Type::SpecularLighting:
+    case FilterEffect::Type::Tile:
+    case FilterEffect::Type::Turbulence:
+    case FilterEffect::Type::SourceAlpha:
+    case FilterEffect::Type::SourceGraphic:
+    default:
+        return nullptr;
+    }
+    return nullptr;
+}
+
+bool FilterEffectRendererCoreImage::canRenderUsingCIFilters(FilterEffect& effect)
+{
+    if (!supportsCoreImageRendering(effect))
+        return false;
+    
+    for (auto in : effect.inputEffects()) {
+        if (!supportsCoreImageRendering(*in) || !canRenderUsingCIFilters(*in))
+            return false;
+    }
+    return true;
+}
+
+ImageBuffer* FilterEffectRendererCoreImage::output() const
+{
+    return m_outputImageBuffer.get();
+}
+    
+void FilterEffectRendererCoreImage::renderToImageBuffer(FilterEffect& lastEffect)
+{
+    FloatSize clampedSize = ImageBuffer::clampedSize(lastEffect.absolutePaintRect().size());
+    m_outputImageBuffer = ImageBuffer::create(clampedSize, RenderingMode::Accelerated, lastEffect.filter().filterScale(), lastEffect.resultColorSpace());
+    
+    if (!m_outputImageBuffer) {
+        clearResult();
+        return;
+    }
+    
+    // FIXME: In the situation where the Image is too large, an UnacceleratedImageBuffer will be created
+    // in this case, special handling is needed to render to ImageBufferCGBackend instead
+    if (!is<AcceleratedImageBuffer>(*m_outputImageBuffer))
+        return;
+    
+    auto& surface = downcast<AcceleratedImageBuffer>(*m_outputImageBuffer).surface();
+    CGColorSpaceRef resultColorSpace = cachedCGColorSpace(lastEffect.resultColorSpace());
+    [m_context.get() render: m_outputImage.get() toIOSurface: surface.surface() bounds:destRect(lastEffect) colorSpace:resultColorSpace];
+}
+    
+FloatRect FilterEffectRendererCoreImage::destRect(const FilterEffect& lastEffect) const
+{
+    IntSize destSize = lastEffect.absolutePaintRect().size();
+    destSize.scale(lastEffect.filter().filterScale());
+    FloatRect destRect = FloatRect(FloatPoint(), destSize);
+    return destRect;
+}
+
+void FilterEffectRendererCoreImage::clearResult()
+{
+    m_outputImageBuffer.reset();
+    m_ciFilterStorageMap.clear();
+    m_outputImage = nullptr;
+    m_context = nullptr;
+}
+
+FilterEffectRendererCoreImage::FilterEffectRendererCoreImage()
+    : FilterEffectRenderer()
+{
+    CGColorSpaceRef colorSpace = cachedCGColorSpace(ColorSpace::SRGB);
+    m_context = [CIContext contextWithOptions: @{ kCIContextWorkingColorSpace: (__bridge id)colorSpace}];
+}
+    
+} // namespace WebCore
+
+#endif

Modified: trunk/Source/WebCore/platform/graphics/filters/FEBlend.cpp (264804 => 264805)


--- trunk/Source/WebCore/platform/graphics/filters/FEBlend.cpp	2020-07-23 23:08:19 UTC (rev 264804)
+++ trunk/Source/WebCore/platform/graphics/filters/FEBlend.cpp	2020-07-23 23:42:42 UTC (rev 264805)
@@ -35,7 +35,7 @@
 namespace WebCore {
 
 FEBlend::FEBlend(Filter& filter, BlendMode mode)
-    : FilterEffect(filter)
+    : FilterEffect(filter, Type::Blend)
     , m_mode(mode)
 {
 }

Modified: trunk/Source/WebCore/platform/graphics/filters/FEColorMatrix.cpp (264804 => 264805)


--- trunk/Source/WebCore/platform/graphics/filters/FEColorMatrix.cpp	2020-07-23 23:08:19 UTC (rev 264804)
+++ trunk/Source/WebCore/platform/graphics/filters/FEColorMatrix.cpp	2020-07-23 23:42:42 UTC (rev 264805)
@@ -36,7 +36,7 @@
 namespace WebCore {
 
 FEColorMatrix::FEColorMatrix(Filter& filter, ColorMatrixType type, const Vector<float>& values)
-    : FilterEffect(filter)
+    : FilterEffect(filter, Type::ColorMatrix)
     , m_type(type)
     , m_values(values)
 {

Modified: trunk/Source/WebCore/platform/graphics/filters/FEComponentTransfer.cpp (264804 => 264805)


--- trunk/Source/WebCore/platform/graphics/filters/FEComponentTransfer.cpp	2020-07-23 23:08:19 UTC (rev 264804)
+++ trunk/Source/WebCore/platform/graphics/filters/FEComponentTransfer.cpp	2020-07-23 23:42:42 UTC (rev 264805)
@@ -35,7 +35,7 @@
 
 FEComponentTransfer::FEComponentTransfer(Filter& filter, const ComponentTransferFunction& redFunction,
     const ComponentTransferFunction& greenFunction, const ComponentTransferFunction& blueFunction, const ComponentTransferFunction& alphaFunction)
-    : FilterEffect(filter)
+    : FilterEffect(filter, Type::ComponentTransfer)
     , m_redFunction(redFunction)
     , m_greenFunction(greenFunction)
     , m_blueFunction(blueFunction)

Modified: trunk/Source/WebCore/platform/graphics/filters/FEComposite.cpp (264804 => 264805)


--- trunk/Source/WebCore/platform/graphics/filters/FEComposite.cpp	2020-07-23 23:08:19 UTC (rev 264804)
+++ trunk/Source/WebCore/platform/graphics/filters/FEComposite.cpp	2020-07-23 23:42:42 UTC (rev 264805)
@@ -33,7 +33,7 @@
 namespace WebCore {
 
 FEComposite::FEComposite(Filter& filter, const CompositeOperationType& type, float k1, float k2, float k3, float k4)
-    : FilterEffect(filter)
+    : FilterEffect(filter, Type::Composite)
     , m_type(type)
     , m_k1(k1)
     , m_k2(k2)

Modified: trunk/Source/WebCore/platform/graphics/filters/FEConvolveMatrix.cpp (264804 => 264805)


--- trunk/Source/WebCore/platform/graphics/filters/FEConvolveMatrix.cpp	2020-07-23 23:08:19 UTC (rev 264804)
+++ trunk/Source/WebCore/platform/graphics/filters/FEConvolveMatrix.cpp	2020-07-23 23:42:42 UTC (rev 264805)
@@ -35,7 +35,7 @@
 FEConvolveMatrix::FEConvolveMatrix(Filter& filter, const IntSize& kernelSize,
     float divisor, float bias, const IntPoint& targetOffset, EdgeModeType edgeMode,
     const FloatPoint& kernelUnitLength, bool preserveAlpha, const Vector<float>& kernelMatrix)
-    : FilterEffect(filter)
+    : FilterEffect(filter, Type::ConvolveMatrix)
     , m_kernelSize(kernelSize)
     , m_divisor(divisor)
     , m_bias(bias)

Modified: trunk/Source/WebCore/platform/graphics/filters/FEDiffuseLighting.cpp (264804 => 264805)


--- trunk/Source/WebCore/platform/graphics/filters/FEDiffuseLighting.cpp	2020-07-23 23:08:19 UTC (rev 264804)
+++ trunk/Source/WebCore/platform/graphics/filters/FEDiffuseLighting.cpp	2020-07-23 23:42:42 UTC (rev 264805)
@@ -28,7 +28,7 @@
 namespace WebCore {
 
 FEDiffuseLighting::FEDiffuseLighting(Filter& filter, const Color& lightingColor, float surfaceScale, float diffuseConstant, float kernelUnitLengthX, float kernelUnitLengthY, Ref<LightSource>&& lightSource)
-    : FELighting(filter, DiffuseLighting, lightingColor, surfaceScale, diffuseConstant, 0, 0, kernelUnitLengthX, kernelUnitLengthY, WTFMove(lightSource))
+    : FELighting(filter, DiffuseLighting, lightingColor, surfaceScale, diffuseConstant, 0, 0, kernelUnitLengthX, kernelUnitLengthY, WTFMove(lightSource), Type::DiffuseLighting)
 {
 }
 

Modified: trunk/Source/WebCore/platform/graphics/filters/FEDisplacementMap.cpp (264804 => 264805)


--- trunk/Source/WebCore/platform/graphics/filters/FEDisplacementMap.cpp	2020-07-23 23:08:19 UTC (rev 264804)
+++ trunk/Source/WebCore/platform/graphics/filters/FEDisplacementMap.cpp	2020-07-23 23:42:42 UTC (rev 264805)
@@ -32,7 +32,7 @@
 namespace WebCore {
 
 FEDisplacementMap::FEDisplacementMap(Filter& filter, ChannelSelectorType xChannelSelector, ChannelSelectorType yChannelSelector, float scale)
-    : FilterEffect(filter)
+    : FilterEffect(filter, Type::DisplacementMap)
     , m_xChannelSelector(xChannelSelector)
     , m_yChannelSelector(yChannelSelector)
     , m_scale(scale)

Modified: trunk/Source/WebCore/platform/graphics/filters/FEDropShadow.cpp (264804 => 264805)


--- trunk/Source/WebCore/platform/graphics/filters/FEDropShadow.cpp	2020-07-23 23:08:19 UTC (rev 264804)
+++ trunk/Source/WebCore/platform/graphics/filters/FEDropShadow.cpp	2020-07-23 23:42:42 UTC (rev 264805)
@@ -32,7 +32,7 @@
 namespace WebCore {
     
 FEDropShadow::FEDropShadow(Filter& filter, float stdX, float stdY, float dx, float dy, const Color& shadowColor, float shadowOpacity)
-    : FilterEffect(filter)
+    : FilterEffect(filter, Type::DropShadow)
     , m_stdX(stdX)
     , m_stdY(stdY)
     , m_dx(dx)

Modified: trunk/Source/WebCore/platform/graphics/filters/FEFlood.cpp (264804 => 264805)


--- trunk/Source/WebCore/platform/graphics/filters/FEFlood.cpp	2020-07-23 23:08:19 UTC (rev 264804)
+++ trunk/Source/WebCore/platform/graphics/filters/FEFlood.cpp	2020-07-23 23:42:42 UTC (rev 264805)
@@ -31,7 +31,7 @@
 namespace WebCore {
 
 FEFlood::FEFlood(Filter& filter, const Color& floodColor, float floodOpacity)
-    : FilterEffect(filter)
+    : FilterEffect(filter, Type::Flood)
     , m_floodColor(floodColor)
     , m_floodOpacity(floodOpacity)
 {

Modified: trunk/Source/WebCore/platform/graphics/filters/FEGaussianBlur.cpp (264804 => 264805)


--- trunk/Source/WebCore/platform/graphics/filters/FEGaussianBlur.cpp	2020-07-23 23:08:19 UTC (rev 264804)
+++ trunk/Source/WebCore/platform/graphics/filters/FEGaussianBlur.cpp	2020-07-23 23:42:42 UTC (rev 264805)
@@ -80,7 +80,7 @@
 }
 
 FEGaussianBlur::FEGaussianBlur(Filter& filter, float x, float y, EdgeModeType edgeMode)
-    : FilterEffect(filter)
+    : FilterEffect(filter, Type::GaussianBlur)
     , m_stdX(x)
     , m_stdY(y)
     , m_edgeMode(edgeMode)

Modified: trunk/Source/WebCore/platform/graphics/filters/FELighting.cpp (264804 => 264805)


--- trunk/Source/WebCore/platform/graphics/filters/FELighting.cpp	2020-07-23 23:08:19 UTC (rev 264804)
+++ trunk/Source/WebCore/platform/graphics/filters/FELighting.cpp	2020-07-23 23:42:42 UTC (rev 264805)
@@ -35,8 +35,8 @@
 
 namespace WebCore {
 
-FELighting::FELighting(Filter& filter, LightingType lightingType, const Color& lightingColor, float surfaceScale, float diffuseConstant, float specularConstant, float specularExponent, float kernelUnitLengthX, float kernelUnitLengthY, Ref<LightSource>&& lightSource)
-    : FilterEffect(filter)
+FELighting::FELighting(Filter& filter, LightingType lightingType, const Color& lightingColor, float surfaceScale, float diffuseConstant, float specularConstant, float specularExponent, float kernelUnitLengthX, float kernelUnitLengthY, Ref<LightSource>&& lightSource, Type type)
+    : FilterEffect(filter, type)
     , m_lightingType(lightingType)
     , m_lightSource(WTFMove(lightSource))
     , m_lightingColor(lightingColor)

Modified: trunk/Source/WebCore/platform/graphics/filters/FELighting.h (264804 => 264805)


--- trunk/Source/WebCore/platform/graphics/filters/FELighting.h	2020-07-23 23:08:19 UTC (rev 264804)
+++ trunk/Source/WebCore/platform/graphics/filters/FELighting.h	2020-07-23 23:42:42 UTC (rev 264805)
@@ -131,7 +131,7 @@
     static void platformApplyGenericWorker(PlatformApplyGenericParameters*);
     static void platformApplyNeonWorker(FELightingPaintingDataForNeon*);
 
-    FELighting(Filter&, LightingType, const Color&, float, float, float, float, float, float, Ref<LightSource>&&);
+    FELighting(Filter&, LightingType, const Color&, float, float, float, float, float, float, Ref<LightSource>&&, Type);
 
     const char* filterName() const final { return "FELighting"; }
 

Modified: trunk/Source/WebCore/platform/graphics/filters/FEMerge.cpp (264804 => 264805)


--- trunk/Source/WebCore/platform/graphics/filters/FEMerge.cpp	2020-07-23 23:08:19 UTC (rev 264804)
+++ trunk/Source/WebCore/platform/graphics/filters/FEMerge.cpp	2020-07-23 23:42:42 UTC (rev 264805)
@@ -29,7 +29,7 @@
 namespace WebCore {
 
 FEMerge::FEMerge(Filter& filter)
-    : FilterEffect(filter)
+    : FilterEffect(filter, Type::Merge)
 {
 }
 

Modified: trunk/Source/WebCore/platform/graphics/filters/FEMorphology.cpp (264804 => 264805)


--- trunk/Source/WebCore/platform/graphics/filters/FEMorphology.cpp	2020-07-23 23:08:19 UTC (rev 264804)
+++ trunk/Source/WebCore/platform/graphics/filters/FEMorphology.cpp	2020-07-23 23:42:42 UTC (rev 264805)
@@ -35,7 +35,7 @@
 namespace WebCore {
 
 FEMorphology::FEMorphology(Filter& filter, MorphologyOperatorType type, float radiusX, float radiusY)
-    : FilterEffect(filter)
+    : FilterEffect(filter, Type::Morphology)
     , m_type(type)
     , m_radiusX(radiusX)
     , m_radiusY(radiusY)

Modified: trunk/Source/WebCore/platform/graphics/filters/FEOffset.cpp (264804 => 264805)


--- trunk/Source/WebCore/platform/graphics/filters/FEOffset.cpp	2020-07-23 23:08:19 UTC (rev 264804)
+++ trunk/Source/WebCore/platform/graphics/filters/FEOffset.cpp	2020-07-23 23:42:42 UTC (rev 264805)
@@ -31,7 +31,7 @@
 namespace WebCore {
 
 FEOffset::FEOffset(Filter& filter, float dx, float dy)
-    : FilterEffect(filter)
+    : FilterEffect(filter, Type::Offset)
     , m_dx(dx)
     , m_dy(dy)
 {

Modified: trunk/Source/WebCore/platform/graphics/filters/FESpecularLighting.cpp (264804 => 264805)


--- trunk/Source/WebCore/platform/graphics/filters/FESpecularLighting.cpp	2020-07-23 23:08:19 UTC (rev 264804)
+++ trunk/Source/WebCore/platform/graphics/filters/FESpecularLighting.cpp	2020-07-23 23:42:42 UTC (rev 264805)
@@ -28,7 +28,7 @@
 namespace WebCore {
 
 FESpecularLighting::FESpecularLighting(Filter& filter, const Color& lightingColor, float surfaceScale, float specularConstant, float specularExponent, float kernelUnitLengthX, float kernelUnitLengthY, Ref<LightSource>&& lightSource)
-    : FELighting(filter, SpecularLighting, lightingColor, surfaceScale, 0, specularConstant, specularExponent, kernelUnitLengthX, kernelUnitLengthY, WTFMove(lightSource))
+    : FELighting(filter, SpecularLighting, lightingColor, surfaceScale, 0, specularConstant, specularExponent, kernelUnitLengthX, kernelUnitLengthY, WTFMove(lightSource), Type::SpecularLighting)
 {
 }
 

Modified: trunk/Source/WebCore/platform/graphics/filters/FETile.cpp (264804 => 264805)


--- trunk/Source/WebCore/platform/graphics/filters/FETile.cpp	2020-07-23 23:08:19 UTC (rev 264804)
+++ trunk/Source/WebCore/platform/graphics/filters/FETile.cpp	2020-07-23 23:42:42 UTC (rev 264805)
@@ -32,7 +32,7 @@
 namespace WebCore {
 
 FETile::FETile(Filter& filter)
-    : FilterEffect(filter)
+    : FilterEffect(filter, Type::Tile)
 {
 }
 

Modified: trunk/Source/WebCore/platform/graphics/filters/FETurbulence.cpp (264804 => 264805)


--- trunk/Source/WebCore/platform/graphics/filters/FETurbulence.cpp	2020-07-23 23:08:19 UTC (rev 264804)
+++ trunk/Source/WebCore/platform/graphics/filters/FETurbulence.cpp	2020-07-23 23:42:42 UTC (rev 264805)
@@ -49,7 +49,7 @@
 static const int s_randR = 2836; // m % a
 
 FETurbulence::FETurbulence(Filter& filter, TurbulenceType type, float baseFrequencyX, float baseFrequencyY, int numOctaves, float seed, bool stitchTiles)
-    : FilterEffect(filter)
+    : FilterEffect(filter, Type::Turbulence)
     , m_type(type)
     , m_baseFrequencyX(baseFrequencyX)
     , m_baseFrequencyY(baseFrequencyY)

Modified: trunk/Source/WebCore/platform/graphics/filters/FilterEffect.cpp (264804 => 264805)


--- trunk/Source/WebCore/platform/graphics/filters/FilterEffect.cpp	2020-07-23 23:08:19 UTC (rev 264804)
+++ trunk/Source/WebCore/platform/graphics/filters/FilterEffect.cpp	2020-07-23 23:42:42 UTC (rev 264805)
@@ -45,8 +45,9 @@
 
 namespace WebCore {
 
-FilterEffect::FilterEffect(Filter& filter)
+FilterEffect::FilterEffect(Filter& filter, Type type)
     : m_filter(filter)
+    , m_filterEffectClassType(type)
 {
 }
 

Modified: trunk/Source/WebCore/platform/graphics/filters/FilterEffect.h (264804 => 264805)


--- trunk/Source/WebCore/platform/graphics/filters/FilterEffect.h	2020-07-23 23:08:19 UTC (rev 264804)
+++ trunk/Source/WebCore/platform/graphics/filters/FilterEffect.h	2020-07-23 23:42:42 UTC (rev 264805)
@@ -54,6 +54,28 @@
 
 class FilterEffect : public RefCounted<FilterEffect> {
 public:
+    enum class Type : uint8_t {
+        Blend,
+        ColorMatrix,
+        ComponentTransfer,
+        Composite,
+        ConvolveMatrix,
+        DiffuseLighting,
+        DisplacementMap,
+        DropShadow,
+        Flood,
+        GaussianBlur,
+        Image,
+        Lighting,
+        Merge,
+        Morphology,
+        Offset,
+        SpecularLighting,
+        Tile,
+        Turbulence,
+        SourceAlpha,
+        SourceGraphic
+    };
     virtual ~FilterEffect();
 
     void clearResult();
@@ -132,6 +154,8 @@
     void setUnclippedAbsoluteSubregion(const FloatRect& r) { m_absoluteUnclippedSubregion = r; }
     
     FloatPoint mapPointFromUserSpaceToBuffer(FloatPoint) const;
+    
+    Type filterEffectClassType() { return m_filterEffectClassType; }
 
     Filter& filter() { return m_filter; }
     const Filter& filter() const { return m_filter; }
@@ -148,7 +172,7 @@
     void transformResultColorSpace(ColorSpace);
 
 protected:
-    FilterEffect(Filter&);
+    FilterEffect(Filter&, Type);
     
     virtual const char* filterName() const = 0;
 
@@ -219,6 +243,8 @@
 
     ColorSpace m_operatingColorSpace { ColorSpace::LinearRGB };
     ColorSpace m_resultColorSpace { ColorSpace::SRGB };
+    
+    const Type m_filterEffectClassType;
 };
 
 WEBCORE_EXPORT WTF::TextStream& operator<<(WTF::TextStream&, const FilterEffect&);

Added: trunk/Source/WebCore/platform/graphics/filters/FilterEffectRenderer.cpp (0 => 264805)


--- trunk/Source/WebCore/platform/graphics/filters/FilterEffectRenderer.cpp	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/filters/FilterEffectRenderer.cpp	2020-07-23 23:42:42 UTC (rev 264805)
@@ -0,0 +1,45 @@
+/*
+* Copyright (C) 2020 Apple Inc. All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions
+* are met:
+* 1. Redistributions of source code must retain the above copyright
+*    notice, this list of conditions and the following disclaimer.
+* 2. Redistributions in binary form must reproduce the above copyright
+*    notice, this list of conditions and the following disclaimer in the
+*    documentation and/or other materials provided with the distribution.
+*
+* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+* PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include "config.h"
+#include "FilterEffectRenderer.h"
+
+#if USE(CORE_IMAGE)
+#include "FilterEffectRendererCoreImage.h"
+#endif
+
+namespace WebCore {
+
+std::unique_ptr<FilterEffectRenderer> FilterEffectRenderer::tryCreate(bool acceleratedFilterRenderingEnabled, FilterEffect& lastEffect)
+{
+#if USE(CORE_IMAGE)
+    if (acceleratedFilterRenderingEnabled)
+        return FilterEffectRendererCoreImage::tryCreate(lastEffect);
+#endif
+    return nullptr;
+}
+
+
+} // namspace WebCore

Added: trunk/Source/WebCore/platform/graphics/filters/FilterEffectRenderer.h (0 => 264805)


--- trunk/Source/WebCore/platform/graphics/filters/FilterEffectRenderer.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/filters/FilterEffectRenderer.h	2020-07-23 23:42:42 UTC (rev 264805)
@@ -0,0 +1,52 @@
+/*
+* Copyright (C) 2020 Apple Inc. All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions
+* are met:
+* 1. Redistributions of source code must retain the above copyright
+*    notice, this list of conditions and the following disclaimer.
+* 2. Redistributions in binary form must reproduce the above copyright
+*    notice, this list of conditions and the following disclaimer in the
+*    documentation and/or other materials provided with the distribution.
+*
+* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+* PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#pragma once
+
+#include "FilterEffect.h"
+#include "ImageBuffer.h"
+#include "Settings.h"
+
+namespace WebCore {
+
+class FilterEffectRenderer {
+    WTF_MAKE_FAST_ALLOCATED;
+    
+public:
+    static std::unique_ptr<FilterEffectRenderer> tryCreate(bool, FilterEffect&);
+    virtual void applyEffects(FilterEffect&) = 0;
+    virtual bool hasResult() const = 0;
+    virtual ImageBuffer* output() const = 0;
+    virtual FloatRect destRect(const FilterEffect&) const = 0;
+    virtual void clearResult() = 0;
+    
+    virtual ~FilterEffectRenderer() = default;
+    
+protected:
+    FilterEffectRenderer() = default;
+    virtual void renderToImageBuffer(FilterEffect&) = 0;
+};
+
+} // namespace WebCore

Modified: trunk/Source/WebCore/platform/graphics/filters/SourceAlpha.cpp (264804 => 264805)


--- trunk/Source/WebCore/platform/graphics/filters/SourceAlpha.cpp	2020-07-23 23:08:19 UTC (rev 264804)
+++ trunk/Source/WebCore/platform/graphics/filters/SourceAlpha.cpp	2020-07-23 23:42:42 UTC (rev 264805)
@@ -70,7 +70,7 @@
 }
 
 SourceAlpha::SourceAlpha(FilterEffect& sourceEffect)
-    : FilterEffect(sourceEffect.filter())
+    : FilterEffect(sourceEffect.filter(), Type::SourceAlpha)
 {
     setOperatingColorSpace(sourceEffect.operatingColorSpace());
     inputEffects().append(&sourceEffect);

Modified: trunk/Source/WebCore/platform/graphics/filters/SourceGraphic.h (264804 => 264805)


--- trunk/Source/WebCore/platform/graphics/filters/SourceGraphic.h	2020-07-23 23:08:19 UTC (rev 264804)
+++ trunk/Source/WebCore/platform/graphics/filters/SourceGraphic.h	2020-07-23 23:42:42 UTC (rev 264805)
@@ -34,7 +34,7 @@
 
 private:
     SourceGraphic(Filter& filter)
-        : FilterEffect(filter)
+        : FilterEffect(filter, Type::SourceGraphic)
     {
         setOperatingColorSpace(ColorSpace::SRGB);
     }

Modified: trunk/Source/WebCore/rendering/CSSFilter.cpp (264804 => 264805)


--- trunk/Source/WebCore/rendering/CSSFilter.cpp	2020-07-23 23:08:19 UTC (rev 264804)
+++ trunk/Source/WebCore/rendering/CSSFilter.cpp	2020-07-23 23:42:42 UTC (rev 264805)
@@ -35,6 +35,7 @@
 #include "FEDropShadow.h"
 #include "FEGaussianBlur.h"
 #include "FEMerge.h"
+#include "FilterEffectRenderer.h"
 #include "Logging.h"
 #include "RenderLayer.h"
 #include "SVGElement.h"
@@ -304,6 +305,9 @@
         return false;
 
     setMaxEffectRects(m_sourceDrawingRegion);
+#if USE(CORE_IMAGE)
+    m_filterRenderer = FilterEffectRenderer::tryCreate(renderer.settings().coreImageAcceleratedFilterRenderEnabled(), m_effects.last().get());
+#endif
     return true;
 }
 
@@ -365,6 +369,13 @@
 void CSSFilter::apply()
 {
     auto& effect = m_effects.last().get();
+    if (m_filterRenderer) {
+        m_filterRenderer->applyEffects(effect);
+        if (m_filterRenderer->hasResult()) {
+            effect.transformResultColorSpace(ColorSpace::SRGB);
+            return;
+        }
+    }
     effect.apply();
     effect.transformResultColorSpace(ColorSpace::SRGB);
 }
@@ -381,6 +392,9 @@
 
 ImageBuffer* CSSFilter::output() const
 {
+    if (m_filterRenderer && m_filterRenderer->hasResult())
+        return m_filterRenderer->output();
+    
     return m_effects.last()->imageBufferResult();
 }
 
@@ -401,9 +415,11 @@
 IntRect CSSFilter::outputRect() const
 {
     auto& lastEffect = m_effects.last().get();
-    if (!lastEffect.hasResult())
-        return { };
-    return lastEffect.requestedRegionOfInputImageData(IntRect { m_filterRegion });
+    
+    if (lastEffect.hasResult() || (m_filterRenderer && m_filterRenderer->hasResult()))
+        return lastEffect.requestedRegionOfInputImageData(IntRect { m_filterRegion });
+    
+    return { };
 }
 
 IntOutsets CSSFilter::outsets() const

Modified: trunk/Source/WebCore/rendering/CSSFilter.h (264804 => 264805)


--- trunk/Source/WebCore/rendering/CSSFilter.h	2020-07-23 23:08:19 UTC (rev 264804)
+++ trunk/Source/WebCore/rendering/CSSFilter.h	2020-07-23 23:42:42 UTC (rev 264805)
@@ -33,6 +33,7 @@
 namespace WebCore {
 
 class FilterEffect;
+class FilterEffectRenderer;
 class FilterOperations;
 class GraphicsContext;
 class ReferenceFilterOperation;
@@ -99,6 +100,8 @@
     bool m_graphicsBufferAttached { false };
     bool m_hasFilterThatMovesPixels { false };
     bool m_hasFilterThatShouldBeRestrictedBySecurityOrigin { false };
+    
+    std::unique_ptr<FilterEffectRenderer> m_filterRenderer;
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/svg/graphics/filters/SVGFEImage.cpp (264804 => 264805)


--- trunk/Source/WebCore/svg/graphics/filters/SVGFEImage.cpp	2020-07-23 23:08:19 UTC (rev 264804)
+++ trunk/Source/WebCore/svg/graphics/filters/SVGFEImage.cpp	2020-07-23 23:42:42 UTC (rev 264805)
@@ -36,7 +36,7 @@
 namespace WebCore {
 
 FEImage::FEImage(Filter& filter, RefPtr<Image> image, const SVGPreserveAspectRatioValue& preserveAspectRatio)
-    : FilterEffect(filter)
+    : FilterEffect(filter, Type::Image)
     , m_image(image)
     , m_preserveAspectRatio(preserveAspectRatio)
 {
@@ -43,7 +43,7 @@
 }
 
 FEImage::FEImage(Filter& filter, TreeScope& treeScope, const String& href, const SVGPreserveAspectRatioValue& preserveAspectRatio)
-    : FilterEffect(filter)
+    : FilterEffect(filter, Type::Image)
     , m_treeScope(&treeScope)
     , m_href(href)
     , m_preserveAspectRatio(preserveAspectRatio)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to