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

Side by Side Diff: Source/core/svg/graphics/SVGImage.cpp

Issue 1334703002: NOT FOR LANDING Pass URL to Image::draw (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 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
« no previous file with comments | « Source/core/svg/graphics/SVGImage.h ('k') | Source/core/svg/graphics/SVGImageForContainer.h » ('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) 2006 Eric Seidel <eric@webkit.org> 2 * Copyright (C) 2006 Eric Seidel <eric@webkit.org>
3 * Copyright (C) 2008, 2009 Apple Inc. All rights reserved. 3 * Copyright (C) 2008, 2009 Apple Inc. All rights reserved.
4 * Copyright (C) Research In Motion Limited 2011. All rights reserved. 4 * Copyright (C) Research In Motion Limited 2011. All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 intrinsicSize = rootElement->currentViewBoxRect().size(); 186 intrinsicSize = rootElement->currentViewBoxRect().size();
187 187
188 if (!intrinsicSize.isEmpty()) 188 if (!intrinsicSize.isEmpty())
189 return expandedIntSize(intrinsicSize); 189 return expandedIntSize(intrinsicSize);
190 190
191 // As last resort, use CSS replaced element fallback size. 191 // As last resort, use CSS replaced element fallback size.
192 return IntSize(300, 150); 192 return IntSize(300, 150);
193 } 193 }
194 194
195 void SVGImage::drawForContainer(SkCanvas* canvas, const SkPaint& paint, const Fl oatSize containerSize, float zoom, const FloatRect& dstRect, 195 void SVGImage::drawForContainer(SkCanvas* canvas, const SkPaint& paint, const Fl oatSize containerSize, float zoom, const FloatRect& dstRect,
196 const FloatRect& srcRect) 196 const FloatRect& srcRect, const KURL& url)
197 { 197 {
198 if (!m_page) 198 if (!m_page)
199 return; 199 return;
200 200
201 // Temporarily disable the image observer to prevent changeInRect() calls du e re-laying out the image. 201 // Temporarily disable the image observer to prevent changeInRect() calls du e re-laying out the image.
202 ImageObserverDisabler imageObserverDisabler(this); 202 ImageObserverDisabler imageObserverDisabler(this);
203 203
204 IntSize roundedContainerSize = roundedIntSize(containerSize); 204 IntSize roundedContainerSize = roundedIntSize(containerSize);
205 setContainerSize(roundedContainerSize); 205 setContainerSize(roundedContainerSize);
206 206
207 FloatRect scaledSrc = srcRect; 207 FloatRect scaledSrc = srcRect;
208 scaledSrc.scale(1 / zoom); 208 scaledSrc.scale(1 / zoom);
209 209
210 // Compensate for the container size rounding by adjusting the source rect. 210 // Compensate for the container size rounding by adjusting the source rect.
211 FloatSize adjustedSrcSize = scaledSrc.size(); 211 FloatSize adjustedSrcSize = scaledSrc.size();
212 adjustedSrcSize.scale(roundedContainerSize.width() / containerSize.width(), roundedContainerSize.height() / containerSize.height()); 212 adjustedSrcSize.scale(roundedContainerSize.width() / containerSize.width(), roundedContainerSize.height() / containerSize.height());
213 scaledSrc.setSize(adjustedSrcSize); 213 scaledSrc.setSize(adjustedSrcSize);
214 214
215 draw(canvas, paint, dstRect, scaledSrc, DoNotRespectImageOrientation, ClampI mageToSourceRect); 215 draw(canvas, paint, dstRect, scaledSrc, DoNotRespectImageOrientation, ClampI mageToSourceRect, url);
216 } 216 }
217 217
218 PassRefPtr<SkImage> SVGImage::imageForCurrentFrame() 218 PassRefPtr<SkImage> SVGImage::imageForCurrentFrame()
219 { 219 {
220 if (!m_page) 220 if (!m_page)
221 return nullptr; 221 return nullptr;
222 222
223 SkPictureRecorder recorder; 223 SkPictureRecorder recorder;
224 SkCanvas* canvas = recorder.beginRecording(width(), height()); 224 SkCanvas* canvas = recorder.beginRecording(width(), height());
225 drawForContainer(canvas, SkPaint(), size(), 1, rect(), rect()); 225 drawForContainer(canvas, SkPaint(), size(), 1, rect(), rect(), KURL()); // T ODO(davve): empty url
226 RefPtr<SkPicture> picture = adoptRef(recorder.endRecording()); 226 RefPtr<SkPicture> picture = adoptRef(recorder.endRecording());
227 227
228 return adoptRef( 228 return adoptRef(
229 SkImage::NewFromPicture(picture.get(), SkISize::Make(width(), height()), nullptr, nullptr)); 229 SkImage::NewFromPicture(picture.get(), SkISize::Make(width(), height()), nullptr, nullptr));
230 } 230 }
231 231
232 void SVGImage::drawPatternForContainer(GraphicsContext* context, const FloatSize containerSize, 232 void SVGImage::drawPatternForContainer(GraphicsContext* context, const FloatSize containerSize,
233 float zoom, const FloatRect& srcRect, const FloatSize& tileScale, const Floa tPoint& phase, 233 float zoom, const FloatRect& srcRect, const FloatSize& tileScale, const Floa tPoint& phase,
234 SkXfermode::Mode compositeOp, const FloatRect& dstRect, 234 SkXfermode::Mode compositeOp, const FloatRect& dstRect,
235 const IntSize& repeatSpacing) 235 const IntSize& repeatSpacing, const KURL& url)
236 { 236 {
237 // Tile adjusted for scaling/stretch. 237 // Tile adjusted for scaling/stretch.
238 FloatRect tile(srcRect); 238 FloatRect tile(srcRect);
239 tile.scale(tileScale.width(), tileScale.height()); 239 tile.scale(tileScale.width(), tileScale.height());
240 240
241 // Expand the tile to account for repeat spacing. 241 // Expand the tile to account for repeat spacing.
242 FloatRect spacedTile(tile); 242 FloatRect spacedTile(tile);
243 spacedTile.expand(repeatSpacing); 243 spacedTile.expand(repeatSpacing);
244 244
245 SkPictureBuilder patternPicture(spacedTile, nullptr, context); 245 SkPictureBuilder patternPicture(spacedTile, nullptr, context);
246 if (!DrawingRecorder::useCachedDrawingIfPossible(patternPicture.context(), * this, DisplayItem::Type::SVGImage)) { 246 if (!DrawingRecorder::useCachedDrawingIfPossible(patternPicture.context(), * this, DisplayItem::Type::SVGImage)) {
247 DrawingRecorder patternPictureRecorder(patternPicture.context(), *this, DisplayItem::Type::SVGImage, spacedTile); 247 DrawingRecorder patternPictureRecorder(patternPicture.context(), *this, DisplayItem::Type::SVGImage, spacedTile);
248 // When generating an expanded tile, make sure we don't draw into the sp acing area. 248 // When generating an expanded tile, make sure we don't draw into the sp acing area.
249 if (tile != spacedTile) 249 if (tile != spacedTile)
250 patternPicture.context().clip(tile); 250 patternPicture.context().clip(tile);
251 SkPaint paint; 251 SkPaint paint;
252 drawForContainer(patternPicture.context().canvas(), paint, containerSize , zoom, tile, srcRect); 252 drawForContainer(patternPicture.context().canvas(), paint, containerSize , zoom, tile, srcRect, url);
253 } 253 }
254 RefPtr<const SkPicture> tilePicture = patternPicture.endRecording(); 254 RefPtr<const SkPicture> tilePicture = patternPicture.endRecording();
255 255
256 SkMatrix patternTransform; 256 SkMatrix patternTransform;
257 patternTransform.setTranslate(phase.x() + spacedTile.x(), phase.y() + spaced Tile.y()); 257 patternTransform.setTranslate(phase.x() + spacedTile.x(), phase.y() + spaced Tile.y());
258 RefPtr<SkShader> patternShader = adoptRef(SkShader::CreatePictureShader( 258 RefPtr<SkShader> patternShader = adoptRef(SkShader::CreatePictureShader(
259 tilePicture.get(), SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMod e, 259 tilePicture.get(), SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMod e,
260 &patternTransform, nullptr)); 260 &patternTransform, nullptr));
261 261
262 SkPaint paint; 262 SkPaint paint;
(...skipping 10 matching lines...) Expand all
273 273
274 SkXfermode::Mode xfermode; 274 SkXfermode::Mode xfermode;
275 if (SkXfermode::AsMode(paint.getXfermode(), &xfermode)) { 275 if (SkXfermode::AsMode(paint.getXfermode(), &xfermode)) {
276 if (xfermode != SkXfermode::kSrcOver_Mode) 276 if (xfermode != SkXfermode::kSrcOver_Mode)
277 return true; 277 return true;
278 } 278 }
279 279
280 return false; 280 return false;
281 } 281 }
282 282
283 void SVGImage::draw(SkCanvas* canvas, const SkPaint& paint, const FloatRect& dst Rect, const FloatRect& srcRect, RespectImageOrientationEnum, ImageClampingMode) 283 void SVGImage::draw(SkCanvas* canvas, const SkPaint& paint, const FloatRect& dst Rect, const FloatRect& srcRect,
284 RespectImageOrientationEnum shouldRespectImageOrientation, ImageClampingMode clampMode, const KURL& url)
284 { 285 {
285 if (!m_page) 286 if (!m_page)
286 return; 287 return;
287 288
288 FrameView* view = frameView(); 289 FrameView* view = frameView();
289 view->resize(containerSize()); 290 view->resize(containerSize());
290 291
291 // Always call processUrlFragment, even if the url is empty, because 292 // Always call processUrlFragment, even if the url is empty, because
292 // there may have been a previous url/fragment that needs to be reset. 293 // there may have been a previous url/fragment that needs to be reset.
293 view->processUrlFragment(m_url); 294 view->processUrlFragment(url);
294 295
295 SkPictureBuilder imagePicture(dstRect); 296 SkPictureBuilder imagePicture(dstRect);
296 { 297 {
297 ClipRecorder clipRecorder(imagePicture.context(), *this, DisplayItem::Cl ipNodeImage, LayoutRect(enclosingIntRect(dstRect))); 298 ClipRecorder clipRecorder(imagePicture.context(), *this, DisplayItem::Cl ipNodeImage, LayoutRect(enclosingIntRect(dstRect)));
298 299
299 // We can only draw the entire frame, clipped to the rect we want. So co mpute where the top left 300 // We can only draw the entire frame, clipped to the rect we want. So co mpute where the top left
300 // of the image would be if we were drawing without clipping, and transl ate accordingly. 301 // of the image would be if we were drawing without clipping, and transl ate accordingly.
301 FloatSize scale(dstRect.width() / srcRect.width(), dstRect.height() / sr cRect.height()); 302 FloatSize scale(dstRect.width() / srcRect.width(), dstRect.height() / sr cRect.height());
302 FloatSize topLeftOffset(srcRect.location().x() * scale.width(), srcRect. location().y() * scale.height()); 303 FloatSize topLeftOffset(srcRect.location().x() * scale.width(), srcRect. location().y() * scale.height());
303 FloatPoint destOffset = dstRect.location() - topLeftOffset; 304 FloatPoint destOffset = dstRect.location() - topLeftOffset;
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 480
480 return m_page; 481 return m_page;
481 } 482 }
482 483
483 String SVGImage::filenameExtension() const 484 String SVGImage::filenameExtension() const
484 { 485 {
485 return "svg"; 486 return "svg";
486 } 487 }
487 488
488 } 489 }
OLDNEW
« no previous file with comments | « Source/core/svg/graphics/SVGImage.h ('k') | Source/core/svg/graphics/SVGImageForContainer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698