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

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

Issue 105363002: Make SVG images for custom CSS cursors appear sharp on retina displays (Closed) Base URL: http://src.chromium.org/blink/trunk/
Patch Set: 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
« no previous file with comments | « Source/core/svg/graphics/SVGImage.h ('k') | Source/core/svg/graphics/SVGImageForContainer.h » ('j') | 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 "wtf/PassRefPtr.h" 51 #include "wtf/PassRefPtr.h"
52 52
53 namespace WebCore { 53 namespace WebCore {
54 54
55 SVGImage::SVGImage(ImageObserver* observer) 55 SVGImage::SVGImage(ImageObserver* observer, float deviceScaleFactor)
56 : Image(observer) 56 : Image(observer)
57 , m_deviceScaleFactor(deviceScaleFactor)
57 { 58 {
58 } 59 }
59 60
60 SVGImage::~SVGImage() 61 SVGImage::~SVGImage()
61 { 62 {
62 if (m_page) { 63 if (m_page) {
63 // Store m_page in a local variable, clearing m_page, so that SVGImageCh romeClient knows we're destructed. 64 // Store m_page in a local variable, clearing m_page, so that SVGImageCh romeClient knows we're destructed.
64 OwnPtr<Page> currentPage = m_page.release(); 65 OwnPtr<Page> currentPage = m_page.release();
65 currentPage->mainFrame()->loader().frameDetached(); // Break both the lo ader and view references to the frame 66 currentPage->mainFrame()->loader().frameDetached(); // Break both the lo ader and view references to the frame
66 } 67 }
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 scaledSrc.scale(1 / zoom); 181 scaledSrc.scale(1 / zoom);
181 182
182 // Compensate for the container size rounding by adjusting the source rect. 183 // Compensate for the container size rounding by adjusting the source rect.
183 FloatSize adjustedSrcSize = scaledSrc.size(); 184 FloatSize adjustedSrcSize = scaledSrc.size();
184 adjustedSrcSize.scale(roundedContainerSize.width() / containerSize.width(), roundedContainerSize.height() / containerSize.height()); 185 adjustedSrcSize.scale(roundedContainerSize.width() / containerSize.width(), roundedContainerSize.height() / containerSize.height());
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(ScaleHint hint)
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 IntSize scaledSize = size();
197 float scale = hint == PreferDeviceScale ? m_deviceScaleFactor : 1;
198 scaledSize.scale(scale);
199
200 OwnPtr<ImageBuffer> buffer = ImageBuffer::create(scaledSize, 1);
196 if (!buffer) // failed to allocate image 201 if (!buffer) // failed to allocate image
197 return 0; 202 return 0;
198 203
199 drawForContainer(buffer->context(), size(), 1, rect(), rect(), CompositeSour ceOver, blink::WebBlendModeNormal); 204 drawForContainer(buffer->context(), size(), 1, FloatRect(IntRect(IntPoint(), scaledSize)), rect(), CompositeSourceOver, blink::WebBlendModeNormal);
200 205
201 // FIXME: WK(Bug 113657): We should use DontCopyBackingStore here. 206 // FIXME: WK(Bug 113657): We should use DontCopyBackingStore here.
202 return buffer->copyImage(CopyBackingStore)->nativeImageForCurrentFrame(); 207 return buffer->copyImage(CopyBackingStore)->nativeImageForCurrentFrame();
203 } 208 }
204 209
205 void SVGImage::drawPatternForContainer(GraphicsContext* context, const FloatSize containerSize, float zoom, const FloatRect& srcRect, 210 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) 211 const FloatSize& scale, const FloatPoint& phase, CompositeOperator composite Op, const FloatRect& dstRect, blink::WebBlendMode blendMode, const IntSize& repe atSpacing)
207 { 212 {
208 FloatRect zoomedContainerRect = FloatRect(FloatPoint(), containerSize); 213 FloatRect zoomedContainerRect = FloatRect(FloatPoint(), containerSize);
209 zoomedContainerRect.scale(zoom); 214 zoomedContainerRect.scale(zoom);
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 413
409 return m_page; 414 return m_page;
410 } 415 }
411 416
412 String SVGImage::filenameExtension() const 417 String SVGImage::filenameExtension() const
413 { 418 {
414 return "svg"; 419 return "svg";
415 } 420 }
416 421
417 } 422 }
OLDNEW
« no previous file with comments | « Source/core/svg/graphics/SVGImage.h ('k') | Source/core/svg/graphics/SVGImageForContainer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698