1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef MOZILLA_GFX_FILTERNODED2D1_H_
8 #define MOZILLA_GFX_FILTERNODED2D1_H_
20 class FilterNodeD2D1
: public FilterNode
{
22 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeD2D1
, override
)
24 static already_AddRefed
<FilterNode
> Create(ID2D1DeviceContext
* aDC
,
27 FilterNodeD2D1(ID2D1Effect
* aEffect
, FilterType aType
)
28 : mEffect(aEffect
), mType(aType
) {
29 InitUnmappedProperties();
32 virtual FilterBackend
GetBackendType() { return FILTER_BACKEND_DIRECT2D1_1
; }
34 virtual void SetInput(uint32_t aIndex
, SourceSurface
* aSurface
);
35 virtual void SetInput(uint32_t aIndex
, FilterNode
* aFilter
);
37 virtual void SetAttribute(uint32_t aIndex
, uint32_t aValue
);
38 virtual void SetAttribute(uint32_t aIndex
, Float aValue
);
39 virtual void SetAttribute(uint32_t aIndex
, const Point
& aValue
);
40 virtual void SetAttribute(uint32_t aIndex
, const Matrix5x4
& aValue
);
41 virtual void SetAttribute(uint32_t aIndex
, const Point3D
& aValue
);
42 virtual void SetAttribute(uint32_t aIndex
, const Size
& aValue
);
43 virtual void SetAttribute(uint32_t aIndex
, const IntSize
& aValue
);
44 virtual void SetAttribute(uint32_t aIndex
, const DeviceColor
& aValue
);
45 virtual void SetAttribute(uint32_t aIndex
, const Rect
& aValue
);
46 virtual void SetAttribute(uint32_t aIndex
, const IntRect
& aValue
);
47 virtual void SetAttribute(uint32_t aIndex
, bool aValue
);
48 virtual void SetAttribute(uint32_t aIndex
, const Float
* aValues
,
50 virtual void SetAttribute(uint32_t aIndex
, const IntPoint
& aValue
);
51 virtual void SetAttribute(uint32_t aIndex
, const Matrix
& aValue
);
53 // Called by DrawTarget before it draws our OutputEffect, and recursively
54 // by the filter nodes that have this filter as one of their inputs. This
55 // gives us a chance to convert any input surfaces to the target format for
56 // the DrawTarget that we will draw to.
57 virtual void WillDraw(DrawTarget
* aDT
);
59 virtual ID2D1Effect
* MainEffect() { return mEffect
.get(); }
60 virtual ID2D1Effect
* InputEffect() { return mEffect
.get(); }
61 virtual ID2D1Effect
* OutputEffect() { return mEffect
.get(); }
64 friend class DrawTargetD2D1
;
65 friend class DrawTargetD2D
;
66 friend class FilterNodeConvolveD2D1
;
68 void InitUnmappedProperties();
70 RefPtr
<ID2D1Effect
> mEffect
;
71 std::vector
<RefPtr
<FilterNodeD2D1
>> mInputFilters
;
72 std::vector
<RefPtr
<SourceSurface
>> mInputSurfaces
;
76 using FilterNode::SetAttribute
;
77 using FilterNode::SetInput
;
80 class FilterNodeConvolveD2D1
: public FilterNodeD2D1
{
82 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeConvolveD2D1
, override
)
83 explicit FilterNodeConvolveD2D1(ID2D1DeviceContext
* aDC
);
85 void SetInput(uint32_t aIndex
, FilterNode
* aFilter
) override
;
87 void SetAttribute(uint32_t aIndex
, uint32_t aValue
) override
;
88 void SetAttribute(uint32_t aIndex
, const IntSize
& aValue
) override
;
89 void SetAttribute(uint32_t aIndex
, const IntPoint
& aValue
) override
;
90 void SetAttribute(uint32_t aIndex
, const IntRect
& aValue
) override
;
92 ID2D1Effect
* InputEffect() override
;
95 using FilterNode::SetAttribute
;
96 using FilterNode::SetInput
;
100 void UpdateSourceRect();
102 RefPtr
<ID2D1Effect
> mExtendInputEffect
;
103 RefPtr
<ID2D1Effect
> mBorderEffect
;
104 ConvolveMatrixEdgeMode mEdgeMode
;
110 class FilterNodeOpacityD2D1
: public FilterNodeD2D1
{
112 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeOpacityD2D1
, override
)
113 FilterNodeOpacityD2D1(ID2D1Effect
* aEffect
, FilterType aType
)
114 : FilterNodeD2D1(aEffect
, aType
) {}
116 void SetAttribute(uint32_t aIndex
, Float aValue
) override
;
119 class FilterNodeExtendInputAdapterD2D1
: public FilterNodeD2D1
{
121 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeExtendInputAdapterD2D1
,
123 FilterNodeExtendInputAdapterD2D1(ID2D1DeviceContext
* aDC
,
124 FilterNodeD2D1
* aFilterNode
,
127 ID2D1Effect
* InputEffect() override
{ return mExtendInputEffect
.get(); }
128 ID2D1Effect
* OutputEffect() override
{
129 return mWrappedFilterNode
->OutputEffect();
133 RefPtr
<FilterNodeD2D1
> mWrappedFilterNode
;
134 RefPtr
<ID2D1Effect
> mExtendInputEffect
;
137 class FilterNodePremultiplyAdapterD2D1
: public FilterNodeD2D1
{
139 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodePremultiplyAdapterD2D1
,
141 FilterNodePremultiplyAdapterD2D1(ID2D1DeviceContext
* aDC
,
142 FilterNodeD2D1
* aFilterNode
,
145 ID2D1Effect
* InputEffect() override
{ return mPrePremultiplyEffect
.get(); }
146 ID2D1Effect
* OutputEffect() override
{
147 return mPostUnpremultiplyEffect
.get();
151 RefPtr
<ID2D1Effect
> mPrePremultiplyEffect
;
152 RefPtr
<ID2D1Effect
> mPostUnpremultiplyEffect
;
156 } // namespace mozilla