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

SVGImage::PopulatePaintRecordForCurrentFrameForContainer need zoom

SVGImageForContainer::PaintImageForCurrentFrame() doesn't pass on zoom,
and will thus produce a result an image that differs from how the same
image would look if it was painted using a more direct code-path - such
as Draw().
Add a |zoom| argument to
SVGImage::PopulatePaintRecordForCurrentFrameForContainer and adjust
callers to pass a relevant zoom-factor. Re-order the order of the
arguments to match other methods that accept zoom.

Bug: 1121177
Change-Id: If2e1abe8ee3f9f29e176044b1ea3261bc300a87f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2368593Reviewed-by: default avatarPhilip Rogers <pdr@chromium.org>
Commit-Queue: Fredrik Söderquist <fs@opera.com>
Cr-Commit-Position: refs/heads/master@{#801303}
parent 4bd14869
...@@ -410,7 +410,7 @@ void SVGImage::DrawForContainer(cc::PaintCanvas* canvas, ...@@ -410,7 +410,7 @@ void SVGImage::DrawForContainer(cc::PaintCanvas* canvas,
PaintImage SVGImage::PaintImageForCurrentFrame() { PaintImage SVGImage::PaintImageForCurrentFrame() {
auto builder = auto builder =
CreatePaintImageBuilder().set_completion_state(completion_state()); CreatePaintImageBuilder().set_completion_state(completion_state());
PopulatePaintRecordForCurrentFrameForContainer(builder, NullURL(), Size()); PopulatePaintRecordForCurrentFrameForContainer(builder, Size(), 1, NullURL());
return builder.TakePaintImage(); return builder.TakePaintImage();
} }
...@@ -489,16 +489,21 @@ sk_sp<PaintRecord> SVGImage::PaintRecordForContainer( ...@@ -489,16 +489,21 @@ sk_sp<PaintRecord> SVGImage::PaintRecordForContainer(
void SVGImage::PopulatePaintRecordForCurrentFrameForContainer( void SVGImage::PopulatePaintRecordForCurrentFrameForContainer(
PaintImageBuilder& builder, PaintImageBuilder& builder,
const KURL& url, const IntSize& zoomed_container_size,
const IntSize& container_size) { float zoom,
const KURL& url) {
if (!page_) if (!page_)
return; return;
const IntRect container_rect(IntPoint(), container_size); const IntRect container_rect(IntPoint(), zoomed_container_size);
// Compute a new container size based on the zoomed (and potentially
// rounded) size.
FloatSize container_size(zoomed_container_size);
container_size.Scale(1 / zoom);
PaintRecorder recorder; PaintRecorder recorder;
cc::PaintCanvas* canvas = recorder.beginRecording(container_rect); cc::PaintCanvas* canvas = recorder.beginRecording(container_rect);
DrawForContainer(canvas, PaintFlags(), FloatSize(container_rect.Size()), 1, DrawForContainer(canvas, PaintFlags(), container_size, zoom,
FloatRect(container_rect), FloatRect(container_rect), url); FloatRect(container_rect), FloatRect(container_rect), url);
builder.set_paint_record(recorder.finishRecordingAsPicture(), container_rect, builder.set_paint_record(recorder.finishRecordingAsPicture(), container_rect,
PaintImage::GetNextContentId()); PaintImage::GetNextContentId());
...@@ -937,8 +942,9 @@ SkBitmap SVGImage::AsSkBitmapForCursor(float device_scale_factor) { ...@@ -937,8 +942,9 @@ SkBitmap SVGImage::AsSkBitmapForCursor(float device_scale_factor) {
auto builder = auto builder =
CreatePaintImageBuilder().set_completion_state(completion_state()); CreatePaintImageBuilder().set_completion_state(completion_state());
PopulatePaintRecordForCurrentFrameForContainer(builder, NullURL(), // TODO(fs): Pass |device_scale_factor| as zoom.
scaled_size); PopulatePaintRecordForCurrentFrameForContainer(builder, scaled_size, 1,
NullURL());
PaintImage paint_image = builder.TakePaintImage(); PaintImage paint_image = builder.TakePaintImage();
if (!paint_image) if (!paint_image)
......
...@@ -181,8 +181,9 @@ class CORE_EXPORT SVGImage final : public Image { ...@@ -181,8 +181,9 @@ class CORE_EXPORT SVGImage final : public Image {
const KURL&); const KURL&);
void PopulatePaintRecordForCurrentFrameForContainer( void PopulatePaintRecordForCurrentFrameForContainer(
PaintImageBuilder&, PaintImageBuilder&,
const KURL&, const IntSize& container_size,
const IntSize& container_size); float zoom,
const KURL&);
// Paints the current frame. Returns new PaintRecord. // Paints the current frame. Returns new PaintRecord.
sk_sp<PaintRecord> PaintRecordForCurrentFrame(const KURL&); sk_sp<PaintRecord> PaintRecordForCurrentFrame(const KURL&);
......
...@@ -72,7 +72,8 @@ bool SVGImageForContainer::ApplyShader(cc::PaintFlags& flags, ...@@ -72,7 +72,8 @@ bool SVGImageForContainer::ApplyShader(cc::PaintFlags& flags,
PaintImage SVGImageForContainer::PaintImageForCurrentFrame() { PaintImage SVGImageForContainer::PaintImageForCurrentFrame() {
auto builder = CreatePaintImageBuilder().set_completion_state( auto builder = CreatePaintImageBuilder().set_completion_state(
image_->completion_state()); image_->completion_state());
image_->PopulatePaintRecordForCurrentFrameForContainer(builder, url_, Size()); image_->PopulatePaintRecordForCurrentFrameForContainer(builder, Size(), zoom_,
url_);
return builder.TakePaintImage(); return builder.TakePaintImage();
} }
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_SVG_GRAPHICS_SVG_IMAGE_FOR_CONTAINER_H_ #ifndef THIRD_PARTY_BLINK_RENDERER_CORE_SVG_GRAPHICS_SVG_IMAGE_FOR_CONTAINER_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_SVG_GRAPHICS_SVG_IMAGE_FOR_CONTAINER_H_ #define THIRD_PARTY_BLINK_RENDERER_CORE_SVG_GRAPHICS_SVG_IMAGE_FOR_CONTAINER_H_
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/svg/graphics/svg_image.h" #include "third_party/blink/renderer/core/svg/graphics/svg_image.h"
#include "third_party/blink/renderer/platform/geometry/float_rect.h" #include "third_party/blink/renderer/platform/geometry/float_rect.h"
#include "third_party/blink/renderer/platform/geometry/float_size.h" #include "third_party/blink/renderer/platform/geometry/float_size.h"
...@@ -54,7 +55,7 @@ namespace blink { ...@@ -54,7 +55,7 @@ namespace blink {
// //
// SVGImageForContainer stores this per-use information and delegates to the // SVGImageForContainer stores this per-use information and delegates to the
// SVGImage for how to draw the image. // SVGImage for how to draw the image.
class SVGImageForContainer final : public Image { class CORE_EXPORT SVGImageForContainer final : public Image {
USING_FAST_MALLOC(SVGImageForContainer); USING_FAST_MALLOC(SVGImageForContainer);
public: public:
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "third_party/blink/renderer/core/paint/paint_layer.h" #include "third_party/blink/renderer/core/paint/paint_layer.h"
#include "third_party/blink/renderer/core/svg/animation/smil_time_container.h" #include "third_party/blink/renderer/core/svg/animation/smil_time_container.h"
#include "third_party/blink/renderer/core/svg/graphics/svg_image_chrome_client.h" #include "third_party/blink/renderer/core/svg/graphics/svg_image_chrome_client.h"
#include "third_party/blink/renderer/core/svg/graphics/svg_image_for_container.h"
#include "third_party/blink/renderer/core/svg/svg_svg_element.h" #include "third_party/blink/renderer/core/svg/svg_svg_element.h"
#include "third_party/blink/renderer/core/testing/sim/sim_request.h" #include "third_party/blink/renderer/core/testing/sim/sim_request.h"
#include "third_party/blink/renderer/core/testing/sim/sim_test.h" #include "third_party/blink/renderer/core/testing/sim/sim_test.h"
...@@ -234,6 +235,27 @@ TEST_F(SVGImageTest, DisablesSMILEvents) { ...@@ -234,6 +235,27 @@ TEST_F(SVGImageTest, DisablesSMILEvents) {
EXPECT_TRUE(time_container->EventsDisabled()); EXPECT_TRUE(time_container->EventsDisabled());
} }
TEST_F(SVGImageTest, PaintFrameForCurrentFrameWithMQAndZoom) {
const bool kShouldPause = false;
Load(R"SVG(
<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 10'>
<style>@media(max-width:50px){rect{fill:blue}}</style>
<rect width='10' height='10' fill='red'/>
</svg>)SVG",
kShouldPause);
scoped_refptr<SVGImageForContainer> container = SVGImageForContainer::Create(
&GetImage(), FloatSize(100, 100), 2, NullURL());
SkBitmap bitmap =
container->AsSkBitmapForCurrentFrame(kDoNotRespectImageOrientation);
ASSERT_EQ(bitmap.width(), 100);
ASSERT_EQ(bitmap.height(), 100);
EXPECT_EQ(bitmap.getColor(10, 10), SK_ColorBLUE);
EXPECT_EQ(bitmap.getColor(90, 10), SK_ColorBLUE);
EXPECT_EQ(bitmap.getColor(10, 90), SK_ColorBLUE);
EXPECT_EQ(bitmap.getColor(90, 90), SK_ColorBLUE);
}
class SVGImageSimTest : public SimTest, private ScopedMockOverlayScrollbars {}; class SVGImageSimTest : public SimTest, private ScopedMockOverlayScrollbars {};
TEST_F(SVGImageSimTest, PageVisibilityHiddenToVisible) { TEST_F(SVGImageSimTest, PageVisibilityHiddenToVisible) {
......
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