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

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

Issue 1230073002: Teach SkyShell.apk to stop posting frames when not visible (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 5 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
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 "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"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 Engine::Config::Config() { 52 Engine::Config::Config() {
53 } 53 }
54 54
55 Engine::Config::~Config() { 55 Engine::Config::~Config() {
56 } 56 }
57 57
58 Engine::Engine(const Config& config) 58 Engine::Engine(const Config& config)
59 : config_(config), 59 : config_(config),
60 animator_(new Animator(config, this)), 60 animator_(new Animator(config, this)),
61 binding_(this), 61 binding_(this),
62 activity_running_(false),
63 have_surface_(false),
62 weak_factory_(this) { 64 weak_factory_(this) {
63 } 65 }
64 66
65 Engine::~Engine() { 67 Engine::~Engine() {
66 } 68 }
67 69
68 base::WeakPtr<Engine> Engine::GetWeakPtr() { 70 base::WeakPtr<Engine> Engine::GetWeakPtr() {
69 return weak_factory_.GetWeakPtr(); 71 return weak_factory_.GetWeakPtr();
70 } 72 }
71 73
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 } 113 }
112 114
113 void Engine::ConnectToEngine(mojo::InterfaceRequest<SkyEngine> request) { 115 void Engine::ConnectToEngine(mojo::InterfaceRequest<SkyEngine> request) {
114 binding_.Bind(request.Pass()); 116 binding_.Bind(request.Pass());
115 } 117 }
116 118
117 void Engine::OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget) { 119 void Engine::OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget) {
118 config_.gpu_task_runner->PostTask( 120 config_.gpu_task_runner->PostTask(
119 FROM_HERE, base::Bind(&GPUDelegate::OnAcceleratedWidgetAvailable, 121 FROM_HERE, base::Bind(&GPUDelegate::OnAcceleratedWidgetAvailable,
120 config_.gpu_delegate, widget)); 122 config_.gpu_delegate, widget));
123 have_surface_ = true;
124 StartAnimatorIfPossible();
121 if (sky_view_) 125 if (sky_view_)
122 ScheduleFrame(); 126 ScheduleFrame();
123 } 127 }
124 128
125 void Engine::OnOutputSurfaceDestroyed() { 129 void Engine::OnOutputSurfaceDestroyed() {
130 have_surface_ = false;
131 StopAnimator();
126 config_.gpu_task_runner->PostTask( 132 config_.gpu_task_runner->PostTask(
127 FROM_HERE, 133 FROM_HERE,
128 base::Bind(&GPUDelegate::OnOutputSurfaceDestroyed, config_.gpu_delegate)); 134 base::Bind(&GPUDelegate::OnOutputSurfaceDestroyed, config_.gpu_delegate));
129 } 135 }
130 136
131 void Engine::OnViewportMetricsChanged(ViewportMetricsPtr metrics) { 137 void Engine::OnViewportMetricsChanged(ViewportMetricsPtr metrics) {
132 physical_size_.SetSize(metrics->physical_width, metrics->physical_height); 138 physical_size_.SetSize(metrics->physical_width, metrics->physical_height);
133 139
134 display_metrics_.physical_size = physical_size_; 140 display_metrics_.physical_size = physical_size_;
135 display_metrics_.device_pixel_ratio = metrics->device_pixel_ratio; 141 display_metrics_.device_pixel_ratio = metrics->device_pixel_ratio;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 void Engine::RunFromBundle(const mojo::String& path) { 194 void Engine::RunFromBundle(const mojo::String& path) {
189 AssetUnpackerJob* unpacker = new AssetUnpackerJob( 195 AssetUnpackerJob* unpacker = new AssetUnpackerJob(
190 mojo::GetProxy(&root_bundle_), base::WorkerPool::GetTaskRunner(true)); 196 mojo::GetProxy(&root_bundle_), base::WorkerPool::GetTaskRunner(true));
191 std::string path_str = path; 197 std::string path_str = path;
192 unpacker->Unpack(Fetch(base::FilePath(path_str))); 198 unpacker->Unpack(Fetch(base::FilePath(path_str)));
193 root_bundle_->GetAsStream(kSnapshotKey, 199 root_bundle_->GetAsStream(kSnapshotKey,
194 base::Bind(&Engine::RunFromSnapshotStream, 200 base::Bind(&Engine::RunFromSnapshotStream,
195 weak_factory_.GetWeakPtr(), path_str)); 201 weak_factory_.GetWeakPtr(), path_str));
196 } 202 }
197 203
204 void Engine::OnActivityPaused() {
205 activity_running_ = false;
206 StopAnimator();
207 }
208
209 void Engine::OnActivityResumed() {
210 activity_running_ = true;
211 StartAnimatorIfPossible();
212 }
213
198 void Engine::DidCreateIsolate(Dart_Isolate isolate) { 214 void Engine::DidCreateIsolate(Dart_Isolate isolate) {
199 Internals::Create(isolate, 215 Internals::Create(isolate,
200 CreateServiceProvider(config_.service_provider_context), 216 CreateServiceProvider(config_.service_provider_context),
201 root_bundle_.Pass()); 217 root_bundle_.Pass());
202 } 218 }
203 219
220 void Engine::StopAnimator() {
221 animator_->Stop();
222 }
223
224 void Engine::StartAnimatorIfPossible() {
225 if (activity_running_ && have_surface_)
226 animator_->Start();
227 }
228
204 void Engine::ScheduleFrame() { 229 void Engine::ScheduleFrame() {
205 animator_->RequestFrame(); 230 animator_->RequestFrame();
206 } 231 }
207 232
208 mojo::NavigatorHost* Engine::NavigatorHost() { 233 mojo::NavigatorHost* Engine::NavigatorHost() {
209 return this; 234 return this;
210 } 235 }
211 236
212 void Engine::RequestNavigate(mojo::Target target, 237 void Engine::RequestNavigate(mojo::Target target,
213 mojo::URLRequestPtr request) { 238 mojo::URLRequestPtr request) {
214 // Ignoring target for now. 239 // Ignoring target for now.
215 base::MessageLoop::current()->PostTask( 240 base::MessageLoop::current()->PostTask(
216 FROM_HERE, 241 FROM_HERE,
217 base::Bind(&Engine::RunFromNetwork, GetWeakPtr(), request->url)); 242 base::Bind(&Engine::RunFromNetwork, GetWeakPtr(), request->url));
218 } 243 }
219 244
220 void Engine::DidNavigateLocally(const mojo::String& url) { 245 void Engine::DidNavigateLocally(const mojo::String& url) {
221 } 246 }
222 247
223 void Engine::RequestNavigateHistory(int32_t delta) { 248 void Engine::RequestNavigateHistory(int32_t delta) {
224 NOTIMPLEMENTED(); 249 NOTIMPLEMENTED();
225 } 250 }
226 251
227 } // namespace shell 252 } // namespace shell
228 } // namespace sky 253 } // namespace sky
OLDNEW
« sky/shell/android/org/domokit/sky/shell/SkyActivity.java ('K') | « sky/shell/ui/engine.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698