OLD | NEW |
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" |
11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
12 #include "base/thread_task_runner_handle.h" | 12 #include "base/thread_task_runner_handle.h" |
13 #include "mojo/converters/geometry/geometry_type_converters.h" | 13 #include "mojo/converters/geometry/geometry_type_converters.h" |
14 #include "mojo/public/cpp/application/connect.h" | 14 #include "mojo/public/cpp/application/connect.h" |
15 #include "mojo/public/cpp/system/data_pipe.h" | 15 #include "mojo/public/cpp/system/data_pipe.h" |
16 #include "mojo/public/interfaces/application/shell.mojom.h" | 16 #include "mojo/public/interfaces/application/shell.mojom.h" |
17 #include "mojo/services/surfaces/public/interfaces/surfaces_service.mojom.h" | 17 #include "mojo/services/surfaces/public/interfaces/surfaces_service.mojom.h" |
18 #include "mojo/services/view_manager/public/cpp/view.h" | 18 #include "mojo/services/view_manager/public/cpp/view.h" |
19 #include "mojo/services/view_manager/public/cpp/view_manager.h" | 19 #include "mojo/services/view_manager/public/cpp/view_manager.h" |
20 #include "skia/ext/refptr.h" | 20 #include "skia/ext/refptr.h" |
21 #include "sky/compositor/layer.h" | 21 #include "sky/compositor/layer.h" |
22 #include "sky/compositor/layer_host.h" | 22 #include "sky/compositor/layer_host.h" |
| 23 #include "sky/compositor/rasterizer_bitmap.h" |
| 24 #include "sky/compositor/rasterizer_ganesh.h" |
23 #include "sky/engine/public/platform/Platform.h" | 25 #include "sky/engine/public/platform/Platform.h" |
24 #include "sky/engine/public/platform/WebHTTPHeaderVisitor.h" | 26 #include "sky/engine/public/platform/WebHTTPHeaderVisitor.h" |
25 #include "sky/engine/public/platform/WebScreenInfo.h" | 27 #include "sky/engine/public/platform/WebScreenInfo.h" |
26 #include "sky/engine/public/web/Sky.h" | 28 #include "sky/engine/public/web/Sky.h" |
27 #include "sky/engine/public/web/WebConsoleMessage.h" | 29 #include "sky/engine/public/web/WebConsoleMessage.h" |
28 #include "sky/engine/public/web/WebDocument.h" | 30 #include "sky/engine/public/web/WebDocument.h" |
29 #include "sky/engine/public/web/WebElement.h" | 31 #include "sky/engine/public/web/WebElement.h" |
30 #include "sky/engine/public/web/WebInputEvent.h" | 32 #include "sky/engine/public/web/WebInputEvent.h" |
31 #include "sky/engine/public/web/WebLocalFrame.h" | 33 #include "sky/engine/public/web/WebLocalFrame.h" |
32 #include "sky/engine/public/web/WebScriptSource.h" | 34 #include "sky/engine/public/web/WebScriptSource.h" |
33 #include "sky/engine/public/web/WebSettings.h" | 35 #include "sky/engine/public/web/WebSettings.h" |
34 #include "sky/engine/public/web/WebView.h" | 36 #include "sky/engine/public/web/WebView.h" |
35 #include "sky/engine/v8_inspector/inspector_backend_mojo.h" | 37 #include "sky/engine/v8_inspector/inspector_backend_mojo.h" |
36 #include "sky/engine/v8_inspector/inspector_host.h" | 38 #include "sky/engine/v8_inspector/inspector_host.h" |
37 #include "sky/viewer/converters/input_event_types.h" | 39 #include "sky/viewer/converters/input_event_types.h" |
38 #include "sky/viewer/converters/url_request_types.h" | 40 #include "sky/viewer/converters/url_request_types.h" |
39 #include "sky/viewer/internals.h" | 41 #include "sky/viewer/internals.h" |
40 #include "sky/viewer/platform/weburlloader_impl.h" | 42 #include "sky/viewer/platform/weburlloader_impl.h" |
| 43 #include "sky/viewer/runtime_flags.h" |
41 #include "sky/viewer/script/script_runner.h" | 44 #include "sky/viewer/script/script_runner.h" |
42 #include "third_party/skia/include/core/SkCanvas.h" | 45 #include "third_party/skia/include/core/SkCanvas.h" |
43 #include "third_party/skia/include/core/SkColor.h" | 46 #include "third_party/skia/include/core/SkColor.h" |
44 #include "third_party/skia/include/core/SkDevice.h" | 47 #include "third_party/skia/include/core/SkDevice.h" |
45 #include "v8/include/v8.h" | 48 #include "v8/include/v8.h" |
46 | 49 |
47 namespace sky { | 50 namespace sky { |
48 namespace { | 51 namespace { |
49 | 52 |
50 void ConfigureSettings(blink::WebSettings* settings) { | 53 void ConfigureSettings(blink::WebSettings* settings) { |
(...skipping 21 matching lines...) Expand all Loading... |
72 | 75 |
73 static int s_next_debugger_id = 1; | 76 static int s_next_debugger_id = 1; |
74 | 77 |
75 DocumentView::DocumentView( | 78 DocumentView::DocumentView( |
76 mojo::InterfaceRequest<mojo::ServiceProvider> services, | 79 mojo::InterfaceRequest<mojo::ServiceProvider> services, |
77 mojo::ServiceProviderPtr exported_services, | 80 mojo::ServiceProviderPtr exported_services, |
78 mojo::URLResponsePtr response, | 81 mojo::URLResponsePtr response, |
79 mojo::Shell* shell) | 82 mojo::Shell* shell) |
80 : response_(response.Pass()), | 83 : response_(response.Pass()), |
81 shell_(shell), | 84 shell_(shell), |
82 web_view_(NULL), | 85 web_view_(nullptr), |
83 root_(NULL), | 86 root_(nullptr), |
84 view_manager_client_factory_(shell_, this), | 87 view_manager_client_factory_(shell_, this), |
85 inspector_service_factory_(this), | 88 inspector_service_factory_(this), |
86 weak_factory_(this), | 89 bitmap_rasterizer_(nullptr), |
87 debugger_id_(s_next_debugger_id++) { | 90 debugger_id_(s_next_debugger_id++), |
| 91 weak_factory_(this) { |
88 // TODO(jamesr): Is this right? | 92 // TODO(jamesr): Is this right? |
89 exported_services_.AddService(&view_manager_client_factory_); | 93 exported_services_.AddService(&view_manager_client_factory_); |
90 mojo::WeakBindToPipe(&exported_services_, services.PassMessagePipe()); | 94 mojo::WeakBindToPipe(&exported_services_, services.PassMessagePipe()); |
91 } | 95 } |
92 | 96 |
93 DocumentView::~DocumentView() { | 97 DocumentView::~DocumentView() { |
94 if (web_view_) | 98 if (web_view_) |
95 web_view_->close(); | 99 web_view_->close(); |
96 if (root_) | 100 if (root_) |
97 root_->RemoveObserver(this); | 101 root_->RemoveObserver(this); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 void DocumentView::Load(mojo::URLResponsePtr response) { | 134 void DocumentView::Load(mojo::URLResponsePtr response) { |
131 web_view_ = blink::WebView::create(this); | 135 web_view_ = blink::WebView::create(this); |
132 ConfigureSettings(web_view_->settings()); | 136 ConfigureSettings(web_view_->settings()); |
133 web_view_->setMainFrame(blink::WebLocalFrame::create(this)); | 137 web_view_->setMainFrame(blink::WebLocalFrame::create(this)); |
134 web_view_->mainFrame()->load(GURL(response->url), response->body.Pass()); | 138 web_view_->mainFrame()->load(GURL(response->url), response->body.Pass()); |
135 } | 139 } |
136 | 140 |
137 void DocumentView::initializeLayerTreeView() { | 141 void DocumentView::initializeLayerTreeView() { |
138 layer_host_.reset(new LayerHost(this)); | 142 layer_host_.reset(new LayerHost(this)); |
139 root_layer_ = make_scoped_refptr(new Layer(this)); | 143 root_layer_ = make_scoped_refptr(new Layer(this)); |
| 144 root_layer_->set_rasterizer(CreateRasterizer()); |
140 layer_host_->SetRootLayer(root_layer_); | 145 layer_host_->SetRootLayer(root_layer_); |
141 } | 146 } |
142 | 147 |
| 148 scoped_ptr<Rasterizer> DocumentView::CreateRasterizer() { |
| 149 if (!RuntimeFlags::Get().testing) |
| 150 return make_scoped_ptr(new RasterizerGanesh(layer_host_.get())); |
| 151 // TODO(abarth): If we have more than one layer, we'll need to re-think how |
| 152 // we capture pixels for testing; |
| 153 DCHECK(!bitmap_rasterizer_); |
| 154 bitmap_rasterizer_ = new RasterizerBitmap(layer_host_.get()); |
| 155 return make_scoped_ptr(bitmap_rasterizer_); |
| 156 } |
| 157 |
143 void DocumentView::GetPixelsForTesting(std::vector<unsigned char>* pixels) { | 158 void DocumentView::GetPixelsForTesting(std::vector<unsigned char>* pixels) { |
144 return layer_host_->GetPixelsForTesting(pixels); | 159 DCHECK(RuntimeFlags::Get().testing) << "Requires testing runtime flag"; |
| 160 DCHECK(root_layer_) << "The root layer owns the rasterizer"; |
| 161 return bitmap_rasterizer_->GetPixelsForTesting(pixels); |
145 } | 162 } |
146 | 163 |
147 mojo::Shell* DocumentView::GetShell() { | 164 mojo::Shell* DocumentView::GetShell() { |
148 return shell_; | 165 return shell_; |
149 } | 166 } |
150 | 167 |
151 void DocumentView::BeginFrame(base::TimeTicks frame_time) { | 168 void DocumentView::BeginFrame(base::TimeTicks frame_time) { |
152 double frame_time_sec = (frame_time - base::TimeTicks()).InSecondsF(); | 169 double frame_time_sec = (frame_time - base::TimeTicks()).InSecondsF(); |
153 double deadline_sec = frame_time_sec; | 170 double deadline_sec = frame_time_sec; |
154 double interval_sec = 1.0/60; | 171 double interval_sec = 1.0/60; |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 void DocumentView::StartDebuggerInspectorBackend() { | 318 void DocumentView::StartDebuggerInspectorBackend() { |
302 if (!inspector_backend_) { | 319 if (!inspector_backend_) { |
303 inspector_host_.reset(new InspectorHostImpl(web_view_, shell_)); | 320 inspector_host_.reset(new InspectorHostImpl(web_view_, shell_)); |
304 inspector_backend_.reset( | 321 inspector_backend_.reset( |
305 new inspector::InspectorBackendMojo(inspector_host_.get())); | 322 new inspector::InspectorBackendMojo(inspector_host_.get())); |
306 } | 323 } |
307 inspector_backend_->Connect(); | 324 inspector_backend_->Connect(); |
308 } | 325 } |
309 | 326 |
310 } // namespace sky | 327 } // namespace sky |
OLD | NEW |