OLD | NEW |
---|---|
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 "sky/engine/public/web/Sky.h" | 8 #include "sky/engine/public/web/Sky.h" |
8 #include "sky/engine/public/web/WebLocalFrame.h" | 9 #include "sky/engine/public/web/WebLocalFrame.h" |
9 #include "sky/engine/public/web/WebView.h" | 10 #include "sky/engine/public/web/WebView.h" |
11 #include "sky/shell/ui/animator.h" | |
10 #include "sky/shell/ui/platform_impl.h" | 12 #include "sky/shell/ui/platform_impl.h" |
13 #include "third_party/skia/include/core/SkCanvas.h" | |
14 #include "third_party/skia/include/core/SkPictureRecorder.h" | |
11 | 15 |
12 namespace sky { | 16 namespace sky { |
13 namespace shell { | 17 namespace shell { |
14 | 18 |
15 Engine::Engine() : web_view_(nullptr), weak_factory_(this) { | 19 Engine::Engine(const Config& config) |
20 : animator_(new Animator(config, this)), | |
21 web_view_(nullptr), | |
22 weak_factory_(this) { | |
16 } | 23 } |
17 | 24 |
18 Engine::~Engine() { | 25 Engine::~Engine() { |
19 if (web_view_) | 26 if (web_view_) |
20 web_view_->close(); | 27 web_view_->close(); |
21 } | 28 } |
22 | 29 |
23 base::WeakPtr<Engine> Engine::GetWeakPtr() { | 30 base::WeakPtr<Engine> Engine::GetWeakPtr() { |
24 return weak_factory_.GetWeakPtr(); | 31 return weak_factory_.GetWeakPtr(); |
25 } | 32 } |
26 | 33 |
27 void Engine::Init() { | 34 void Engine::Init(mojo::ScopedMessagePipeHandle service_provider) { |
28 platform_impl_.reset(new PlatformImpl); | 35 platform_impl_.reset(new PlatformImpl(mojo::MakeProxy<mojo::ServiceProvider>( |
36 service_provider.Pass()))); | |
29 blink::initialize(platform_impl_.get()); | 37 blink::initialize(platform_impl_.get()); |
30 | 38 |
31 web_view_ = blink::WebView::create(this); | 39 web_view_ = blink::WebView::create(this); |
32 web_view_->setMainFrame(blink::WebLocalFrame::create(this)); | 40 web_view_->setMainFrame(blink::WebLocalFrame::create(this)); |
41 web_view_->mainFrame()->load( | |
42 GURL("http://127.0.0.1:8000/sky/examples/spinning-square.sky")); | |
33 } | 43 } |
34 | 44 |
35 void Engine::OnViewportMetricsChanged(const gfx::Size& size, | 45 void Engine::BeginFrame(base::TimeTicks frame_time) { |
46 double frame_time_sec = (frame_time - base::TimeTicks()).InSecondsF(); | |
47 double deadline_sec = frame_time_sec; | |
48 double interval_sec = 1.0 / 60; | |
49 blink::WebBeginFrameArgs args(frame_time_sec, deadline_sec, interval_sec); | |
50 | |
51 web_view_->beginFrame(args); | |
52 web_view_->layout(); | |
53 } | |
54 | |
55 skia::RefPtr<SkPicture> Engine::Paint() { | |
56 SkRTreeFactory factory; | |
57 SkPictureRecorder recorder; | |
58 auto canvas = skia::SharePtr(recorder.beginRecording( | |
59 physical_size_.width(), physical_size_.height(), &factory, | |
60 SkPictureRecorder::kComputeSaveLayerInfo_RecordFlag)); | |
61 | |
62 web_view_->paint(canvas.get(), blink::WebRect(0, 0, physical_size_.width(), | |
eseidel
2015/02/18 20:55:57
blink::WebRect(gfx::Rect(physical_size))
| |
63 physical_size_.height())); | |
64 | |
65 return skia::AdoptRef(recorder.endRecordingAsPicture()); | |
66 } | |
67 | |
68 void Engine::OnViewportMetricsChanged(const gfx::Size& physical_size, | |
36 float device_pixel_ratio) { | 69 float device_pixel_ratio) { |
37 blink::WebSize web_size(size.width() / device_pixel_ratio, | 70 physical_size_ = physical_size; |
38 size.height() / device_pixel_ratio); | |
39 web_view_->setDeviceScaleFactor(device_pixel_ratio); | 71 web_view_->setDeviceScaleFactor(device_pixel_ratio); |
40 web_view_->resize(web_size); | 72 web_view_->resize( |
eseidel
2015/02/18 20:55:57
blink::WebSize(gfx::ScaleSize(physical_size, 1 / d
| |
73 blink::WebSize(physical_size.width() / device_pixel_ratio, | |
74 physical_size.height() / device_pixel_ratio)); | |
75 } | |
76 | |
77 void Engine::initializeLayerTreeView() { | |
78 } | |
79 | |
80 void Engine::scheduleVisualUpdate() { | |
81 animator_->RequestFrame(); | |
41 } | 82 } |
42 | 83 |
43 } // namespace shell | 84 } // namespace shell |
44 } // namespace sky | 85 } // namespace sky |
OLD | NEW |