Index: Source/core/platform/Cursor.cpp |
=================================================================== |
--- Source/core/platform/Cursor.cpp (revision 162906) |
+++ Source/core/platform/Cursor.cpp (working copy) |
@@ -25,6 +25,7 @@ |
#include "config.h" |
#include "core/platform/Cursor.h" |
+#include "core/platform/graphics/ImageBuffer.h" |
namespace WebCore { |
@@ -47,6 +48,27 @@ |
return IntPoint(); |
} |
+// Similar to Image::nativeImageForCurrentFrame() but incorporates the image |
+// scale factor. This ensures that SVG cursors are sharp at high DPI settings. |
+Cursor rasterizeSVGCursor(const Cursor& cursor, float imageScaleFactor) |
+{ |
+ Image* image = cursor.image(); |
+ if (!image || !image->isSVGImage() || imageScaleFactor == 1) |
+ return cursor; |
+ |
+ IntSize size = image->size(); |
+ IntPoint hotSpot = cursor.hotSpot(); |
+ size.scale(imageScaleFactor); |
+ hotSpot.scale(imageScaleFactor, imageScaleFactor); |
+ |
+ OwnPtr<ImageBuffer> buffer = ImageBuffer::create(size, 1); |
+ if (!buffer) // failed to allocate image |
+ return cursor; |
+ |
+ buffer->context()->drawImage(image, FloatRect(IntRect(IntPoint(), size))); |
+ return Cursor(buffer->copyImage(DontCopyBackingStore).get(), hotSpot, imageScaleFactor); |
+} |
+ |
const Cursor& Cursor::fromType(Cursor::Type type) |
{ |
switch (type) { |