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_FILTERNODECAPTURE_H_
8 #define MOZILLA_GFX_FILTERNODECAPTURE_H_
12 #include <unordered_map>
14 #include "mozilla/Variant.h"
19 class FilterNodeCapture final
: public FilterNode
{
21 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeCapture
, override
)
23 explicit FilterNodeCapture(FilterType aType
)
24 : mType
{aType
}, mInputsChanged
{true} {}
26 FilterBackend
GetBackendType() override
{ return FILTER_BACKEND_CAPTURE
; }
28 RefPtr
<FilterNode
> Validate(DrawTarget
* aDT
);
30 template <typename T
, typename C
>
31 void Replace(uint32_t aIndex
, const T
& aValue
, C
& aContainer
) {
32 // This replace function avoids generating the hash twice.
33 auto result
= aContainer
.insert({aIndex
, typename
C::mapped_type(aValue
)});
35 result
.first
->second
= typename
C::mapped_type(aValue
);
39 void SetInput(uint32_t aIndex
, SourceSurface
* aSurface
) override
{
40 mInputsChanged
= true;
41 Replace(aIndex
, RefPtr
<SourceSurface
>(aSurface
), mInputs
);
43 void SetInput(uint32_t aIndex
, FilterNode
* aFilter
) override
{
44 mInputsChanged
= true;
45 Replace(aIndex
, RefPtr
<FilterNode
>(aFilter
), mInputs
);
48 using AttributeValue
= Variant
<uint32_t, Float
, Point
, Matrix5x4
, Point3D
,
49 Size
, IntSize
, DeviceColor
, Rect
, IntRect
,
50 bool, std::vector
<Float
>, IntPoint
, Matrix
>;
52 void SetAttribute(uint32_t aIndex
, uint32_t aValue
) override
{
53 Replace(aIndex
, aValue
, mAttributes
);
55 void SetAttribute(uint32_t aIndex
, Float aValue
) override
{
56 Replace(aIndex
, aValue
, mAttributes
);
58 void SetAttribute(uint32_t aIndex
, const Point
& aValue
) override
{
59 Replace(aIndex
, aValue
, mAttributes
);
61 void SetAttribute(uint32_t aIndex
, const Matrix5x4
& aValue
) override
{
62 Replace(aIndex
, aValue
, mAttributes
);
64 void SetAttribute(uint32_t aIndex
, const Point3D
& aValue
) override
{
65 Replace(aIndex
, aValue
, mAttributes
);
67 void SetAttribute(uint32_t aIndex
, const Size
& aValue
) override
{
68 Replace(aIndex
, aValue
, mAttributes
);
70 void SetAttribute(uint32_t aIndex
, const IntSize
& aValue
) override
{
71 Replace(aIndex
, aValue
, mAttributes
);
73 void SetAttribute(uint32_t aIndex
, const DeviceColor
& aValue
) override
{
74 Replace(aIndex
, aValue
, mAttributes
);
76 void SetAttribute(uint32_t aIndex
, const Rect
& aValue
) override
{
77 Replace(aIndex
, aValue
, mAttributes
);
79 void SetAttribute(uint32_t aIndex
, const IntRect
& aValue
) override
{
80 Replace(aIndex
, aValue
, mAttributes
);
82 void SetAttribute(uint32_t aIndex
, bool aValue
) override
{
83 Replace(aIndex
, aValue
, mAttributes
);
85 virtual void SetAttribute(uint32_t aIndex
, const Float
* aValues
,
86 uint32_t aSize
) override
;
87 void SetAttribute(uint32_t aIndex
, const IntPoint
& aValue
) override
{
88 Replace(aIndex
, aValue
, mAttributes
);
90 void SetAttribute(uint32_t aIndex
, const Matrix
& aValue
) override
{
91 Replace(aIndex
, aValue
, mAttributes
);
96 RefPtr
<FilterNode
> mFilterNodeInternal
;
98 // This only contains attributes that were set since the last validation.
99 std::unordered_map
<uint32_t, AttributeValue
> mAttributes
;
101 // This always contains all inputs, so that Validate may be called on input
103 std::unordered_map
<uint32_t,
104 Variant
<RefPtr
<SourceSurface
>, RefPtr
<FilterNode
>>>
107 // This is true if SetInput was called since the last validation.
112 } // namespace mozilla