Commit 86cd32b6 authored by Adam Raine's avatar Adam Raine Committed by Commit Bot

Get device scale factor in CSSPaintValue::GetImage

Originally we got the device scale factor in PaintWorklet::Paint, but
now we get the value is CSSPaintValue::GetImage so that future patches
can use it in the off thread case as well as the main thread case.

Bug: 980594
Change-Id: Idff87f901de7a821d37d1631ad33babab795fd4f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1702146Reviewed-by: default avatarXida Chen <xidachen@chromium.org>
Reviewed-by: default avatarAnders Hartvoll Ruud <andruud@chromium.org>
Commit-Queue: Adam Raine <asraine@google.com>
Cr-Commit-Position: refs/heads/master@{#678279}
parent f43a23b5
...@@ -52,7 +52,8 @@ class CORE_EXPORT CSSPaintImageGenerator ...@@ -52,7 +52,8 @@ class CORE_EXPORT CSSPaintImageGenerator
// 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 FloatSize& container_size, const FloatSize& container_size,
const CSSStyleValueVector*) = 0; const CSSStyleValueVector*,
float device_scale_factor) = 0;
virtual const Vector<CSSPropertyID>& NativeInvalidationProperties() const = 0; virtual const Vector<CSSPropertyID>& NativeInvalidationProperties() const = 0;
virtual const Vector<AtomicString>& CustomInvalidationProperties() const = 0; virtual const Vector<AtomicString>& CustomInvalidationProperties() const = 0;
......
...@@ -11,7 +11,9 @@ ...@@ -11,7 +11,9 @@
#include "third_party/blink/renderer/core/css/cssom/paint_worklet_input.h" #include "third_party/blink/renderer/core/css/cssom/paint_worklet_input.h"
#include "third_party/blink/renderer/core/css/cssom/style_value_factory.h" #include "third_party/blink/renderer/core/css/cssom/style_value_factory.h"
#include "third_party/blink/renderer/core/css/properties/computed_style_utils.h" #include "third_party/blink/renderer/core/css/properties/computed_style_utils.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/layout/layout_object.h" #include "third_party/blink/renderer/core/layout/layout_object.h"
#include "third_party/blink/renderer/core/page/page.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/wtf/text/string_builder.h" #include "third_party/blink/renderer/platform/wtf/text/string_builder.h"
...@@ -72,13 +74,24 @@ scoped_refptr<Image> CSSPaintValue::GetImage( ...@@ -72,13 +74,24 @@ scoped_refptr<Image> CSSPaintValue::GetImage(
if (!ParseInputArguments(document)) if (!ParseInputArguments(document))
return nullptr; return nullptr;
// TODO(crbug.com/946515): Break dependency on LayoutObject.
const LayoutObject& layout_object = static_cast<const LayoutObject&>(client);
// TODO(crbug.com/716231): Remove this hack once zoom_for_dsf is enabled on
// all platforms (currently not enabled on Mac).
float device_scale_factor = 1;
if (layout_object.GetFrame() && layout_object.GetFrame()->GetPage()) {
// The value of DeviceScaleFactorDeprecated would be 1 on a platform where
// zoom_for_dsf is enabled, even if we run chrome with
// --force-device-scale-factor with a value that is not 1.
device_scale_factor =
layout_object.GetFrame()->GetPage()->DeviceScaleFactorDeprecated();
}
// For Off-Thread PaintWorklet, we just collect the necessary inputs together // For Off-Thread PaintWorklet, we just collect the necessary inputs together
// and defer the actual JavaScript call until much later (during cc Raster). // and defer the actual JavaScript call until much later (during cc Raster).
if (RuntimeEnabledFeatures::OffMainThreadCSSPaintEnabled()) { if (RuntimeEnabledFeatures::OffMainThreadCSSPaintEnabled()) {
if (paint_off_thread_) { if (paint_off_thread_) {
// TODO(crbug.com/946515): Break dependency on LayoutObject.
const LayoutObject& layout_object =
static_cast<const LayoutObject&>(client);
Vector<CSSPropertyID> native_properties = Vector<CSSPropertyID> native_properties =
generator_->NativeInvalidationProperties(); generator_->NativeInvalidationProperties();
Vector<AtomicString> custom_properties = Vector<AtomicString> custom_properties =
...@@ -102,7 +115,8 @@ scoped_refptr<Image> CSSPaintValue::GetImage( ...@@ -102,7 +115,8 @@ scoped_refptr<Image> CSSPaintValue::GetImage(
} }
} }
return generator_->Paint(client, target_size, parsed_input_arguments_); return generator_->Paint(client, target_size, parsed_input_arguments_,
device_scale_factor);
} }
void CSSPaintValue::BuildInputArgumentValues( void CSSPaintValue::BuildInputArgumentValues(
......
...@@ -66,10 +66,11 @@ class MockCSSPaintImageGenerator : public CSSPaintImageGenerator { ...@@ -66,10 +66,11 @@ class MockCSSPaintImageGenerator : public CSSPaintImageGenerator {
.WillByDefault(ReturnRef(input_argument_types_)); .WillByDefault(ReturnRef(input_argument_types_));
} }
MOCK_METHOD3(Paint, MOCK_METHOD4(Paint,
scoped_refptr<Image>(const ImageResourceObserver&, scoped_refptr<Image>(const ImageResourceObserver&,
const FloatSize& container_size, const FloatSize& container_size,
const CSSStyleValueVector*)); const CSSStyleValueVector*,
float device_scale_factor));
MOCK_CONST_METHOD0(NativeInvalidationProperties, Vector<CSSPropertyID>&()); MOCK_CONST_METHOD0(NativeInvalidationProperties, Vector<CSSPropertyID>&());
MOCK_CONST_METHOD0(CustomInvalidationProperties, Vector<AtomicString>&()); MOCK_CONST_METHOD0(CustomInvalidationProperties, Vector<AtomicString>&());
MOCK_CONST_METHOD0(HasAlpha, bool()); MOCK_CONST_METHOD0(HasAlpha, bool());
...@@ -118,7 +119,7 @@ TEST_P(CSSPaintValueTest, DelayPaintUntilGeneratorReady) { ...@@ -118,7 +119,7 @@ TEST_P(CSSPaintValueTest, DelayPaintUntilGeneratorReady) {
// Initially the generator is not ready, so GetImage should fail (and no paint // Initially the generator is not ready, so GetImage should fail (and no paint
// should happen). // should happen).
EXPECT_CALL(*mock_generator, Paint(_, _, _)).Times(0); EXPECT_CALL(*mock_generator, Paint(_, _, _, _)).Times(0);
EXPECT_FALSE( EXPECT_FALSE(
paint_value->GetImage(*target, GetDocument(), style, target_size)); paint_value->GetImage(*target, GetDocument(), style, target_size));
...@@ -127,7 +128,7 @@ TEST_P(CSSPaintValueTest, DelayPaintUntilGeneratorReady) { ...@@ -127,7 +128,7 @@ TEST_P(CSSPaintValueTest, DelayPaintUntilGeneratorReady) {
// In off-thread CSS Paint, the actual paint call is deferred and so will // In off-thread CSS Paint, the actual paint call is deferred and so will
// never happen. // never happen.
if (!RuntimeEnabledFeatures::OffMainThreadCSSPaintEnabled()) { if (!RuntimeEnabledFeatures::OffMainThreadCSSPaintEnabled()) {
EXPECT_CALL(*mock_generator, Paint(_, _, _)) EXPECT_CALL(*mock_generator, Paint(_, _, _, _))
.WillRepeatedly( .WillRepeatedly(
Return(PaintGeneratedImage::Create(nullptr, target_size))); Return(PaintGeneratedImage::Create(nullptr, target_size)));
} }
......
...@@ -54,8 +54,10 @@ void CSSPaintImageGeneratorImpl::NotifyGeneratorReady() { ...@@ -54,8 +54,10 @@ void CSSPaintImageGeneratorImpl::NotifyGeneratorReady() {
scoped_refptr<Image> CSSPaintImageGeneratorImpl::Paint( scoped_refptr<Image> CSSPaintImageGeneratorImpl::Paint(
const ImageResourceObserver& observer, const ImageResourceObserver& observer,
const FloatSize& container_size, const FloatSize& container_size,
const CSSStyleValueVector* data) { const CSSStyleValueVector* data,
return paint_worklet_->Paint(name_, observer, container_size, data); float device_scale_factor) {
return paint_worklet_->Paint(name_, observer, container_size, data,
device_scale_factor);
} }
bool CSSPaintImageGeneratorImpl::HasDocumentDefinition() const { bool CSSPaintImageGeneratorImpl::HasDocumentDefinition() const {
......
...@@ -35,7 +35,8 @@ class MODULES_EXPORT CSSPaintImageGeneratorImpl final ...@@ -35,7 +35,8 @@ class MODULES_EXPORT CSSPaintImageGeneratorImpl final
// The |container_size| is without subpixel snapping. // The |container_size| is without subpixel snapping.
scoped_refptr<Image> Paint(const ImageResourceObserver&, scoped_refptr<Image> Paint(const ImageResourceObserver&,
const FloatSize& container_size, const FloatSize& container_size,
const CSSStyleValueVector*) final; const CSSStyleValueVector*,
float device_scale_factor) 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;
bool HasAlpha() const final; bool HasAlpha() const final;
......
...@@ -101,7 +101,8 @@ wtf_size_t PaintWorklet::SelectNewGlobalScope() { ...@@ -101,7 +101,8 @@ wtf_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 FloatSize& container_size, const FloatSize& container_size,
const CSSStyleValueVector* data) { const CSSStyleValueVector* data,
float device_scale_factor) {
if (!document_definition_map_.Contains(name)) if (!document_definition_map_.Contains(name))
return nullptr; return nullptr;
...@@ -121,17 +122,6 @@ scoped_refptr<Image> PaintWorklet::Paint(const String& name, ...@@ -121,17 +122,6 @@ scoped_refptr<Image> PaintWorklet::Paint(const String& name,
static_cast<const LayoutObject&>(observer); static_cast<const LayoutObject&>(observer);
float zoom = layout_object.StyleRef().EffectiveZoom(); float zoom = layout_object.StyleRef().EffectiveZoom();
// TODO(crbug.com/716231): Remove this hack once zoom_for_dsf is enabled on
// all platforms (currently not enabled on Mac).
float device_scale_factor = 1;
if (layout_object.GetFrame() && layout_object.GetFrame()->GetPage()) {
// The value of DeviceScaleFactorDeprecated would be 1 on a platform where
// zoom_for_dsf is enabled, even if we run chrome with
// --force-device-scale-factor with a value that is not 1.
device_scale_factor =
layout_object.GetFrame()->GetPage()->DeviceScaleFactorDeprecated();
}
StylePropertyMapReadOnly* style_map = StylePropertyMapReadOnly* style_map =
MakeGarbageCollected<PrepopulatedComputedStylePropertyMap>( MakeGarbageCollected<PrepopulatedComputedStylePropertyMap>(
layout_object.GetDocument(), layout_object.StyleRef(), layout_object.GetDocument(), layout_object.StyleRef(),
......
...@@ -42,7 +42,8 @@ class MODULES_EXPORT PaintWorklet : public Worklet, ...@@ -42,7 +42,8 @@ class MODULES_EXPORT PaintWorklet : public Worklet,
scoped_refptr<Image> Paint(const String& name, scoped_refptr<Image> Paint(const String& name,
const ImageResourceObserver&, const ImageResourceObserver&,
const FloatSize& container_size, const FloatSize& container_size,
const CSSStyleValueVector*); const CSSStyleValueVector*,
float device_scale_factor);
int WorkletId() const { return worklet_id_; } int WorkletId() const { return worklet_id_; }
void Trace(blink::Visitor*) override; void Trace(blink::Visitor*) override;
......
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