Chromium Code Reviews| 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 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 187 if (intrinsicSize.isEmpty()) | 187 if (intrinsicSize.isEmpty()) |
| 188 intrinsicSize = rootElement->currentViewBoxRect().size(); | 188 intrinsicSize = rootElement->currentViewBoxRect().size(); |
| 189 | 189 |
| 190 if (!intrinsicSize.isEmpty()) | 190 if (!intrinsicSize.isEmpty()) |
| 191 return expandedIntSize(intrinsicSize); | 191 return expandedIntSize(intrinsicSize); |
| 192 | 192 |
| 193 // As last resort, use CSS replaced element fallback size. | 193 // As last resort, use CSS replaced element fallback size. |
| 194 return IntSize(300, 150); | 194 return IntSize(300, 150); |
| 195 } | 195 } |
| 196 | 196 |
| 197 void SVGImage::drawForContainer(GraphicsContext* context, const FloatSize contai nerSize, float zoom, const FloatRect& dstRect, | 197 void SVGImage::drawForContainer(SkCanvas* canvas, const SkPaint& paint, const Fl oatSize containerSize, float zoom, const FloatRect& dstRect, |
| 198 const FloatRect& srcRect, SkXfermode::Mode compositeOp) | 198 const FloatRect& srcRect) |
| 199 { | 199 { |
| 200 if (!m_page) | 200 if (!m_page) |
| 201 return; | 201 return; |
| 202 | 202 |
| 203 // Temporarily disable the image observer to prevent changeInRect() calls du e re-laying out the image. | 203 // Temporarily disable the image observer to prevent changeInRect() calls du e re-laying out the image. |
| 204 ImageObserverDisabler imageObserverDisabler(this); | 204 ImageObserverDisabler imageObserverDisabler(this); |
| 205 | 205 |
| 206 IntSize roundedContainerSize = roundedIntSize(containerSize); | 206 IntSize roundedContainerSize = roundedIntSize(containerSize); |
| 207 setContainerSize(roundedContainerSize); | 207 setContainerSize(roundedContainerSize); |
| 208 | 208 |
| 209 FloatRect scaledSrc = srcRect; | 209 FloatRect scaledSrc = srcRect; |
| 210 scaledSrc.scale(1 / zoom); | 210 scaledSrc.scale(1 / zoom); |
| 211 | 211 |
| 212 // Compensate for the container size rounding by adjusting the source rect. | 212 // Compensate for the container size rounding by adjusting the source rect. |
| 213 FloatSize adjustedSrcSize = scaledSrc.size(); | 213 FloatSize adjustedSrcSize = scaledSrc.size(); |
| 214 adjustedSrcSize.scale(roundedContainerSize.width() / containerSize.width(), roundedContainerSize.height() / containerSize.height()); | 214 adjustedSrcSize.scale(roundedContainerSize.width() / containerSize.width(), roundedContainerSize.height() / containerSize.height()); |
| 215 scaledSrc.setSize(adjustedSrcSize); | 215 scaledSrc.setSize(adjustedSrcSize); |
| 216 | 216 |
| 217 draw(context, dstRect, scaledSrc, compositeOp, DoNotRespectImageOrientation) ; | 217 draw(canvas, paint, dstRect, scaledSrc, DoNotRespectImageOrientation, nullpt r); |
| 218 } | 218 } |
| 219 | 219 |
| 220 bool SVGImage::bitmapForCurrentFrame(SkBitmap* bitmap) | 220 bool SVGImage::bitmapForCurrentFrame(SkBitmap* bitmap) |
| 221 { | 221 { |
| 222 if (!m_page) | 222 if (!m_page) |
| 223 return false; | 223 return false; |
| 224 | 224 |
| 225 OwnPtr<ImageBuffer> buffer = ImageBuffer::create(size()); | 225 OwnPtr<ImageBuffer> buffer = ImageBuffer::create(size()); |
| 226 if (!buffer) | 226 if (!buffer) |
| 227 return false; | 227 return false; |
| 228 | 228 |
| 229 drawForContainer(buffer->context(), size(), 1, rect(), rect(), SkXfermode::k SrcOver_Mode); | 229 SkPaint paint; |
| 230 drawForContainer(buffer->canvas(), paint, size(), 1, rect(), rect()); | |
| 230 | 231 |
| 231 *bitmap = buffer->bitmap(); | 232 *bitmap = buffer->bitmap(); |
| 232 return true; | 233 return true; |
| 233 } | 234 } |
| 234 | 235 |
| 235 void SVGImage::drawPatternForContainer(GraphicsContext* context, const FloatSize containerSize, | 236 void SVGImage::drawPatternForContainer(GraphicsContext* context, const FloatSize containerSize, |
| 236 float zoom, const FloatRect& srcRect, const FloatSize& tileScale, const Floa tPoint& phase, | 237 float zoom, const FloatRect& srcRect, const FloatSize& tileScale, const Floa tPoint& phase, |
| 237 SkXfermode::Mode compositeOp, const FloatRect& dstRect, | 238 SkXfermode::Mode compositeOp, const FloatRect& dstRect, |
| 238 const IntSize& repeatSpacing) | 239 const IntSize& repeatSpacing) |
| 239 { | 240 { |
| 240 // Tile adjusted for scaling/stretch. | 241 // Tile adjusted for scaling/stretch. |
| 241 FloatRect tile(srcRect); | 242 FloatRect tile(srcRect); |
| 242 tile.scale(tileScale.width(), tileScale.height()); | 243 tile.scale(tileScale.width(), tileScale.height()); |
| 243 | 244 |
| 244 // Expand the tile to account for repeat spacing. | 245 // Expand the tile to account for repeat spacing. |
| 245 FloatRect spacedTile(tile); | 246 FloatRect spacedTile(tile); |
| 246 spacedTile.expand(repeatSpacing); | 247 spacedTile.expand(repeatSpacing); |
| 247 | 248 |
| 248 SkPictureBuilder patternPicture(spacedTile); | 249 SkPictureBuilder patternPicture(spacedTile); |
| 249 { | 250 { |
| 250 DrawingRecorder patternPictureRecorder(patternPicture.context(), *this, DisplayItem::Type::SVGImage, spacedTile); | 251 DrawingRecorder patternPictureRecorder(patternPicture.context(), *this, DisplayItem::Type::SVGImage, spacedTile); |
| 251 if (!patternPictureRecorder.canUseCachedDrawing()) { | 252 if (!patternPictureRecorder.canUseCachedDrawing()) { |
| 252 // When generating an expanded tile, make sure we don't draw into th e spacing area. | 253 // When generating an expanded tile, make sure we don't draw into th e spacing area. |
| 253 if (tile != spacedTile) | 254 if (tile != spacedTile) |
| 254 patternPicture.context().clip(tile); | 255 patternPicture.context().clip(tile); |
| 255 drawForContainer(&patternPicture.context(), containerSize, zoom, til e, srcRect, SkXfermode::kSrcOver_Mode); | 256 SkPaint paint; |
| 257 drawForContainer(patternPicture.context().canvas(), paint, container Size, zoom, tile, srcRect); | |
| 256 } | 258 } |
| 257 } | 259 } |
| 258 RefPtr<const SkPicture> tilePicture = patternPicture.endRecording(); | 260 RefPtr<const SkPicture> tilePicture = patternPicture.endRecording(); |
| 259 | 261 |
| 260 SkMatrix patternTransform; | 262 SkMatrix patternTransform; |
| 261 patternTransform.setTranslate(phase.x() + spacedTile.x(), phase.y() + spaced Tile.y()); | 263 patternTransform.setTranslate(phase.x() + spacedTile.x(), phase.y() + spaced Tile.y()); |
| 262 RefPtr<SkShader> patternShader = adoptRef(SkShader::CreatePictureShader( | 264 RefPtr<SkShader> patternShader = adoptRef(SkShader::CreatePictureShader( |
| 263 tilePicture.get(), SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMod e, | 265 tilePicture.get(), SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMod e, |
| 264 &patternTransform, nullptr)); | 266 &patternTransform, nullptr)); |
| 265 | 267 |
| 266 SkPaint paint; | 268 SkPaint paint; |
| 267 paint.setShader(patternShader.get()); | 269 paint.setShader(patternShader.get()); |
| 268 paint.setXfermodeMode(compositeOp); | 270 paint.setXfermodeMode(compositeOp); |
| 269 paint.setColorFilter(context->colorFilter()); | 271 paint.setColorFilter(context->colorFilter()); |
| 270 context->drawRect(dstRect, paint); | 272 context->drawRect(dstRect, paint); |
| 271 } | 273 } |
| 272 | 274 |
| 273 void SVGImage::draw(GraphicsContext* context, const FloatRect& dstRect, const Fl oatRect& srcRect, SkXfermode::Mode compositeOp, RespectImageOrientationEnum) | 275 void SVGImage::draw(SkCanvas* canvas, const SkPaint& paint, const FloatRect& dst Rect, const FloatRect& srcRect, RespectImageOrientationEnum, const ImageFilterQu alityHelper*) |
| 274 { | 276 { |
| 275 if (!m_page) | 277 if (!m_page) |
| 276 return; | 278 return; |
| 277 | 279 |
| 278 float opacity = context->getNormalizedAlpha() / 255.f; | |
| 279 | |
| 280 FrameView* view = frameView(); | 280 FrameView* view = frameView(); |
| 281 view->resize(containerSize()); | 281 view->resize(containerSize()); |
| 282 | 282 |
| 283 // Always call scrollToFragment, even if the url is empty, because | 283 // Always call scrollToFragment, even if the url is empty, because |
| 284 // there may have been a previous url/fragment that needs to be reset. | 284 // there may have been a previous url/fragment that needs to be reset. |
| 285 view->scrollToFragment(m_url); | 285 view->scrollToFragment(m_url); |
| 286 | 286 |
| 287 SkPictureBuilder imagePicture(dstRect); | |
| 287 { | 288 { |
| 288 DisplayItemListContextRecorder contextRecorder(*context); | 289 ClipRecorder clipRecorder(imagePicture.context(), *this, DisplayItem::Cl ipNodeImage, LayoutRect(enclosingIntRect(dstRect))); |
| 289 GraphicsContext& paintContext = contextRecorder.context(); | |
| 290 | |
| 291 ClipRecorder clipRecorder(paintContext, *this, DisplayItem::ClipNodeImag e, LayoutRect(enclosingIntRect(dstRect))); | |
| 292 | |
| 293 bool hasCompositing = compositeOp != SkXfermode::kSrcOver_Mode; | |
| 294 OwnPtr<CompositingRecorder> compositingRecorder; | |
| 295 if (hasCompositing || opacity < 1) | |
| 296 compositingRecorder = adoptPtr(new CompositingRecorder(paintContext, *this, compositeOp, opacity)); | |
| 297 | 290 |
| 298 // We can only draw the entire frame, clipped to the rect we want. So co mpute where the top left | 291 // We can only draw the entire frame, clipped to the rect we want. So co mpute where the top left |
| 299 // of the image would be if we were drawing without clipping, and transl ate accordingly. | 292 // of the image would be if we were drawing without clipping, and transl ate accordingly. |
| 300 FloatSize scale(dstRect.width() / srcRect.width(), dstRect.height() / sr cRect.height()); | 293 FloatSize scale(dstRect.width() / srcRect.width(), dstRect.height() / sr cRect.height()); |
| 301 FloatSize topLeftOffset(srcRect.location().x() * scale.width(), srcRect. location().y() * scale.height()); | 294 FloatSize topLeftOffset(srcRect.location().x() * scale.width(), srcRect. location().y() * scale.height()); |
| 302 FloatPoint destOffset = dstRect.location() - topLeftOffset; | 295 FloatPoint destOffset = dstRect.location() - topLeftOffset; |
| 303 AffineTransform transform = AffineTransform::translation(destOffset.x(), destOffset.y()); | 296 AffineTransform transform = AffineTransform::translation(destOffset.x(), destOffset.y()); |
| 304 transform.scale(scale.width(), scale.height()); | 297 transform.scale(scale.width(), scale.height()); |
| 305 TransformRecorder transformRecorder(paintContext, *this, transform); | 298 TransformRecorder transformRecorder(imagePicture.context(), *this, trans form); |
| 306 | 299 |
| 307 view->updateLayoutAndStyleForPainting(); | 300 view->updateLayoutAndStyleForPainting(); |
| 308 view->paint(&paintContext, enclosingIntRect(srcRect)); | 301 view->paint(&imagePicture.context(), enclosingIntRect(srcRect)); |
| 309 ASSERT(!view->needsLayout()); | 302 ASSERT(!view->needsLayout()); |
| 310 } | 303 } |
| 311 | 304 |
| 305 { | |
| 306 SkAutoCanvasRestore ar(canvas, false); | |
| 307 | |
| 308 bool needsLayer = false; | |
|
pdr.
2015/05/27 04:23:30
Can you move this needsLayer code into a helper fu
| |
| 309 // FIXME: Might be more efficient to apply image filters and box shadows right | |
| 310 // here instead of in another saveLayer | |
| 311 if (SkColorGetA(paint.getColor()) < 255) { | |
| 312 needsLayer = true; | |
| 313 } else { | |
| 314 SkXfermode::Mode xfermode; | |
| 315 if (SkXfermode::AsMode(paint.getXfermode(), &xfermode)) { | |
| 316 if (xfermode != SkXfermode::kSrcOver_Mode) | |
| 317 needsLayer = true; | |
| 318 } | |
| 319 } | |
| 320 | |
| 321 if (needsLayer) { | |
| 322 SkRect layerRect = dstRect; | |
| 323 canvas->saveLayer(&layerRect, &paint); | |
| 324 } | |
| 325 | |
| 326 RefPtr<const SkPicture> recording = imagePicture.endRecording(); | |
| 327 canvas->drawPicture(recording.get()); | |
| 328 } | |
| 329 | |
| 312 if (imageObserver()) | 330 if (imageObserver()) |
| 313 imageObserver()->didDraw(this); | 331 imageObserver()->didDraw(this); |
| 314 | 332 |
| 315 // Start any (SMIL) animations if needed. This will restart or continue | 333 // Start any (SMIL) animations if needed. This will restart or continue |
| 316 // animations if preceded by calls to resetAnimation or stopAnimation | 334 // animations if preceded by calls to resetAnimation or stopAnimation |
| 317 // respectively. | 335 // respectively. |
| 318 startAnimation(); | 336 startAnimation(); |
| 319 } | 337 } |
| 320 | 338 |
| 321 LayoutBox* SVGImage::embeddedContentBox() const | 339 LayoutBox* SVGImage::embeddedContentBox() const |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 456 | 474 |
| 457 return m_page; | 475 return m_page; |
| 458 } | 476 } |
| 459 | 477 |
| 460 String SVGImage::filenameExtension() const | 478 String SVGImage::filenameExtension() const |
| 461 { | 479 { |
| 462 return "svg"; | 480 return "svg"; |
| 463 } | 481 } |
| 464 | 482 |
| 465 } | 483 } |
| OLD | NEW |