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

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: Address review issues 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"
10 #include "mojo/application/public/cpp/application_impl.h" 17 #include "mojo/application/public/cpp/application_impl.h"
11 #include "mojo/converters/geometry/geometry_type_converters.h" 18 #include "mojo/converters/geometry/geometry_type_converters.h"
12 #include "mojo/converters/surfaces/surfaces_utils.h" 19 #include "mojo/converters/surfaces/surfaces_utils.h"
13 20
14 namespace content { 21 namespace content {
15 22
23 namespace {
24
25 typedef std::map<int, RenderWidgetMusConnection*> ConnectionMap;
26 base::LazyInstance<ConnectionMap>::Leaky g_connections =
27 LAZY_INSTANCE_INITIALIZER;
28
29 }
30
16 RenderWidgetMusConnection::RenderWidgetMusConnection( 31 RenderWidgetMusConnection::RenderWidgetMusConnection(
17 int routing_id, 32 int routing_id)
Fady Samuel 2015/12/01 15:52:27 nit: Run git cl format
Peng 2015/12/01 15:54:47 Done.
18 mojo::InterfaceRequest<mus::mojom::WindowTreeClient> request)
19 : routing_id_(routing_id), root_(nullptr) { 33 : routing_id_(routing_id), root_(nullptr) {
20 // TODO(fsamuel): We should probably introduce a 34 DCHECK(routing_id);
21 // RenderWidgetMusConnection::FromRoutingID that's usable from RenderWidget. 35 }
36
37 RenderWidgetMusConnection::~RenderWidgetMusConnection() {
38 }
39
40 void RenderWidgetMusConnection::Connect(
41 mojo::InterfaceRequest<mus::mojom::WindowTreeClient> request) {
22 // TODO(fsamuel): We probably want to pause processing of incoming 42 // TODO(fsamuel): We probably want to pause processing of incoming
23 // messages until we have an associated RenderWidget. 43 // messages until we have an associated RenderWidget.
44 DCHECK(!root_);
24 mus::WindowTreeConnection::Create( 45 mus::WindowTreeConnection::Create(
25 this, request.Pass(), 46 this, request.Pass(),
26 mus::WindowTreeConnection::CreateType::DONT_WAIT_FOR_EMBED); 47 mus::WindowTreeConnection::CreateType::DONT_WAIT_FOR_EMBED);
27 } 48 }
28 49
29 RenderWidgetMusConnection::~RenderWidgetMusConnection() {} 50 scoped_ptr<cc::OutputSurface> RenderWidgetMusConnection::CreateOutputSurface() {
51 DCHECK(!window_surface_binding_);
52 mus::mojom::GpuPtr gpu_service;
53 MojoShellConnection::Get()->GetApplication()->ConnectToService(
54 "mojo:mus", &gpu_service);
55 mus::mojom::CommandBufferPtr cb;
56 gpu_service->CreateOffscreenGLES2Context(GetProxy(&cb));
57 scoped_refptr<cc::ContextProvider> context_provider(
58 new mus::ContextProvider(cb.PassInterface().PassHandle()));
59 scoped_ptr<cc::OutputSurface> output_surface(new mus::OutputSurface(
60 context_provider,
61 mus::WindowSurface::Create(&window_surface_binding_)));
62 if (root_) {
63 root_->AttachSurface(mus::mojom::SURFACE_TYPE_DEFAULT,
64 window_surface_binding_.Pass());
65 }
66 return output_surface.Pass();
67 }
30 68
31 void RenderWidgetMusConnection::SubmitCompositorFrame() { 69 // static
32 const gfx::Rect bounds(root_->bounds()); 70 RenderWidgetMusConnection* RenderWidgetMusConnection::GetOrCreate(
33 mus::mojom::PassPtr pass = mojo::CreateDefaultPass(1, bounds); 71 int routing_id) {
34 mus::mojom::CompositorFramePtr frame = mus::mojom::CompositorFrame::New(); 72 auto it = g_connections.Get().find(routing_id);
73 if (it != g_connections.Get().end())
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
« no previous file with comments | « content/renderer/render_widget_mus_connection.h ('k') | content/renderer/render_widget_window_tree_client_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698