Commit 437dd440 authored by Fredrik Söderqvist's avatar Fredrik Söderqvist Committed by Commit Bot

Remove SVGImage::AsSkBitmapForCursor

We can use a wrapping SVGImageForContainer instead, and then call
AsSkBitmapForCurrentFrame() as in the BitmapImage case.

Drop unnecessary null-checks for |image| (it is dereferenced already,
and cannot be null because of ImageResourceContent::GetImage).

Bug: 1121177
Change-Id: I1f327bdca72b6ba60ae30413607246226c4c7e49
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2375171Reviewed-by: default avatarPhilip Rogers <pdr@chromium.org>
Commit-Queue: Fredrik Söderquist <fs@opera.com>
Cr-Commit-Position: refs/heads/master@{#801689}
parent 51b28b64
......@@ -97,6 +97,7 @@
#include "third_party/blink/renderer/core/style/computed_style.h"
#include "third_party/blink/renderer/core/style/cursor_data.h"
#include "third_party/blink/renderer/core/svg/graphics/svg_image.h"
#include "third_party/blink/renderer/core/svg/graphics/svg_image_for_container.h"
#include "third_party/blink/renderer/platform/bindings/exception_state.h"
#include "third_party/blink/renderer/platform/cursors.h"
#include "third_party/blink/renderer/platform/geometry/float_point.h"
......@@ -622,9 +623,11 @@ base::Optional<ui::Cursor> EventHandler::SelectCursor(
// If the image is an SVG, then adjust the scale to reflect the device
// scale factor so that the SVG can be rasterized in the native
// resolution and scaled down to the correct size for the cursor.
if (image && image->IsSVGImage()) {
scale *=
float device_scale_factor = 1;
if (image->IsSVGImage()) {
device_scale_factor =
page->GetChromeClient().GetScreenInfo(*frame_).device_scale_factor;
scale *= device_scale_factor;
}
// Ensure no overflow possible in calculations above.
......@@ -634,23 +637,21 @@ base::Optional<ui::Cursor> EventHandler::SelectCursor(
// Convert from logical pixels to physical pixels.
hot_spot.Scale(scale, scale);
ui::Cursor cursor(ui::mojom::blink::CursorType::kCustom);
if (image) {
// Special case for SVG so that it can be rasterized in the appropriate
// resolution for high DPI displays.
if (image->IsSVGImage()) {
SVGImage* svg = static_cast<SVGImage*>(image);
cursor.set_custom_bitmap(
svg->AsSkBitmapForCursor(page->GetChromeClient()
.GetScreenInfo(*frame_)
.device_scale_factor));
} else {
cursor.set_custom_bitmap(
image->AsSkBitmapForCurrentFrame(kRespectImageOrientation));
}
} else {
cursor.set_custom_bitmap(SkBitmap());
// Special case for SVG so that it can be rasterized in the appropriate
// resolution for high DPI displays.
scoped_refptr<Image> svg_image_holder;
if (auto* svg_image = DynamicTo<SVGImage>(image)) {
IntSize scaled_size(svg_image->Size());
scaled_size.Scale(device_scale_factor);
// TODO(fs): Should pass proper URL. Use StyleImage::GetImage.
svg_image_holder = SVGImageForContainer::Create(
svg_image, FloatSize(scaled_size), device_scale_factor, NullURL());
image = svg_image_holder.get();
}
ui::Cursor cursor(ui::mojom::blink::CursorType::kCustom);
cursor.set_custom_bitmap(
image->AsSkBitmapForCurrentFrame(kRespectImageOrientation));
cursor.set_custom_hotspot(
DetermineHotSpot(*image, hot_spot_specified, hot_spot));
cursor.set_image_scale_factor(scale);
......
......@@ -931,32 +931,4 @@ String SVGImage::FilenameExtension() const {
return "svg";
}
SkBitmap SVGImage::AsSkBitmapForCursor(float device_scale_factor) {
// The size should be scaled by the device scale factor for the cursor so that
// the SVG can be drawn at the correct resolution for a crisp image on high
// DPI displays. Scaling the size here causes the SVG to be rasterized at the
// correct resolution and causes the canvas that it is rasterized into being
// the correct size so that the cursor is not clipped.
IntSize scaled_size = Size();
scaled_size.Scale(device_scale_factor);
auto builder =
CreatePaintImageBuilder().set_completion_state(completion_state());
// TODO(fs): Pass |device_scale_factor| as zoom.
PopulatePaintRecordForCurrentFrameForContainer(builder, scaled_size, 1,
NullURL());
PaintImage paint_image = builder.TakePaintImage();
if (!paint_image)
return {};
sk_sp<SkImage> sk_image = paint_image.GetSkImage();
if (!sk_image)
return {};
SkBitmap bitmap;
sk_image->asLegacyBitmap(&bitmap);
return bitmap;
}
} // namespace blink
......@@ -126,8 +126,6 @@ class CORE_EXPORT SVGImage final : public Image {
PaintImage PaintImageForCurrentFrame() override;
SkBitmap AsSkBitmapForCursor(float device_scale_factor);
protected:
// Whether or not size is available yet.
bool IsSizeAvailable() override;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment