提交 e687626a 编写于 作者: J Jason Simmons 提交者: GitHub

Incorporate the device pixel ratio when drawing shadows (#3919)

上级 193de2f4
......@@ -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
......@@ -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_;
......
......@@ -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<flow::PhysicalModelLayer> 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);
}
......
......@@ -7,8 +7,10 @@
#include <math.h>
#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() {
......
......@@ -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;
......
......@@ -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;
......
......@@ -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,
......
......@@ -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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册