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

Remove Image::PaintRecordForContainer

This interface has a single user and is overridden by a single subclass
(SVGImage), so it seems more pertinent to just implement this using
other existing building blocks.

Change-Id: I241c382c71052821e59280cd4cee10d2deef33dd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2372285
Commit-Queue: Fredrik Söderquist <fs@opera.com>
Reviewed-by: default avatarStephen Chenney <schenney@chromium.org>
Cr-Commit-Position: refs/heads/master@{#801702}
parent b39ee7d6
...@@ -144,6 +144,7 @@ ScriptPromise ImageElementBase::CreateImageBitmap( ...@@ -144,6 +144,7 @@ ScriptPromise ImageElementBase::CreateImageBitmap(
"specified."); "specified.");
return ScriptPromise(); return ScriptPromise();
} }
// The following function only works on SVGImages (as checked above).
return ImageBitmap::CreateAsync(this, crop_rect, script_state, options); return ImageBitmap::CreateAsync(this, crop_rect, script_state, options);
} }
return ImageBitmapSource::FulfillImageBitmap( return ImageBitmapSource::FulfillImageBitmap(
......
...@@ -16,8 +16,10 @@ ...@@ -16,8 +16,10 @@
#include "third_party/blink/renderer/core/dom/dom_exception.h" #include "third_party/blink/renderer/core/dom/dom_exception.h"
#include "third_party/blink/renderer/core/html/canvas/html_canvas_element.h" #include "third_party/blink/renderer/core/html/canvas/html_canvas_element.h"
#include "third_party/blink/renderer/core/html/canvas/image_data.h" #include "third_party/blink/renderer/core/html/canvas/image_data.h"
#include "third_party/blink/renderer/core/html/canvas/image_element_base.h"
#include "third_party/blink/renderer/core/html/media/html_video_element.h" #include "third_party/blink/renderer/core/html/media/html_video_element.h"
#include "third_party/blink/renderer/core/offscreencanvas/offscreen_canvas.h" #include "third_party/blink/renderer/core/offscreencanvas/offscreen_canvas.h"
#include "third_party/blink/renderer/core/svg/graphics/svg_image_for_container.h"
#include "third_party/blink/renderer/platform/bindings/enumeration_base.h" #include "third_party/blink/renderer/platform/bindings/enumeration_base.h"
#include "third_party/blink/renderer/platform/graphics/accelerated_static_bitmap_image.h" #include "third_party/blink/renderer/platform/graphics/accelerated_static_bitmap_image.h"
#include "third_party/blink/renderer/platform/graphics/canvas_color_params.h" #include "third_party/blink/renderer/platform/graphics/canvas_color_params.h"
...@@ -998,7 +1000,6 @@ ScriptPromise ImageBitmap::CreateAsync(ImageElementBase* image, ...@@ -998,7 +1000,6 @@ ScriptPromise ImageBitmap::CreateAsync(ImageElementBase* image,
auto* resolver = MakeGarbageCollected<ScriptPromiseResolver>(script_state); auto* resolver = MakeGarbageCollected<ScriptPromiseResolver>(script_state);
ScriptPromise promise = resolver->Promise(); ScriptPromise promise = resolver->Promise();
scoped_refptr<Image> input = image->CachedImage()->GetImage();
ParsedOptions parsed_options = ParsedOptions parsed_options =
ParseOptions(options, crop_rect, image->BitmapSourceSize()); ParseOptions(options, crop_rect, image->BitmapSourceSize());
if (DstBufferSizeHasOverflow(parsed_options)) { if (DstBufferSizeHasOverflow(parsed_options)) {
...@@ -1008,13 +1009,14 @@ ScriptPromise ImageBitmap::CreateAsync(ImageElementBase* image, ...@@ -1008,13 +1009,14 @@ ScriptPromise ImageBitmap::CreateAsync(ImageElementBase* image,
return promise; return promise;
} }
scoped_refptr<Image> input = image->CachedImage()->GetImage();
DCHECK(input->IsSVGImage());
IntRect input_rect(IntPoint(), input->Size()); IntRect input_rect(IntPoint(), input->Size());
const IntRect src_rect = Intersection(input_rect, parsed_options.crop_rect);
// In the case when |crop_rect| doesn't intersect the source image, we return // In the case when |crop_rect| doesn't intersect the source image, we return
// a transparent black image, respecting the color_params but ignoring // a transparent black image, respecting the color_params but ignoring
// poremultiply_alpha. // premultiply_alpha.
if (src_rect.IsEmpty()) { if (!parsed_options.crop_rect.Intersects(input_rect)) {
ImageBitmap* bitmap = ImageBitmap* bitmap =
MakeGarbageCollected<ImageBitmap>(MakeBlankImage(parsed_options)); MakeGarbageCollected<ImageBitmap>(MakeBlankImage(parsed_options));
if (bitmap->BitmapImage()) { if (bitmap->BitmapImage()) {
...@@ -1031,9 +1033,21 @@ ScriptPromise ImageBitmap::CreateAsync(ImageElementBase* image, ...@@ -1031,9 +1033,21 @@ ScriptPromise ImageBitmap::CreateAsync(ImageElementBase* image,
IntRect draw_src_rect(parsed_options.crop_rect); IntRect draw_src_rect(parsed_options.crop_rect);
IntRect draw_dst_rect(0, 0, parsed_options.resize_width, IntRect draw_dst_rect(0, 0, parsed_options.resize_width,
parsed_options.resize_height); parsed_options.resize_height);
sk_sp<PaintRecord> paint_record = PaintRecorder recorder;
input->PaintRecordForContainer(NullURL(), input->Size(), draw_src_rect, cc::PaintCanvas* canvas = recorder.beginRecording(draw_src_rect);
draw_dst_rect, parsed_options.flip_y); if (parsed_options.flip_y) {
canvas->translate(0, draw_dst_rect.Height());
canvas->scale(1, -1);
}
SVGImageForContainer::Create(To<SVGImage>(input.get()),
FloatSize(input_rect.Size()), 1, NullURL())
->Draw(canvas, cc::PaintFlags(), FloatRect(draw_dst_rect),
FloatRect(draw_src_rect),
// The following will all be ignored.
kRespectImageOrientation, Image::kDoNotClampImageToSourceRect,
Image::kSyncDecode);
sk_sp<PaintRecord> paint_record = recorder.finishRecordingAsPicture();
std::unique_ptr<ParsedOptions> passed_parsed_options = std::unique_ptr<ParsedOptions> passed_parsed_options =
std::make_unique<ParsedOptions>(parsed_options); std::make_unique<ParsedOptions>(parsed_options);
worker_pool::PostTask( worker_pool::PostTask(
......
...@@ -11,12 +11,12 @@ ...@@ -11,12 +11,12 @@
#include "third_party/blink/renderer/bindings/core/v8/v8_image_bitmap_options.h" #include "third_party/blink/renderer/bindings/core/v8/v8_image_bitmap_options.h"
#include "third_party/blink/renderer/core/core_export.h" #include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/html/canvas/canvas_image_source.h" #include "third_party/blink/renderer/core/html/canvas/canvas_image_source.h"
#include "third_party/blink/renderer/core/html/canvas/image_element_base.h"
#include "third_party/blink/renderer/core/imagebitmap/image_bitmap_source.h" #include "third_party/blink/renderer/core/imagebitmap/image_bitmap_source.h"
#include "third_party/blink/renderer/platform/bindings/script_wrappable.h" #include "third_party/blink/renderer/platform/bindings/script_wrappable.h"
#include "third_party/blink/renderer/platform/geometry/int_rect.h" #include "third_party/blink/renderer/platform/geometry/int_rect.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/graphics/image_orientation.h" #include "third_party/blink/renderer/platform/graphics/image_orientation.h"
#include "third_party/blink/renderer/platform/graphics/paint/paint_record.h"
#include "third_party/blink/renderer/platform/graphics/static_bitmap_image.h" #include "third_party/blink/renderer/platform/graphics/static_bitmap_image.h"
#include "third_party/blink/renderer/platform/heap/handle.h" #include "third_party/blink/renderer/platform/heap/handle.h"
#include "third_party/blink/renderer/platform/wtf/functional.h" #include "third_party/blink/renderer/platform/wtf/functional.h"
...@@ -26,6 +26,7 @@ namespace blink { ...@@ -26,6 +26,7 @@ namespace blink {
class HTMLCanvasElement; class HTMLCanvasElement;
class HTMLVideoElement; class HTMLVideoElement;
class ImageData; class ImageData;
class ImageElementBase;
class ImageDecoder; class ImageDecoder;
class OffscreenCanvas; class OffscreenCanvas;
...@@ -40,6 +41,7 @@ class CORE_EXPORT ImageBitmap final : public ScriptWrappable, ...@@ -40,6 +41,7 @@ class CORE_EXPORT ImageBitmap final : public ScriptWrappable,
DEFINE_WRAPPERTYPEINFO(); DEFINE_WRAPPERTYPEINFO();
public: public:
// Expects the ImageElementBase to return/have an SVGImage.
static ScriptPromise CreateAsync( static ScriptPromise CreateAsync(
ImageElementBase*, ImageElementBase*,
base::Optional<IntRect>, base::Optional<IntRect>,
......
...@@ -467,26 +467,6 @@ void SVGImage::DrawPatternForContainer(GraphicsContext& context, ...@@ -467,26 +467,6 @@ void SVGImage::DrawPatternForContainer(GraphicsContext& context,
StartAnimation(); StartAnimation();
} }
sk_sp<PaintRecord> SVGImage::PaintRecordForContainer(
const KURL& url,
const IntSize& container_size,
const IntRect& draw_src_rect,
const IntRect& draw_dst_rect,
bool flip_y) {
if (!page_)
return nullptr;
PaintRecorder recorder;
cc::PaintCanvas* canvas = recorder.beginRecording(draw_src_rect);
if (flip_y) {
canvas->translate(0, draw_dst_rect.Height());
canvas->scale(1, -1);
}
DrawForContainer(canvas, PaintFlags(), FloatSize(container_size), 1,
FloatRect(draw_dst_rect), FloatRect(draw_src_rect), url);
return recorder.finishRecordingAsPicture();
}
void SVGImage::PopulatePaintRecordForCurrentFrameForContainer( void SVGImage::PopulatePaintRecordForCurrentFrameForContainer(
PaintImageBuilder& builder, PaintImageBuilder& builder,
const IntSize& zoomed_container_size, const IntSize& zoomed_container_size,
......
...@@ -118,12 +118,6 @@ class CORE_EXPORT SVGImage final : public Image { ...@@ -118,12 +118,6 @@ class CORE_EXPORT SVGImage final : public Image {
// object size is non-empty.) // object size is non-empty.)
bool HasIntrinsicDimensions() const; bool HasIntrinsicDimensions() const;
sk_sp<PaintRecord> PaintRecordForContainer(const KURL&,
const IntSize& container_size,
const IntRect& draw_src_rect,
const IntRect& draw_dst_rect,
bool flip_y) override;
PaintImage PaintImageForCurrentFrame() override; PaintImage PaintImageForCurrentFrame() override;
protected: protected:
......
...@@ -38,7 +38,6 @@ ...@@ -38,7 +38,6 @@
#include "third_party/blink/renderer/platform/graphics/image_observer.h" #include "third_party/blink/renderer/platform/graphics/image_observer.h"
#include "third_party/blink/renderer/platform/graphics/image_orientation.h" #include "third_party/blink/renderer/platform/graphics/image_orientation.h"
#include "third_party/blink/renderer/platform/graphics/paint/paint_image.h" #include "third_party/blink/renderer/platform/graphics/paint/paint_image.h"
#include "third_party/blink/renderer/platform/graphics/paint/paint_record.h"
#include "third_party/blink/renderer/platform/heap/persistent.h" #include "third_party/blink/renderer/platform/heap/persistent.h"
#include "third_party/blink/renderer/platform/platform_export.h" #include "third_party/blink/renderer/platform/platform_export.h"
#include "third_party/blink/renderer/platform/wtf/forward.h" #include "third_party/blink/renderer/platform/wtf/forward.h"
...@@ -60,7 +59,6 @@ namespace blink { ...@@ -60,7 +59,6 @@ namespace blink {
class FloatRect; class FloatRect;
class GraphicsContext; class GraphicsContext;
class Image; class Image;
class KURL;
class WebGraphicsContext3DProvider; class WebGraphicsContext3DProvider;
class WebGraphicsContext3DProviderWrapper; class WebGraphicsContext3DProviderWrapper;
...@@ -249,15 +247,6 @@ class PLATFORM_EXPORT Image : public ThreadSafeRefCounted<Image> { ...@@ -249,15 +247,6 @@ class PLATFORM_EXPORT Image : public ThreadSafeRefCounted<Image> {
return nullptr; return nullptr;
} }
virtual sk_sp<PaintRecord> PaintRecordForContainer(
const KURL& url,
const IntSize& container_size,
const IntRect& draw_src_rect,
const IntRect& draw_dst_rect,
bool flip_y) {
return nullptr;
}
PaintImage::Id paint_image_id() const { return stable_image_id_; } PaintImage::Id paint_image_id() const { return stable_image_id_; }
// Returns an SkBitmap that is a copy of the image's current frame. // Returns an SkBitmap that is a copy of the image's current frame.
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "third_party/blink/renderer/platform/geometry/int_size.h" #include "third_party/blink/renderer/platform/geometry/int_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/graphics/image_orientation.h" #include "third_party/blink/renderer/platform/graphics/image_orientation.h"
#include "third_party/blink/renderer/platform/graphics/paint/paint_record.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h" #include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
#include "third_party/skia/include/core/SkImage.h" #include "third_party/skia/include/core/SkImage.h"
#include "third_party/skia/include/core/SkRefCnt.h" #include "third_party/skia/include/core/SkRefCnt.h"
......
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