Bug 1706464 [wpt PR 28605] - Off-thread CSS paint: handle no-op animation, a=testonly
[gecko.git] / gfx / 2d / FilterNodeD2D1.h
bloba2f6e684f9e1054b18ddc4722486cdb31f2a914c
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_
10 #include "2D.h"
11 #include "Filters.h"
12 #include <vector>
13 #include <windows.h>
14 #include <d2d1_1.h>
15 #include <cguid.h>
17 namespace mozilla {
18 namespace gfx {
20 class FilterNodeD2D1 : public FilterNode {
21 public:
22 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeD2D1, override)
24 static already_AddRefed<FilterNode> Create(ID2D1DeviceContext* aDC,
25 FilterType aType);
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,
49 uint32_t aSize);
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(); }
63 protected:
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;
73 FilterType mType;
75 private:
76 using FilterNode::SetAttribute;
77 using FilterNode::SetInput;
80 class FilterNodeConvolveD2D1 : public FilterNodeD2D1 {
81 public:
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;
94 private:
95 using FilterNode::SetAttribute;
96 using FilterNode::SetInput;
98 void UpdateChain();
99 void UpdateOffset();
100 void UpdateSourceRect();
102 RefPtr<ID2D1Effect> mExtendInputEffect;
103 RefPtr<ID2D1Effect> mBorderEffect;
104 ConvolveMatrixEdgeMode mEdgeMode;
105 IntPoint mTarget;
106 IntSize mKernelSize;
107 IntRect mSourceRect;
110 class FilterNodeOpacityD2D1 : public FilterNodeD2D1 {
111 public:
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 {
120 public:
121 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeExtendInputAdapterD2D1,
122 override)
123 FilterNodeExtendInputAdapterD2D1(ID2D1DeviceContext* aDC,
124 FilterNodeD2D1* aFilterNode,
125 FilterType aType);
127 ID2D1Effect* InputEffect() override { return mExtendInputEffect.get(); }
128 ID2D1Effect* OutputEffect() override {
129 return mWrappedFilterNode->OutputEffect();
132 private:
133 RefPtr<FilterNodeD2D1> mWrappedFilterNode;
134 RefPtr<ID2D1Effect> mExtendInputEffect;
137 class FilterNodePremultiplyAdapterD2D1 : public FilterNodeD2D1 {
138 public:
139 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodePremultiplyAdapterD2D1,
140 override)
141 FilterNodePremultiplyAdapterD2D1(ID2D1DeviceContext* aDC,
142 FilterNodeD2D1* aFilterNode,
143 FilterType aType);
145 ID2D1Effect* InputEffect() override { return mPrePremultiplyEffect.get(); }
146 ID2D1Effect* OutputEffect() override {
147 return mPostUnpremultiplyEffect.get();
150 private:
151 RefPtr<ID2D1Effect> mPrePremultiplyEffect;
152 RefPtr<ID2D1Effect> mPostUnpremultiplyEffect;
155 } // namespace gfx
156 } // namespace mozilla
158 #endif