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

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

Issue 687433002: Remove mojo/shell and (most) service implementations (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove mojo/gles2, disable mojo apps in component build 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 | « mojo/services/native_viewport/viewport_surface.h ('k') | mojo/services/network/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/converters/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 if (id_.is_null())
44 return;
45
46 surface_->DestroySurface(SurfaceId::From(id_));
47 if (widget_id_)
48 BindSurfaceToNativeViewport();
49 }
50
51 void ViewportSurface::SetChildId(cc::SurfaceId child_id) {
52 child_id_ = child_id;
53 SubmitFrame();
54 }
55
56 void ViewportSurface::OnSurfaceConnectionCreated(SurfacePtr surface,
57 uint32_t id_namespace) {
58 surface_ = surface.Pass();
59 surface_.set_client(this);
60 id_allocator_.reset(new cc::SurfaceIdAllocator(id_namespace));
61 if (widget_id_ != 0u)
62 BindSurfaceToNativeViewport();
63 }
64
65 void ViewportSurface::BindSurfaceToNativeViewport() {
66 CommandBufferPtr cb;
67 gpu_service_->CreateOnscreenGLES2Context(
68 widget_id_, Size::From(size_), GetProxy(&cb));
69
70 id_ = id_allocator_->GenerateId();
71 surface_->CreateGLES2BoundSurface(
72 cb.Pass(), SurfaceId::From(id_), Size::From(size_));
73
74 SubmitFrame();
75 }
76
77 void ViewportSurface::SubmitFrame() {
78 if (child_id_.is_null() || id_.is_null())
79 return;
80
81 SurfaceQuadStatePtr surface_quad_state = SurfaceQuadState::New();
82 surface_quad_state->surface = SurfaceId::From(child_id_);
83
84 gfx::Rect bounds(size_);
85
86 QuadPtr surface_quad = Quad::New();
87 surface_quad->material = Material::MATERIAL_SURFACE_CONTENT;
88 surface_quad->rect = Rect::From(bounds);
89 surface_quad->opaque_rect = Rect::From(bounds);
90 surface_quad->visible_rect = Rect::From(bounds);
91 surface_quad->needs_blending = true;
92 surface_quad->shared_quad_state_index = 0;
93 surface_quad->surface_quad_state = surface_quad_state.Pass();
94
95 PassPtr pass = CreateDefaultPass(1, bounds);
96
97 pass->quads.push_back(surface_quad.Pass());
98 pass->shared_quad_states.push_back(CreateDefaultSQS(size_));
99
100 FramePtr frame = Frame::New();
101 frame->passes.push_back(pass.Pass());
102 frame->resources.resize(0u);
103 surface_->SubmitFrame(SurfaceId::From(id_), frame.Pass());
104 }
105
106 void ViewportSurface::ReturnResources(Array<ReturnedResourcePtr> resources) {
107 // We never submit resources so we should never get any back.
108 DCHECK_EQ(0u, resources.size());
109 }
110
111 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/services/native_viewport/viewport_surface.h ('k') | mojo/services/network/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698