| 1 | /* |
| 2 | * Copyright (C) 2011-2017 Apple Inc. All rights reserved. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions |
| 6 | * are met: |
| 7 | * 1. Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * 2. Redistributions in binary form must reproduce the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer in the |
| 11 | * documentation and/or other materials provided with the distribution. |
| 12 | * |
| 13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
| 14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
| 17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 18 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 | */ |
| 25 | |
| 26 | #pragma once |
| 27 | |
| 28 | #include "Filter.h" |
| 29 | #include "IntRectExtent.h" |
| 30 | #include "LayoutRect.h" |
| 31 | #include <wtf/TypeCasts.h> |
| 32 | |
| 33 | namespace WebCore { |
| 34 | |
| 35 | class FilterEffect; |
| 36 | class FilterOperations; |
| 37 | class GraphicsContext; |
| 38 | class ReferenceFilterOperation; |
| 39 | class RenderElement; |
| 40 | class SourceAlpha; |
| 41 | class SourceGraphic; |
| 42 | |
| 43 | enum class FilterConsumer { FilterProperty, FilterFunction }; |
| 44 | |
| 45 | class CSSFilter final : public Filter { |
| 46 | WTF_MAKE_FAST_ALLOCATED; |
| 47 | friend class RenderLayerFilters; |
| 48 | public: |
| 49 | static Ref<CSSFilter> create(); |
| 50 | |
| 51 | void setSourceImageRect(const FloatRect&); |
| 52 | void setFilterRegion(const FloatRect& filterRegion) { m_filterRegion = filterRegion; } |
| 53 | |
| 54 | ImageBuffer* output() const; |
| 55 | |
| 56 | bool build(RenderElement&, const FilterOperations&, FilterConsumer); |
| 57 | void clearIntermediateResults(); |
| 58 | void apply(); |
| 59 | |
| 60 | bool hasFilterThatMovesPixels() const { return m_hasFilterThatMovesPixels; } |
| 61 | bool hasFilterThatShouldBeRestrictedBySecurityOrigin() const { return m_hasFilterThatShouldBeRestrictedBySecurityOrigin; } |
| 62 | |
| 63 | void determineFilterPrimitiveSubregion(); |
| 64 | |
| 65 | private: |
| 66 | CSSFilter(); |
| 67 | virtual ~CSSFilter(); |
| 68 | |
| 69 | bool isCSSFilter() const final { return true; } |
| 70 | |
| 71 | FloatRect sourceImageRect() const final { return m_sourceDrawingRegion; } |
| 72 | |
| 73 | FloatRect filterRegion() const final { return m_filterRegion; } |
| 74 | FloatRect filterRegionInUserSpace() const final { return m_filterRegion; } |
| 75 | |
| 76 | RefPtr<FilterEffect> buildReferenceFilter(RenderElement&, FilterEffect& previousEffect, ReferenceFilterOperation&); |
| 77 | |
| 78 | void setMaxEffectRects(const FloatRect&); |
| 79 | |
| 80 | GraphicsContext* inputContext(); |
| 81 | |
| 82 | bool updateBackingStoreRect(const FloatRect& filterRect); |
| 83 | void allocateBackingStoreIfNeeded(const GraphicsContext&); |
| 84 | |
| 85 | IntRect outputRect() const; |
| 86 | |
| 87 | LayoutRect computeSourceImageRectForDirtyRect(const LayoutRect& filterBoxRect, const LayoutRect& dirtyRect); |
| 88 | |
| 89 | FloatRect m_sourceDrawingRegion; |
| 90 | FloatRect m_filterRegion; |
| 91 | |
| 92 | Vector<Ref<FilterEffect>> m_effects; |
| 93 | Ref<SourceGraphic> m_sourceGraphic; |
| 94 | RefPtr<FilterEffect> m_sourceAlpha; |
| 95 | |
| 96 | IntRectExtent m_outsets; |
| 97 | |
| 98 | bool m_graphicsBufferAttached { false }; |
| 99 | bool m_hasFilterThatMovesPixels { false }; |
| 100 | bool m_hasFilterThatShouldBeRestrictedBySecurityOrigin { false }; |
| 101 | }; |
| 102 | |
| 103 | } // namespace WebCore |
| 104 | |
| 105 | SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::CSSFilter) |
| 106 | static bool isType(const WebCore::Filter& filter) { return filter.isCSSFilter(); } |
| 107 | SPECIALIZE_TYPE_TRAITS_END() |
| 108 | |