diff --git a/flow/layers/physical_model_layer.cc b/flow/layers/physical_model_layer.cc index d6dc5e92d201ae5022bf500cf63d570a93b37a40..7d7f9102abefd8b4fa0e2071df1111f9e0cf43f7 100644 --- a/flow/layers/physical_model_layer.cc +++ b/flow/layers/physical_model_layer.cc @@ -9,7 +9,7 @@ namespace flow { -PhysicalModelLayer::PhysicalModelLayer() : rrect_(SkRRect::MakeEmpty()) {} +PhysicalModelLayer::PhysicalModelLayer() = default; PhysicalModelLayer::~PhysicalModelLayer() = default; @@ -70,7 +70,7 @@ void PhysicalModelLayer::Paint(PaintContext& context) { if (elevation_ != 0) { DrawShadow(&context.canvas, path, SK_ColorBLACK, elevation_, - SkColorGetA(color_) != 0xff); + SkColorGetA(color_) != 0xff, device_pixel_ratio_); } SkPaint paint; @@ -93,16 +93,17 @@ void PhysicalModelLayer::DrawShadow(SkCanvas* canvas, const SkPath& path, SkColor color, float elevation, - bool transparentOccluder) { + bool transparentOccluder, + SkScalar dpr) { SkShadowFlags flags = transparentOccluder ? SkShadowFlags::kTransparentOccluder_ShadowFlag : SkShadowFlags::kNone_ShadowFlag; const SkRect& bounds = path.getBounds(); SkScalar shadow_x = (bounds.left() + bounds.right()) / 2; SkScalar shadow_y = bounds.top() - 600.0f; - SkShadowUtils::DrawShadow(canvas, path, elevation, - SkPoint3::Make(shadow_x, shadow_y, 600.0f), 800.0f, - 0.039f, 0.25f, color, flags); + SkShadowUtils::DrawShadow(canvas, path, dpr * elevation, + SkPoint3::Make(shadow_x, shadow_y, dpr * 600.0f), + dpr * 800.0f, 0.039f, 0.25f, color, flags); } } // namespace flow diff --git a/flow/layers/physical_model_layer.h b/flow/layers/physical_model_layer.h index 653e1839c7b341d727719dbeda700909a237bfb7..1c15f444d2780c55edf507d576fc2a4f983dc523 100644 --- a/flow/layers/physical_model_layer.h +++ b/flow/layers/physical_model_layer.h @@ -17,12 +17,14 @@ class PhysicalModelLayer : public ContainerLayer { void set_rrect(const SkRRect& rrect) { rrect_ = rrect; } void set_elevation(float elevation) { elevation_ = elevation; } void set_color(SkColor color) { color_ = color; } + void set_device_pixel_ratio(SkScalar dpr) { device_pixel_ratio_ = dpr; } static void DrawShadow(SkCanvas* canvas, const SkPath& path, SkColor color, float elevation, - bool transparentOccluder); + bool transparentOccluder, + SkScalar dpr); void Preroll(PrerollContext* context, const SkMatrix& matrix) override; void Paint(PaintContext& context) override; @@ -35,6 +37,7 @@ class PhysicalModelLayer : public ContainerLayer { SkRRect rrect_; float elevation_; SkColor color_; + SkScalar device_pixel_ratio_; #if defined(OS_FUCHSIA) SkScalar scale_x_; diff --git a/lib/ui/compositing/scene_builder.cc b/lib/ui/compositing/scene_builder.cc index 1645781c9951fed2b67dc7f358ce755e4885e3ea..cb8b158e26dfdaf38d3bf3ed538038ef54ced4a2 100644 --- a/lib/ui/compositing/scene_builder.cc +++ b/lib/ui/compositing/scene_builder.cc @@ -16,8 +16,10 @@ #include "flutter/flow/layers/picture_layer.h" #include "flutter/flow/layers/shader_mask_layer.h" #include "flutter/flow/layers/transform_layer.h" +#include "flutter/lib/ui/ui_dart_state.h" #include "flutter/lib/ui/painting/matrix.h" #include "flutter/lib/ui/painting/shader.h" +#include "flutter/lib/ui/window/window.h" #include "lib/ftl/build_config.h" #include "lib/tonic/converter/dart_converter.h" #include "lib/tonic/dart_args.h" @@ -163,11 +165,14 @@ void SceneBuilder::pushPhysicalModel(const RRect& rrect, if (!cullRect.intersect(rrect.sk_rrect.rect(), m_cullRects.top())) cullRect = SkRect::MakeEmpty(); + SkScalar dpr = UIDartState::Current()->window()->viewport_metrics().device_pixel_ratio; + std::unique_ptr layer( new flow::PhysicalModelLayer()); layer->set_rrect(rrect.sk_rrect); layer->set_elevation(elevation); layer->set_color(color); + layer->set_device_pixel_ratio(dpr); addLayer(std::move(layer), cullRect); } diff --git a/lib/ui/painting/canvas.cc b/lib/ui/painting/canvas.cc index bf993ff87a8622b3799200a110f01cbd6d590dd2..ea9810afc58687f7faaac5c1a26a9723fb9cd9ac 100644 --- a/lib/ui/painting/canvas.cc +++ b/lib/ui/painting/canvas.cc @@ -7,8 +7,10 @@ #include #include "flutter/flow/layers/physical_model_layer.h" +#include "flutter/lib/ui/ui_dart_state.h" #include "flutter/lib/ui/painting/image.h" #include "flutter/lib/ui/painting/matrix.h" +#include "flutter/lib/ui/window/window.h" #include "lib/tonic/converter/dart_converter.h" #include "lib/tonic/dart_args.h" #include "lib/tonic/dart_binding_macros.h" @@ -399,11 +401,13 @@ void Canvas::drawShadow(const CanvasPath* path, bool transparentOccluder) { if (!path) Dart_ThrowException(ToDart("Canvas.drawShader called with non-genuine Path.")); + SkScalar dpr = UIDartState::Current()->window()->viewport_metrics().device_pixel_ratio; flow::PhysicalModelLayer::DrawShadow(canvas_, path->path(), color, elevation, - transparentOccluder); + transparentOccluder, + dpr); } void Canvas::Clear() { diff --git a/lib/ui/window/window.cc b/lib/ui/window/window.cc index 88bb4d0ddc502d7b6cc5b6889ae56401f0f22e5f..755bf23b4fa3625b4413576fb79380415df0daf9 100644 --- a/lib/ui/window/window.cc +++ b/lib/ui/window/window.cc @@ -129,6 +129,8 @@ void Window::DidCreateIsolate() { } void Window::UpdateWindowMetrics(const ViewportMetrics& metrics) { + viewport_metrics_ = metrics; + tonic::DartState* dart_state = library_.dart_state().get(); if (!dart_state) return; diff --git a/lib/ui/window/window.h b/lib/ui/window/window.h index e875f09082f1d002560f03fa670cb54f3502fc55..49b66b25c2c5fbf38c37b25b3d69feb3809b7d22 100644 --- a/lib/ui/window/window.h +++ b/lib/ui/window/window.h @@ -39,6 +39,7 @@ class Window { ~Window(); WindowClient* client() const { return client_; } + const ViewportMetrics& viewport_metrics() { return viewport_metrics_; } void DidCreateIsolate(); void UpdateWindowMetrics(const ViewportMetrics& metrics); @@ -59,6 +60,7 @@ class Window { private: WindowClient* client_; tonic::DartPersistentValue library_; + ViewportMetrics viewport_metrics_; // We use id 0 to mean that no response is expected. int next_response_id_ = 1; diff --git a/runtime/runtime_controller.cc b/runtime/runtime_controller.cc index b823f2942c87fa78ebc036762ae979e124656821..f998d41a84ff24997feb55c950046fa33a845ec0 100644 --- a/runtime/runtime_controller.cc +++ b/runtime/runtime_controller.cc @@ -45,7 +45,6 @@ void RuntimeController::CreateDartController( Window* window = GetWindow(); - window->UpdateWindowMetrics(viewport_metrics_); window->UpdateLocale(language_code_, country_code_); if (semantics_enabled_) @@ -53,8 +52,7 @@ void RuntimeController::CreateDartController( } void RuntimeController::SetViewportMetrics(const ViewportMetrics& metrics) { - viewport_metrics_ = metrics; - GetWindow()->UpdateWindowMetrics(viewport_metrics_); + GetWindow()->UpdateWindowMetrics(metrics); } void RuntimeController::SetLocale(const std::string& language_code, diff --git a/runtime/runtime_controller.h b/runtime/runtime_controller.h index c08fae7c2d52e3821edb2c7e141d26ffde4482cf..8c95954a6740e466862a730bc6e56d2c8f661bdd 100644 --- a/runtime/runtime_controller.h +++ b/runtime/runtime_controller.h @@ -62,7 +62,6 @@ class RuntimeController : public WindowClient, public IsolateClient { void DidCreateSecondaryIsolate(Dart_Isolate isolate) override; RuntimeDelegate* client_; - ViewportMetrics viewport_metrics_; std::string language_code_; std::string country_code_; bool semantics_enabled_ = false;