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 {
// FIXME: Implement this to be less conservative.
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*,
const cc::PaintFlags&,
const FloatRect& dst_rect,
......@@ -151,50 +167,41 @@ class CORE_EXPORT SVGImage final : public Image {
RespectImageOrientationEnum,
ImageClampingMode,
ImageDecodingMode) override;
void DrawForContainer(cc::PaintCanvas*,
void DrawForContainer(const DrawInfo&,
cc::PaintCanvas*,
const cc::PaintFlags&,
const FloatSize&,
float,
const FloatRect&,
const FloatRect&,
const KURL&);
void DrawPatternForContainer(GraphicsContext&,
const FloatSize,
float,
const FloatRect&,
const FloatSize&,
const FloatPoint&,
SkBlendMode,
const FloatRect&,
const FloatSize& repeat_spacing,
const KURL&);
void PopulatePaintRecordForCurrentFrameForContainer(
PaintImageBuilder&,
const IntSize& container_size,
float zoom,
const KURL&);
const FloatRect& dst_rect,
const FloatRect& src_rect);
void DrawPatternForContainer(const DrawInfo&,
GraphicsContext&,
const FloatRect& src_rect,
const FloatSize& tile_scale,
const FloatPoint& phase,
SkBlendMode composite_op,
const FloatRect& dst_rect,
const FloatSize& repeat_spacing);
void PopulatePaintRecordForCurrentFrameForContainer(const DrawInfo&,
PaintImageBuilder&);
// 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 FloatRect& dst_rect,
const FloatRect& src_rect,
const KURL&);
const FloatRect& src_rect);
template <typename Func>
void ForContainer(const FloatSize&, Func&&);
void ForContainer(const DrawInfo&, Func&&);
bool ApplyShader(cc::PaintFlags&, const SkMatrix& local_matrix) override;
bool ApplyShaderForContainer(const FloatSize&,
float zoom,
const KURL&,
bool ApplyShaderForContainer(const DrawInfo&,
cc::PaintFlags&,
const SkMatrix& local_matrix);
bool ApplyShaderInternal(cc::PaintFlags&,
const SkMatrix& local_matrix,
const KURL&);
bool ApplyShaderInternal(const DrawInfo&,
cc::PaintFlags&,
const SkMatrix& local_matrix);
void StopAnimation();
void ScheduleTimelineRewind();
......
......@@ -19,12 +19,6 @@
#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 {
IntSize SVGImageForContainer::Size() const {
......@@ -34,9 +28,7 @@ IntSize SVGImageForContainer::Size() const {
}
FloatSize SVGImageForContainer::SizeAsFloat(RespectImageOrientationEnum) const {
FloatSize scaled_container_size(container_size_);
scaled_container_size.Scale(zoom_);
return scaled_container_size;
return container_size_.ScaledBy(zoom_);
}
void SVGImageForContainer::Draw(cc::PaintCanvas* canvas,
......@@ -46,8 +38,8 @@ void SVGImageForContainer::Draw(cc::PaintCanvas* canvas,
RespectImageOrientationEnum,
ImageClampingMode,
ImageDecodingMode) {
image_->DrawForContainer(canvas, flags, container_size_, zoom_, dst_rect,
src_rect, url_);
const SVGImage::DrawInfo draw_info(container_size_, zoom_, url_);
image_->DrawForContainer(draw_info, canvas, flags, dst_rect, src_rect);
}
void SVGImageForContainer::DrawPattern(GraphicsContext& context,
......@@ -58,21 +50,21 @@ void SVGImageForContainer::DrawPattern(GraphicsContext& context,
const FloatRect& dst_rect,
const FloatSize& repeat_spacing,
RespectImageOrientationEnum) {
image_->DrawPatternForContainer(context, container_size_, zoom_, src_rect,
scale, phase, op, dst_rect, repeat_spacing,
url_);
const SVGImage::DrawInfo draw_info(container_size_, zoom_, url_);
image_->DrawPatternForContainer(draw_info, context, src_rect, scale, phase,
op, dst_rect, repeat_spacing);
}
bool SVGImageForContainer::ApplyShader(cc::PaintFlags& flags,
const SkMatrix& local_matrix) {
return image_->ApplyShaderForContainer(container_size_, zoom_, url_, flags,
local_matrix);
const SVGImage::DrawInfo draw_info(container_size_, zoom_, url_);
return image_->ApplyShaderForContainer(draw_info, flags, local_matrix);
}
PaintImage SVGImageForContainer::PaintImageForCurrentFrame() {
const SVGImage::DrawInfo draw_info(container_size_, zoom_, url_);
auto builder = CreatePaintImageBuilder();
image_->PopulatePaintRecordForCurrentFrameForContainer(builder, Size(), zoom_,
url_);
image_->PopulatePaintRecordForCurrentFrameForContainer(draw_info, builder);
return builder.TakePaintImage();
}
......
......@@ -32,7 +32,6 @@
#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/weborigin/kurl.h"
#include "third_party/skia/include/core/SkRefCnt.h"
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