Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2757)

Unified Diff: Source/core/rendering/svg/ReferenceFilterBuilder.cpp

Issue 13984002: Extracting the SVG Filter Reference implementation out of the FilterEffectRenderer into its own typ… Base URL: https://chromium.googlesource.com/chromium/blink@master
Patch Set: Updated to ToT, fixed style, warnings Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/rendering/svg/ReferenceFilterBuilder.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/rendering/svg/ReferenceFilterBuilder.cpp
diff --git a/Source/core/rendering/svg/ReferenceFilterBuilder.cpp b/Source/core/rendering/svg/ReferenceFilterBuilder.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..a916f62bc7713f52f9cac53063d404cbc37775d7
--- /dev/null
+++ b/Source/core/rendering/svg/ReferenceFilterBuilder.cpp
@@ -0,0 +1,97 @@
+/*
+ * Copyright (C) 2013 Adobe Systems Inc. All rights reserved.
+ * Copyright (C) 2013 Google Inc. All rights reserved.
+ * Copyright (C) 2011 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#include "core/rendering/svg/ReferenceFilterBuilder.h"
+
+#include "core/dom/Element.h"
+#include "core/loader/cache/CachedSVGDocument.h"
+#include "core/loader/cache/CachedSVGDocumentReference.h"
+#include "core/platform/graphics/filters/FilterEffect.h"
+#include "core/platform/graphics/filters/SourceAlpha.h"
+#include "core/svg/SVGDocumentExtensions.h"
+#include "core/svg/SVGFilterPrimitiveStandardAttributes.h"
+#include "core/svg/graphics/filters/SVGFilterBuilder.h"
+
+namespace WebCore {
+
+PassRefPtr<FilterEffect> ReferenceFilterBuilder::build(Filter* filter, RenderObject* renderer, FilterEffect* previousEffect, const ReferenceFilterOperation* filterOperation)
+{
+ if (!renderer)
+ return 0;
+
+ Document* document = renderer->document();
+ ASSERT(document);
+
+ CachedSVGDocumentReference* cachedSVGDocumentReference = filterOperation->cachedSVGDocumentReference();
+ CachedSVGDocument* cachedSVGDocument = cachedSVGDocumentReference ? cachedSVGDocumentReference->document() : 0;
+
+ // If we have an SVG document, this is an external reference. Otherwise
+ // we look up the referenced node in the current document.
+ if (cachedSVGDocument)
+ document = cachedSVGDocument->document();
+
+ if (!document)
+ return 0;
+
+ Element* filterElement = document->getElementById(filterOperation->fragment());
+ if (!filterElement) {
+ // Although we did not find the referenced filter, it might exist later
+ // in the document
+ document->accessSVGExtensions()->addPendingResource(filterOperation->fragment(), toElement(renderer->node()));
+ return 0;
+ }
+
+ // FIXME: Figure out what to do with SourceAlpha. Right now, we're
+ // using the alpha of the original input layer, which is obviously
+ // wrong. We should probably be extracting the alpha from the
+ // previousEffect, but this requires some more processing.
+ // This may need a spec clarification.
+ RefPtr<SVGFilterBuilder> builder = SVGFilterBuilder::create(previousEffect, SourceAlpha::create(filter));
+
+ for (Node* node = filterElement->firstChild(); node; node = node->nextSibling()) {
+ if (!node->isSVGElement())
+ continue;
+
+ SVGElement* element = toSVGElement(node);
+ if (!element->isFilterEffect())
+ continue;
+
+ SVGFilterPrimitiveStandardAttributes* effectElement = static_cast<SVGFilterPrimitiveStandardAttributes*>(element);
+
+ RefPtr<FilterEffect> effect = effectElement->build(builder.get(), filter);
+ if (!effect)
+ continue;
+
+ effectElement->setStandardAttributes(effect.get());
+ builder->add(effectElement->result(), effect);
+ }
+ return builder->lastEffect();
+}
+
+} // namespace WebCore
« no previous file with comments | « Source/core/rendering/svg/ReferenceFilterBuilder.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698