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

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

Issue 1327473003: Use picture-backed SkImages for SVGImage::imageForCurrentFrame() (Closed) Base URL: svn://svn.chromium.org/blink/trunk
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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 #include "platform/LengthFunctions.h" 51 #include "platform/LengthFunctions.h"
52 #include "platform/TraceEvent.h" 52 #include "platform/TraceEvent.h"
53 #include "platform/geometry/IntRect.h" 53 #include "platform/geometry/IntRect.h"
54 #include "platform/graphics/GraphicsContext.h" 54 #include "platform/graphics/GraphicsContext.h"
55 #include "platform/graphics/ImageBuffer.h" 55 #include "platform/graphics/ImageBuffer.h"
56 #include "platform/graphics/ImageObserver.h" 56 #include "platform/graphics/ImageObserver.h"
57 #include "platform/graphics/paint/ClipRecorder.h" 57 #include "platform/graphics/paint/ClipRecorder.h"
58 #include "platform/graphics/paint/DrawingRecorder.h" 58 #include "platform/graphics/paint/DrawingRecorder.h"
59 #include "platform/graphics/paint/SkPictureBuilder.h" 59 #include "platform/graphics/paint/SkPictureBuilder.h"
60 #include "third_party/skia/include/core/SkPicture.h" 60 #include "third_party/skia/include/core/SkPicture.h"
61 #include "third_party/skia/include/core/SkSurface.h"
62 #include "wtf/PassRefPtr.h" 61 #include "wtf/PassRefPtr.h"
63 62
64 namespace blink { 63 namespace blink {
65 64
66 SVGImage::SVGImage(ImageObserver* observer) 65 SVGImage::SVGImage(ImageObserver* observer)
67 : Image(observer) 66 : Image(observer)
68 { 67 {
69 } 68 }
70 69
71 SVGImage::~SVGImage() 70 SVGImage::~SVGImage()
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 // Compensate for the container size rounding by adjusting the source rect. 210 // Compensate for the container size rounding by adjusting the source rect.
212 FloatSize adjustedSrcSize = scaledSrc.size(); 211 FloatSize adjustedSrcSize = scaledSrc.size();
213 adjustedSrcSize.scale(roundedContainerSize.width() / containerSize.width(), roundedContainerSize.height() / containerSize.height()); 212 adjustedSrcSize.scale(roundedContainerSize.width() / containerSize.width(), roundedContainerSize.height() / containerSize.height());
214 scaledSrc.setSize(adjustedSrcSize); 213 scaledSrc.setSize(adjustedSrcSize);
215 214
216 draw(canvas, paint, dstRect, scaledSrc, DoNotRespectImageOrientation, ClampI mageToSourceRect); 215 draw(canvas, paint, dstRect, scaledSrc, DoNotRespectImageOrientation, ClampI mageToSourceRect);
217 } 216 }
218 217
219 PassRefPtr<SkImage> SVGImage::imageForCurrentFrame() 218 PassRefPtr<SkImage> SVGImage::imageForCurrentFrame()
220 { 219 {
221 // TODO(fmalita): instead of rasterizing, investigate returning a SkPicture- backed image.
222
223 if (!m_page) 220 if (!m_page)
224 return nullptr; 221 return nullptr;
225 222
226 IntSize size = this->size(); 223 SkPictureRecorder recorder;
227 SkImageInfo imageInfo = SkImageInfo::MakeN32(size.width(), size.height(), kP remul_SkAlphaType); 224 SkCanvas* canvas = recorder.beginRecording(width(), height());
228 SkSurfaceProps disableLCDProps(0, kUnknown_SkPixelGeometry); 225 drawForContainer(canvas, SkPaint(), size(), 1, rect(), rect());
229 RefPtr<SkSurface> surface = adoptRef(SkSurface::NewRaster(imageInfo, &disabl eLCDProps)); 226 RefPtr<SkPicture> picture = adoptRef(recorder.endRecording());
230 if (!surface)
231 return nullptr;
232 227
233 drawForContainer(surface->getCanvas(), SkPaint(), size, 1, rect(), rect()); 228 return adoptRef(
234 229 SkImage::NewFromPicture(picture.get(), SkISize::Make(width(), height()), nullptr, nullptr));
235 return adoptRef(surface->newImageSnapshot());
236 } 230 }
237 231
238 void SVGImage::drawPatternForContainer(GraphicsContext* context, const FloatSize containerSize, 232 void SVGImage::drawPatternForContainer(GraphicsContext* context, const FloatSize containerSize,
239 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,
240 SkXfermode::Mode compositeOp, const FloatRect& dstRect, 234 SkXfermode::Mode compositeOp, const FloatRect& dstRect,
241 const IntSize& repeatSpacing) 235 const IntSize& repeatSpacing)
242 { 236 {
243 // Tile adjusted for scaling/stretch. 237 // Tile adjusted for scaling/stretch.
244 FloatRect tile(srcRect); 238 FloatRect tile(srcRect);
245 tile.scale(tileScale.width(), tileScale.height()); 239 tile.scale(tileScale.width(), tileScale.height());
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 479
486 return m_page; 480 return m_page;
487 } 481 }
488 482
489 String SVGImage::filenameExtension() const 483 String SVGImage::filenameExtension() const
490 { 484 {
491 return "svg"; 485 return "svg";
492 } 486 }
493 487
494 } 488 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698