| Index: Source/modules/canvas2d/CanvasRenderingContext2DState.cpp
|
| diff --git a/Source/modules/canvas2d/CanvasRenderingContext2DState.cpp b/Source/modules/canvas2d/CanvasRenderingContext2DState.cpp
|
| index 94b6d969cc35ec778d0894bd298375ebb4331097..b2b880cfb8c53847e32ca257f772c60944cffe1e 100644
|
| --- a/Source/modules/canvas2d/CanvasRenderingContext2DState.cpp
|
| +++ b/Source/modules/canvas2d/CanvasRenderingContext2DState.cpp
|
| @@ -36,6 +36,7 @@ CanvasRenderingContext2DState::CanvasRenderingContext2DState()
|
| , m_lineDashOffset(0)
|
| , m_unparsedFont(defaultFont)
|
| , m_unparsedFilter(defaultFilter)
|
| + , m_unparsedBackdropFilter(defaultFilter)
|
| , m_textAlign(StartTextAlign)
|
| , m_textBaseline(AlphabeticTextBaseline)
|
| , m_direction(DirectionInherit)
|
| @@ -85,8 +86,11 @@ CanvasRenderingContext2DState::CanvasRenderingContext2DState(const CanvasRenderi
|
| , m_unparsedFont(other.m_unparsedFont)
|
| , m_font(other.m_font)
|
| , m_unparsedFilter(other.m_unparsedFilter)
|
| + , m_unparsedBackdropFilter(other.m_unparsedBackdropFilter)
|
| , m_filterValue(other.m_filterValue)
|
| , m_resolvedFilter(other.m_resolvedFilter)
|
| + , m_backdropFilterValue(other.m_backdropFilterValue)
|
| + , m_resolvedBackdropFilter(other.m_resolvedBackdropFilter)
|
| , m_textAlign(other.m_textAlign)
|
| , m_textBaseline(other.m_textBaseline)
|
| , m_direction(other.m_direction)
|
| @@ -172,6 +176,7 @@ void CanvasRenderingContext2DState::fontsNeedUpdate(CSSFontSelector* fontSelecto
|
| // FIXME: We only really need to invalidate the resolved filter if the font
|
| // update above changed anything and the filter uses font-dependent units.
|
| m_resolvedFilter.clear();
|
| + m_resolvedBackdropFilter.clear(); // TODO(hendrikw): Not so sure if this is needed.
|
| }
|
|
|
| DEFINE_TRACE(CanvasRenderingContext2DState)
|
| @@ -179,6 +184,7 @@ DEFINE_TRACE(CanvasRenderingContext2DState)
|
| visitor->trace(m_strokeStyle);
|
| visitor->trace(m_fillStyle);
|
| visitor->trace(m_filterValue);
|
| + visitor->trace(m_backdropFilterValue);
|
| CSSFontSelectorClient::trace(visitor);
|
| }
|
|
|
| @@ -307,6 +313,7 @@ void CanvasRenderingContext2DState::setFont(const Font& font, CSSFontSelector* s
|
| // FIXME: We only really need to invalidate the resolved filter if it
|
| // uses font-relative units.
|
| m_resolvedFilter.clear();
|
| + m_resolvedBackdropFilter.clear(); // TODO(hendrikw): Not so sure if this is needed.
|
| }
|
|
|
| const Font& CanvasRenderingContext2DState::font() const
|
| @@ -355,6 +362,36 @@ SkImageFilter* CanvasRenderingContext2DState::getFilter(Element* styleResolution
|
| return m_resolvedFilter.get();
|
| }
|
|
|
| +SkImageFilter* CanvasRenderingContext2DState::getBackdropFilter(Element* styleResolutionHost, const Font& font) const
|
| +{
|
| + // TODO(hendrikw): Better understand what this function is doing and determine if we can reuse getFilter,
|
| + // of if this function needs to be modified.
|
| + if (!m_backdropFilterValue)
|
| + return nullptr;
|
| +
|
| + if (!m_resolvedBackdropFilter) {
|
| + RefPtr<ComputedStyle> filterStyle = ComputedStyle::create();
|
| + // Must set font in case the filter uses any font-relative units (em, ex)
|
| + filterStyle->setFont(font);
|
| +
|
| + StyleResolverState resolverState(styleResolutionHost->document(), styleResolutionHost, filterStyle.get());
|
| + resolverState.setStyle(filterStyle);
|
| +
|
| + // TODO(junov): crbug.com/502877 Feed m_fillStyle and m_strokeStyle into FillPaint and
|
| + // StrokePaint respectively for filters that reference SVG.
|
| + StyleBuilder::applyProperty(CSSPropertyBackdropFilter, resolverState, m_backdropFilterValue.get());
|
| + RefPtrWillBeRawPtr<FilterEffectBuilder> filterEffectBuilder = FilterEffectBuilder::create();
|
| + const float effectiveZoom = 1.0f; // Deliberately ignore zoom on the canvas element
|
| + filterEffectBuilder->build(styleResolutionHost, filterStyle->filter(), effectiveZoom);
|
| +
|
| + SkiaImageFilterBuilder imageFilterBuilder;
|
| + RefPtrWillBeRawPtr<FilterEffect> lastEffect = filterEffectBuilder->lastEffect();
|
| + m_resolvedBackdropFilter = imageFilterBuilder.build(lastEffect.get(), ColorSpaceDeviceRGB);
|
| + }
|
| +
|
| + return m_resolvedBackdropFilter.get();
|
| +}
|
| +
|
| SkDrawLooper* CanvasRenderingContext2DState::emptyDrawLooper() const
|
| {
|
| if (!m_emptyDrawLooper) {
|
| @@ -441,6 +478,12 @@ void CanvasRenderingContext2DState::setFilter(PassRefPtrWillBeRawPtr<CSSValue> f
|
| m_resolvedFilter.clear();
|
| }
|
|
|
| +void CanvasRenderingContext2DState::setBackdropFilter(PassRefPtrWillBeRawPtr<CSSValue> filterValue)
|
| +{
|
| + m_backdropFilterValue = filterValue;
|
| + m_resolvedBackdropFilter.clear();
|
| +}
|
| +
|
| void CanvasRenderingContext2DState::setGlobalComposite(SkXfermode::Mode mode)
|
| {
|
| m_strokePaint.setXfermodeMode(mode);
|
|
|