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

Side by Side Diff: sky/compositor/layer_host.cc

Issue 744753003: Use the scheduler to drive the Sky compositor (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years, 1 month 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/compositor/layer_host.h ('k') | sky/compositor/layer_host_client.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/compositor/layer_host.h" 5 #include "sky/compositor/layer_host.h"
6 6
7 #include "base/message_loop/message_loop.h"
7 #include "mojo/converters/geometry/geometry_type_converters.h" 8 #include "mojo/converters/geometry/geometry_type_converters.h"
8 #include "mojo/gpu/gl_context.h" 9 #include "mojo/gpu/gl_context.h"
9 #include "mojo/services/public/cpp/surfaces/surfaces_utils.h" 10 #include "mojo/services/public/cpp/surfaces/surfaces_utils.h"
10 #include "mojo/skia/ganesh_context.h" 11 #include "mojo/skia/ganesh_context.h"
11 #include "sky/compositor/layer.h" 12 #include "sky/compositor/layer.h"
12 13
13 namespace sky { 14 namespace sky {
14 15
15 LayerHost::LayerHost(LayerHostClient* client) 16 LayerHost::LayerHost(LayerHostClient* client)
16 : client_(client), 17 : client_(client),
17 surface_holder_(this, client->GetShell()), 18 surface_holder_(this, client->GetShell()),
18 gl_context_(mojo::GLContext::Create(client->GetShell())), 19 gl_context_(mojo::GLContext::Create(client->GetShell())),
19 ganesh_context_(gl_context_), 20 ganesh_context_(gl_context_),
20 resource_manager_(gl_context_) { 21 resource_manager_(gl_context_),
22 scheduler_(this, base::MessageLoop::current()->task_runner()) {
23 scheduler_.UpdateVSync(
24 TimeInterval(base::TimeTicks(), base::TimeDelta::FromSecondsD(1.0 / 60)));
21 } 25 }
22 26
23 LayerHost::~LayerHost() { 27 LayerHost::~LayerHost() {
24 } 28 }
25 29
26 void LayerHost::SetNeedsAnimate() { 30 void LayerHost::SetNeedsAnimate() {
31 scheduler_.SetNeedsFrame();
27 } 32 }
28 33
29 void LayerHost::SetRootLayer(scoped_refptr<Layer> layer) { 34 void LayerHost::SetRootLayer(scoped_refptr<Layer> layer) {
30 DCHECK(!root_layer_.get()); 35 DCHECK(!root_layer_.get());
31 root_layer_ = layer; 36 root_layer_ = layer;
32 root_layer_->set_host(this); 37 root_layer_->set_host(this);
33 } 38 }
34 39
35 void LayerHost::OnReadyForNextFrame() {
36 client_->BeginFrame();
37 root_layer_->Display();
38 Upload(root_layer_.get());
39 }
40
41 void LayerHost::OnSurfaceIdAvailable(mojo::SurfaceIdPtr surface_id) { 40 void LayerHost::OnSurfaceIdAvailable(mojo::SurfaceIdPtr surface_id) {
42 client_->OnSurfaceIdAvailable(surface_id.Pass()); 41 client_->OnSurfaceIdAvailable(surface_id.Pass());
43 } 42 }
44 43
45 void LayerHost::ReturnResources( 44 void LayerHost::ReturnResources(
46 mojo::Array<mojo::ReturnedResourcePtr> resources) { 45 mojo::Array<mojo::ReturnedResourcePtr> resources) {
47 resource_manager_.ReturnResources(resources.Pass()); 46 resource_manager_.ReturnResources(resources.Pass());
48 } 47 }
49 48
49 void LayerHost::BeginFrame(base::TimeTicks frame_time,
50 base::TimeTicks deadline) {
51 client_->BeginFrame(frame_time);
52 root_layer_->Display();
53 Upload(root_layer_.get());
54 }
55
50 void LayerHost::Upload(Layer* layer) { 56 void LayerHost::Upload(Layer* layer) {
51 gfx::Size size = layer->size(); 57 gfx::Size size = layer->size();
52 surface_holder_.SetSize(size); 58 surface_holder_.SetSize(size);
53 59
54 mojo::FramePtr frame = mojo::Frame::New(); 60 mojo::FramePtr frame = mojo::Frame::New();
55 frame->resources.resize(0u); 61 frame->resources.resize(0u);
56 62
57 mojo::Rect bounds; 63 mojo::Rect bounds;
58 bounds.width = size.width(); 64 bounds.width = size.width();
59 bounds.height = size.height(); 65 bounds.height = size.height();
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 98
93 frame->resources.push_back(resource.Pass()); 99 frame->resources.push_back(resource.Pass());
94 quad->texture_quad_state = texture_state.Pass(); 100 quad->texture_quad_state = texture_state.Pass();
95 pass->quads.push_back(quad.Pass()); 101 pass->quads.push_back(quad.Pass());
96 102
97 frame->passes.push_back(pass.Pass()); 103 frame->passes.push_back(pass.Pass());
98 surface_holder_.SubmitFrame(frame.Pass()); 104 surface_holder_.SubmitFrame(frame.Pass());
99 } 105 }
100 106
101 } // namespace sky 107 } // namespace sky
OLDNEW
« no previous file with comments | « sky/compositor/layer_host.h ('k') | sky/compositor/layer_host_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698