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

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

Issue 753643002: Enable the Sky compositor again (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Moar comments 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/surface_holder.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 "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) {
75 // Currently we use a timer to drive the BeginFrame cycle, which means we
76 // can produce frames before the surfaces service is ready to receive
77 // frames from us. In that situation, we wait for surfaces before
78 // uploading the frame. The upload will actually happen when the surface
79 // id is available (i.e., in OnSurfaceIdAvailable). If SetNeedsAnimate is
80 // called before then, we'll go back into the kWaitingForBeginFrame state
81 // and defer to the timer again.
82 //
83 // We can avoid this complexity if we use feedback from the surfaces
84 // service to drive the BeginFrame cycle. In that approach, we wouldn't
85 // get here before we've attached to a surface.
86 state_ = kWaitingForSurfaceToUploadFrame;
87 }
88 return;
89 }
90
63 gfx::Size size = layer->size(); 91 gfx::Size size = layer->size();
64 surface_holder_.SetSize(size); 92 surface_holder_.SetSize(size);
65 93
66 mojo::FramePtr frame = mojo::Frame::New(); 94 mojo::FramePtr frame = mojo::Frame::New();
67 frame->resources.resize(0u); 95 frame->resources.resize(0u);
68 96
69 mojo::Rect bounds; 97 mojo::Rect bounds;
70 bounds.width = size.width(); 98 bounds.width = size.width();
71 bounds.height = size.height(); 99 bounds.height = size.height();
72 mojo::PassPtr pass = mojo::CreateDefaultPass(1, bounds); 100 mojo::PassPtr pass = mojo::CreateDefaultPass(1, bounds);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 132
105 frame->resources.push_back(resource.Pass()); 133 frame->resources.push_back(resource.Pass());
106 quad->texture_quad_state = texture_state.Pass(); 134 quad->texture_quad_state = texture_state.Pass();
107 pass->quads.push_back(quad.Pass()); 135 pass->quads.push_back(quad.Pass());
108 136
109 frame->passes.push_back(pass.Pass()); 137 frame->passes.push_back(pass.Pass());
110 surface_holder_.SubmitFrame(frame.Pass()); 138 surface_holder_.SubmitFrame(frame.Pass());
111 } 139 }
112 140
113 } // namespace sky 141 } // namespace sky
OLDNEW
« no previous file with comments | « sky/compositor/layer_host.h ('k') | sky/compositor/surface_holder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698