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

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

Issue 104023007: Refactoring ImageBuffer to decouple it from Canvas2DLayerBridge (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: build fixes for win+mac Created 7 years 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
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 30 matching lines...) Expand all
41 #include "core/rendering/style/RenderStyle.h" 41 #include "core/rendering/style/RenderStyle.h"
42 #include "core/rendering/svg/RenderSVGRoot.h" 42 #include "core/rendering/svg/RenderSVGRoot.h"
43 #include "core/svg/SVGDocument.h" 43 #include "core/svg/SVGDocument.h"
44 #include "core/svg/SVGFEImageElement.h" 44 #include "core/svg/SVGFEImageElement.h"
45 #include "core/svg/SVGImageElement.h" 45 #include "core/svg/SVGImageElement.h"
46 #include "core/svg/SVGSVGElement.h" 46 #include "core/svg/SVGSVGElement.h"
47 #include "core/svg/graphics/SVGImageChromeClient.h" 47 #include "core/svg/graphics/SVGImageChromeClient.h"
48 #include "platform/LengthFunctions.h" 48 #include "platform/LengthFunctions.h"
49 #include "platform/geometry/IntRect.h" 49 #include "platform/geometry/IntRect.h"
50 #include "platform/graphics/ImageObserver.h" 50 #include "platform/graphics/ImageObserver.h"
51 #include "platform/graphics/UnacceleratedImageBufferSurface.h"
51 #include "wtf/PassRefPtr.h" 52 #include "wtf/PassRefPtr.h"
52 53
53 namespace WebCore { 54 namespace WebCore {
54 55
55 SVGImage::SVGImage(ImageObserver* observer) 56 SVGImage::SVGImage(ImageObserver* observer)
56 : Image(observer) 57 : Image(observer)
57 { 58 {
58 } 59 }
59 60
60 SVGImage::~SVGImage() 61 SVGImage::~SVGImage()
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 scaledSrc.setSize(adjustedSrcSize); 186 scaledSrc.setSize(adjustedSrcSize);
186 187
187 draw(context, dstRect, scaledSrc, compositeOp, blendMode); 188 draw(context, dstRect, scaledSrc, compositeOp, blendMode);
188 } 189 }
189 190
190 PassRefPtr<NativeImageSkia> SVGImage::nativeImageForCurrentFrame() 191 PassRefPtr<NativeImageSkia> SVGImage::nativeImageForCurrentFrame()
191 { 192 {
192 if (!m_page) 193 if (!m_page)
193 return 0; 194 return 0;
194 195
195 OwnPtr<ImageBuffer> buffer = ImageBuffer::create(size(), 1); 196 OwnPtr<ImageBufferSurface> surface = adoptPtr(new UnacceleratedImageBufferSu rface(size()));
196 if (!buffer) // failed to allocate image 197 if (!surface->isValid())
197 return 0; 198 return 0;
199 ImageBuffer buffer(surface.release());
198 200
199 drawForContainer(buffer->context(), size(), 1, rect(), rect(), CompositeSour ceOver, blink::WebBlendModeNormal); 201 drawForContainer(buffer.context(), size(), 1, rect(), rect(), CompositeSourc eOver, blink::WebBlendModeNormal);
200 202
201 // FIXME: WK(Bug 113657): We should use DontCopyBackingStore here. 203 // FIXME: WK(Bug 113657): We should use DontCopyBackingStore here.
202 return buffer->copyImage(CopyBackingStore)->nativeImageForCurrentFrame(); 204 return buffer.copyImage(CopyBackingStore)->nativeImageForCurrentFrame();
203 } 205 }
204 206
205 void SVGImage::drawPatternForContainer(GraphicsContext* context, const FloatSize containerSize, float zoom, const FloatRect& srcRect, 207 void SVGImage::drawPatternForContainer(GraphicsContext* context, const FloatSize containerSize, float zoom, const FloatRect& srcRect,
206 const FloatSize& scale, const FloatPoint& phase, CompositeOperator composite Op, const FloatRect& dstRect, blink::WebBlendMode blendMode, const IntSize& repe atSpacing) 208 const FloatSize& scale, const FloatPoint& phase, CompositeOperator composite Op, const FloatRect& dstRect, blink::WebBlendMode blendMode, const IntSize& repe atSpacing)
207 { 209 {
208 FloatRect zoomedContainerRect = FloatRect(FloatPoint(), containerSize); 210 FloatRect zoomedContainerRect = FloatRect(FloatPoint(), containerSize);
209 zoomedContainerRect.scale(zoom); 211 zoomedContainerRect.scale(zoom);
210 212
211 // The ImageBuffer size needs to be scaled to match the final resolution. 213 // The ImageBuffer size needs to be scaled to match the final resolution.
212 // FIXME: No need to get the full CTM here, we just need the scale. 214 // FIXME: No need to get the full CTM here, we just need the scale.
213 AffineTransform transform = context->getCTM(); 215 AffineTransform transform = context->getCTM();
214 FloatSize imageBufferScale = FloatSize(transform.xScale(), transform.yScale( )); 216 FloatSize imageBufferScale = FloatSize(transform.xScale(), transform.yScale( ));
215 ASSERT(imageBufferScale.width()); 217 ASSERT(imageBufferScale.width());
216 ASSERT(imageBufferScale.height()); 218 ASSERT(imageBufferScale.height());
217 219
218 FloatSize scaleWithoutCTM(scale.width() / imageBufferScale.width(), scale.he ight() / imageBufferScale.height()); 220 FloatSize scaleWithoutCTM(scale.width() / imageBufferScale.width(), scale.he ight() / imageBufferScale.height());
219 221
220 FloatRect imageBufferSize = zoomedContainerRect; 222 FloatRect imageBufferSize = zoomedContainerRect;
221 imageBufferSize.scale(imageBufferScale.width(), imageBufferScale.height()); 223 imageBufferSize.scale(imageBufferScale.width(), imageBufferScale.height());
222 224
223 OwnPtr<ImageBuffer> buffer = ImageBuffer::create(expandedIntSize(imageBuffer Size.size()), 1); 225 OwnPtr<ImageBufferSurface> surface = adoptPtr(new UnacceleratedImageBufferSu rface(expandedIntSize(imageBufferSize.size())));
224 if (!buffer) // Failed to allocate buffer. 226 if (!surface->isValid())
225 return; 227 return;
226 drawForContainer(buffer->context(), containerSize, zoom, imageBufferSize, zo omedContainerRect, CompositeSourceOver, blink::WebBlendModeNormal); 228 ImageBuffer buffer(surface.release());
227 RefPtr<Image> image = buffer->copyImage(DontCopyBackingStore, Unscaled); 229 drawForContainer(buffer.context(), containerSize, zoom, imageBufferSize, zoo medContainerRect, CompositeSourceOver, blink::WebBlendModeNormal);
230 RefPtr<Image> image = buffer.copyImage(DontCopyBackingStore, Unscaled);
228 231
229 // Adjust the source rect and transform due to the image buffer's scaling. 232 // Adjust the source rect and transform due to the image buffer's scaling.
230 FloatRect scaledSrcRect = srcRect; 233 FloatRect scaledSrcRect = srcRect;
231 scaledSrcRect.scale(imageBufferScale.width(), imageBufferScale.height()); 234 scaledSrcRect.scale(imageBufferScale.width(), imageBufferScale.height());
232 235
233 image->drawPattern(context, scaledSrcRect, scaleWithoutCTM, phase, composite Op, dstRect, blendMode, repeatSpacing); 236 image->drawPattern(context, scaledSrcRect, scaleWithoutCTM, phase, composite Op, dstRect, blendMode, repeatSpacing);
234 } 237 }
235 238
236 void SVGImage::draw(GraphicsContext* context, const FloatRect& dstRect, const Fl oatRect& srcRect, CompositeOperator compositeOp, blink::WebBlendMode blendMode) 239 void SVGImage::draw(GraphicsContext* context, const FloatRect& dstRect, const Fl oatRect& srcRect, CompositeOperator compositeOp, blink::WebBlendMode blendMode)
237 { 240 {
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 411
409 return m_page; 412 return m_page;
410 } 413 }
411 414
412 String SVGImage::filenameExtension() const 415 String SVGImage::filenameExtension() const
413 { 416 {
414 return "svg"; 417 return "svg";
415 } 418 }
416 419
417 } 420 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698