OLD | NEW |
---|---|
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 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
226 } | 226 } |
227 | 227 |
228 ASSERT(solutionHeight <= defaultObjectSize.height()); | 228 ASSERT(solutionHeight <= defaultObjectSize.height()); |
229 return FloatSize(defaultObjectSize.width(), solutionHeight); | 229 return FloatSize(defaultObjectSize.width(), solutionHeight); |
230 } | 230 } |
231 | 231 |
232 return defaultObjectSize; | 232 return defaultObjectSize; |
233 } | 233 } |
234 | 234 |
235 void SVGImage::drawForContainer(SkCanvas* canvas, const SkPaint& paint, const Fl oatSize containerSize, float zoom, const FloatRect& dstRect, | 235 void SVGImage::drawForContainer(SkCanvas* canvas, const SkPaint& paint, const Fl oatSize containerSize, float zoom, const FloatRect& dstRect, |
236 const FloatRect& srcRect, const KURL& url) | 236 const FloatRect& srcRect, bool imageSmoothingEnabled, const KURL& url) |
237 { | 237 { |
238 if (!m_page) | 238 if (!m_page) |
239 return; | 239 return; |
240 | 240 |
241 // Temporarily disable the image observer to prevent changeInRect() calls du e re-laying out the image. | 241 // Temporarily disable the image observer to prevent changeInRect() calls du e re-laying out the image. |
242 ImageObserverDisabler imageObserverDisabler(this); | 242 ImageObserverDisabler imageObserverDisabler(this); |
243 | 243 |
244 IntSize roundedContainerSize = roundedIntSize(containerSize); | 244 IntSize roundedContainerSize = roundedIntSize(containerSize); |
245 | 245 |
246 if (SVGSVGElement* rootElement = svgRootElement(m_page.get())) { | 246 if (SVGSVGElement* rootElement = svgRootElement(m_page.get())) { |
247 if (LayoutSVGRoot* layoutObject = toLayoutSVGRoot(rootElement->layoutObj ect())) | 247 if (LayoutSVGRoot* layoutObject = toLayoutSVGRoot(rootElement->layoutObj ect())) |
248 layoutObject->setContainerSize(roundedContainerSize); | 248 layoutObject->setContainerSize(roundedContainerSize); |
249 } | 249 } |
250 | 250 |
251 FloatRect scaledSrc = srcRect; | 251 FloatRect scaledSrc = srcRect; |
252 scaledSrc.scale(1 / zoom); | 252 scaledSrc.scale(1 / zoom); |
253 | 253 |
254 // Compensate for the container size rounding by adjusting the source rect. | 254 // Compensate for the container size rounding by adjusting the source rect. |
255 FloatSize adjustedSrcSize = scaledSrc.size(); | 255 FloatSize adjustedSrcSize = scaledSrc.size(); |
256 adjustedSrcSize.scale(roundedContainerSize.width() / containerSize.width(), roundedContainerSize.height() / containerSize.height()); | 256 adjustedSrcSize.scale(roundedContainerSize.width() / containerSize.width(), roundedContainerSize.height() / containerSize.height()); |
257 scaledSrc.setSize(adjustedSrcSize); | 257 scaledSrc.setSize(adjustedSrcSize); |
258 | 258 |
259 drawInternal(canvas, paint, dstRect, scaledSrc, DoNotRespectImageOrientation , ClampImageToSourceRect, url); | 259 SkPaint adjustedPaint = paint; |
260 if (!imageSmoothingEnabled && Image::isDrawScalingDown(scaledSrc, dstRect)) | |
261 adjustedPaint.setFilterQuality(kLow_SkFilterQuality); | |
fs
2016/07/18 15:56:55
This should not have any effect. Ditto below, and
| |
262 | |
263 drawInternal(canvas, adjustedPaint, dstRect, scaledSrc, DoNotRespectImageOri entation, ClampImageToSourceRect, url); | |
260 } | 264 } |
261 | 265 |
262 PassRefPtr<SkImage> SVGImage::imageForCurrentFrame() | 266 PassRefPtr<SkImage> SVGImage::imageForCurrentFrame() |
263 { | 267 { |
264 return imageForCurrentFrameForContainer(KURL(), FloatSize(size())); | 268 return imageForCurrentFrameForContainer(KURL(), FloatSize(size())); |
265 } | 269 } |
266 | 270 |
267 void SVGImage::drawPatternForContainer(GraphicsContext& context, const FloatSize containerSize, | 271 void SVGImage::drawPatternForContainer(GraphicsContext& context, const FloatSize containerSize, |
268 float zoom, const FloatRect& srcRect, const FloatSize& tileScale, const Floa tPoint& phase, | 272 float zoom, const FloatRect& srcRect, const FloatSize& tileScale, const Floa tPoint& phase, |
269 SkXfermode::Mode compositeOp, const FloatRect& dstRect, | 273 SkXfermode::Mode compositeOp, const FloatRect& dstRect, |
270 const FloatSize& repeatSpacing, const KURL& url) | 274 const FloatSize& repeatSpacing, const KURL& url) |
271 { | 275 { |
272 // Tile adjusted for scaling/stretch. | 276 // Tile adjusted for scaling/stretch. |
273 FloatRect tile(srcRect); | 277 FloatRect tile(srcRect); |
274 tile.scale(tileScale.width(), tileScale.height()); | 278 tile.scale(tileScale.width(), tileScale.height()); |
275 | 279 |
276 // Expand the tile to account for repeat spacing. | 280 // Expand the tile to account for repeat spacing. |
277 FloatRect spacedTile(tile); | 281 FloatRect spacedTile(tile); |
278 spacedTile.expand(FloatSize(repeatSpacing)); | 282 spacedTile.expand(FloatSize(repeatSpacing)); |
279 | 283 |
280 SkPictureBuilder patternPicture(spacedTile, nullptr, &context); | 284 SkPictureBuilder patternPicture(spacedTile, nullptr, &context); |
281 { | 285 { |
282 DrawingRecorder patternPictureRecorder(patternPicture.context(), pattern Picture, DisplayItem::Type::SVGImage, spacedTile); | 286 DrawingRecorder patternPictureRecorder(patternPicture.context(), pattern Picture, DisplayItem::Type::SVGImage, spacedTile); |
283 // When generating an expanded tile, make sure we don't draw into the sp acing area. | 287 // When generating an expanded tile, make sure we don't draw into the sp acing area. |
284 if (tile != spacedTile) | 288 if (tile != spacedTile) |
285 patternPicture.context().clip(tile); | 289 patternPicture.context().clip(tile); |
286 SkPaint paint; | 290 SkPaint paint; |
287 drawForContainer(patternPicture.context().canvas(), paint, containerSize , zoom, tile, srcRect, url); | 291 drawForContainer(patternPicture.context().canvas(), paint, containerSize , zoom, tile, srcRect, true, url); |
288 } | 292 } |
289 RefPtr<SkPicture> tilePicture = patternPicture.endRecording(); | 293 RefPtr<SkPicture> tilePicture = patternPicture.endRecording(); |
290 | 294 |
291 SkMatrix patternTransform; | 295 SkMatrix patternTransform; |
292 patternTransform.setTranslate(phase.x() + spacedTile.x(), phase.y() + spaced Tile.y()); | 296 patternTransform.setTranslate(phase.x() + spacedTile.x(), phase.y() + spaced Tile.y()); |
293 | 297 |
294 SkPaint paint; | 298 SkPaint paint; |
295 paint.setShader(SkShader::MakePictureShader(toSkSp(tilePicture.release()), | 299 paint.setShader(SkShader::MakePictureShader(toSkSp(tilePicture.release()), |
296 SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode, &patternTransfor m, nullptr)); | 300 SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode, &patternTransfor m, nullptr)); |
297 paint.setXfermodeMode(compositeOp); | 301 paint.setXfermodeMode(compositeOp); |
298 paint.setColorFilter(sk_ref_sp(context.colorFilter())); | 302 paint.setColorFilter(sk_ref_sp(context.colorFilter())); |
299 context.drawRect(dstRect, paint); | 303 context.drawRect(dstRect, paint); |
300 } | 304 } |
301 | 305 |
302 PassRefPtr<SkImage> SVGImage::imageForCurrentFrameForContainer(const KURL& url, const FloatSize& containerSize) | 306 PassRefPtr<SkImage> SVGImage::imageForCurrentFrameForContainer(const KURL& url, const FloatSize& containerSize) |
303 { | 307 { |
304 if (!m_page) | 308 if (!m_page) |
305 return nullptr; | 309 return nullptr; |
306 | 310 |
307 SkPictureRecorder recorder; | 311 SkPictureRecorder recorder; |
308 SkCanvas* canvas = recorder.beginRecording(width(), height()); | 312 SkCanvas* canvas = recorder.beginRecording(width(), height()); |
309 drawForContainer(canvas, SkPaint(), containerSize, 1, rect(), rect(), url); | 313 drawForContainer(canvas, SkPaint(), containerSize, 1, rect(), rect(), true, url); |
310 | 314 |
311 return fromSkSp(SkImage::MakeFromPicture(recorder.finishRecordingAsPicture() , | 315 return fromSkSp(SkImage::MakeFromPicture(recorder.finishRecordingAsPicture() , |
312 SkISize::Make(width(), height()), nullptr, nullptr)); | 316 SkISize::Make(width(), height()), nullptr, nullptr)); |
313 } | 317 } |
314 | 318 |
315 static bool drawNeedsLayer(const SkPaint& paint) | 319 static bool drawNeedsLayer(const SkPaint& paint) |
316 { | 320 { |
317 if (SkColorGetA(paint.getColor()) < 255) | 321 if (SkColorGetA(paint.getColor()) < 255) |
318 return true; | 322 return true; |
319 | 323 |
320 SkXfermode::Mode xfermode; | 324 SkXfermode::Mode xfermode; |
321 if (SkXfermode::AsMode(paint.getXfermode(), &xfermode)) { | 325 if (SkXfermode::AsMode(paint.getXfermode(), &xfermode)) { |
322 if (xfermode != SkXfermode::kSrcOver_Mode) | 326 if (xfermode != SkXfermode::kSrcOver_Mode) |
323 return true; | 327 return true; |
324 } | 328 } |
325 | 329 |
326 return false; | 330 return false; |
327 } | 331 } |
328 | 332 |
329 void SVGImage::draw(SkCanvas* canvas, const SkPaint& paint, const FloatRect& dst Rect, const FloatRect& srcRect, | 333 void SVGImage::draw(SkCanvas* canvas, const SkPaint& paint, const FloatRect& dst Rect, const FloatRect& srcRect, |
330 RespectImageOrientationEnum shouldRespectImageOrientation, ImageClampingMode clampMode) | 334 bool imageSmoothingEnabled, RespectImageOrientationEnum shouldRespectImageOr ientation, ImageClampingMode clampMode) |
331 { | 335 { |
332 if (!m_page) | 336 if (!m_page) |
333 return; | 337 return; |
334 | 338 |
335 drawInternal(canvas, paint, dstRect, srcRect, shouldRespectImageOrientation, clampMode, KURL()); | 339 SkPaint adjustedPaint = paint; |
340 if (!imageSmoothingEnabled && Image::isDrawScalingDown(srcRect, dstRect)) | |
341 adjustedPaint.setFilterQuality(kLow_SkFilterQuality); | |
342 | |
343 drawInternal(canvas, adjustedPaint, dstRect, srcRect, shouldRespectImageOrie ntation, clampMode, KURL()); | |
336 } | 344 } |
337 | 345 |
338 void SVGImage::drawInternal(SkCanvas* canvas, const SkPaint& paint, const FloatR ect& dstRect, const FloatRect& srcRect, | 346 void SVGImage::drawInternal(SkCanvas* canvas, const SkPaint& paint, const FloatR ect& dstRect, const FloatRect& srcRect, |
339 RespectImageOrientationEnum, ImageClampingMode, const KURL& url) | 347 RespectImageOrientationEnum, ImageClampingMode, const KURL& url) |
340 { | 348 { |
341 DCHECK(m_page); | 349 DCHECK(m_page); |
342 FrameView* view = toLocalFrame(m_page->mainFrame())->view(); | 350 FrameView* view = toLocalFrame(m_page->mainFrame())->view(); |
343 view->resize(containerSize()); | 351 view->resize(containerSize()); |
344 | 352 |
345 // Always call processUrlFragment, even if the url is empty, because | 353 // Always call processUrlFragment, even if the url is empty, because |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
561 | 569 |
562 return m_page; | 570 return m_page; |
563 } | 571 } |
564 | 572 |
565 String SVGImage::filenameExtension() const | 573 String SVGImage::filenameExtension() const |
566 { | 574 { |
567 return "svg"; | 575 return "svg"; |
568 } | 576 } |
569 | 577 |
570 } // namespace blink | 578 } // namespace blink |
OLD | NEW |