提交 0906da7f 编写于 作者: A Adam Barth

Plumb display metrics into SkyView

This CL teaches SkyView the width, height, and device pixel ratio of the
display. In the future, we'll want some sort of notification system for when
these values change.

R=eseidel@chromium.org

Review URL: https://codereview.chromium.org/1139823010
上级 aec042c9
......@@ -21,9 +21,26 @@ View::~View()
{
}
double View::width() const
{
double w = m_displayMetrics.physical_size.width;
return w / m_displayMetrics.device_pixel_ratio;
}
double View::height() const
{
double h = m_displayMetrics.physical_size.height;
return h / m_displayMetrics.device_pixel_ratio;
}
void View::schedulePaint()
{
m_schedulePaintCallback.Run();
}
void View::setDisplayMetrics(const SkyDisplayMetrics& metrics)
{
m_displayMetrics = metrics;
}
} // namespace blink
......@@ -7,6 +7,7 @@
#include "base/callback.h"
#include "sky/engine/core/painting/Picture.h"
#include "sky/engine/public/platform/sky_display_metrics.h"
#include "sky/engine/tonic/dart_wrappable.h"
#include "sky/engine/wtf/PassRefPtr.h"
#include "sky/engine/wtf/RefCounted.h"
......@@ -19,15 +20,22 @@ public:
~View() override;
static PassRefPtr<View> create(const base::Closure& schedulePaintCallback);
double devicePixelRatio() const { return m_displayMetrics.device_pixel_ratio; }
double width() const;
double height() const;
Picture* picture() const { return m_picture.get(); }
void setPicture(Picture* picture) { m_picture = picture; }
void schedulePaint();
void setDisplayMetrics(const SkyDisplayMetrics& metrics);
private:
explicit View(const base::Closure& schedulePaintCallback);
base::Closure m_schedulePaintCallback;
SkyDisplayMetrics m_displayMetrics;
RefPtr<Picture> m_picture;
};
......
......@@ -3,6 +3,10 @@
// found in the LICENSE file.
interface View {
readonly attribute double devicePixelRatio;
readonly attribute double width;
readonly attribute double height;
attribute Picture picture;
void schedulePaint();
......
......@@ -68,6 +68,7 @@ source_set("platform_headers") {
"platform/WebURLResponse.h",
"platform/WebUnitTestSupport.h",
"platform/WebVector.h",
"platform/sky_display_metrics.h",
"platform/android/WebSandboxSupport.h",
"platform/linux/WebFallbackFont.h",
"platform/linux/WebFontInfo.h",
......
......@@ -10,8 +10,8 @@
namespace blink {
struct SkyDisplayMetrics {
WebSize size;
float device_pixel_ratio;
WebSize physical_size;
float device_pixel_ratio = 1.0;
};
} // namespace blink
......
......@@ -17,7 +17,6 @@ source_set("sky") {
]
sources = [
"sky_display_metrics.h",
"sky_view.cc",
"sky_view.h",
"sky_view_client.cc",
......
......@@ -37,11 +37,14 @@ SkyView::~SkyView() {
}
void SkyView::SetDisplayMetrics(const SkyDisplayMetrics& metrics) {
display_metrics_ = metrics;
data_->view_->setDisplayMetrics(display_metrics_);
}
void SkyView::Load(const WebURL& url) {
data_->view_ = View::create(base::Bind(
&SkyView::SchedulePaint, weak_factory_.GetWeakPtr()));
data_->view_->setDisplayMetrics(display_metrics_);
dart_controller_.reset(new DartController);
dart_controller_->CreateIsolateFor(adoptPtr(new DOMDartState(nullptr)), url);
......
......@@ -10,7 +10,7 @@
#include "skia/ext/refptr.h"
#include "sky/engine/public/platform/WebCommon.h"
#include "sky/engine/public/platform/WebURL.h"
#include "sky/engine/public/sky/sky_display_metrics.h"
#include "sky/engine/public/platform/sky_display_metrics.h"
#include "third_party/skia/include/core/SkPicture.h"
namespace blink {
......@@ -36,6 +36,7 @@ class SkyView {
class Data;
SkyViewClient* client_;
SkyDisplayMetrics display_metrics_;
std::unique_ptr<DartController> dart_controller_;
std::unique_ptr<Data> data_;
......
......@@ -8,8 +8,8 @@ import 'dart:sky';
void main() {
print("Hello, world");
double width = 500.0;
double height = 500.0;
double width = view.width;
double height = view.height;
PictureRecorder recorder = new PictureRecorder(width, height);
double radius = min(width, height) * 0.45;
......
......@@ -8,6 +8,8 @@
#include "base/trace_event/trace_event.h"
#include "mojo/public/cpp/application/connect.h"
#include "sky/engine/public/platform/WebInputEvent.h"
#include "sky/engine/public/platform/sky_display_metrics.h"
#include "sky/engine/public/platform/sky_display_metrics.h"
#include "sky/engine/public/web/Sky.h"
#include "sky/engine/public/web/WebLocalFrame.h"
#include "sky/engine/public/web/WebSettings.h"
......@@ -88,6 +90,7 @@ skia::RefPtr<SkPicture> Engine::Paint() {
if (sky_view_) {
skia::RefPtr<SkPicture> picture = sky_view_->Paint();
canvas->clear(SK_ColorBLACK);
canvas->scale(device_pixel_ratio_, device_pixel_ratio_);
if (picture)
canvas->drawPicture(picture.get());
}
......@@ -121,6 +124,14 @@ void Engine::OnViewportMetricsChanged(int width, int height,
float device_pixel_ratio) {
physical_size_.SetSize(width, height);
device_pixel_ratio_ = device_pixel_ratio;
if (sky_view_) {
blink::SkyDisplayMetrics metrics;
metrics.physical_size = physical_size_;
metrics.device_pixel_ratio = device_pixel_ratio_;
sky_view_->SetDisplayMetrics(metrics);
}
if (web_view_)
UpdateWebViewSize();
}
......@@ -150,7 +161,8 @@ void Engine::OnInputEvent(InputEventPtr event) {
ConvertEvent(event, device_pixel_ratio_);
if (!web_event)
return;
web_view_->handleInputEvent(*web_event);
if (web_view_)
web_view_->handleInputEvent(*web_event);
}
void Engine::LoadURL(const mojo::String& url) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册