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

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

Issue 21430003: Implement interfaces in PaintInfo and make it a class. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@getterPaintInfo01
Patch Set: Fixed Linux compilation (hopefuly Windows too), addressing some reviewer's suggestions. Created 7 years, 4 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
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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 & EndFilterLayer) {
60 ASSERT(m_filter); 60 ASSERT(m_filter);
61 m_filter->postApplyResource(m_object, m_paintInfo->context, ApplyToDefau ltMode, 0, 0); 61 GraphicsContext* context = m_paintInfo->getContext();
do-not-use 2013/08/05 11:16:30 Useless new local variable?
62 m_paintInfo->context = m_savedContext; 62 m_filter->postApplyResource(m_object, context, ApplyToDefaultMode, 0, 0) ;
63 m_paintInfo->rect = m_savedPaintRect; 63 m_paintInfo->setContext(m_savedContext);
64 m_paintInfo->setRect(m_savedPaintRect);
64 } 65 }
65 66
66 if (m_renderingFlags & EndOpacityLayer) 67 if (m_renderingFlags & EndOpacityLayer)
67 m_paintInfo->context->endTransparencyLayer(); 68 m_paintInfo->getContext()->endTransparencyLayer();
68 69
69 if (m_renderingFlags & RestoreGraphicsContext) 70 if (m_renderingFlags & RestoreGraphicsContext)
70 m_paintInfo->context->restore(); 71 m_paintInfo->getContext()->restore();
71 } 72 }
72 73
73 void SVGRenderingContext::prepareToRenderSVGContent(RenderObject* object, PaintI nfo& paintInfo, NeedsGraphicsContextSave needsGraphicsContextSave) 74 void SVGRenderingContext::prepareToRenderSVGContent(RenderObject* object, PaintI nfo& paintInfo, NeedsGraphicsContextSave needsGraphicsContextSave)
74 { 75 {
75 ASSERT(object); 76 ASSERT(object);
76 77
77 #ifndef NDEBUG 78 #ifndef NDEBUG
78 // This function must not be called twice! 79 // This function must not be called twice!
79 ASSERT(!(m_renderingFlags & PrepareToRenderSVGContentWasCalled)); 80 ASSERT(!(m_renderingFlags & PrepareToRenderSVGContentWasCalled));
80 m_renderingFlags |= PrepareToRenderSVGContentWasCalled; 81 m_renderingFlags |= PrepareToRenderSVGContentWasCalled;
81 #endif 82 #endif
82 83
83 m_object = object; 84 m_object = object;
84 m_paintInfo = &paintInfo; 85 m_paintInfo = &paintInfo;
85 m_filter = 0; 86 m_filter = 0;
86 87
87 // We need to save / restore the context even if the initialization failed. 88 // We need to save / restore the context even if the initialization failed.
88 if (needsGraphicsContextSave == SaveGraphicsContext) { 89 if (needsGraphicsContextSave == SaveGraphicsContext) {
89 m_paintInfo->context->save(); 90 m_paintInfo->getContext()->save();
90 m_renderingFlags |= RestoreGraphicsContext; 91 m_renderingFlags |= RestoreGraphicsContext;
91 } 92 }
92 93
93 RenderStyle* style = m_object->style(); 94 RenderStyle* style = m_object->style();
94 ASSERT(style); 95 ASSERT(style);
95 96
96 const SVGRenderStyle* svgStyle = style->svgStyle(); 97 const SVGRenderStyle* svgStyle = style->svgStyle();
97 ASSERT(svgStyle); 98 ASSERT(svgStyle);
98 99
99 // Setup transparency layers before setting up SVG resources! 100 // Setup transparency layers before setting up SVG resources!
100 bool isRenderingMask = isRenderingMaskImage(m_object); 101 bool isRenderingMask = isRenderingMaskImage(m_object);
101 float opacity = isRenderingMask ? 1 : style->opacity(); 102 float opacity = isRenderingMask ? 1 : style->opacity();
102 BlendMode blendMode = isRenderingMask ? BlendModeNormal : style->blendMode() ; 103 BlendMode blendMode = isRenderingMask ? BlendModeNormal : style->blendMode() ;
103 if (opacity < 1 || blendMode != BlendModeNormal) { 104 if (opacity < 1 || blendMode != BlendModeNormal) {
104 FloatRect repaintRect = m_object->repaintRectInLocalCoordinates(); 105 FloatRect repaintRect = m_object->repaintRectInLocalCoordinates();
105 106
106 if (opacity < 1 || blendMode != BlendModeNormal) { 107 if (opacity < 1 || blendMode != BlendModeNormal) {
107 m_paintInfo->context->clip(repaintRect); 108 m_paintInfo->getContext()->clip(repaintRect);
108 if (blendMode != BlendModeNormal) { 109 if (blendMode != BlendModeNormal) {
109 if (!(m_renderingFlags & RestoreGraphicsContext)) { 110 if (!(m_renderingFlags & RestoreGraphicsContext)) {
110 m_paintInfo->context->save(); 111 m_paintInfo->getContext()->save();
111 m_renderingFlags |= RestoreGraphicsContext; 112 m_renderingFlags |= RestoreGraphicsContext;
112 } 113 }
113 m_paintInfo->context->setCompositeOperation(CompositeSourceOver, blendMode); 114 m_paintInfo->getContext()->setCompositeOperation(CompositeSource Over, blendMode);
114 } 115 }
115 m_paintInfo->context->beginTransparencyLayer(opacity); 116 m_paintInfo->getContext()->beginTransparencyLayer(opacity);
116 m_renderingFlags |= EndOpacityLayer; 117 m_renderingFlags |= EndOpacityLayer;
117 } 118 }
118 } 119 }
119 120
120 ClipPathOperation* clipPathOperation = style->clipPath(); 121 ClipPathOperation* clipPathOperation = style->clipPath();
121 if (clipPathOperation && clipPathOperation->getOperationType() == ClipPathOp eration::SHAPE) { 122 if (clipPathOperation && clipPathOperation->getOperationType() == ClipPathOp eration::SHAPE) {
122 ShapeClipPathOperation* clipPath = static_cast<ShapeClipPathOperation*>( clipPathOperation); 123 ShapeClipPathOperation* clipPath = static_cast<ShapeClipPathOperation*>( clipPathOperation);
123 m_paintInfo->context->clipPath(clipPath->path(object->objectBoundingBox( )), clipPath->windRule()); 124 m_paintInfo->getContext()->clipPath(clipPath->path(object->objectBoundin gBox()), clipPath->windRule());
124 } 125 }
125 126
126 SVGResources* resources = SVGResourcesCache::cachedResourcesForRenderObject( m_object); 127 SVGResources* resources = SVGResourcesCache::cachedResourcesForRenderObject( m_object);
127 if (!resources) { 128 if (!resources) {
128 if (svgStyle->hasFilter()) 129 if (svgStyle->hasFilter())
129 return; 130 return;
130 131
131 m_renderingFlags |= RenderingPrepared; 132 m_renderingFlags |= RenderingPrepared;
132 return; 133 return;
133 } 134 }
134 135
135 if (!isRenderingMask) { 136 if (!isRenderingMask) {
136 if (RenderSVGResourceMasker* masker = resources->masker()) { 137 if (RenderSVGResourceMasker* masker = resources->masker()) {
137 if (!masker->applyResource(m_object, style, m_paintInfo->context, Ap plyToDefaultMode)) 138 GraphicsContext* context = m_paintInfo->getContext();
139 if (!masker->applyResource(m_object, style, context, ApplyToDefaultM ode)) {
140 m_paintInfo->setContext(context);
do-not-use 2013/08/05 11:16:30 IMHO, this results in less readable code. Maybe th
138 return; 141 return;
142 }
143 m_paintInfo->setContext(context);
139 } 144 }
140 } 145 }
141 146
142 RenderSVGResourceClipper* clipper = resources->clipper(); 147 RenderSVGResourceClipper* clipper = resources->clipper();
143 if (!clipPathOperation && clipper) { 148 if (!clipPathOperation && clipper) {
144 if (!clipper->applyResource(m_object, style, m_paintInfo->context, Apply ToDefaultMode)) 149 GraphicsContext* context = m_paintInfo->getContext();
150 if (!clipper->applyResource(m_object, style, context, ApplyToDefaultMode )) {
151 m_paintInfo->setContext(context);
145 return; 152 return;
153 }
154 m_paintInfo->setContext(context);
146 } 155 }
147 156
148 if (!isRenderingMask) { 157 if (!isRenderingMask) {
149 m_filter = resources->filter(); 158 m_filter = resources->filter();
150 if (m_filter) { 159 if (m_filter) {
151 m_savedContext = m_paintInfo->context; 160 m_savedContext = m_paintInfo->getContext();
152 m_savedPaintRect = m_paintInfo->rect; 161 m_savedPaintRect = m_paintInfo->getRect();
153 // Return with false here may mean that we don't need to draw the co ntent 162 // 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. 163 // (because it was either drawn before or empty) but we still need t o apply the filter.
155 m_renderingFlags |= EndFilterLayer; 164 m_renderingFlags |= EndFilterLayer;
156 if (!m_filter->applyResource(m_object, style, m_paintInfo->context, ApplyToDefaultMode)) 165 GraphicsContext* context = m_paintInfo->getContext();
166 if (!m_filter->applyResource(m_object, style, context, ApplyToDefaul tMode)) {
167 m_paintInfo->setContext(context);
157 return; 168 return;
169 }
170 m_paintInfo->setContext(context);
158 171
159 // Since we're caching the resulting bitmap and do not invalidate it on repaint rect 172 // 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 173 // 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 174 // at the time of the initial paint (due to scrolling, window size, etc.) will never
162 // be drawn. 175 // be drawn.
163 m_paintInfo->rect = IntRect(m_filter->drawingRegion(m_object)); 176 m_paintInfo->setRect(IntRect(m_filter->drawingRegion(m_object)));
164 } 177 }
165 } 178 }
166 179
167 m_renderingFlags |= RenderingPrepared; 180 m_renderingFlags |= RenderingPrepared;
168 } 181 }
169 182
170 static AffineTransform& currentContentTransformation() 183 static AffineTransform& currentContentTransformation()
171 { 184 {
172 DEFINE_STATIC_LOCAL(AffineTransform, s_currentContentTransformation, ()); 185 DEFINE_STATIC_LOCAL(AffineTransform, s_currentContentTransformation, ());
173 return s_currentContentTransformation; 186 return s_currentContentTransformation;
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 } 327 }
315 328
316 bool SVGRenderingContext::bufferForeground(OwnPtr<ImageBuffer>& imageBuffer) 329 bool SVGRenderingContext::bufferForeground(OwnPtr<ImageBuffer>& imageBuffer)
317 { 330 {
318 ASSERT(m_paintInfo); 331 ASSERT(m_paintInfo);
319 ASSERT(m_object->isSVGImage()); 332 ASSERT(m_object->isSVGImage());
320 FloatRect boundingBox = m_object->objectBoundingBox(); 333 FloatRect boundingBox = m_object->objectBoundingBox();
321 334
322 // Invalidate an existing buffer if the scale is not correct. 335 // Invalidate an existing buffer if the scale is not correct.
323 if (imageBuffer) { 336 if (imageBuffer) {
324 AffineTransform transform = m_paintInfo->context->getCTM(GraphicsContext ::DefinitelyIncludeDeviceScale); 337 AffineTransform transform = m_paintInfo->getContext()->getCTM(GraphicsCo ntext::DefinitelyIncludeDeviceScale);
325 IntSize expandedBoundingBox = expandedIntSize(boundingBox.size()); 338 IntSize expandedBoundingBox = expandedIntSize(boundingBox.size());
326 IntSize bufferSize(static_cast<int>(ceil(expandedBoundingBox.width() * t ransform.xScale())), static_cast<int>(ceil(expandedBoundingBox.height() * transf orm.yScale()))); 339 IntSize bufferSize(static_cast<int>(ceil(expandedBoundingBox.width() * t ransform.xScale())), static_cast<int>(ceil(expandedBoundingBox.height() * transf orm.yScale())));
327 if (bufferSize != imageBuffer->internalSize()) 340 if (bufferSize != imageBuffer->internalSize())
328 imageBuffer.clear(); 341 imageBuffer.clear();
329 } 342 }
330 343
331 // Create a new buffer and paint the foreground into it. 344 // Create a new buffer and paint the foreground into it.
332 if (!imageBuffer) { 345 if (!imageBuffer) {
333 if ((imageBuffer = m_paintInfo->context->createCompatibleBuffer(expanded IntSize(boundingBox.size()), true))) { 346 if ((imageBuffer = m_paintInfo->getContext()->createCompatibleBuffer(exp andedIntSize(boundingBox.size()), true))) {
334 GraphicsContext* bufferedRenderingContext = imageBuffer->context(); 347 GraphicsContext* bufferedRenderingContext = imageBuffer->context();
335 bufferedRenderingContext->translate(-boundingBox.x(), -boundingBox.y ()); 348 bufferedRenderingContext->translate(-boundingBox.x(), -boundingBox.y ());
336 PaintInfo bufferedInfo(*m_paintInfo); 349 PaintInfo bufferedInfo(*m_paintInfo);
337 bufferedInfo.context = bufferedRenderingContext; 350 bufferedInfo.setContext(bufferedRenderingContext);
338 toRenderSVGImage(m_object)->paintForeground(bufferedInfo); 351 toRenderSVGImage(m_object)->paintForeground(bufferedInfo);
339 } else 352 } else
340 return false; 353 return false;
341 } 354 }
342 355
343 m_paintInfo->context->drawImageBuffer(imageBuffer.get(), boundingBox); 356 m_paintInfo->getContext()->drawImageBuffer(imageBuffer.get(), boundingBox);
344 return true; 357 return true;
345 } 358 }
346 359
347 } 360 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698