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/compositor/layer_host.h" | 5 #include "sky/compositor/layer_host.h" |
6 | 6 |
7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
8 #include "mojo/converters/geometry/geometry_type_converters.h" | 8 #include "mojo/converters/geometry/geometry_type_converters.h" |
9 #include "mojo/gpu/gl_context.h" | 9 #include "mojo/gpu/gl_context.h" |
10 #include "mojo/services/public/cpp/surfaces/surfaces_utils.h" | 10 #include "mojo/services/public/cpp/surfaces/surfaces_utils.h" |
11 #include "mojo/skia/ganesh_context.h" | 11 #include "mojo/skia/ganesh_context.h" |
12 #include "sky/compositor/layer.h" | 12 #include "sky/compositor/layer.h" |
13 | 13 |
14 namespace sky { | 14 namespace sky { |
15 | 15 |
16 LayerHost::LayerHost(LayerHostClient* client) | 16 LayerHost::LayerHost(LayerHostClient* client) |
17 : client_(client), | 17 : client_(client), |
18 state_(kIdle), | |
18 surface_holder_(this, client->GetShell()), | 19 surface_holder_(this, client->GetShell()), |
19 gl_context_(mojo::GLContext::Create(client->GetShell())), | 20 gl_context_(mojo::GLContext::Create(client->GetShell())), |
20 ganesh_context_(gl_context_), | 21 ganesh_context_(gl_context_), |
21 resource_manager_(gl_context_), | 22 resource_manager_(gl_context_), |
22 scheduler_(this, base::MessageLoop::current()->task_runner()) { | 23 scheduler_(this, base::MessageLoop::current()->task_runner()) { |
23 scheduler_.UpdateVSync( | 24 scheduler_.UpdateVSync( |
24 TimeInterval(base::TimeTicks(), base::TimeDelta::FromSecondsD(1.0 / 60))); | 25 TimeInterval(base::TimeTicks(), base::TimeDelta::FromSecondsD(1.0 / 60))); |
25 } | 26 } |
26 | 27 |
27 LayerHost::~LayerHost() { | 28 LayerHost::~LayerHost() { |
28 } | 29 } |
29 | 30 |
30 void LayerHost::SetNeedsAnimate() { | 31 void LayerHost::SetNeedsAnimate() { |
31 scheduler_.SetNeedsFrame(); | 32 scheduler_.SetNeedsFrame(); |
33 state_ = kWaitingForBeginFrame; | |
32 } | 34 } |
33 | 35 |
34 void LayerHost::SetRootLayer(scoped_refptr<Layer> layer) { | 36 void LayerHost::SetRootLayer(scoped_refptr<Layer> layer) { |
35 DCHECK(!root_layer_.get()); | 37 DCHECK(!root_layer_.get()); |
36 root_layer_ = layer; | 38 root_layer_ = layer; |
37 root_layer_->set_host(this); | 39 root_layer_->set_host(this); |
38 } | 40 } |
39 | 41 |
40 void LayerHost::OnSurfaceIdAvailable(mojo::SurfaceIdPtr surface_id) { | 42 void LayerHost::OnSurfaceIdAvailable(mojo::SurfaceIdPtr surface_id) { |
41 client_->OnSurfaceIdAvailable(surface_id.Pass()); | 43 client_->OnSurfaceIdAvailable(surface_id.Pass()); |
44 | |
45 if (state_ == kWaitingForSurfaceToUploadFrame) | |
46 Upload(root_layer_.get()); | |
42 } | 47 } |
43 | 48 |
44 void LayerHost::ReturnResources( | 49 void LayerHost::ReturnResources( |
45 mojo::Array<mojo::ReturnedResourcePtr> resources) { | 50 mojo::Array<mojo::ReturnedResourcePtr> resources) { |
46 resource_manager_.ReturnResources(resources.Pass()); | 51 resource_manager_.ReturnResources(resources.Pass()); |
47 } | 52 } |
48 | 53 |
49 void LayerHost::BeginFrame(base::TimeTicks frame_time, | 54 void LayerHost::BeginFrame(base::TimeTicks frame_time, |
50 base::TimeTicks deadline) { | 55 base::TimeTicks deadline) { |
56 DCHECK_EQ(state_, kWaitingForBeginFrame); | |
57 state_ = kProducingFrame; | |
51 client_->BeginFrame(frame_time); | 58 client_->BeginFrame(frame_time); |
52 | 59 |
53 { | 60 { |
54 mojo::GaneshContext::Scope scope(&ganesh_context_); | 61 mojo::GaneshContext::Scope scope(&ganesh_context_); |
55 ganesh_context_.gr()->resetContext(); | 62 ganesh_context_.gr()->resetContext(); |
56 root_layer_->Display(); | 63 root_layer_->Display(); |
57 } | 64 } |
58 | 65 |
59 Upload(root_layer_.get()); | 66 Upload(root_layer_.get()); |
67 | |
68 if (state_ == kProducingFrame) | |
69 state_ = kIdle; | |
60 } | 70 } |
61 | 71 |
62 void LayerHost::Upload(Layer* layer) { | 72 void LayerHost::Upload(Layer* layer) { |
73 if (!surface_holder_.IsReadyForFrame()) { | |
74 if (state_ == kProducingFrame) | |
esprehn
2014/11/21 19:34:45
What schedules the eventual upload if it wasn't re
abarth-chromium
2014/11/21 20:01:17
The OnSurfaceIdAvailable callback is called whenev
| |
75 state_ = kWaitingForSurfaceToUploadFrame; | |
76 return; | |
77 } | |
78 | |
63 gfx::Size size = layer->size(); | 79 gfx::Size size = layer->size(); |
64 surface_holder_.SetSize(size); | 80 surface_holder_.SetSize(size); |
65 | 81 |
66 mojo::FramePtr frame = mojo::Frame::New(); | 82 mojo::FramePtr frame = mojo::Frame::New(); |
67 frame->resources.resize(0u); | 83 frame->resources.resize(0u); |
68 | 84 |
69 mojo::Rect bounds; | 85 mojo::Rect bounds; |
70 bounds.width = size.width(); | 86 bounds.width = size.width(); |
71 bounds.height = size.height(); | 87 bounds.height = size.height(); |
72 mojo::PassPtr pass = mojo::CreateDefaultPass(1, bounds); | 88 mojo::PassPtr pass = mojo::CreateDefaultPass(1, bounds); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
104 | 120 |
105 frame->resources.push_back(resource.Pass()); | 121 frame->resources.push_back(resource.Pass()); |
106 quad->texture_quad_state = texture_state.Pass(); | 122 quad->texture_quad_state = texture_state.Pass(); |
107 pass->quads.push_back(quad.Pass()); | 123 pass->quads.push_back(quad.Pass()); |
108 | 124 |
109 frame->passes.push_back(pass.Pass()); | 125 frame->passes.push_back(pass.Pass()); |
110 surface_holder_.SubmitFrame(frame.Pass()); | 126 surface_holder_.SubmitFrame(frame.Pass()); |
111 } | 127 } |
112 | 128 |
113 } // namespace sky | 129 } // namespace sky |
OLD | NEW |