2017-12-07 05:21:49 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef MOZILLA_GFX_FILTERNODECAPTURE_H_
|
|
|
|
#define MOZILLA_GFX_FILTERNODECAPTURE_H_
|
|
|
|
|
|
|
|
#include "2D.h"
|
|
|
|
#include "Filters.h"
|
|
|
|
#include <unordered_map>
|
|
|
|
#include <vector>
|
|
|
|
#include "mozilla/Variant.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace gfx {
|
|
|
|
|
|
|
|
class FilterNodeCapture final : public FilterNode {
|
|
|
|
public:
|
|
|
|
MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeCapture, override)
|
|
|
|
|
|
|
|
explicit FilterNodeCapture(FilterType aType)
|
|
|
|
: mType{aType}, mInputsChanged{true} {}
|
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
FilterBackend GetBackendType() override { return FILTER_BACKEND_CAPTURE; }
|
2017-12-07 05:21:49 +03:00
|
|
|
|
|
|
|
RefPtr<FilterNode> Validate(DrawTarget *aDT);
|
|
|
|
|
|
|
|
template <typename T, typename C>
|
|
|
|
void Replace(uint32_t aIndex, const T &aValue, C &aContainer) {
|
|
|
|
// This replace function avoids generating the hash twice.
|
|
|
|
auto result = aContainer.insert({aIndex, typename C::mapped_type(aValue)});
|
|
|
|
if (!result.second) {
|
|
|
|
result.first->second = typename C::mapped_type(aValue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
void SetInput(uint32_t aIndex, SourceSurface *aSurface) override {
|
2017-12-07 05:21:49 +03:00
|
|
|
mInputsChanged = true;
|
|
|
|
Replace(aIndex, RefPtr<SourceSurface>(aSurface), mInputs);
|
|
|
|
}
|
2019-04-11 15:36:51 +03:00
|
|
|
void SetInput(uint32_t aIndex, FilterNode *aFilter) override {
|
2017-12-07 05:21:49 +03:00
|
|
|
mInputsChanged = true;
|
|
|
|
Replace(aIndex, RefPtr<FilterNode>(aFilter), mInputs);
|
|
|
|
}
|
|
|
|
|
|
|
|
using AttributeValue =
|
|
|
|
Variant<uint32_t, Float, Point, Matrix5x4, Point3D, Size, IntSize, Color,
|
|
|
|
Rect, IntRect, bool, std::vector<Float>, IntPoint, Matrix>;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
void SetAttribute(uint32_t aIndex, uint32_t aValue) override {
|
2017-12-07 05:21:49 +03:00
|
|
|
Replace(aIndex, aValue, mAttributes);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2019-04-11 15:36:51 +03:00
|
|
|
void SetAttribute(uint32_t aIndex, Float aValue) override {
|
2017-12-07 05:21:49 +03:00
|
|
|
Replace(aIndex, aValue, mAttributes);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2019-04-11 15:36:51 +03:00
|
|
|
void SetAttribute(uint32_t aIndex, const Point &aValue) override {
|
2017-12-07 05:21:49 +03:00
|
|
|
Replace(aIndex, aValue, mAttributes);
|
|
|
|
}
|
2019-04-11 15:36:51 +03:00
|
|
|
void SetAttribute(uint32_t aIndex, const Matrix5x4 &aValue) override {
|
2017-12-07 05:21:49 +03:00
|
|
|
Replace(aIndex, aValue, mAttributes);
|
|
|
|
}
|
2019-04-11 15:36:51 +03:00
|
|
|
void SetAttribute(uint32_t aIndex, const Point3D &aValue) override {
|
2017-12-07 05:21:49 +03:00
|
|
|
Replace(aIndex, aValue, mAttributes);
|
|
|
|
}
|
2019-04-11 15:36:51 +03:00
|
|
|
void SetAttribute(uint32_t aIndex, const Size &aValue) override {
|
2017-12-07 05:21:49 +03:00
|
|
|
Replace(aIndex, aValue, mAttributes);
|
|
|
|
}
|
2019-04-11 15:36:51 +03:00
|
|
|
void SetAttribute(uint32_t aIndex, const IntSize &aValue) override {
|
2017-12-07 05:21:49 +03:00
|
|
|
Replace(aIndex, aValue, mAttributes);
|
|
|
|
}
|
2019-04-11 15:36:51 +03:00
|
|
|
void SetAttribute(uint32_t aIndex, const Color &aValue) override {
|
2017-12-07 05:21:49 +03:00
|
|
|
Replace(aIndex, aValue, mAttributes);
|
|
|
|
}
|
2019-04-11 15:36:51 +03:00
|
|
|
void SetAttribute(uint32_t aIndex, const Rect &aValue) override {
|
2017-12-07 05:21:49 +03:00
|
|
|
Replace(aIndex, aValue, mAttributes);
|
|
|
|
}
|
2019-04-11 15:36:51 +03:00
|
|
|
void SetAttribute(uint32_t aIndex, const IntRect &aValue) override {
|
2017-12-07 05:21:49 +03:00
|
|
|
Replace(aIndex, aValue, mAttributes);
|
|
|
|
}
|
2019-04-11 15:36:51 +03:00
|
|
|
void SetAttribute(uint32_t aIndex, bool aValue) override {
|
2017-12-07 05:21:49 +03:00
|
|
|
Replace(aIndex, aValue, mAttributes);
|
|
|
|
}
|
|
|
|
virtual void SetAttribute(uint32_t aIndex, const Float *aValues,
|
|
|
|
uint32_t aSize) override;
|
2019-04-11 15:36:51 +03:00
|
|
|
void SetAttribute(uint32_t aIndex, const IntPoint &aValue) override {
|
2017-12-07 05:21:49 +03:00
|
|
|
Replace(aIndex, aValue, mAttributes);
|
|
|
|
}
|
2019-04-11 15:36:51 +03:00
|
|
|
void SetAttribute(uint32_t aIndex, const Matrix &aValue) override {
|
2017-12-07 05:21:49 +03:00
|
|
|
Replace(aIndex, aValue, mAttributes);
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-12-07 05:21:49 +03:00
|
|
|
private:
|
|
|
|
FilterType mType;
|
|
|
|
RefPtr<FilterNode> mFilterNodeInternal;
|
|
|
|
|
|
|
|
// This only contains attributes that were set since the last validation.
|
|
|
|
std::unordered_map<uint32_t, AttributeValue> mAttributes;
|
|
|
|
|
|
|
|
// This always contains all inputs, so that Validate may be called on input
|
|
|
|
// filter nodes.
|
|
|
|
std::unordered_map<uint32_t,
|
|
|
|
Variant<RefPtr<SourceSurface>, RefPtr<FilterNode>>>
|
|
|
|
mInputs;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-12-07 05:21:49 +03:00
|
|
|
// This is true if SetInput was called since the last validation.
|
|
|
|
bool mInputsChanged;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace gfx
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif
|