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

Use a DrawInfo for passing per-draw information in SVGImage

The new class DrawInfo packages the various parameters used when drawing
an SVGImage - container size, zoom and URL.
The intent is to reduce the amount of arguments that needs to be passed
around as well as prepare for better (more centralized) handling of the
container size to get better control of the various representations used
(FloatSize, LayoutSize, IntSize).

Also move DrawNeedsLayer() closer to its user and perform minor tweaks
to DrawPatternForContainer() (reorder matrix setup; return PaintRecord
directly to MakePaintRecord).

Change-Id: Id231682c9d85a322a3c585a75b2793a68628c348
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2550915Reviewed-by: default avatarStephen Chenney <schenney@chromium.org>
Commit-Queue: Fredrik Söderquist <fs@opera.com>
Cr-Commit-Position: refs/heads/master@{#830131}
parent f62142c6
...@@ -144,6 +144,22 @@ class CORE_EXPORT SVGImage final : public Image { ...@@ -144,6 +144,22 @@ class CORE_EXPORT SVGImage final : public Image {
// FIXME: Implement this to be less conservative. // FIXME: Implement this to be less conservative.
bool CurrentFrameKnownToBeOpaque() override { return false; } bool CurrentFrameKnownToBeOpaque() override { return false; }
class DrawInfo {
STACK_ALLOCATED();
public:
DrawInfo(const FloatSize& container_size, float zoom, const KURL& url);
float Zoom() const { return zoom_; }
const FloatSize& ContainerSize() const { return container_size_; }
const KURL& Url() const { return url_; }
private:
const FloatSize container_size_;
const float zoom_;
const KURL& url_;
};
void Draw(cc::PaintCanvas*, void Draw(cc::PaintCanvas*,
const cc::PaintFlags&, const cc::PaintFlags&,
const FloatRect& dst_rect, const FloatRect& dst_rect,
...@@ -151,50 +167,41 @@ class CORE_EXPORT SVGImage final : public Image { ...@@ -151,50 +167,41 @@ class CORE_EXPORT SVGImage final : public Image {
RespectImageOrientationEnum, RespectImageOrientationEnum,
ImageClampingMode, ImageClampingMode,
ImageDecodingMode) override; ImageDecodingMode) override;
void DrawForContainer(cc::PaintCanvas*, void DrawForContainer(const DrawInfo&,
cc::PaintCanvas*,
const cc::PaintFlags&, const cc::PaintFlags&,
const FloatSize&, const FloatRect& dst_rect,
float, const FloatRect& src_rect);
const FloatRect&, void DrawPatternForContainer(const DrawInfo&,
const FloatRect&, GraphicsContext&,
const KURL&); const FloatRect& src_rect,
void DrawPatternForContainer(GraphicsContext&, const FloatSize& tile_scale,
const FloatSize, const FloatPoint& phase,
float, SkBlendMode composite_op,
const FloatRect&, const FloatRect& dst_rect,
const FloatSize&, const FloatSize& repeat_spacing);
const FloatPoint&, void PopulatePaintRecordForCurrentFrameForContainer(const DrawInfo&,
SkBlendMode, PaintImageBuilder&);
const FloatRect&,
const FloatSize& repeat_spacing,
const KURL&);
void PopulatePaintRecordForCurrentFrameForContainer(
PaintImageBuilder&,
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 DrawInfo&);
void DrawInternal(cc::PaintCanvas*, void DrawInternal(const DrawInfo&,
cc::PaintCanvas*,
const cc::PaintFlags&, const cc::PaintFlags&,
const FloatRect& dst_rect, const FloatRect& dst_rect,
const FloatRect& src_rect, const FloatRect& src_rect);
const KURL&);
template <typename Func> template <typename Func>
void ForContainer(const FloatSize&, Func&&); void ForContainer(const DrawInfo&, Func&&);
bool ApplyShader(cc::PaintFlags&, const SkMatrix& local_matrix) override; bool ApplyShader(cc::PaintFlags&, const SkMatrix& local_matrix) override;
bool ApplyShaderForContainer(const FloatSize&, bool ApplyShaderForContainer(const DrawInfo&,
float zoom, cc::PaintFlags&,
const KURL&, const SkMatrix& local_matrix);
bool ApplyShaderInternal(const DrawInfo&,
cc::PaintFlags&, cc::PaintFlags&,
const SkMatrix& local_matrix); const SkMatrix& local_matrix);
bool ApplyShaderInternal(cc::PaintFlags&,
const SkMatrix& local_matrix,
const KURL&);
void StopAnimation(); void StopAnimation();
void ScheduleTimelineRewind(); void ScheduleTimelineRewind();
......
...@@ -19,12 +19,6 @@ ...@@ -19,12 +19,6 @@
#include "third_party/blink/renderer/core/svg/graphics/svg_image_for_container.h" #include "third_party/blink/renderer/core/svg/graphics/svg_image_for_container.h"
#include "base/memory/scoped_refptr.h"
#include "third_party/blink/renderer/platform/geometry/float_rect.h"
#include "third_party/blink/renderer/platform/geometry/float_size.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkImage.h"
namespace blink { namespace blink {
IntSize SVGImageForContainer::Size() const { IntSize SVGImageForContainer::Size() const {
...@@ -34,9 +28,7 @@ IntSize SVGImageForContainer::Size() const { ...@@ -34,9 +28,7 @@ IntSize SVGImageForContainer::Size() const {
} }
FloatSize SVGImageForContainer::SizeAsFloat(RespectImageOrientationEnum) const { FloatSize SVGImageForContainer::SizeAsFloat(RespectImageOrientationEnum) const {
FloatSize scaled_container_size(container_size_); return container_size_.ScaledBy(zoom_);
scaled_container_size.Scale(zoom_);
return scaled_container_size;
} }
void SVGImageForContainer::Draw(cc::PaintCanvas* canvas, void SVGImageForContainer::Draw(cc::PaintCanvas* canvas,
...@@ -46,8 +38,8 @@ void SVGImageForContainer::Draw(cc::PaintCanvas* canvas, ...@@ -46,8 +38,8 @@ void SVGImageForContainer::Draw(cc::PaintCanvas* canvas,
RespectImageOrientationEnum, RespectImageOrientationEnum,
ImageClampingMode, ImageClampingMode,
ImageDecodingMode) { ImageDecodingMode) {
image_->DrawForContainer(canvas, flags, container_size_, zoom_, dst_rect, const SVGImage::DrawInfo draw_info(container_size_, zoom_, url_);
src_rect, url_); image_->DrawForContainer(draw_info, canvas, flags, dst_rect, src_rect);
} }
void SVGImageForContainer::DrawPattern(GraphicsContext& context, void SVGImageForContainer::DrawPattern(GraphicsContext& context,
...@@ -58,21 +50,21 @@ void SVGImageForContainer::DrawPattern(GraphicsContext& context, ...@@ -58,21 +50,21 @@ void SVGImageForContainer::DrawPattern(GraphicsContext& context,
const FloatRect& dst_rect, const FloatRect& dst_rect,
const FloatSize& repeat_spacing, const FloatSize& repeat_spacing,
RespectImageOrientationEnum) { RespectImageOrientationEnum) {
image_->DrawPatternForContainer(context, container_size_, zoom_, src_rect, const SVGImage::DrawInfo draw_info(container_size_, zoom_, url_);
scale, phase, op, dst_rect, repeat_spacing, image_->DrawPatternForContainer(draw_info, context, src_rect, scale, phase,
url_); op, dst_rect, repeat_spacing);
} }
bool SVGImageForContainer::ApplyShader(cc::PaintFlags& flags, bool SVGImageForContainer::ApplyShader(cc::PaintFlags& flags,
const SkMatrix& local_matrix) { const SkMatrix& local_matrix) {
return image_->ApplyShaderForContainer(container_size_, zoom_, url_, flags, const SVGImage::DrawInfo draw_info(container_size_, zoom_, url_);
local_matrix); return image_->ApplyShaderForContainer(draw_info, flags, local_matrix);
} }
PaintImage SVGImageForContainer::PaintImageForCurrentFrame() { PaintImage SVGImageForContainer::PaintImageForCurrentFrame() {
const SVGImage::DrawInfo draw_info(container_size_, zoom_, url_);
auto builder = CreatePaintImageBuilder(); auto builder = CreatePaintImageBuilder();
image_->PopulatePaintRecordForCurrentFrameForContainer(builder, Size(), zoom_, image_->PopulatePaintRecordForCurrentFrameForContainer(draw_info, builder);
url_);
return builder.TakePaintImage(); return builder.TakePaintImage();
} }
......
...@@ -32,7 +32,6 @@ ...@@ -32,7 +32,6 @@
#include "third_party/blink/renderer/platform/geometry/float_size.h" #include "third_party/blink/renderer/platform/geometry/float_size.h"
#include "third_party/blink/renderer/platform/graphics/image.h" #include "third_party/blink/renderer/platform/graphics/image.h"
#include "third_party/blink/renderer/platform/weborigin/kurl.h" #include "third_party/blink/renderer/platform/weborigin/kurl.h"
#include "third_party/skia/include/core/SkRefCnt.h"
namespace blink { namespace blink {
......
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