Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(548)

Side by Side Diff: sky/shell/ui/engine.cc

Issue 932283002: Port touch-demo.sky to Dart and make it work in SkyShell (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "sky/shell/ui/engine.h" 5 #include "sky/shell/ui/engine.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "sky/engine/public/platform/WebInputEvent.h"
8 #include "sky/engine/public/web/Sky.h" 9 #include "sky/engine/public/web/Sky.h"
9 #include "sky/engine/public/web/WebLocalFrame.h" 10 #include "sky/engine/public/web/WebLocalFrame.h"
10 #include "sky/engine/public/web/WebView.h" 11 #include "sky/engine/public/web/WebView.h"
11 #include "sky/shell/ui/animator.h" 12 #include "sky/shell/ui/animator.h"
13 #include "sky/shell/ui/input_event_converter.h"
12 #include "sky/shell/ui/platform_impl.h" 14 #include "sky/shell/ui/platform_impl.h"
13 #include "third_party/skia/include/core/SkCanvas.h" 15 #include "third_party/skia/include/core/SkCanvas.h"
14 #include "third_party/skia/include/core/SkPictureRecorder.h" 16 #include "third_party/skia/include/core/SkPictureRecorder.h"
15 17
16 namespace sky { 18 namespace sky {
17 namespace shell { 19 namespace shell {
18 20
19 Engine::Engine(const Config& config) 21 Engine::Engine(const Config& config)
20 : animator_(new Animator(config, this)), 22 : animator_(new Animator(config, this)),
21 web_view_(nullptr), 23 web_view_(nullptr),
24 device_pixel_ratio_(1.0f),
25 viewport_observer_binding_(this),
22 weak_factory_(this) { 26 weak_factory_(this) {
23 } 27 }
24 28
25 Engine::~Engine() { 29 Engine::~Engine() {
26 if (web_view_) 30 if (web_view_)
27 web_view_->close(); 31 web_view_->close();
28 } 32 }
29 33
30 base::WeakPtr<Engine> Engine::GetWeakPtr() { 34 base::WeakPtr<Engine> Engine::GetWeakPtr() {
31 return weak_factory_.GetWeakPtr(); 35 return weak_factory_.GetWeakPtr();
32 } 36 }
33 37
34 void Engine::Init(mojo::ScopedMessagePipeHandle service_provider) { 38 void Engine::Init(mojo::ScopedMessagePipeHandle service_provider) {
35 platform_impl_.reset(new PlatformImpl( 39 platform_impl_.reset(new PlatformImpl(
36 mojo::MakeProxy<mojo::ServiceProvider>(service_provider.Pass()))); 40 mojo::MakeProxy<mojo::ServiceProvider>(service_provider.Pass())));
37 blink::initialize(platform_impl_.get()); 41 blink::initialize(platform_impl_.get());
38 42
39 web_view_ = blink::WebView::create(this); 43 web_view_ = blink::WebView::create(this);
40 web_view_->setMainFrame(blink::WebLocalFrame::create(this)); 44 web_view_->setMainFrame(blink::WebLocalFrame::create(this));
41 web_view_->mainFrame()->load( 45 web_view_->mainFrame()->load(
42 GURL("http://127.0.0.1:8000/sky/examples/spinning-square.sky")); 46 GURL("http://domokit.github.io/sky/examples/spinning-square.sky"));
43 } 47 }
44 48
45 void Engine::BeginFrame(base::TimeTicks frame_time) { 49 void Engine::BeginFrame(base::TimeTicks frame_time) {
46 double frame_time_sec = (frame_time - base::TimeTicks()).InSecondsF(); 50 double frame_time_sec = (frame_time - base::TimeTicks()).InSecondsF();
47 double deadline_sec = frame_time_sec; 51 double deadline_sec = frame_time_sec;
48 double interval_sec = 1.0 / 60; 52 double interval_sec = 1.0 / 60;
49 blink::WebBeginFrameArgs args(frame_time_sec, deadline_sec, interval_sec); 53 blink::WebBeginFrameArgs args(frame_time_sec, deadline_sec, interval_sec);
50 54
51 web_view_->beginFrame(args); 55 web_view_->beginFrame(args);
52 web_view_->layout(); 56 web_view_->layout();
53 } 57 }
54 58
55 skia::RefPtr<SkPicture> Engine::Paint() { 59 skia::RefPtr<SkPicture> Engine::Paint() {
56 SkRTreeFactory factory; 60 SkRTreeFactory factory;
57 SkPictureRecorder recorder; 61 SkPictureRecorder recorder;
58 auto canvas = skia::SharePtr(recorder.beginRecording( 62 auto canvas = skia::SharePtr(recorder.beginRecording(
59 physical_size_.width(), physical_size_.height(), &factory, 63 physical_size_.width(), physical_size_.height(), &factory,
60 SkPictureRecorder::kComputeSaveLayerInfo_RecordFlag)); 64 SkPictureRecorder::kComputeSaveLayerInfo_RecordFlag));
61 65
62 web_view_->paint(canvas.get(), blink::WebRect(gfx::Rect(physical_size_))); 66 web_view_->paint(canvas.get(), blink::WebRect(gfx::Rect(physical_size_)));
63 return skia::AdoptRef(recorder.endRecordingAsPicture()); 67 return skia::AdoptRef(recorder.endRecordingAsPicture());
64 } 68 }
65 69
66 void Engine::OnViewportMetricsChanged(const gfx::Size& physical_size, 70 void Engine::ConnectToViewportObserver(
71 mojo::InterfaceRequest<ViewportObserver> request) {
72 viewport_observer_binding_.Bind(request.Pass());
73 }
74
75 void Engine::OnViewportMetricsChanged(int width, int height,
67 float device_pixel_ratio) { 76 float device_pixel_ratio) {
68 physical_size_ = physical_size; 77 physical_size_.SetSize(width, height);
78 device_pixel_ratio_ = device_pixel_ratio;
69 web_view_->setDeviceScaleFactor(device_pixel_ratio); 79 web_view_->setDeviceScaleFactor(device_pixel_ratio);
70 gfx::SizeF size = gfx::ScaleSize(physical_size, 1 / device_pixel_ratio); 80 gfx::SizeF size = gfx::ScaleSize(physical_size_, 1 / device_pixel_ratio);
71 // FIXME: We should be able to set the size of the WebView in floating point 81 // FIXME: We should be able to set the size of the WebView in floating point
72 // because its in logical pixels. 82 // because its in logical pixels.
73 web_view_->resize(blink::WebSize(size.width(), size.height())); 83 web_view_->resize(blink::WebSize(size.width(), size.height()));
74 } 84 }
75 85
86 void Engine::OnInputEvent(InputEventPtr event) {
87 scoped_ptr<blink::WebInputEvent> web_event =
88 ConvertEvent(event, device_pixel_ratio_);
89 if (!web_event)
90 return;
91 web_view_->handleInputEvent(*web_event);
92 }
93
76 void Engine::initializeLayerTreeView() { 94 void Engine::initializeLayerTreeView() {
77 } 95 }
78 96
79 void Engine::scheduleVisualUpdate() { 97 void Engine::scheduleVisualUpdate() {
80 animator_->RequestFrame(); 98 animator_->RequestFrame();
81 } 99 }
82 100
83 } // namespace shell 101 } // namespace shell
84 } // namespace sky 102 } // namespace sky
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698