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

Side by Side Diff: content/renderer/render_widget_mus_connection.cc

Issue 1472063007: mustash: enable GPU Compositing in renderer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update Created 5 years 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 "content/renderer/render_widget_mus_connection.h" 5 #include "content/renderer/render_widget_mus_connection.h"
6 6
7 #include <map>
8
9 #include "base/lazy_instance.h"
10 #include "components/mus/public/cpp/context_provider.h"
11 #include "components/mus/public/cpp/output_surface.h"
12 #include "components/mus/public/interfaces/command_buffer.mojom.h"
7 #include "components/mus/public/interfaces/compositor_frame.mojom.h" 13 #include "components/mus/public/interfaces/compositor_frame.mojom.h"
14 #include "components/mus/public/interfaces/gpu.mojom.h"
8 #include "components/mus/public/interfaces/window_tree.mojom.h" 15 #include "components/mus/public/interfaces/window_tree.mojom.h"
9 #include "content/public/common/mojo_shell_connection.h" 16 #include "content/public/common/mojo_shell_connection.h"
17 #include "content/renderer/render_view_impl.h"
Fady Samuel 2015/11/30 23:06:54 Do you need this?
Peng 2015/12/01 15:22:47 Done.
10 #include "mojo/application/public/cpp/application_impl.h" 18 #include "mojo/application/public/cpp/application_impl.h"
11 #include "mojo/converters/geometry/geometry_type_converters.h" 19 #include "mojo/converters/geometry/geometry_type_converters.h"
12 #include "mojo/converters/surfaces/surfaces_utils.h" 20 #include "mojo/converters/surfaces/surfaces_utils.h"
13 21
14 namespace content { 22 namespace content {
15 23
24 namespace {
25
26 typedef std::map<int, RenderWidgetMusConnection*> ConnectionMap;
27 base::LazyInstance<ConnectionMap>::Leaky g_connections =
28 LAZY_INSTANCE_INITIALIZER;
29
30 }
31
16 RenderWidgetMusConnection::RenderWidgetMusConnection( 32 RenderWidgetMusConnection::RenderWidgetMusConnection(
17 int routing_id, 33 int routing_id)
18 mojo::InterfaceRequest<mus::mojom::WindowTreeClient> request) 34 : routing_id_(routing_id), connected_(false), root_(nullptr) {
19 : routing_id_(routing_id), root_(nullptr) { 35 DCHECK(routing_id);
20 // TODO(fsamuel): We should probably introduce a 36 }
21 // RenderWidgetMusConnection::FromRoutingID that's usable from RenderWidget. 37
38 RenderWidgetMusConnection::~RenderWidgetMusConnection() {
39 }
40
41 void RenderWidgetMusConnection::Connect(
42 mojo::InterfaceRequest<mus::mojom::WindowTreeClient> request) {
22 // TODO(fsamuel): We probably want to pause processing of incoming 43 // TODO(fsamuel): We probably want to pause processing of incoming
23 // messages until we have an associated RenderWidget. 44 // messages until we have an associated RenderWidget.
45 DCHECK(!connected_);
Fady Samuel 2015/11/30 23:06:54 Just check if you have a root. You don't need this
Peng 2015/12/01 15:22:47 Done.
24 mus::WindowTreeConnection::Create( 46 mus::WindowTreeConnection::Create(
25 this, request.Pass(), 47 this, request.Pass(),
26 mus::WindowTreeConnection::CreateType::DONT_WAIT_FOR_EMBED); 48 mus::WindowTreeConnection::CreateType::DONT_WAIT_FOR_EMBED);
49 connected_ = true;
27 } 50 }
28 51
29 RenderWidgetMusConnection::~RenderWidgetMusConnection() {} 52 scoped_ptr<cc::OutputSurface> RenderWidgetMusConnection::CreateOutputSurface() {
53 DCHECK(!window_surface_binding_);
54 mus::mojom::GpuPtr gpu_service;
55 MojoShellConnection::Get()->GetApplication()->ConnectToService(
56 "mojo:mus", &gpu_service);
57 mus::mojom::CommandBufferPtr cb;
58 gpu_service->CreateOffscreenGLES2Context(GetProxy(&cb));
59 scoped_refptr<cc::ContextProvider> context_provider(
60 new mus::ContextProvider(cb.PassInterface().PassHandle()));
61 scoped_ptr<cc::OutputSurface> output_surface(new mus::OutputSurface(
62 context_provider,
63 mus::WindowSurface::Create(&window_surface_binding_)));
64 if (root_) {
65 root_->AttachSurface(mus::mojom::SURFACE_TYPE_DEFAULT,
66 window_surface_binding_.Pass());
67 }
68 return output_surface.Pass();
69 }
30 70
31 void RenderWidgetMusConnection::SubmitCompositorFrame() { 71 RenderWidgetMusConnection* RenderWidgetMusConnection::Get(int routing_id) {
Fady Samuel 2015/11/30 23:06:54 Add // static above.
Peng 2015/12/01 15:22:47 Done.
32 const gfx::Rect bounds(root_->bounds()); 72 auto it = g_connections.Get().find(routing_id);
33 mus::mojom::PassPtr pass = mojo::CreateDefaultPass(1, bounds); 73 if (it != g_connections.Get().end())
34 mus::mojom::CompositorFramePtr frame = mus::mojom::CompositorFrame::New(); 74 return it->second;
35 75
36 mus::mojom::CompositorFrameMetadataPtr meta = 76 RenderWidgetMusConnection* connection = new RenderWidgetMusConnection(
37 mus::mojom::CompositorFrameMetadata::New(); 77 routing_id);
38 meta->device_scale_factor = 1.0f; 78 g_connections.Get().insert(std::make_pair(routing_id, connection));
39 frame->metadata = meta.Pass(); 79 return connection;
40
41 frame->resources.resize(0u);
42
43 pass->quads.resize(0u);
44 pass->shared_quad_states.push_back(mojo::CreateDefaultSQS(bounds.size()));
45
46 mus::mojom::QuadPtr quad = mus::mojom::Quad::New();
47 quad->material = mus::mojom::MATERIAL_SOLID_COLOR;
48 quad->rect = mojo::Rect::From(bounds);
49 quad->opaque_rect = mojo::Rect::New();
50 quad->visible_rect = mojo::Rect::From(bounds);
51 quad->needs_blending = false;
52 quad->shared_quad_state_index = 0u;
53
54 mus::mojom::SolidColorQuadStatePtr color_state =
55 mus::mojom::SolidColorQuadState::New();
56 color_state->color = mus::mojom::Color::New();
57 color_state->color->rgba = 0xff00ff00;
58 color_state->force_anti_aliasing_off = false;
59
60 quad->solid_color_quad_state = color_state.Pass();
61 pass->quads.push_back(quad.Pass());
62 frame->passes.push_back(pass.Pass());
63 surface_->SubmitCompositorFrame(frame.Pass(), mojo::Closure());
64 } 80 }
65 81
66 void RenderWidgetMusConnection::OnConnectionLost( 82 void RenderWidgetMusConnection::OnConnectionLost(
67 mus::WindowTreeConnection* connection) { 83 mus::WindowTreeConnection* connection) {
84 g_connections.Get().erase(routing_id_);
68 delete this; 85 delete this;
69 } 86 }
70 87
71 void RenderWidgetMusConnection::OnEmbed(mus::Window* root) { 88 void RenderWidgetMusConnection::OnEmbed(mus::Window* root) {
72 root_ = root; 89 root_ = root;
73 root_->AddObserver(this); 90 root_->AddObserver(this);
74 surface_ = root_->RequestSurface(mus::mojom::SURFACE_TYPE_DEFAULT); 91 if (window_surface_binding_) {
75 surface_->BindToThread(); 92 root->AttachSurface(mus::mojom::SURFACE_TYPE_DEFAULT,
76 SubmitCompositorFrame(); 93 window_surface_binding_.Pass());
94 }
77 } 95 }
78 96
79 void RenderWidgetMusConnection::OnUnembed() {} 97 void RenderWidgetMusConnection::OnUnembed() {}
80 98
81 void RenderWidgetMusConnection::OnWindowBoundsChanged( 99 void RenderWidgetMusConnection::OnWindowBoundsChanged(
82 mus::Window* window, 100 mus::Window* window,
83 const gfx::Rect& old_bounds, 101 const gfx::Rect& old_bounds,
84 const gfx::Rect& new_bounds) { 102 const gfx::Rect& new_bounds) {
85 SubmitCompositorFrame();
86 } 103 }
87 104
88 } // namespace content 105 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698