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

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

Issue 510553002: Teach the native viewport service to draw a Surface into itself (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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
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/services/public/cpp/geometry/geometry_type_converters.h"
10 #include "mojo/services/public/cpp/surfaces/surfaces_type_converters.h"
11 #include "ui/gfx/transform.h"
12
13 namespace mojo {
14
15 ViewportSurface::ViewportSurface(SurfacesService* surfaces_service,
16 Gpu* gpu_service,
17 const gfx::Rect& bounds,
18 cc::SurfaceId child_id)
19 : gpu_service_(gpu_service),
20 widget_id_(0u),
21 bounds_(bounds),
22 child_id_(child_id),
23 weak_factory_(this) {
24 surfaces_service->CreateSurfaceConnection(
25 base::Bind(&ViewportSurface::OnSurfaceConnectionCreated,
26 weak_factory_.GetWeakPtr()));
27 }
28
29 ViewportSurface::~ViewportSurface() {
30 }
31
32 void ViewportSurface::SetWidgetId(uint64_t widget_id) {
33 widget_id_ = widget_id;
34 if (id_allocator_)
35 BindSurfaceToNativeViewport();
36 }
37
38 void ViewportSurface::SetBounds(const gfx::Rect& bounds) {
39 if (bounds_ == bounds)
40 return;
41
42 if (id_.is_null())
43 return;
44
45 surface_->DestroySurface(SurfaceId::From(id_));
46 BindSurfaceToNativeViewport();
47 }
48
49 void ViewportSurface::SetChildId(cc::SurfaceId child_id) {
50 child_id_ = child_id;
51 SubmitFrame();
52 }
53
54 void ViewportSurface::OnSurfaceConnectionCreated(SurfacePtr surface,
55 uint32_t id_namespace) {
56 surface_ = surface.Pass();
57 id_allocator_.reset(new cc::SurfaceIdAllocator(id_namespace));
58 if (widget_id_ != 0u)
59 BindSurfaceToNativeViewport();
60 }
61
62 void ViewportSurface::BindSurfaceToNativeViewport() {
63 CommandBufferPtr cb;
64 gpu_service_->CreateOnscreenGLES2Context(
65 widget_id_, Size::From(bounds_.size()), Get(&cb));
66
67 id_ = id_allocator_->GenerateId();
68 surface_->CreateGLES2BoundSurface(
69 cb.Pass(), SurfaceId::From(id_), Size::From(bounds_.size()));
70
71 SubmitFrame();
72 }
73
74 void ViewportSurface::SubmitFrame() {
75 if (child_id_.is_null() || id_.is_null())
76 return;
77
78 SurfaceQuadStatePtr surface_quad_state = SurfaceQuadState::New();
79 surface_quad_state->surface = SurfaceId::From(child_id_);
80
81 QuadPtr surface_quad = Quad::New();
82 surface_quad->material = Material::MATERIAL_SURFACE_CONTENT;
83 surface_quad->rect = Rect::From(bounds_);
84 surface_quad->opaque_rect = Rect::From(bounds_);
85 surface_quad->visible_rect = Rect::From(bounds_);
86 surface_quad->needs_blending = true;
87 surface_quad->shared_quad_state_index = 0;
88 surface_quad->surface_quad_state = surface_quad_state.Pass();
89
90 SharedQuadStatePtr sqs = SharedQuadState::New();
91 sqs->content_to_target_transform = Transform::From(gfx::Transform());
92 sqs->content_bounds = Size::From(bounds_.size());
93 sqs->visible_content_rect = Rect::From(bounds_);
94 sqs->clip_rect = Rect::From(bounds_);
95 sqs->is_clipped = false;
96 sqs->opacity = 1.0f;
97 sqs->blend_mode = SkXfermode::SK_XFERMODE_kSrcOver_Mode;
98 sqs->sorting_context_id = 1;
99
100 PassPtr pass = Pass::New();
101 pass->id = 1;
102 pass->output_rect = Rect::From(bounds_);
103 pass->damage_rect = Rect::From(bounds_);
104 pass->transform_to_root_target = Transform::From(gfx::Transform());
105 pass->has_transparent_background = false;
106 pass->quads.push_back(surface_quad.Pass());
107 pass->shared_quad_states.push_back(sqs.Pass());
108
109 FramePtr frame = Frame::New();
110 frame->passes.push_back(pass.Pass());
111 frame->resources.resize(0u);
112 surface_->SubmitFrame(SurfaceId::From(id_), frame.Pass());
113 }
114
115 void ViewportSurface::ReturnResources(Array<ReturnedResourcePtr> resources) {
116 // We never submit resources so we should never get any back.
117 DCHECK_EQ(0u, resources.size());
118 }
119
120 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/services/native_viewport/viewport_surface.h ('k') | mojo/services/public/interfaces/native_viewport/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698