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

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

Issue 936883002: Connect Sky and Ganesh in SkyShell (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Address review comments 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
« no previous file with comments | « sky/shell/ui/engine.h ('k') | sky/shell/ui/platform_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "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(
36 mojo::MakeProxy<mojo::ServiceProvider>(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(gfx::Rect(physical_size_)));
63 return skia::AdoptRef(recorder.endRecordingAsPicture());
64 }
65
66 void Engine::OnViewportMetricsChanged(const gfx::Size& physical_size,
36 float device_pixel_ratio) { 67 float device_pixel_ratio) {
37 blink::WebSize web_size(size.width() / device_pixel_ratio, 68 physical_size_ = physical_size;
38 size.height() / device_pixel_ratio);
39 web_view_->setDeviceScaleFactor(device_pixel_ratio); 69 web_view_->setDeviceScaleFactor(device_pixel_ratio);
40 web_view_->resize(web_size); 70 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
72 // because its in logical pixels.
73 web_view_->resize(blink::WebSize(size.width(), size.height()));
74 }
75
76 void Engine::initializeLayerTreeView() {
77 }
78
79 void Engine::scheduleVisualUpdate() {
80 animator_->RequestFrame();
41 } 81 }
42 82
43 } // namespace shell 83 } // namespace shell
44 } // namespace sky 84 } // namespace sky
OLDNEW
« no previous file with comments | « sky/shell/ui/engine.h ('k') | sky/shell/ui/platform_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698