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

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

Issue 940293003: Add a Display and ContextProvider concept to mojom, use to recreate (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 9 months 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 | « services/native_viewport/viewport_surface.h ('k') | services/surfaces/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 "services/native_viewport/viewport_surface.h"
6
7 #include "base/bind.h"
8 #include "mojo/converters/geometry/geometry_type_converters.h"
9 #include "mojo/converters/surfaces/surfaces_type_converters.h"
10 #include "mojo/services/surfaces/public/cpp/surfaces_utils.h"
11 #include "ui/gfx/transform.h"
12
13 using mojo::Size;
14 using mojo::SurfaceId;
15
16 static uint32_t kGLES2BoundSurfaceLocalId = 1u;
17
18 namespace native_viewport {
19
20 ViewportSurface::ViewportSurface(mojo::SurfacePtr surface,
21 mojo::Gpu* gpu_service,
22 const gfx::Size& size,
23 cc::SurfaceId child_id)
24 : surface_(surface.Pass()),
25 gpu_service_(gpu_service),
26 widget_id_(0u),
27 size_(size),
28 gles2_bound_surface_created_(false),
29 child_id_(child_id),
30 weak_factory_(this) {
31 }
32
33 ViewportSurface::~ViewportSurface() {
34 }
35
36 void ViewportSurface::SetWidgetId(uint64_t widget_id) {
37 widget_id_ = widget_id;
38 BindSurfaceToNativeViewport();
39 }
40
41 void ViewportSurface::SetSize(const gfx::Size& size) {
42 if (size_ == size)
43 return;
44
45 size_ = size;
46 if (!gles2_bound_surface_created_)
47 return;
48
49 surface_->DestroySurface(kGLES2BoundSurfaceLocalId);
50 if (widget_id_)
51 BindSurfaceToNativeViewport();
52 }
53
54 void ViewportSurface::SetChildId(cc::SurfaceId child_id) {
55 child_id_ = child_id;
56 SubmitFrame();
57 }
58
59 void ViewportSurface::BindSurfaceToNativeViewport() {
60 mojo::ViewportParameterListenerPtr listener;
61 auto listener_request = GetProxy(&listener);
62 mojo::CommandBufferPtr command_buffer;
63 gpu_service_->CreateOnscreenGLES2Context(widget_id_, Size::From(size_),
64 GetProxy(&command_buffer),
65 listener.Pass());
66
67 gles2_bound_surface_created_ = true;
68 surface_->CreateGLES2BoundSurface(command_buffer.Pass(),
69 kGLES2BoundSurfaceLocalId,
70 Size::From(size_), listener_request.Pass());
71
72 SubmitFrame();
73 }
74
75 void ViewportSurface::SubmitFrame() {
76 if (child_id_.is_null() || !gles2_bound_surface_created_)
77 return;
78
79 auto surface_quad_state = mojo::SurfaceQuadState::New();
80 surface_quad_state->surface = SurfaceId::From(child_id_);
81
82 gfx::Rect bounds(size_);
83
84 auto surface_quad = mojo::Quad::New();
85 surface_quad->material = mojo::Material::MATERIAL_SURFACE_CONTENT;
86 surface_quad->rect = mojo::Rect::From(bounds);
87 surface_quad->opaque_rect = mojo::Rect::From(bounds);
88 surface_quad->visible_rect = mojo::Rect::From(bounds);
89 surface_quad->needs_blending = true;
90 surface_quad->shared_quad_state_index = 0;
91 surface_quad->surface_quad_state = surface_quad_state.Pass();
92
93 auto pass = CreateDefaultPass(1, *mojo::Rect::From(bounds));
94
95 pass->quads.push_back(surface_quad.Pass());
96 pass->shared_quad_states.push_back(CreateDefaultSQS(
97 *mojo::Size::From(size_)));
98
99 auto frame = mojo::Frame::New();
100 frame->passes.push_back(pass.Pass());
101 frame->resources.resize(0u);
102 surface_->SubmitFrame(kGLES2BoundSurfaceLocalId, frame.Pass(),
103 mojo::Closure());
104 }
105
106 } // namespace native_viewport
OLDNEW
« no previous file with comments | « services/native_viewport/viewport_surface.h ('k') | services/surfaces/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698