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 #include "FilterNodeCapture.h"
13 Setter(FilterNode
* aNode
, DrawTarget
* aDT
, bool aInputsChanged
)
14 : mNode
{aNode
}, mIndex
{0}, mDT
{aDT
}, mInputsChanged
{aInputsChanged
} {}
16 void operator()(T
& aValue
) {
17 mNode
->SetAttribute(mIndex
, aValue
);
27 void Setter::operator()<std::vector
<Float
>>(std::vector
<Float
>& aValue
) {
28 mNode
->SetAttribute(mIndex
, aValue
.data(), aValue
.size());
32 void Setter::operator()<RefPtr
<SourceSurface
>>(
33 RefPtr
<SourceSurface
>& aSurface
) {
34 if (!mInputsChanged
) {
37 mNode
->SetInput(mIndex
, aSurface
);
41 void Setter::operator()<RefPtr
<FilterNode
>>(RefPtr
<FilterNode
>& aNode
) {
42 RefPtr
<FilterNode
> node
= aNode
;
43 if (node
->GetBackendType() == FilterBackend::FILTER_BACKEND_CAPTURE
) {
44 FilterNodeCapture
* captureNode
=
45 static_cast<FilterNodeCapture
*>(node
.get());
46 node
= captureNode
->Validate(mDT
);
48 if (!mInputsChanged
) {
52 mNode
->SetInput(mIndex
, node
);
55 RefPtr
<FilterNode
> FilterNodeCapture::Validate(DrawTarget
* aDT
) {
56 if (!mFilterNodeInternal
) {
57 mFilterNodeInternal
= aDT
->CreateFilter(mType
);
60 if (!mFilterNodeInternal
) {
64 Setter
setter(mFilterNodeInternal
, aDT
, mInputsChanged
);
66 for (auto attribute
: mAttributes
) {
67 setter
.mIndex
= attribute
.first
;
68 // Variant's matching doesn't seem to compile to terribly efficient code,
69 // this is probably fine since this happens on the paint thread, if ever
70 // needed it would be fairly simple to write something more optimized.
71 attribute
.second
.match(setter
);
75 for (auto input
: mInputs
) {
76 setter
.mIndex
= input
.first
;
77 input
.second
.match(setter
);
79 mInputsChanged
= false;
81 return mFilterNodeInternal
.get();
84 void FilterNodeCapture::SetAttribute(uint32_t aIndex
, const Float
* aValues
,
86 std::vector
<Float
> vec(aSize
);
87 memcpy(vec
.data(), aValues
, sizeof(Float
) * aSize
);
88 AttributeValue
att(std::move(vec
));
89 auto result
= mAttributes
.insert({aIndex
, att
});
91 result
.first
->second
= att
;
96 } // namespace mozilla