| 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 "base/bind.h" |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/threading/worker_pool.h" | 9 #include "base/threading/worker_pool.h" |
| 10 #include "base/trace_event/trace_event.h" | 10 #include "base/trace_event/trace_event.h" |
| 11 #include "mojo/common/data_pipe_utils.h" | 11 #include "mojo/common/data_pipe_utils.h" |
| 12 #include "mojo/public/cpp/application/connect.h" | 12 #include "mojo/public/cpp/application/connect.h" |
| 13 #include "services/asset_bundle/asset_unpacker_job.h" |
| 13 #include "sky/engine/public/platform/WebInputEvent.h" | 14 #include "sky/engine/public/platform/WebInputEvent.h" |
| 14 #include "sky/engine/public/platform/sky_display_metrics.h" | 15 #include "sky/engine/public/platform/sky_display_metrics.h" |
| 15 #include "sky/engine/public/platform/sky_display_metrics.h" | 16 #include "sky/engine/public/platform/sky_display_metrics.h" |
| 16 #include "sky/engine/public/web/Sky.h" | 17 #include "sky/engine/public/web/Sky.h" |
| 17 #include "sky/services/platform/platform_impl.h" | 18 #include "sky/services/platform/platform_impl.h" |
| 18 #include "sky/shell/dart/dart_library_provider_files.h" | 19 #include "sky/shell/dart/dart_library_provider_files.h" |
| 19 #include "sky/shell/dart/dart_library_provider_network.h" | 20 #include "sky/shell/dart/dart_library_provider_network.h" |
| 20 #include "sky/shell/service_provider.h" | 21 #include "sky/shell/service_provider.h" |
| 21 #include "sky/shell/ui/animator.h" | 22 #include "sky/shell/ui/animator.h" |
| 22 #include "sky/shell/ui/input_event_converter.h" | 23 #include "sky/shell/ui/input_event_converter.h" |
| 23 #include "sky/shell/ui/internals.h" | 24 #include "sky/shell/ui/internals.h" |
| 24 #include "third_party/skia/include/core/SkCanvas.h" | 25 #include "third_party/skia/include/core/SkCanvas.h" |
| 25 #include "third_party/skia/include/core/SkPictureRecorder.h" | 26 #include "third_party/skia/include/core/SkPictureRecorder.h" |
| 26 | 27 |
| 27 namespace sky { | 28 namespace sky { |
| 28 namespace shell { | 29 namespace shell { |
| 29 | 30 |
| 31 const char kSnapshotKey[] = "snapshot_blob.bin"; |
| 32 |
| 30 namespace { | 33 namespace { |
| 31 | 34 |
| 32 void Ignored(bool) { | 35 void Ignored(bool) { |
| 33 } | 36 } |
| 34 | 37 |
| 35 mojo::ScopedDataPipeConsumerHandle Fetch(const base::FilePath& path) { | 38 mojo::ScopedDataPipeConsumerHandle Fetch(const base::FilePath& path) { |
| 36 mojo::DataPipe pipe; | 39 mojo::DataPipe pipe; |
| 37 auto runner = base::WorkerPool::GetTaskRunner(true); | 40 auto runner = base::WorkerPool::GetTaskRunner(true); |
| 38 mojo::common::CopyFromFile(base::FilePath(path), pipe.producer_handle.Pass(), | 41 mojo::common::CopyFromFile(base::FilePath(path), pipe.producer_handle.Pass(), |
| 39 0, runner.get(), base::Bind(&Ignored)); | 42 0, runner.get(), base::Bind(&Ignored)); |
| 40 return pipe.consumer_handle.Pass(); | 43 return pipe.consumer_handle.Pass(); |
| 41 } | 44 } |
| 42 | 45 |
| 43 PlatformImpl* g_platform_impl = nullptr; | 46 PlatformImpl* g_platform_impl = nullptr; |
| 44 | 47 |
| 45 } | 48 } // namespace |
| 49 |
| 50 using mojo::asset_bundle::AssetUnpackerJob; |
| 46 | 51 |
| 47 Engine::Config::Config() { | 52 Engine::Config::Config() { |
| 48 } | 53 } |
| 49 | 54 |
| 50 Engine::Config::~Config() { | 55 Engine::Config::~Config() { |
| 51 } | 56 } |
| 52 | 57 |
| 53 Engine::Engine(const Config& config) | 58 Engine::Engine(const Config& config) |
| 54 : config_(config), | 59 : config_(config), |
| 55 animator_(new Animator(config, this)), | 60 animator_(new Animator(config, this)), |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 void Engine::OnInputEvent(InputEventPtr event) { | 148 void Engine::OnInputEvent(InputEventPtr event) { |
| 144 TRACE_EVENT0("sky", "Engine::OnInputEvent"); | 149 TRACE_EVENT0("sky", "Engine::OnInputEvent"); |
| 145 scoped_ptr<blink::WebInputEvent> web_event = | 150 scoped_ptr<blink::WebInputEvent> web_event = |
| 146 ConvertEvent(event, device_pixel_ratio_); | 151 ConvertEvent(event, device_pixel_ratio_); |
| 147 if (!web_event) | 152 if (!web_event) |
| 148 return; | 153 return; |
| 149 if (sky_view_) | 154 if (sky_view_) |
| 150 sky_view_->HandleInputEvent(*web_event); | 155 sky_view_->HandleInputEvent(*web_event); |
| 151 } | 156 } |
| 152 | 157 |
| 153 void Engine::RunFromLibrary(const mojo::String& name) { | 158 void Engine::RunFromLibrary(const std::string& name) { |
| 154 sky_view_ = blink::SkyView::Create(this); | 159 sky_view_ = blink::SkyView::Create(this); |
| 155 sky_view_->RunFromLibrary(blink::WebString::fromUTF8(name), | 160 sky_view_->RunFromLibrary(blink::WebString::fromUTF8(name), |
| 156 dart_library_provider_.get()); | 161 dart_library_provider_.get()); |
| 157 UpdateSkyViewSize(); | 162 UpdateSkyViewSize(); |
| 158 } | 163 } |
| 159 | 164 |
| 165 void Engine::RunFromSnapshotStream( |
| 166 const std::string& name, |
| 167 mojo::ScopedDataPipeConsumerHandle snapshot) { |
| 168 sky_view_ = blink::SkyView::Create(this); |
| 169 sky_view_->RunFromSnapshot(blink::WebString::fromUTF8(name), snapshot.Pass()); |
| 170 UpdateSkyViewSize(); |
| 171 } |
| 172 |
| 160 void Engine::RunFromNetwork(const mojo::String& url) { | 173 void Engine::RunFromNetwork(const mojo::String& url) { |
| 161 dart_library_provider_.reset( | 174 dart_library_provider_.reset( |
| 162 new DartLibraryProviderNetwork(g_platform_impl->networkService())); | 175 new DartLibraryProviderNetwork(g_platform_impl->networkService())); |
| 163 RunFromLibrary(url); | 176 RunFromLibrary(url); |
| 164 } | 177 } |
| 165 | 178 |
| 166 void Engine::RunFromFile(const mojo::String& main, | 179 void Engine::RunFromFile(const mojo::String& main, |
| 167 const mojo::String& package_root) { | 180 const mojo::String& package_root) { |
| 168 dart_library_provider_.reset( | 181 dart_library_provider_.reset( |
| 169 new DartLibraryProviderFiles(base::FilePath(package_root))); | 182 new DartLibraryProviderFiles(base::FilePath(package_root))); |
| 170 RunFromLibrary(main); | 183 RunFromLibrary(main); |
| 171 } | 184 } |
| 172 | 185 |
| 173 void Engine::RunFromSnapshot(const mojo::String& path) { | 186 void Engine::RunFromSnapshot(const mojo::String& path) { |
| 174 sky_view_ = blink::SkyView::Create(this); | 187 std::string path_str = path; |
| 175 sky_view_->RunFromSnapshot(blink::WebString::fromUTF8(path), | 188 RunFromSnapshotStream(path_str, Fetch(base::FilePath(path_str))); |
| 176 Fetch(base::FilePath(path))); | 189 } |
| 177 UpdateSkyViewSize(); | 190 |
| 191 void Engine::RunFromBundle(const mojo::String& path) { |
| 192 AssetUnpackerJob* unpacker = new AssetUnpackerJob( |
| 193 mojo::GetProxy(&root_bundle_), base::WorkerPool::GetTaskRunner(true)); |
| 194 std::string path_str = path; |
| 195 unpacker->Unpack(Fetch(base::FilePath(path_str))); |
| 196 root_bundle_->GetAsStream(kSnapshotKey, |
| 197 base::Bind(&Engine::RunFromSnapshotStream, |
| 198 weak_factory_.GetWeakPtr(), path_str)); |
| 178 } | 199 } |
| 179 | 200 |
| 180 void Engine::DidCreateIsolate(Dart_Isolate isolate) { | 201 void Engine::DidCreateIsolate(Dart_Isolate isolate) { |
| 181 Internals::Create(isolate, | 202 Internals::Create(isolate, |
| 182 CreateServiceProvider(config_.service_provider_context)); | 203 CreateServiceProvider(config_.service_provider_context)); |
| 183 } | 204 } |
| 184 | 205 |
| 185 void Engine::ScheduleFrame() { | 206 void Engine::ScheduleFrame() { |
| 186 animator_->RequestFrame(); | 207 animator_->RequestFrame(); |
| 187 } | 208 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 200 | 221 |
| 201 void Engine::DidNavigateLocally(const mojo::String& url) { | 222 void Engine::DidNavigateLocally(const mojo::String& url) { |
| 202 } | 223 } |
| 203 | 224 |
| 204 void Engine::RequestNavigateHistory(int32_t delta) { | 225 void Engine::RequestNavigateHistory(int32_t delta) { |
| 205 NOTIMPLEMENTED(); | 226 NOTIMPLEMENTED(); |
| 206 } | 227 } |
| 207 | 228 |
| 208 } // namespace shell | 229 } // namespace shell |
| 209 } // namespace sky | 230 } // namespace sky |
| OLD | NEW |