1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247
|
/*
* Copyright (C) Research In Motion Limited 2010. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "config.h"
#include "LegacyRenderSVGResourceContainer.h"
#include "LegacyRenderSVGRoot.h"
#include "RenderLayer.h"
#include "RenderView.h"
#include "SVGElementTypeHelpers.h"
#include "SVGGraphicsElement.h"
#include "SVGRenderingContext.h"
#include "SVGResourcesCache.h"
#include <wtf/SetForScope.h>
#include <wtf/StackStats.h>
#include <wtf/TZoneMallocInlines.h>
namespace WebCore {
WTF_MAKE_TZONE_OR_ISO_ALLOCATED_IMPL(LegacyRenderSVGResourceContainer);
LegacyRenderSVGResourceContainer::LegacyRenderSVGResourceContainer(Type type, SVGElement& element, RenderStyle&& style)
: LegacyRenderSVGHiddenContainer(type, element, WTFMove(style), SVGModelObjectFlag::IsResourceContainer)
, m_id(element.getIdAttribute())
{
}
LegacyRenderSVGResourceContainer::~LegacyRenderSVGResourceContainer() = default;
void LegacyRenderSVGResourceContainer::layout()
{
StackStats::LayoutCheckPoint layoutCheckPoint;
// Invalidate all resources if our layout changed.
if (selfNeedsClientInvalidation())
LegacyRenderSVGRoot::addResourceForClientInvalidation(this);
LegacyRenderSVGHiddenContainer::layout();
}
void LegacyRenderSVGResourceContainer::willBeDestroyed()
{
SVGResourcesCache::resourceDestroyed(*this);
if (m_registered) {
treeScopeForSVGReferences().removeSVGResource(m_id);
m_registered = false;
}
LegacyRenderSVGHiddenContainer::willBeDestroyed();
}
void LegacyRenderSVGResourceContainer::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle)
{
LegacyRenderSVGHiddenContainer::styleDidChange(diff, oldStyle);
if (!m_registered) {
m_registered = true;
registerResource();
}
}
void LegacyRenderSVGResourceContainer::idChanged()
{
// Invalidate all our current clients.
removeAllClientsFromCache();
// Remove old id, that is guaranteed to be present in cache.
treeScopeForSVGReferences().removeSVGResource(m_id);
m_id = element().getIdAttribute();
registerResource();
}
void LegacyRenderSVGResourceContainer::markAllClientsForRepaint()
{
markAllClientsForInvalidation(RepaintInvalidation);
}
void LegacyRenderSVGResourceContainer::markAllClientsForInvalidation(InvalidationMode mode)
{
SingleThreadWeakHashSet<RenderObject> visitedRenderers;
markAllClientsForInvalidationIfNeeded(mode, &visitedRenderers);
}
void LegacyRenderSVGResourceContainer::markAllClientsForInvalidationIfNeeded(InvalidationMode mode, SingleThreadWeakHashSet<RenderObject>* visitedRenderers)
{
// FIXME: Style invalidation should either be a pre-layout task or this function
// should never get called while in layout. See webkit.org/b/208903.
if ((m_clients.isEmptyIgnoringNullReferences() && m_clientLayers.isEmptyIgnoringNullReferences()) || m_isInvalidating)
return;
SetForScope isInvalidating(m_isInvalidating, true);
bool needsLayout = mode == LayoutAndBoundariesInvalidation;
bool markForInvalidation = mode != ParentOnlyInvalidation;
auto* root = SVGRenderSupport::findTreeRootObject(*this);
for (auto& client : m_clients) {
// We should not mark any client outside the current root for invalidation
if (root != SVGRenderSupport::findTreeRootObject(client))
continue;
if (CheckedPtr container = dynamicDowncast<LegacyRenderSVGResourceContainer>(client)) {
container->removeAllClientsFromCacheIfNeeded(markForInvalidation, visitedRenderers);
continue;
}
if (markForInvalidation)
markClientForInvalidation(client, mode);
LegacyRenderSVGResource::markForLayoutAndParentResourceInvalidationIfNeeded(client, needsLayout, visitedRenderers);
}
markAllClientLayersForInvalidation();
}
void LegacyRenderSVGResourceContainer::markAllClientLayersForInvalidation()
{
if (m_clientLayers.isEmptyIgnoringNullReferences())
return;
Ref document = (*m_clientLayers.begin()).renderer().document();
if (!document->view() || document->renderTreeBeingDestroyed())
return;
auto inLayout = document->view()->layoutContext().isInLayout();
for (auto& clientLayer : m_clientLayers) {
// FIXME: We should not get here while in layout. See webkit.org/b/208903.
// Repaint should also be triggered through some other means.
if (inLayout) {
clientLayer.renderer().repaint();
continue;
}
if (auto* enclosingElement = clientLayer.enclosingElement())
enclosingElement->invalidateStyleAndLayerComposition();
clientLayer.renderer().repaint();
}
}
void LegacyRenderSVGResourceContainer::markClientForInvalidation(RenderObject& client, InvalidationMode mode)
{
ASSERT(!m_clients.isEmptyIgnoringNullReferences() || client.style().clipPath());
switch (mode) {
case LayoutAndBoundariesInvalidation:
case BoundariesInvalidation:
client.invalidateCachedBoundaries();
break;
case RepaintInvalidation:
if (!client.renderTreeBeingDestroyed())
client.repaint();
break;
case ParentOnlyInvalidation:
break;
}
}
void LegacyRenderSVGResourceContainer::addClient(RenderElement& client)
{
m_clients.add(client);
}
void LegacyRenderSVGResourceContainer::removeClient(RenderElement& client)
{
removeClientFromCache(client, false);
m_clients.remove(client);
}
void LegacyRenderSVGResourceContainer::addClientRenderLayer(RenderLayer& client)
{
m_clientLayers.add(client);
}
void LegacyRenderSVGResourceContainer::removeClientRenderLayer(RenderLayer& client)
{
m_clientLayers.remove(client);
}
void LegacyRenderSVGResourceContainer::registerResource()
{
Ref treeScope = this->treeScopeForSVGReferences();
if (!treeScope->isIdOfPendingSVGResource(m_id)) {
treeScope->addSVGResource(m_id, *this);
return;
}
auto elements = copyToVectorOf<Ref<SVGElement>>(treeScope->removePendingSVGResource(m_id));
treeScope->addSVGResource(m_id, *this);
// Update cached resources of pending clients.
for (auto& client : elements) {
ASSERT(client->hasPendingResources());
treeScope->clearHasPendingSVGResourcesIfPossible(client);
auto* renderer = client->renderer();
if (!renderer)
continue;
SVGResourcesCache::clientStyleChanged(*renderer, StyleDifference::Layout, nullptr, renderer->style());
renderer->setNeedsLayout();
}
}
float LegacyRenderSVGResourceContainer::computeTextPaintingScale(const RenderElement& renderer)
{
#if USE(CG)
UNUSED_PARAM(renderer);
return 1;
#else
// This method should only be called for RenderObjects that deal with text rendering. Cmp. RenderObject.h's is*() methods.
ASSERT(renderer.isRenderSVGText() || renderer.isRenderSVGTextPath() || renderer.isRenderSVGInline());
// In text drawing, the scaling part of the graphics context CTM is removed, compare SVGInlineTextBox::paintTextWithShadows.
// So, we use that scaling factor here, too, and then push it down to pattern or gradient space
// in order to keep the pattern or gradient correctly scaled.
return SVGRenderingContext::calculateScreenFontSizeScalingFactor(renderer);
#endif
}
// FIXME: This does not belong here.
AffineTransform LegacyRenderSVGResourceContainer::transformOnNonScalingStroke(RenderObject* object, const AffineTransform& resourceTransform)
{
if (!object->isRenderOrLegacyRenderSVGShape())
return resourceTransform;
RefPtr element = downcast<SVGGraphicsElement>(object->node());
AffineTransform transform = element->getScreenCTM(SVGLocatable::DisallowStyleUpdate);
transform *= resourceTransform;
return transform;
}
}
|