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

Unified Diff: Source/core/platform/Cursor.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 side-by-side diff with in-line comments
Download patch
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) {

Powered by Google App Engine
This is Rietveld 408576698