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

Side by Side Diff: mojo/services/native_viewport/viewport_surface.cc

Issue 769173002: Move native_viewport and gles2 service impls to //services (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 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
« no previous file with comments | « mojo/services/native_viewport/viewport_surface.h ('k') | mojo/shell/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 "mojo/services/native_viewport/viewport_surface.h"
6
7 #include "base/bind.h"
8 #include "cc/surfaces/surface_id_allocator.h"
9 #include "mojo/converters/geometry/geometry_type_converters.h"
10 #include "mojo/converters/surfaces/surfaces_type_converters.h"
11 #include "mojo/services/public/cpp/surfaces/surfaces_utils.h"
12 #include "ui/gfx/transform.h"
13
14 namespace mojo {
15
16 ViewportSurface::ViewportSurface(SurfacesService* surfaces_service,
17 Gpu* gpu_service,
18 const gfx::Size& size,
19 cc::SurfaceId child_id)
20 : gpu_service_(gpu_service),
21 widget_id_(0u),
22 size_(size),
23 child_id_(child_id),
24 weak_factory_(this) {
25 surfaces_service->CreateSurfaceConnection(
26 base::Bind(&ViewportSurface::OnSurfaceConnectionCreated,
27 weak_factory_.GetWeakPtr()));
28 }
29
30 ViewportSurface::~ViewportSurface() {
31 }
32
33 void ViewportSurface::SetWidgetId(uint64_t widget_id) {
34 widget_id_ = widget_id;
35 if (id_allocator_)
36 BindSurfaceToNativeViewport();
37 }
38
39 void ViewportSurface::SetSize(const gfx::Size& size) {
40 if (size_ == size)
41 return;
42
43 size_ = size;
44 if (id_.is_null())
45 return;
46
47 surface_->DestroySurface(SurfaceId::From(id_));
48 if (widget_id_)
49 BindSurfaceToNativeViewport();
50 }
51
52 void ViewportSurface::SetChildId(cc::SurfaceId child_id) {
53 child_id_ = child_id;
54 SubmitFrame();
55 }
56
57 void ViewportSurface::OnSurfaceConnectionCreated(SurfacePtr surface,
58 uint32_t id_namespace) {
59 surface_ = surface.Pass();
60 surface_.set_client(this);
61 id_allocator_.reset(new cc::SurfaceIdAllocator(id_namespace));
62 if (widget_id_ != 0u)
63 BindSurfaceToNativeViewport();
64 }
65
66 void ViewportSurface::BindSurfaceToNativeViewport() {
67 ViewportParameterListenerPtr listener;
68 InterfaceRequest<ViewportParameterListener> listener_request =
69 GetProxy(&listener);
70
71 CommandBufferPtr command_buffer;
72 gpu_service_->CreateOnscreenGLES2Context(widget_id_, Size::From(size_),
73 GetProxy(&command_buffer),
74 listener.Pass());
75
76 id_ = id_allocator_->GenerateId();
77 surface_->CreateGLES2BoundSurface(command_buffer.Pass(), SurfaceId::From(id_),
78 Size::From(size_), listener_request.Pass());
79
80 SubmitFrame();
81 }
82
83 void ViewportSurface::SubmitFrame() {
84 if (child_id_.is_null() || id_.is_null())
85 return;
86
87 SurfaceQuadStatePtr surface_quad_state = SurfaceQuadState::New();
88 surface_quad_state->surface = SurfaceId::From(child_id_);
89
90 gfx::Rect bounds(size_);
91
92 QuadPtr surface_quad = Quad::New();
93 surface_quad->material = Material::MATERIAL_SURFACE_CONTENT;
94 surface_quad->rect = Rect::From(bounds);
95 surface_quad->opaque_rect = Rect::From(bounds);
96 surface_quad->visible_rect = Rect::From(bounds);
97 surface_quad->needs_blending = true;
98 surface_quad->shared_quad_state_index = 0;
99 surface_quad->surface_quad_state = surface_quad_state.Pass();
100
101 PassPtr pass = CreateDefaultPass(1, *mojo::Rect::From(bounds));
102
103 pass->quads.push_back(surface_quad.Pass());
104 pass->shared_quad_states.push_back(CreateDefaultSQS(
105 *mojo::Size::From(size_)));
106
107 FramePtr frame = Frame::New();
108 frame->passes.push_back(pass.Pass());
109 frame->resources.resize(0u);
110 surface_->SubmitFrame(SurfaceId::From(id_), frame.Pass(), mojo::Closure());
111 }
112
113 void ViewportSurface::ReturnResources(Array<ReturnedResourcePtr> resources) {
114 // We never submit resources so we should never get any back.
115 DCHECK_EQ(0u, resources.size());
116 }
117
118 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/services/native_viewport/viewport_surface.h ('k') | mojo/shell/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698