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

Side by Side Diff: Source/core/rendering/svg/SVGRenderingContext.cpp

Issue 23643003: ImageBuffer-less SVG masking and clipping. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fix the Win build. Created 7 years, 3 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/rendering/svg/SVGRenderingContext.h ('k') | Source/core/svg/graphics/SVGImage.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2007, 2008 Rob Buis <buis@kde.org> 2 * Copyright (C) 2007, 2008 Rob Buis <buis@kde.org>
3 * Copyright (C) 2007 Nikolas Zimmermann <zimmermann@kde.org> 3 * Copyright (C) 2007 Nikolas Zimmermann <zimmermann@kde.org>
4 * Copyright (C) 2007 Eric Seidel <eric@webkit.org> 4 * Copyright (C) 2007 Eric Seidel <eric@webkit.org>
5 * Copyright (C) 2009 Google, Inc. All rights reserved. 5 * Copyright (C) 2009 Google, Inc. All rights reserved.
6 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org> 6 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org>
7 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved. 7 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved.
8 * 8 *
9 * This library is free software; you can redistribute it and/or 9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public 10 * modify it under the terms of the GNU Library General Public
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 } 49 }
50 50
51 SVGRenderingContext::~SVGRenderingContext() 51 SVGRenderingContext::~SVGRenderingContext()
52 { 52 {
53 // Fast path if we don't need to restore anything. 53 // Fast path if we don't need to restore anything.
54 if (!(m_renderingFlags & ActionsNeeded)) 54 if (!(m_renderingFlags & ActionsNeeded))
55 return; 55 return;
56 56
57 ASSERT(m_object && m_paintInfo); 57 ASSERT(m_object && m_paintInfo);
58 58
59 if (m_renderingFlags & EndFilterLayer) { 59 if (m_renderingFlags & PostApplyResources) {
60 ASSERT(m_filter); 60 ASSERT(m_masker || m_clipper || m_filter);
61 m_filter->postApplyResource(m_object, m_paintInfo->context, ApplyToDefau ltMode, 0, 0); 61 ASSERT(SVGResourcesCache::cachedResourcesForRenderObject(m_object));
62 m_paintInfo->context = m_savedContext; 62
63 m_paintInfo->setRect(m_savedPaintRect); 63 if (m_filter) {
64 ASSERT(SVGResourcesCache::cachedResourcesForRenderObject(m_object)-> filter() == m_filter);
65 m_filter->postApplyResource(m_object, m_paintInfo->context, ApplyToD efaultMode, 0, 0);
66 m_paintInfo->context = m_savedContext;
67 m_paintInfo->setRect(m_savedPaintRect);
68 }
69
70 if (m_clipper) {
71 ASSERT(SVGResourcesCache::cachedResourcesForRenderObject(m_object)-> clipper() == m_clipper);
72 m_clipper->postApplyResource(m_object, m_paintInfo->context, ApplyTo DefaultMode, 0, 0);
73 }
74
75 if (m_masker) {
76 ASSERT(SVGResourcesCache::cachedResourcesForRenderObject(m_object)-> masker() == m_masker);
77 m_masker->postApplyResource(m_object, m_paintInfo->context, ApplyToD efaultMode, 0, 0);
78 }
64 } 79 }
65 80
66 if (m_renderingFlags & EndOpacityLayer) 81 if (m_renderingFlags & EndOpacityLayer)
67 m_paintInfo->context->endTransparencyLayer(); 82 m_paintInfo->context->endLayer();
68 83
69 if (m_renderingFlags & RestoreGraphicsContext) 84 if (m_renderingFlags & RestoreGraphicsContext)
70 m_paintInfo->context->restore(); 85 m_paintInfo->context->restore();
71 } 86 }
72 87
73 void SVGRenderingContext::prepareToRenderSVGContent(RenderObject* object, PaintI nfo& paintInfo, NeedsGraphicsContextSave needsGraphicsContextSave) 88 void SVGRenderingContext::prepareToRenderSVGContent(RenderObject* object, PaintI nfo& paintInfo, NeedsGraphicsContextSave needsGraphicsContextSave)
74 { 89 {
75 ASSERT(object); 90 ASSERT(object);
76 91
77 #ifndef NDEBUG 92 #ifndef NDEBUG
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 return; 144 return;
130 145
131 m_renderingFlags |= RenderingPrepared; 146 m_renderingFlags |= RenderingPrepared;
132 return; 147 return;
133 } 148 }
134 149
135 if (!isRenderingMask) { 150 if (!isRenderingMask) {
136 if (RenderSVGResourceMasker* masker = resources->masker()) { 151 if (RenderSVGResourceMasker* masker = resources->masker()) {
137 if (!masker->applyResource(m_object, style, m_paintInfo->context, Ap plyToDefaultMode)) 152 if (!masker->applyResource(m_object, style, m_paintInfo->context, Ap plyToDefaultMode))
138 return; 153 return;
154 m_masker = masker;
155 m_renderingFlags |= PostApplyResources;
139 } 156 }
140 } 157 }
141 158
142 RenderSVGResourceClipper* clipper = resources->clipper(); 159 RenderSVGResourceClipper* clipper = resources->clipper();
143 if (!clipPathOperation && clipper) { 160 if (!clipPathOperation && clipper) {
144 if (!clipper->applyResource(m_object, style, m_paintInfo->context, Apply ToDefaultMode)) 161 if (!clipper->applyResource(m_object, style, m_paintInfo->context, Apply ToDefaultMode))
145 return; 162 return;
163 m_clipper = clipper;
164 m_renderingFlags |= PostApplyResources;
146 } 165 }
147 166
148 if (!isRenderingMask) { 167 if (!isRenderingMask) {
149 m_filter = resources->filter(); 168 m_filter = resources->filter();
150 if (m_filter) { 169 if (m_filter) {
151 m_savedContext = m_paintInfo->context; 170 m_savedContext = m_paintInfo->context;
152 m_savedPaintRect = m_paintInfo->rect(); 171 m_savedPaintRect = m_paintInfo->rect();
153 // Return with false here may mean that we don't need to draw the co ntent 172 // Return with false here may mean that we don't need to draw the co ntent
154 // (because it was either drawn before or empty) but we still need t o apply the filter. 173 // (because it was either drawn before or empty) but we still need t o apply the filter.
155 m_renderingFlags |= EndFilterLayer; 174 m_renderingFlags |= PostApplyResources;
156 if (!m_filter->applyResource(m_object, style, m_paintInfo->context, ApplyToDefaultMode)) 175 if (!m_filter->applyResource(m_object, style, m_paintInfo->context, ApplyToDefaultMode))
157 return; 176 return;
158 177
159 // Since we're caching the resulting bitmap and do not invalidate it on repaint rect 178 // Since we're caching the resulting bitmap and do not invalidate it on repaint rect
160 // changes, we need to paint the whole filter region. Otherwise, ele ments not visible 179 // changes, we need to paint the whole filter region. Otherwise, ele ments not visible
161 // at the time of the initial paint (due to scrolling, window size, etc.) will never 180 // at the time of the initial paint (due to scrolling, window size, etc.) will never
162 // be drawn. 181 // be drawn.
163 m_paintInfo->setRect(IntRect(m_filter->drawingRegion(m_object))); 182 m_paintInfo->setRect(IntRect(m_filter->drawingRegion(m_object)));
164 } 183 }
165 } 184 }
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 GraphicsContext* imageContext = image->context(); 268 GraphicsContext* imageContext = image->context();
250 ASSERT(imageContext); 269 ASSERT(imageContext);
251 270
252 // Compensate rounding effects, as the absolute target rect is using floatin g-point numbers and the image buffer size is integer. 271 // Compensate rounding effects, as the absolute target rect is using floatin g-point numbers and the image buffer size is integer.
253 imageContext->scale(FloatSize(unclampedImageSize.width() / absoluteTargetRec t.width(), unclampedImageSize.height() / absoluteTargetRect.height())); 272 imageContext->scale(FloatSize(unclampedImageSize.width() / absoluteTargetRec t.width(), unclampedImageSize.height() / absoluteTargetRect.height()));
254 273
255 imageBuffer = image.release(); 274 imageBuffer = image.release();
256 return true; 275 return true;
257 } 276 }
258 277
259 void SVGRenderingContext::renderSubtreeToImageBuffer(ImageBuffer* image, RenderO bject* item, const AffineTransform& subtreeContentTransformation) 278 void SVGRenderingContext::renderSubtree(GraphicsContext* context, RenderObject* item, const AffineTransform& subtreeContentTransformation)
260 { 279 {
261 ASSERT(item); 280 ASSERT(item);
262 ASSERT(image); 281 ASSERT(context);
263 ASSERT(image->context());
264 282
265 PaintInfo info(image->context(), PaintInfo::infiniteRect(), PaintPhaseForegr ound, PaintBehaviorNormal); 283 PaintInfo info(context, PaintInfo::infiniteRect(), PaintPhaseForeground, Pai ntBehaviorNormal);
266 284
267 AffineTransform& contentTransformation = currentContentTransformation(); 285 AffineTransform& contentTransformation = currentContentTransformation();
268 AffineTransform savedContentTransformation = contentTransformation; 286 AffineTransform savedContentTransformation = contentTransformation;
269 contentTransformation = subtreeContentTransformation * contentTransformation ; 287 contentTransformation = subtreeContentTransformation * contentTransformation ;
270 288
271 ASSERT(!item->needsLayout()); 289 ASSERT(!item->needsLayout());
272 item->paint(info, IntPoint()); 290 item->paint(info, IntPoint());
273 291
274 contentTransformation = savedContentTransformation; 292 contentTransformation = savedContentTransformation;
275 } 293 }
276 294
277 void SVGRenderingContext::clipToImageBuffer(GraphicsContext* context, const Affi neTransform& absoluteTransform, const FloatRect& targetRect, OwnPtr<ImageBuffer> & imageBuffer, bool safeToClear)
278 {
279 ASSERT(context);
280 ASSERT(imageBuffer);
281
282 FloatRect absoluteTargetRect = calculateImageBufferRect(targetRect, absolute Transform);
283
284 // The mask image has been created in the absolute coordinate space, as the image should not be scaled.
285 // So the actual masking process has to be done in the absolute coordinate s pace as well.
286 context->concatCTM(absoluteTransform.inverse());
287 context->clipToImageBuffer(imageBuffer.get(), absoluteTargetRect);
288 context->concatCTM(absoluteTransform);
289
290 // When nesting resources, with objectBoundingBox as content unit types, the re's no use in caching the
291 // resulting image buffer as the parent resource already caches the result.
292 if (safeToClear && !currentContentTransformation().isIdentity())
293 imageBuffer.clear();
294 }
295
296 FloatRect SVGRenderingContext::clampedAbsoluteTargetRect(const FloatRect& absolu teTargetRect) 295 FloatRect SVGRenderingContext::clampedAbsoluteTargetRect(const FloatRect& absolu teTargetRect)
297 { 296 {
298 const FloatSize maxImageBufferSize(kMaxImageBufferSize, kMaxImageBufferSize) ; 297 const FloatSize maxImageBufferSize(kMaxImageBufferSize, kMaxImageBufferSize) ;
299 return FloatRect(absoluteTargetRect.location(), absoluteTargetRect.size().sh runkTo(maxImageBufferSize)); 298 return FloatRect(absoluteTargetRect.location(), absoluteTargetRect.size().sh runkTo(maxImageBufferSize));
300 } 299 }
301 300
302 IntSize SVGRenderingContext::clampedAbsoluteSize(const IntSize& absoluteSize) 301 IntSize SVGRenderingContext::clampedAbsoluteSize(const IntSize& absoluteSize)
303 { 302 {
304 const IntSize maxImageBufferSize(kMaxImageBufferSize, kMaxImageBufferSize); 303 const IntSize maxImageBufferSize(kMaxImageBufferSize, kMaxImageBufferSize);
305 return absoluteSize.shrunkTo(maxImageBufferSize); 304 return absoluteSize.shrunkTo(maxImageBufferSize);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 toRenderSVGImage(m_object)->paintForeground(bufferedInfo); 337 toRenderSVGImage(m_object)->paintForeground(bufferedInfo);
339 } else 338 } else
340 return false; 339 return false;
341 } 340 }
342 341
343 m_paintInfo->context->drawImageBuffer(imageBuffer.get(), boundingBox); 342 m_paintInfo->context->drawImageBuffer(imageBuffer.get(), boundingBox);
344 return true; 343 return true;
345 } 344 }
346 345
347 } 346 }
OLDNEW
« no previous file with comments | « Source/core/rendering/svg/SVGRenderingContext.h ('k') | Source/core/svg/graphics/SVGImage.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698