OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "sky/compositor/layer_host.h" |
| 6 |
| 7 #include "mojo/converters/geometry/geometry_type_converters.h" |
| 8 #include "mojo/gpu/gl_context.h" |
| 9 #include "mojo/services/public/cpp/surfaces/surfaces_utils.h" |
| 10 #include "mojo/skia/ganesh_context.h" |
| 11 #include "sky/compositor/layer.h" |
| 12 |
| 13 namespace sky { |
| 14 |
| 15 LayerHost::LayerHost(LayerHostClient* client) |
| 16 : client_(client), |
| 17 surface_holder_(this, client->GetShell()), |
| 18 gl_context_(mojo::GLContext::Create(client->GetShell())), |
| 19 ganesh_context_(gl_context_), |
| 20 resource_manager_(gl_context_) { |
| 21 } |
| 22 |
| 23 LayerHost::~LayerHost() { |
| 24 } |
| 25 |
| 26 void LayerHost::SetNeedsAnimate() { |
| 27 } |
| 28 |
| 29 void LayerHost::SetRootLayer(scoped_refptr<Layer> layer) { |
| 30 DCHECK(!root_layer_.get()); |
| 31 root_layer_ = layer; |
| 32 root_layer_->set_host(this); |
| 33 } |
| 34 |
| 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) { |
| 42 client_->OnSurfaceIdAvailable(surface_id.Pass()); |
| 43 } |
| 44 |
| 45 void LayerHost::ReturnResources( |
| 46 mojo::Array<mojo::ReturnedResourcePtr> resources) { |
| 47 resource_manager_.ReturnResources(resources.Pass()); |
| 48 } |
| 49 |
| 50 void LayerHost::Upload(Layer* layer) { |
| 51 gfx::Size size = layer->size(); |
| 52 surface_holder_.SetSize(size); |
| 53 |
| 54 mojo::FramePtr frame = mojo::Frame::New(); |
| 55 frame->resources.resize(0u); |
| 56 |
| 57 mojo::Rect bounds; |
| 58 bounds.width = size.width(); |
| 59 bounds.height = size.height(); |
| 60 mojo::PassPtr pass = mojo::CreateDefaultPass(1, bounds); |
| 61 pass->quads.resize(0u); |
| 62 pass->shared_quad_states.push_back(mojo::CreateDefaultSQS( |
| 63 mojo::TypeConverter<mojo::Size, gfx::Size>::Convert(size))); |
| 64 |
| 65 mojo::TransferableResourcePtr resource = |
| 66 resource_manager_.CreateTransferableResource(layer); |
| 67 |
| 68 mojo::QuadPtr quad = mojo::Quad::New(); |
| 69 quad->material = mojo::MATERIAL_TEXTURE_CONTENT; |
| 70 |
| 71 mojo::RectPtr rect = mojo::Rect::New(); |
| 72 rect->width = size.width(); |
| 73 rect->height = size.height(); |
| 74 quad->rect = rect.Clone(); |
| 75 quad->opaque_rect = rect.Clone(); |
| 76 quad->visible_rect = rect.Clone(); |
| 77 quad->needs_blending = true; |
| 78 quad->shared_quad_state_index = 0u; |
| 79 |
| 80 mojo::TextureQuadStatePtr texture_state = mojo::TextureQuadState::New(); |
| 81 texture_state->resource_id = resource->id; |
| 82 texture_state->premultiplied_alpha = true; |
| 83 texture_state->uv_top_left = mojo::PointF::New(); |
| 84 texture_state->uv_bottom_right = mojo::PointF::New(); |
| 85 texture_state->uv_bottom_right->x = 1.f; |
| 86 texture_state->uv_bottom_right->y = 1.f; |
| 87 texture_state->background_color = mojo::Color::New(); |
| 88 texture_state->background_color->rgba = 0; |
| 89 for (int i = 0; i < 4; ++i) |
| 90 texture_state->vertex_opacity.push_back(1.f); |
| 91 texture_state->flipped = false; |
| 92 |
| 93 frame->resources.push_back(resource.Pass()); |
| 94 quad->texture_quad_state = texture_state.Pass(); |
| 95 pass->quads.push_back(quad.Pass()); |
| 96 |
| 97 frame->passes.push_back(pass.Pass()); |
| 98 surface_holder_.SubmitFrame(frame.Pass()); |
| 99 } |
| 100 |
| 101 } // namespace sky |
OLD | NEW |