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

Side by Side Diff: sky/viewer/document_view.cc

Issue 752683002: Break Sky's dependency on cc (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years 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/viewer/document_view.h ('k') | sky/viewer/platform/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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/viewer/document_view.h" 5 #include "sky/viewer/document_view.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/message_loop/message_loop_proxy.h" 9 #include "base/message_loop/message_loop_proxy.h"
10 #include "base/single_thread_task_runner.h" 10 #include "base/single_thread_task_runner.h"
(...skipping 17 matching lines...) Expand all
28 #include "sky/engine/public/web/WebInputEvent.h" 28 #include "sky/engine/public/web/WebInputEvent.h"
29 #include "sky/engine/public/web/WebLocalFrame.h" 29 #include "sky/engine/public/web/WebLocalFrame.h"
30 #include "sky/engine/public/web/WebScriptSource.h" 30 #include "sky/engine/public/web/WebScriptSource.h"
31 #include "sky/engine/public/web/WebSettings.h" 31 #include "sky/engine/public/web/WebSettings.h"
32 #include "sky/engine/public/web/WebView.h" 32 #include "sky/engine/public/web/WebView.h"
33 #include "sky/engine/v8_inspector/inspector_backend_mojo.h" 33 #include "sky/engine/v8_inspector/inspector_backend_mojo.h"
34 #include "sky/engine/v8_inspector/inspector_host.h" 34 #include "sky/engine/v8_inspector/inspector_host.h"
35 #include "sky/viewer/converters/input_event_types.h" 35 #include "sky/viewer/converters/input_event_types.h"
36 #include "sky/viewer/converters/url_request_types.h" 36 #include "sky/viewer/converters/url_request_types.h"
37 #include "sky/viewer/internals.h" 37 #include "sky/viewer/internals.h"
38 #include "sky/viewer/platform/weblayertreeview_impl.h"
39 #include "sky/viewer/platform/weburlloader_impl.h" 38 #include "sky/viewer/platform/weburlloader_impl.h"
40 #include "sky/viewer/script/script_runner.h" 39 #include "sky/viewer/script/script_runner.h"
41 #include "third_party/skia/include/core/SkCanvas.h" 40 #include "third_party/skia/include/core/SkCanvas.h"
42 #include "third_party/skia/include/core/SkColor.h" 41 #include "third_party/skia/include/core/SkColor.h"
43 #include "third_party/skia/include/core/SkDevice.h" 42 #include "third_party/skia/include/core/SkDevice.h"
44 #include "v8/include/v8.h" 43 #include "v8/include/v8.h"
45 44
46 namespace sky { 45 namespace sky {
47 namespace { 46 namespace {
48 47
(...skipping 19 matching lines...) Expand all
68 } 67 }
69 68
70 } // namespace 69 } // namespace
71 70
72 static int s_next_debugger_id = 1; 71 static int s_next_debugger_id = 1;
73 72
74 DocumentView::DocumentView( 73 DocumentView::DocumentView(
75 const base::Closure& destruction_callback, 74 const base::Closure& destruction_callback,
76 mojo::ServiceProviderPtr provider, 75 mojo::ServiceProviderPtr provider,
77 mojo::URLResponsePtr response, 76 mojo::URLResponsePtr response,
78 mojo::Shell* shell, 77 mojo::Shell* shell)
79 scoped_refptr<base::MessageLoopProxy> compositor_thread)
80 : destruction_callback_(destruction_callback), 78 : destruction_callback_(destruction_callback),
81 response_(response.Pass()), 79 response_(response.Pass()),
82 shell_(shell), 80 shell_(shell),
83 web_view_(NULL), 81 web_view_(NULL),
84 root_(NULL), 82 root_(NULL),
85 view_manager_client_factory_(shell_, this), 83 view_manager_client_factory_(shell_, this),
86 inspector_service_factory_(this), 84 inspector_service_factory_(this),
87 compositor_thread_(compositor_thread),
88 debugger_id_(s_next_debugger_id++), 85 debugger_id_(s_next_debugger_id++),
89 weak_factory_(this) { 86 weak_factory_(this) {
90 exported_services_.AddService(&view_manager_client_factory_); 87 exported_services_.AddService(&view_manager_client_factory_);
91 mojo::WeakBindToPipe(&exported_services_, provider.PassMessagePipe()); 88 mojo::WeakBindToPipe(&exported_services_, provider.PassMessagePipe());
92 } 89 }
93 90
94 DocumentView::~DocumentView() { 91 DocumentView::~DocumentView() {
95 if (web_view_) 92 if (web_view_)
96 web_view_->close(); 93 web_view_->close();
97 if (root_) 94 if (root_)
(...skipping 16 matching lines...) Expand all
114 navigator_host_.set_service_provider(imported_services_.get()); 111 navigator_host_.set_service_provider(imported_services_.get());
115 exported_services->AddService(&inspector_service_factory_); 112 exported_services->AddService(&inspector_service_factory_);
116 113
117 Load(response_.Pass()); 114 Load(response_.Pass());
118 115
119 gfx::Size size = root_->bounds().To<gfx::Rect>().size(); 116 gfx::Size size = root_->bounds().To<gfx::Rect>().size();
120 web_view_->resize(size); 117 web_view_->resize(size);
121 // TODO(abarth): We should ask the view whether it is focused instead of 118 // TODO(abarth): We should ask the view whether it is focused instead of
122 // assuming that we're focused. 119 // assuming that we're focused.
123 web_view_->setFocus(true); 120 web_view_->setFocus(true);
124 #if !ENABLE_SKY_COMPOSITOR
125 web_layer_tree_view_impl_->setViewportSize(size);
126 web_layer_tree_view_impl_->set_view(root_);
127 #endif
128 root_->AddObserver(this); 121 root_->AddObserver(this);
129 } 122 }
130 123
131 void DocumentView::OnViewManagerDisconnected(mojo::ViewManager* view_manager) { 124 void DocumentView::OnViewManagerDisconnected(mojo::ViewManager* view_manager) {
132 // TODO(aa): Need to figure out how shutdown works. 125 // TODO(aa): Need to figure out how shutdown works.
133 } 126 }
134 127
135 void DocumentView::Load(mojo::URLResponsePtr response) { 128 void DocumentView::Load(mojo::URLResponsePtr response) {
136 web_view_ = blink::WebView::create(this); 129 web_view_ = blink::WebView::create(this);
137 #if !ENABLE_SKY_COMPOSITOR
138 web_layer_tree_view_impl_->set_widget(web_view_);
139 #endif
140 ConfigureSettings(web_view_->settings()); 130 ConfigureSettings(web_view_->settings());
141 web_view_->setMainFrame(blink::WebLocalFrame::create(this)); 131 web_view_->setMainFrame(blink::WebLocalFrame::create(this));
142 web_view_->mainFrame()->load(GURL(response->url), response->body.Pass()); 132 web_view_->mainFrame()->load(GURL(response->url), response->body.Pass());
143 } 133 }
144 134
145 blink::WebLayerTreeView* DocumentView::initializeLayerTreeView() { 135 blink::WebLayerTreeView* DocumentView::initializeLayerTreeView() {
146 #if ENABLE_SKY_COMPOSITOR
147 layer_host_.reset(new LayerHost(this)); 136 layer_host_.reset(new LayerHost(this));
148 root_layer_ = make_scoped_refptr(new Layer(this)); 137 root_layer_ = make_scoped_refptr(new Layer(this));
149 layer_host_->SetRootLayer(root_layer_); 138 layer_host_->SetRootLayer(root_layer_);
150 return nullptr; 139 return nullptr;
151 #else
152 mojo::ServiceProviderPtr surfaces_service_provider;
153 shell_->ConnectToApplication("mojo:surfaces_service",
154 mojo::GetProxy(&surfaces_service_provider));
155 mojo::InterfacePtr<mojo::SurfacesService> surfaces_service;
156 mojo::ConnectToService(surfaces_service_provider.get(), &surfaces_service);
157
158 mojo::ServiceProviderPtr gpu_service_provider;
159 // TODO(jamesr): Should be mojo:gpu_service
160 shell_->ConnectToApplication("mojo:native_viewport_service",
161 mojo::GetProxy(&gpu_service_provider));
162 mojo::InterfacePtr<mojo::Gpu> gpu_service;
163 mojo::ConnectToService(gpu_service_provider.get(), &gpu_service);
164 web_layer_tree_view_impl_.reset(new WebLayerTreeViewImpl(
165 compositor_thread_, surfaces_service.Pass(), gpu_service.Pass()));
166
167 return web_layer_tree_view_impl_.get();
168 #endif
169 } 140 }
170 141
171 #if ENABLE_SKY_COMPOSITOR
172
173 mojo::Shell* DocumentView::GetShell() { 142 mojo::Shell* DocumentView::GetShell() {
174 return shell_; 143 return shell_;
175 } 144 }
176 145
177 void DocumentView::BeginFrame(base::TimeTicks frame_time) { 146 void DocumentView::BeginFrame(base::TimeTicks frame_time) {
178 double frame_time_sec = (frame_time - base::TimeTicks()).InSecondsF(); 147 double frame_time_sec = (frame_time - base::TimeTicks()).InSecondsF();
179 double deadline_sec = frame_time_sec; 148 double deadline_sec = frame_time_sec;
180 double interval_sec = 1.0/60; 149 double interval_sec = 1.0/60;
181 blink::WebBeginFrameArgs web_begin_frame_args( 150 blink::WebBeginFrameArgs web_begin_frame_args(
182 frame_time_sec, deadline_sec, interval_sec); 151 frame_time_sec, deadline_sec, interval_sec);
183 web_view_->beginFrame(web_begin_frame_args); 152 web_view_->beginFrame(web_begin_frame_args);
184 web_view_->layout(); 153 web_view_->layout();
185 blink::WebSize size = web_view_->size(); 154 blink::WebSize size = web_view_->size();
186 root_layer_->SetSize(gfx::Size(size.width, size.height)); 155 root_layer_->SetSize(gfx::Size(size.width, size.height));
187 } 156 }
188 157
189 void DocumentView::OnSurfaceIdAvailable(mojo::SurfaceIdPtr surface_id) { 158 void DocumentView::OnSurfaceIdAvailable(mojo::SurfaceIdPtr surface_id) {
190 root_->SetSurfaceId(surface_id.Pass()); 159 root_->SetSurfaceId(surface_id.Pass());
191 } 160 }
192 161
193 void DocumentView::PaintContents(SkCanvas* canvas, const gfx::Rect& clip) { 162 void DocumentView::PaintContents(SkCanvas* canvas, const gfx::Rect& clip) {
194 blink::WebRect rect(clip.x(), clip.y(), clip.width(), clip.height()); 163 blink::WebRect rect(clip.x(), clip.y(), clip.width(), clip.height());
195 web_view_->paint(canvas, rect); 164 web_view_->paint(canvas, rect);
196 } 165 }
197 166
198 #endif // ENABLE_SKY_COMPOSITOR
199
200 void DocumentView::scheduleAnimation() { 167 void DocumentView::scheduleAnimation() {
201 DCHECK(web_view_); 168 DCHECK(web_view_);
202
203 #if ENABLE_SKY_COMPOSITOR
204 layer_host_->SetNeedsAnimate(); 169 layer_host_->SetNeedsAnimate();
205 #else
206 if (!web_view_->settings()->compositorIsEnabled())
207 web_layer_tree_view_impl_->setNeedsAnimate();
208 #endif
209 } 170 }
210 171
211 mojo::View* DocumentView::createChildFrame(const blink::WebURL& url) { 172 mojo::View* DocumentView::createChildFrame(const blink::WebURL& url) {
212 if (!root_) 173 if (!root_)
213 return nullptr; 174 return nullptr;
214 175
215 mojo::View* child = mojo::View::Create(root_->view_manager()); 176 mojo::View* child = mojo::View::Create(root_->view_manager());
216 child->SetVisible(true); 177 child->SetVisible(true);
217 root_->AddChild(child); 178 root_->AddChild(child);
218 child->Embed(mojo::String::From(url.string().utf8())); 179 child->Embed(mojo::String::From(url.string().utf8()));
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 mojo::Shell* DocumentView::Shell() { 226 mojo::Shell* DocumentView::Shell() {
266 return shell_; 227 return shell_;
267 } 228 }
268 229
269 void DocumentView::OnViewBoundsChanged(mojo::View* view, 230 void DocumentView::OnViewBoundsChanged(mojo::View* view,
270 const mojo::Rect& old_bounds, 231 const mojo::Rect& old_bounds,
271 const mojo::Rect& new_bounds) { 232 const mojo::Rect& new_bounds) {
272 DCHECK_EQ(view, root_); 233 DCHECK_EQ(view, root_);
273 gfx::Size size = new_bounds.To<gfx::Rect>().size(); 234 gfx::Size size = new_bounds.To<gfx::Rect>().size();
274 web_view_->resize(size); 235 web_view_->resize(size);
275 #if !ENABLE_SKY_COMPOSITOR
276 web_layer_tree_view_impl_->setViewportSize(size);
277 #endif
278 } 236 }
279 237
280 void DocumentView::OnViewFocusChanged(mojo::View* gained_focus, 238 void DocumentView::OnViewFocusChanged(mojo::View* gained_focus,
281 mojo::View* lost_focus) { 239 mojo::View* lost_focus) {
282 if (root_ == lost_focus) { 240 if (root_ == lost_focus) {
283 web_view_->setFocus(false); 241 web_view_->setFocus(false);
284 } else if (root_ == gained_focus) { 242 } else if (root_ == gained_focus) {
285 web_view_->setFocus(true); 243 web_view_->setFocus(true);
286 } 244 }
287 } 245 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 void DocumentView::StartDebuggerInspectorBackend() { 279 void DocumentView::StartDebuggerInspectorBackend() {
322 if (!inspector_backend_) { 280 if (!inspector_backend_) {
323 inspector_host_.reset(new InspectorHostImpl(web_view_, shell_)); 281 inspector_host_.reset(new InspectorHostImpl(web_view_, shell_));
324 inspector_backend_.reset( 282 inspector_backend_.reset(
325 new inspector::InspectorBackendMojo(inspector_host_.get())); 283 new inspector::InspectorBackendMojo(inspector_host_.get()));
326 } 284 }
327 inspector_backend_->Connect(); 285 inspector_backend_->Connect();
328 } 286 }
329 287
330 } // namespace sky 288 } // namespace sky
OLDNEW
« no previous file with comments | « sky/viewer/document_view.h ('k') | sky/viewer/platform/platform_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698