| 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 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 } | 178 } |
| 179 | 179 |
| 180 if (!intrinsicSize.isEmpty()) | 180 if (!intrinsicSize.isEmpty()) |
| 181 return expandedIntSize(intrinsicSize); | 181 return expandedIntSize(intrinsicSize); |
| 182 | 182 |
| 183 // As last resort, use CSS replaced element fallback size. | 183 // As last resort, use CSS replaced element fallback size. |
| 184 return IntSize(300, 150); | 184 return IntSize(300, 150); |
| 185 } | 185 } |
| 186 | 186 |
| 187 void SVGImage::drawForContainer(GraphicsContext* context, const FloatSize contai
nerSize, float zoom, const FloatRect& dstRect, | 187 void SVGImage::drawForContainer(GraphicsContext* context, const FloatSize contai
nerSize, float zoom, const FloatRect& dstRect, |
| 188 const FloatRect& srcRect, CompositeOperator compositeOp, blink::WebBlendMode
blendMode) | 188 const FloatRect& srcRect, SkXfermode::Mode compositeOp) |
| 189 { | 189 { |
| 190 if (!m_page) | 190 if (!m_page) |
| 191 return; | 191 return; |
| 192 | 192 |
| 193 // Temporarily disable the image observer to prevent changeInRect() calls du
e re-laying out the image. | 193 // Temporarily disable the image observer to prevent changeInRect() calls du
e re-laying out the image. |
| 194 ImageObserverDisabler imageObserverDisabler(this); | 194 ImageObserverDisabler imageObserverDisabler(this); |
| 195 | 195 |
| 196 IntSize roundedContainerSize = roundedIntSize(containerSize); | 196 IntSize roundedContainerSize = roundedIntSize(containerSize); |
| 197 setContainerSize(roundedContainerSize); | 197 setContainerSize(roundedContainerSize); |
| 198 | 198 |
| 199 FloatRect scaledSrc = srcRect; | 199 FloatRect scaledSrc = srcRect; |
| 200 scaledSrc.scale(1 / zoom); | 200 scaledSrc.scale(1 / zoom); |
| 201 | 201 |
| 202 // Compensate for the container size rounding by adjusting the source rect. | 202 // Compensate for the container size rounding by adjusting the source rect. |
| 203 FloatSize adjustedSrcSize = scaledSrc.size(); | 203 FloatSize adjustedSrcSize = scaledSrc.size(); |
| 204 adjustedSrcSize.scale(roundedContainerSize.width() / containerSize.width(),
roundedContainerSize.height() / containerSize.height()); | 204 adjustedSrcSize.scale(roundedContainerSize.width() / containerSize.width(),
roundedContainerSize.height() / containerSize.height()); |
| 205 scaledSrc.setSize(adjustedSrcSize); | 205 scaledSrc.setSize(adjustedSrcSize); |
| 206 | 206 |
| 207 draw(context, dstRect, scaledSrc, compositeOp, blendMode, DoNotRespectImageO
rientation); | 207 draw(context, dstRect, scaledSrc, compositeOp, DoNotRespectImageOrientation)
; |
| 208 } | 208 } |
| 209 | 209 |
| 210 PassRefPtr<NativeImageSkia> SVGImage::nativeImageForCurrentFrame() | 210 PassRefPtr<NativeImageSkia> SVGImage::nativeImageForCurrentFrame() |
| 211 { | 211 { |
| 212 if (!m_page) | 212 if (!m_page) |
| 213 return nullptr; | 213 return nullptr; |
| 214 | 214 |
| 215 OwnPtr<ImageBuffer> buffer = ImageBuffer::create(size()); | 215 OwnPtr<ImageBuffer> buffer = ImageBuffer::create(size()); |
| 216 if (!buffer) | 216 if (!buffer) |
| 217 return nullptr; | 217 return nullptr; |
| 218 | 218 |
| 219 drawForContainer(buffer->context(), size(), 1, rect(), rect(), CompositeSour
ceOver, blink::WebBlendModeNormal); | 219 drawForContainer(buffer->context(), size(), 1, rect(), rect(), SkXfermode::k
SrcOver_Mode); |
| 220 | 220 |
| 221 return NativeImageSkia::create(buffer->bitmap()); | 221 return NativeImageSkia::create(buffer->bitmap()); |
| 222 } | 222 } |
| 223 | 223 |
| 224 void SVGImage::drawPatternForContainer(GraphicsContext* context, const FloatSize
containerSize, | 224 void SVGImage::drawPatternForContainer(GraphicsContext* context, const FloatSize
containerSize, |
| 225 float zoom, const FloatRect& srcRect, const FloatSize& tileScale, const Floa
tPoint& phase, | 225 float zoom, const FloatRect& srcRect, const FloatSize& tileScale, const Floa
tPoint& phase, |
| 226 CompositeOperator compositeOp, const FloatRect& dstRect, blink::WebBlendMode
blendMode, | 226 SkXfermode::Mode compositeOp, const FloatRect& dstRect, |
| 227 const IntSize& repeatSpacing) | 227 const IntSize& repeatSpacing) |
| 228 { | 228 { |
| 229 // Tile adjusted for scaling/stretch. | 229 // Tile adjusted for scaling/stretch. |
| 230 FloatRect tile(srcRect); | 230 FloatRect tile(srcRect); |
| 231 tile.scale(tileScale.width(), tileScale.height()); | 231 tile.scale(tileScale.width(), tileScale.height()); |
| 232 | 232 |
| 233 // Expand the tile to account for repeat spacing. | 233 // Expand the tile to account for repeat spacing. |
| 234 FloatRect spacedTile(tile); | 234 FloatRect spacedTile(tile); |
| 235 spacedTile.expand(repeatSpacing); | 235 spacedTile.expand(repeatSpacing); |
| 236 | 236 |
| 237 OwnPtr<DisplayItemList> displayItemList; | 237 OwnPtr<DisplayItemList> displayItemList; |
| 238 if (RuntimeEnabledFeatures::slimmingPaintEnabled()) | 238 if (RuntimeEnabledFeatures::slimmingPaintEnabled()) |
| 239 displayItemList = DisplayItemList::create(); | 239 displayItemList = DisplayItemList::create(); |
| 240 | 240 |
| 241 // Record using a dedicated GC, to avoid inheriting unwanted state (pending
color filters | 241 // Record using a dedicated GC, to avoid inheriting unwanted state (pending
color filters |
| 242 // for example must be applied atomically during the final fill/composite ph
ase). | 242 // for example must be applied atomically during the final fill/composite ph
ase). |
| 243 GraphicsContext recordingContext(nullptr, displayItemList.get()); | 243 GraphicsContext recordingContext(nullptr, displayItemList.get()); |
| 244 recordingContext.beginRecording(spacedTile); | 244 recordingContext.beginRecording(spacedTile); |
| 245 | 245 |
| 246 { | 246 { |
| 247 // When generating an expanded tile, make sure we don't draw into the sp
acing area. | 247 // When generating an expanded tile, make sure we don't draw into the sp
acing area. |
| 248 OwnPtr<FloatClipRecorder> clipRecorder; | 248 OwnPtr<FloatClipRecorder> clipRecorder; |
| 249 if (tile != spacedTile) | 249 if (tile != spacedTile) |
| 250 clipRecorder = adoptPtr(new FloatClipRecorder(recordingContext, disp
layItemClient(), PaintPhaseForeground, tile)); | 250 clipRecorder = adoptPtr(new FloatClipRecorder(recordingContext, disp
layItemClient(), PaintPhaseForeground, tile)); |
| 251 drawForContainer(&recordingContext, containerSize, zoom, tile, srcRect,
CompositeSourceOver, blink::WebBlendModeNormal); | 251 drawForContainer(&recordingContext, containerSize, zoom, tile, srcRect,
SkXfermode::kSrcOver_Mode); |
| 252 } | 252 } |
| 253 | 253 |
| 254 if (displayItemList) | 254 if (displayItemList) |
| 255 displayItemList->replay(&recordingContext); | 255 displayItemList->replay(&recordingContext); |
| 256 | 256 |
| 257 RefPtr<const SkPicture> tilePicture = recordingContext.endRecording(); | 257 RefPtr<const SkPicture> tilePicture = recordingContext.endRecording(); |
| 258 | 258 |
| 259 SkMatrix patternTransform; | 259 SkMatrix patternTransform; |
| 260 patternTransform.setTranslate(phase.x() + spacedTile.x(), phase.y() + spaced
Tile.y()); | 260 patternTransform.setTranslate(phase.x() + spacedTile.x(), phase.y() + spaced
Tile.y()); |
| 261 RefPtr<SkShader> patternShader = adoptRef(SkShader::CreatePictureShader( | 261 RefPtr<SkShader> patternShader = adoptRef(SkShader::CreatePictureShader( |
| 262 tilePicture.get(), SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMod
e, | 262 tilePicture.get(), SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMod
e, |
| 263 &patternTransform, nullptr)); | 263 &patternTransform, nullptr)); |
| 264 | 264 |
| 265 SkPaint paint; | 265 SkPaint paint; |
| 266 paint.setShader(patternShader.get()); | 266 paint.setShader(patternShader.get()); |
| 267 paint.setXfermodeMode(WebCoreCompositeToSkiaComposite(compositeOp, blendMode
)); | 267 paint.setXfermodeMode(compositeOp); |
| 268 paint.setColorFilter(context->colorFilter()); | 268 paint.setColorFilter(context->colorFilter()); |
| 269 context->drawRect(dstRect, paint); | 269 context->drawRect(dstRect, paint); |
| 270 } | 270 } |
| 271 | 271 |
| 272 void SVGImage::draw(GraphicsContext* context, const FloatRect& dstRect, const Fl
oatRect& srcRect, CompositeOperator compositeOp, blink::WebBlendMode blendMode,
RespectImageOrientationEnum) | 272 void SVGImage::draw(GraphicsContext* context, const FloatRect& dstRect, const Fl
oatRect& srcRect, SkXfermode::Mode compositeOp, RespectImageOrientationEnum) |
| 273 { | 273 { |
| 274 if (!m_page) | 274 if (!m_page) |
| 275 return; | 275 return; |
| 276 | 276 |
| 277 float opacity = context->getNormalizedAlpha() / 255.f; | 277 float opacity = context->getNormalizedAlpha() / 255.f; |
| 278 | 278 |
| 279 OwnPtr<DisplayItemList> displayItemList; | 279 OwnPtr<DisplayItemList> displayItemList; |
| 280 if (RuntimeEnabledFeatures::slimmingPaintEnabled()) | 280 if (RuntimeEnabledFeatures::slimmingPaintEnabled()) |
| 281 displayItemList = DisplayItemList::create(); | 281 displayItemList = DisplayItemList::create(); |
| 282 GraphicsContext recordingContext(nullptr, displayItemList.get()); | 282 GraphicsContext recordingContext(nullptr, displayItemList.get()); |
| 283 recordingContext.beginRecording(dstRect); | 283 recordingContext.beginRecording(dstRect); |
| 284 | 284 |
| 285 { | 285 { |
| 286 ClipRecorder clipRecorder(displayItemClient(), &recordingContext, Displa
yItem::ClipNodeImage, enclosingIntRect(dstRect)); | 286 ClipRecorder clipRecorder(displayItemClient(), &recordingContext, Displa
yItem::ClipNodeImage, enclosingIntRect(dstRect)); |
| 287 | 287 |
| 288 bool hasCompositing = compositeOp != CompositeSourceOver || blendMode !=
blink::WebBlendModeNormal; | 288 bool hasCompositing = compositeOp != SkXfermode::kSrcOver_Mode; |
| 289 OwnPtr<CompositingRecorder> compositingRecorder; | 289 OwnPtr<CompositingRecorder> compositingRecorder; |
| 290 if (hasCompositing || opacity < 1) { | 290 if (hasCompositing || opacity < 1) { |
| 291 CompositeOperator postCompositeOp = hasCompositing ? CompositeSource
Over : compositeOp; | 291 SkXfermode::Mode postCompositeOp = hasCompositing ? SkXfermode::kSrc
Over_Mode : compositeOp; |
| 292 compositingRecorder = adoptPtr(new CompositingRecorder(&recordingCon
text, displayItemClient(), compositeOp, blendMode, opacity, postCompositeOp)); | 292 compositingRecorder = adoptPtr(new CompositingRecorder(&recordingCon
text, displayItemClient(), compositeOperatorFromSkia(compositeOp), blendModeFrom
Skia(compositeOp), opacity, compositeOperatorFromSkia(postCompositeOp))); |
| 293 } | 293 } |
| 294 | 294 |
| 295 // We can only draw the entire frame, clipped to the rect we want. So co
mpute where the top left | 295 // We can only draw the entire frame, clipped to the rect we want. So co
mpute where the top left |
| 296 // of the image would be if we were drawing without clipping, and transl
ate accordingly. | 296 // of the image would be if we were drawing without clipping, and transl
ate accordingly. |
| 297 FloatSize scale(dstRect.width() / srcRect.width(), dstRect.height() / sr
cRect.height()); | 297 FloatSize scale(dstRect.width() / srcRect.width(), dstRect.height() / sr
cRect.height()); |
| 298 FloatSize topLeftOffset(srcRect.location().x() * scale.width(), srcRect.
location().y() * scale.height()); | 298 FloatSize topLeftOffset(srcRect.location().x() * scale.width(), srcRect.
location().y() * scale.height()); |
| 299 FloatPoint destOffset = dstRect.location() - topLeftOffset; | 299 FloatPoint destOffset = dstRect.location() - topLeftOffset; |
| 300 AffineTransform transform = AffineTransform::translation(destOffset.x(),
destOffset.y()); | 300 AffineTransform transform = AffineTransform::translation(destOffset.x(),
destOffset.y()); |
| 301 transform.scale(scale.width(), scale.height()); | 301 transform.scale(scale.width(), scale.height()); |
| 302 TransformRecorder transformRecorder(recordingContext, displayItemClient(
), transform); | 302 TransformRecorder transformRecorder(recordingContext, displayItemClient(
), transform); |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 | 458 |
| 459 return m_page; | 459 return m_page; |
| 460 } | 460 } |
| 461 | 461 |
| 462 String SVGImage::filenameExtension() const | 462 String SVGImage::filenameExtension() const |
| 463 { | 463 { |
| 464 return "svg"; | 464 return "svg"; |
| 465 } | 465 } |
| 466 | 466 |
| 467 } | 467 } |
| OLD | NEW |