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 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 if (intrinsicSize.isEmpty()) | 185 if (intrinsicSize.isEmpty()) |
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(GraphicsContext* context, const FloatSize contai
nerSize, 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, SkXfermode::Mode compositeOp) | 196 const FloatRect& srcRect) |
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(context, dstRect, scaledSrc, compositeOp, DoNotRespectImageOrientation)
; | 215 draw(canvas, paint, dstRect, scaledSrc, DoNotRespectImageOrientation); |
216 } | 216 } |
217 | 217 |
218 bool SVGImage::bitmapForCurrentFrame(SkBitmap* bitmap) | 218 bool SVGImage::bitmapForCurrentFrame(SkBitmap* bitmap) |
219 { | 219 { |
220 if (!m_page) | 220 if (!m_page) |
221 return false; | 221 return false; |
222 | 222 |
223 OwnPtr<ImageBuffer> buffer = ImageBuffer::create(size()); | 223 OwnPtr<ImageBuffer> buffer = ImageBuffer::create(size()); |
224 if (!buffer) | 224 if (!buffer) |
225 return false; | 225 return false; |
226 | 226 |
227 drawForContainer(buffer->context(), size(), 1, rect(), rect(), SkXfermode::k
SrcOver_Mode); | 227 SkPaint paint; |
| 228 drawForContainer(buffer->canvas(), paint, size(), 1, rect(), rect()); |
228 | 229 |
229 *bitmap = buffer->bitmap(); | 230 *bitmap = buffer->bitmap(); |
230 return true; | 231 return true; |
231 } | 232 } |
232 | 233 |
233 void SVGImage::drawPatternForContainer(GraphicsContext* context, const FloatSize
containerSize, | 234 void SVGImage::drawPatternForContainer(GraphicsContext* context, const FloatSize
containerSize, |
234 float zoom, const FloatRect& srcRect, const FloatSize& tileScale, const Floa
tPoint& phase, | 235 float zoom, const FloatRect& srcRect, const FloatSize& tileScale, const Floa
tPoint& phase, |
235 SkXfermode::Mode compositeOp, const FloatRect& dstRect, | 236 SkXfermode::Mode compositeOp, const FloatRect& dstRect, |
236 const IntSize& repeatSpacing) | 237 const IntSize& repeatSpacing) |
237 { | 238 { |
(...skipping 11 matching lines...) Expand all Loading... |
249 | 250 |
250 // Record using a dedicated GC, to avoid inheriting unwanted state (pending
color filters | 251 // Record using a dedicated GC, to avoid inheriting unwanted state (pending
color filters |
251 // for example must be applied atomically during the final fill/composite ph
ase). | 252 // for example must be applied atomically during the final fill/composite ph
ase). |
252 GraphicsContext recordingContext(displayItemList.get()); | 253 GraphicsContext recordingContext(displayItemList.get()); |
253 recordingContext.beginRecording(spacedTile); | 254 recordingContext.beginRecording(spacedTile); |
254 { | 255 { |
255 // When generating an expanded tile, make sure we don't draw into the sp
acing area. | 256 // When generating an expanded tile, make sure we don't draw into the sp
acing area. |
256 OwnPtr<FloatClipRecorder> clipRecorder; | 257 OwnPtr<FloatClipRecorder> clipRecorder; |
257 if (tile != spacedTile) | 258 if (tile != spacedTile) |
258 clipRecorder = adoptPtr(new FloatClipRecorder(recordingContext, *thi
s, PaintPhaseForeground, tile)); | 259 clipRecorder = adoptPtr(new FloatClipRecorder(recordingContext, *thi
s, PaintPhaseForeground, tile)); |
259 drawForContainer(&recordingContext, containerSize, zoom, tile, srcRect,
SkXfermode::kSrcOver_Mode); | 260 SkPaint paint; |
| 261 drawForContainer(recordingContext.canvas(), paint, containerSize, zoom,
tile, srcRect); |
260 } | 262 } |
261 | 263 |
262 if (displayItemList) | 264 if (displayItemList) |
263 displayItemList->commitNewDisplayItemsAndReplay(recordingContext); | 265 displayItemList->commitNewDisplayItemsAndReplay(recordingContext); |
264 | 266 |
265 RefPtr<const SkPicture> tilePicture = recordingContext.endRecording(); | 267 RefPtr<const SkPicture> tilePicture = recordingContext.endRecording(); |
266 | 268 |
267 SkMatrix patternTransform; | 269 SkMatrix patternTransform; |
268 patternTransform.setTranslate(phase.x() + spacedTile.x(), phase.y() + spaced
Tile.y()); | 270 patternTransform.setTranslate(phase.x() + spacedTile.x(), phase.y() + spaced
Tile.y()); |
269 RefPtr<SkShader> patternShader = adoptRef(SkShader::CreatePictureShader( | 271 RefPtr<SkShader> patternShader = adoptRef(SkShader::CreatePictureShader( |
270 tilePicture.get(), SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMod
e, | 272 tilePicture.get(), SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMod
e, |
271 &patternTransform, nullptr)); | 273 &patternTransform, nullptr)); |
272 | 274 |
273 SkPaint paint; | 275 SkPaint paint; |
274 paint.setShader(patternShader.get()); | 276 paint.setShader(patternShader.get()); |
275 paint.setXfermodeMode(compositeOp); | 277 paint.setXfermodeMode(compositeOp); |
276 paint.setColorFilter(context->colorFilter()); | 278 paint.setColorFilter(context->colorFilter()); |
277 context->drawRect(dstRect, paint); | 279 context->drawRect(dstRect, paint); |
278 } | 280 } |
279 | 281 |
280 void SVGImage::draw(GraphicsContext* context, const FloatRect& dstRect, const Fl
oatRect& srcRect, SkXfermode::Mode compositeOp, RespectImageOrientationEnum) | 282 void SVGImage::draw(SkCanvas* canvas, const SkPaint& paint, const FloatRect& dst
Rect, const FloatRect& srcRect, RespectImageOrientationEnum) |
281 { | 283 { |
282 if (!m_page) | 284 if (!m_page) |
283 return; | 285 return; |
284 | 286 |
285 float opacity = context->getNormalizedAlpha() / 255.f; | 287 float opacity = paint.getAlpha() / 255.f; |
| 288 SkXfermode::Mode compositeOp; |
| 289 if (!SkXfermode::AsMode(paint.getXfermode(), &compositeOp)) |
| 290 compositeOp = SkXfermode::kSrcOver_Mode; |
286 | 291 |
287 // TODO(fmalita): this recorder is only needed because CompositingRecorder b
elow appears to be | 292 // TODO(fmalita): this recorder is only needed because CompositingRecorder b
elow appears to be |
288 // dropping the current color filter on the floor. Find a proper fix and get
rid of it. | 293 // dropping the current color filter on the floor. Find a proper fix and get
rid of it. |
289 OwnPtr<GraphicsContext> recordingContext = GraphicsContext::deprecatedCreate
WithCanvas(nullptr); | 294 OwnPtr<GraphicsContext> recordingContext = GraphicsContext::deprecatedCreate
WithCanvas(nullptr); |
290 recordingContext->beginRecording(dstRect); | 295 recordingContext->beginRecording(dstRect); |
291 | 296 |
292 FrameView* view = frameView(); | 297 FrameView* view = frameView(); |
293 view->resize(containerSize()); | 298 view->resize(containerSize()); |
294 | 299 |
295 // Always call scrollToFragment, even if the url is empty, because | 300 // Always call scrollToFragment, even if the url is empty, because |
(...skipping 18 matching lines...) Expand all Loading... |
314 FloatPoint destOffset = dstRect.location() - topLeftOffset; | 319 FloatPoint destOffset = dstRect.location() - topLeftOffset; |
315 AffineTransform transform = AffineTransform::translation(destOffset.x(),
destOffset.y()); | 320 AffineTransform transform = AffineTransform::translation(destOffset.x(),
destOffset.y()); |
316 transform.scale(scale.width(), scale.height()); | 321 transform.scale(scale.width(), scale.height()); |
317 TransformRecorder transformRecorder(paintContext, *this, transform); | 322 TransformRecorder transformRecorder(paintContext, *this, transform); |
318 | 323 |
319 view->updateLayoutAndStyleForPainting(); | 324 view->updateLayoutAndStyleForPainting(); |
320 view->paint(&paintContext, enclosingIntRect(srcRect)); | 325 view->paint(&paintContext, enclosingIntRect(srcRect)); |
321 ASSERT(!view->needsLayout()); | 326 ASSERT(!view->needsLayout()); |
322 } | 327 } |
323 RefPtr<const SkPicture> recording = recordingContext->endRecording(); | 328 RefPtr<const SkPicture> recording = recordingContext->endRecording(); |
324 context->drawPicture(recording.get()); | 329 canvas->drawPicture(recording.get()); |
325 | 330 |
326 if (imageObserver()) | 331 if (imageObserver()) |
327 imageObserver()->didDraw(this); | 332 imageObserver()->didDraw(this); |
328 | 333 |
329 // Start any (SMIL) animations if needed. This will restart or continue | 334 // Start any (SMIL) animations if needed. This will restart or continue |
330 // animations if preceded by calls to resetAnimation or stopAnimation | 335 // animations if preceded by calls to resetAnimation or stopAnimation |
331 // respectively. | 336 // respectively. |
332 startAnimation(); | 337 startAnimation(); |
333 } | 338 } |
334 | 339 |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 | 471 |
467 return m_page; | 472 return m_page; |
468 } | 473 } |
469 | 474 |
470 String SVGImage::filenameExtension() const | 475 String SVGImage::filenameExtension() const |
471 { | 476 { |
472 return "svg"; | 477 return "svg"; |
473 } | 478 } |
474 | 479 |
475 } | 480 } |
OLD | NEW |