Commit 443daaf1 authored by Xida Chen's avatar Xida Chen Committed by Commit Bot

[Code health] Pass FloatSize to CSSPaintDefinition::Paint

Right now the CSSPaintDefinition::Paint takes a IntSize which is the
container size with subpixel snapping. At this moment there are two type
cast:
1. The call site of the CSSPaintDefinition::Paint converts a FloatSize
to IntSize
2. Inside the CSSPaintDefinition::Paint, GetSpecifiedSize is called
which type casts the IntSize to float and uses it.

This CL cleans it up by passing a FloatSize. That is, the Paint function
takes a FloatSize such that type casting can be avoided at the
GetSpecifiedSize. When we need to use the subpixel snapped size in the
Paint function, we then conver the FloatSize to an IntSize.

This CL should not introduce any behavior change.

Bug: None
Change-Id: I1387145c03b60380a0e0a53f2686647a54327e71
Reviewed-on: https://chromium-review.googlesource.com/c/1286440Reviewed-by: default avatarStephen McGruer <smcgruer@chromium.org>
Reviewed-by: default avatarAnders Ruud <andruud@chromium.org>
Commit-Queue: Xida Chen <xidachen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#600770}
parent 8981b0bd
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
#include "third_party/blink/renderer/core/core_export.h" #include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/css/cssom/css_style_value.h" #include "third_party/blink/renderer/core/css/cssom/css_style_value.h"
#include "third_party/blink/renderer/core/css_property_names.h" #include "third_party/blink/renderer/core/css_property_names.h"
#include "third_party/blink/renderer/platform/geometry/int_size.h" #include "third_party/blink/renderer/platform/geometry/float_size.h"
#include "third_party/blink/renderer/platform/heap/handle.h" #include "third_party/blink/renderer/platform/heap/handle.h"
namespace blink { namespace blink {
...@@ -50,7 +50,7 @@ class CORE_EXPORT CSSPaintImageGenerator ...@@ -50,7 +50,7 @@ class CORE_EXPORT CSSPaintImageGenerator
// representing an invalid image if an error occurred. // representing an invalid image if an error occurred.
// The |container_size| is the container size with subpixel snapping. // The |container_size| is the container size with subpixel snapping.
virtual scoped_refptr<Image> Paint(const ImageResourceObserver&, virtual scoped_refptr<Image> Paint(const ImageResourceObserver&,
const IntSize& container_size, const FloatSize& container_size,
const CSSStyleValueVector*) = 0; const CSSStyleValueVector*) = 0;
virtual const Vector<CSSPropertyID>& NativeInvalidationProperties() const = 0; virtual const Vector<CSSPropertyID>& NativeInvalidationProperties() const = 0;
......
...@@ -61,8 +61,7 @@ scoped_refptr<Image> CSSPaintValue::GetImage( ...@@ -61,8 +61,7 @@ scoped_refptr<Image> CSSPaintValue::GetImage(
if (!ParseInputArguments(document)) if (!ParseInputArguments(document))
return nullptr; return nullptr;
return generator_->Paint(client, RoundedIntSize(target_size), return generator_->Paint(client, target_size, parsed_input_arguments_);
parsed_input_arguments_);
} }
bool CSSPaintValue::ParseInputArguments(const Document& document) { bool CSSPaintValue::ParseInputArguments(const Document& document) {
......
...@@ -21,13 +21,12 @@ namespace blink { ...@@ -21,13 +21,12 @@ namespace blink {
namespace { namespace {
FloatSize GetSpecifiedSize(const IntSize& size, float zoom) { FloatSize GetSpecifiedSize(const FloatSize& size, float zoom) {
float un_zoom_factor = 1 / zoom; float un_zoom_factor = 1 / zoom;
auto un_zoom_fn = [un_zoom_factor](float a) -> float { auto un_zoom_fn = [un_zoom_factor](float a) -> float {
return a * un_zoom_factor; return a * un_zoom_factor;
}; };
return FloatSize(un_zoom_fn(static_cast<float>(size.Width())), return FloatSize(un_zoom_fn(size.Width()), un_zoom_fn(size.Height()));
un_zoom_fn(static_cast<float>(size.Height())));
} }
} // namespace } // namespace
...@@ -67,7 +66,7 @@ CSSPaintDefinition::~CSSPaintDefinition() = default; ...@@ -67,7 +66,7 @@ CSSPaintDefinition::~CSSPaintDefinition() = default;
scoped_refptr<Image> CSSPaintDefinition::Paint( scoped_refptr<Image> CSSPaintDefinition::Paint(
const ImageResourceObserver& client, const ImageResourceObserver& client,
const IntSize& container_size, const FloatSize& container_size,
const CSSStyleValueVector* paint_arguments) { const CSSStyleValueVector* paint_arguments) {
// TODO: Break dependency on LayoutObject. Passing the Node should work. // TODO: Break dependency on LayoutObject. Passing the Node should work.
const LayoutObject& layout_object = static_cast<const LayoutObject&>(client); const LayoutObject& layout_object = static_cast<const LayoutObject&>(client);
...@@ -93,8 +92,9 @@ scoped_refptr<Image> CSSPaintDefinition::Paint( ...@@ -93,8 +92,9 @@ scoped_refptr<Image> CSSPaintDefinition::Paint(
color_params.SetOpacityMode(kOpaque); color_params.SetOpacityMode(kOpaque);
} }
// Do subpixel snapping for the |container_size|.
PaintRenderingContext2D* rendering_context = PaintRenderingContext2D::Create( PaintRenderingContext2D* rendering_context = PaintRenderingContext2D::Create(
container_size, color_params, context_settings_, zoom); RoundedIntSize(container_size), color_params, context_settings_, zoom);
PaintSize* paint_size = PaintSize::Create(specified_size); PaintSize* paint_size = PaintSize::Create(specified_size);
StylePropertyMapReadOnly* style_map = StylePropertyMapReadOnly* style_map =
new PrepopulatedComputedStylePropertyMap( new PrepopulatedComputedStylePropertyMap(
...@@ -131,7 +131,7 @@ scoped_refptr<Image> CSSPaintDefinition::Paint( ...@@ -131,7 +131,7 @@ scoped_refptr<Image> CSSPaintDefinition::Paint(
} }
return PaintGeneratedImage::Create(rendering_context->GetRecord(), return PaintGeneratedImage::Create(rendering_context->GetRecord(),
FloatSize(container_size)); container_size);
} }
void CSSPaintDefinition::MaybeCreatePaintInstance() { void CSSPaintDefinition::MaybeCreatePaintInstance() {
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
#include "third_party/blink/renderer/platform/bindings/name_client.h" #include "third_party/blink/renderer/platform/bindings/name_client.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/bindings/trace_wrapper_v8_reference.h" #include "third_party/blink/renderer/platform/bindings/trace_wrapper_v8_reference.h"
#include "third_party/blink/renderer/platform/geometry/int_size.h" #include "third_party/blink/renderer/platform/geometry/float_size.h"
#include "third_party/blink/renderer/platform/heap/handle.h" #include "third_party/blink/renderer/platform/heap/handle.h"
#include "v8/include/v8.h" #include "v8/include/v8.h"
...@@ -47,9 +47,9 @@ class MODULES_EXPORT CSSPaintDefinition final ...@@ -47,9 +47,9 @@ class MODULES_EXPORT CSSPaintDefinition final
// This may return a nullptr (representing an invalid image) if javascript // This may return a nullptr (representing an invalid image) if javascript
// throws an error. // throws an error.
// //
// The |container_size| is the container size with subpixel snapping. // The |container_size| is without subpixel snapping.
scoped_refptr<Image> Paint(const ImageResourceObserver&, scoped_refptr<Image> Paint(const ImageResourceObserver&,
const IntSize& container_size, const FloatSize& container_size,
const CSSStyleValueVector*); const CSSStyleValueVector*);
const Vector<CSSPropertyID>& NativeInvalidationProperties() const { const Vector<CSSPropertyID>& NativeInvalidationProperties() const {
return native_invalidation_properties_; return native_invalidation_properties_;
......
...@@ -51,7 +51,7 @@ void CSSPaintImageGeneratorImpl::NotifyGeneratorReady() { ...@@ -51,7 +51,7 @@ void CSSPaintImageGeneratorImpl::NotifyGeneratorReady() {
scoped_refptr<Image> CSSPaintImageGeneratorImpl::Paint( scoped_refptr<Image> CSSPaintImageGeneratorImpl::Paint(
const ImageResourceObserver& observer, const ImageResourceObserver& observer,
const IntSize& container_size, const FloatSize& container_size,
const CSSStyleValueVector* data) { const CSSStyleValueVector* data) {
return paint_worklet_->Paint(name_, observer, container_size, data); return paint_worklet_->Paint(name_, observer, container_size, data);
} }
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#include "third_party/blink/renderer/core/css/cssom/css_style_value.h" #include "third_party/blink/renderer/core/css/cssom/css_style_value.h"
#include "third_party/blink/renderer/modules/modules_export.h" #include "third_party/blink/renderer/modules/modules_export.h"
#include "third_party/blink/renderer/platform/bindings/scoped_persistent.h" #include "third_party/blink/renderer/platform/bindings/scoped_persistent.h"
#include "third_party/blink/renderer/platform/geometry/int_size.h" #include "third_party/blink/renderer/platform/geometry/float_size.h"
#include "third_party/blink/renderer/platform/heap/handle.h" #include "third_party/blink/renderer/platform/heap/handle.h"
#include "v8/include/v8.h" #include "v8/include/v8.h"
...@@ -29,9 +29,9 @@ class MODULES_EXPORT CSSPaintImageGeneratorImpl final ...@@ -29,9 +29,9 @@ class MODULES_EXPORT CSSPaintImageGeneratorImpl final
Observer*); Observer*);
~CSSPaintImageGeneratorImpl() override; ~CSSPaintImageGeneratorImpl() override;
// The |container_size| is the container size with subpixel snapping. // The |container_size| is without subpixel snapping.
scoped_refptr<Image> Paint(const ImageResourceObserver&, scoped_refptr<Image> Paint(const ImageResourceObserver&,
const IntSize& container_size, const FloatSize& container_size,
const CSSStyleValueVector*) final; const CSSStyleValueVector*) final;
const Vector<CSSPropertyID>& NativeInvalidationProperties() const final; const Vector<CSSPropertyID>& NativeInvalidationProperties() const final;
const Vector<AtomicString>& CustomInvalidationProperties() const final; const Vector<AtomicString>& CustomInvalidationProperties() const final;
......
...@@ -88,7 +88,7 @@ size_t PaintWorklet::SelectNewGlobalScope() { ...@@ -88,7 +88,7 @@ size_t PaintWorklet::SelectNewGlobalScope() {
scoped_refptr<Image> PaintWorklet::Paint(const String& name, scoped_refptr<Image> PaintWorklet::Paint(const String& name,
const ImageResourceObserver& observer, const ImageResourceObserver& observer,
const IntSize& container_size, const FloatSize& container_size,
const CSSStyleValueVector* data) { const CSSStyleValueVector* data) {
if (!document_definition_map_.Contains(name)) if (!document_definition_map_.Contains(name))
return nullptr; return nullptr;
......
...@@ -36,10 +36,10 @@ class MODULES_EXPORT PaintWorklet : public Worklet, ...@@ -36,10 +36,10 @@ class MODULES_EXPORT PaintWorklet : public Worklet,
~PaintWorklet() override; ~PaintWorklet() override;
void AddPendingGenerator(const String& name, CSSPaintImageGeneratorImpl*); void AddPendingGenerator(const String& name, CSSPaintImageGeneratorImpl*);
// The |container_size| is the container size with subpixel snapping. // The |container_size| is without subpixel snapping.
scoped_refptr<Image> Paint(const String& name, scoped_refptr<Image> Paint(const String& name,
const ImageResourceObserver&, const ImageResourceObserver&,
const IntSize& container_size, const FloatSize& container_size,
const CSSStyleValueVector*); const CSSStyleValueVector*);
typedef HeapHashMap<String, Member<DocumentPaintDefinition>> typedef HeapHashMap<String, Member<DocumentPaintDefinition>>
......
...@@ -157,7 +157,7 @@ TEST_F(PaintWorkletTest, PaintWithNullPaintArguments) { ...@@ -157,7 +157,7 @@ TEST_F(PaintWorkletTest, PaintWithNullPaintArguments) {
ImageResourceObserver* observer = GetImageResourceObserver(); ImageResourceObserver* observer = GetImageResourceObserver();
ASSERT_TRUE(observer); ASSERT_TRUE(observer);
const IntSize container_size(100, 100); const FloatSize container_size(100, 100);
scoped_refptr<Image> image = scoped_refptr<Image> image =
definition->Paint(*observer, container_size, nullptr); definition->Paint(*observer, container_size, nullptr);
EXPECT_NE(image, nullptr); EXPECT_NE(image, nullptr);
......
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