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

Side by Side Diff: mojo/services/native_viewport/native_viewport_impl.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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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 "mojo/services/native_viewport/native_viewport_impl.h" 5 #include "mojo/services/native_viewport/native_viewport_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/time/time.h" 10 #include "base/time/time.h"
11 #include "mojo/public/cpp/application/application_delegate.h" 11 #include "mojo/public/cpp/application/application_delegate.h"
12 #include "mojo/public/cpp/application/interface_factory.h" 12 #include "mojo/public/cpp/application/interface_factory.h"
13 #include "mojo/services/public/cpp/geometry/geometry_type_converters.h" 13 #include "mojo/services/public/cpp/geometry/geometry_type_converters.h"
14 #include "mojo/services/public/cpp/input_events/input_events_type_converters.h" 14 #include "mojo/services/public/cpp/input_events/input_events_type_converters.h"
15 #include "mojo/services/public/cpp/surfaces/surfaces_type_converters.h"
15 #include "ui/events/event.h" 16 #include "ui/events/event.h"
16 17
17 namespace mojo { 18 namespace mojo {
18 namespace { 19 namespace {
19 20
20 bool IsRateLimitedEventType(ui::Event* event) { 21 bool IsRateLimitedEventType(ui::Event* event) {
21 return event->type() == ui::ET_MOUSE_MOVED || 22 return event->type() == ui::ET_MOUSE_MOVED ||
22 event->type() == ui::ET_MOUSE_DRAGGED || 23 event->type() == ui::ET_MOUSE_DRAGGED ||
23 event->type() == ui::ET_TOUCH_MOVED; 24 event->type() == ui::ET_TOUCH_MOVED;
24 } 25 }
25 26
26 } // namespace 27 } // namespace
27 28
28 NativeViewportImpl::NativeViewportImpl() 29 NativeViewportImpl::NativeViewportImpl(SurfacesServicePtr surfaces_service,
29 : widget_(gfx::kNullAcceleratedWidget), 30 GpuPtr gpu_service)
30 waiting_for_event_ack_(false), 31 : surfaces_service_(surfaces_service.Pass()),
31 weak_factory_(this) {} 32 gpu_service_(gpu_service.Pass()),
33 widget_id_(0u),
34 waiting_for_event_ack_(false),
35 weak_factory_(this) {
36 }
32 37
33 NativeViewportImpl::~NativeViewportImpl() { 38 NativeViewportImpl::~NativeViewportImpl() {
34 // Destroy the NativeViewport early on as it may call us back during 39 // Destroy the NativeViewport early on as it may call us back during
35 // destruction and we want to be in a known state. 40 // destruction and we want to be in a known state.
36 platform_viewport_.reset(); 41 platform_viewport_.reset();
37 } 42 }
38 43
39 void NativeViewportImpl::Create(RectPtr bounds) { 44 void NativeViewportImpl::Create(RectPtr bounds) {
40 platform_viewport_ = PlatformViewport::Create(this); 45 platform_viewport_ = PlatformViewport::Create(this);
41 platform_viewport_->Init(bounds.To<gfx::Rect>()); 46 platform_viewport_->Init(bounds.To<gfx::Rect>());
(...skipping 10 matching lines...) Expand all
52 57
53 void NativeViewportImpl::Close() { 58 void NativeViewportImpl::Close() {
54 DCHECK(platform_viewport_); 59 DCHECK(platform_viewport_);
55 platform_viewport_->Close(); 60 platform_viewport_->Close();
56 } 61 }
57 62
58 void NativeViewportImpl::SetBounds(RectPtr bounds) { 63 void NativeViewportImpl::SetBounds(RectPtr bounds) {
59 platform_viewport_->SetBounds(bounds.To<gfx::Rect>()); 64 platform_viewport_->SetBounds(bounds.To<gfx::Rect>());
60 } 65 }
61 66
67 void NativeViewportImpl::SubmittedFrame(SurfaceIdPtr surface_id) {
68 if (child_surface_id_.is_null()) {
69 // If this is the first indication that the client will use surfaces,
70 // initialize that system.
71 // TODO(jamesr): When everything is converted to surfaces initialize this
72 // eagerly.
73 surfaces_service_->CreateSurfaceConnection(
74 base::Bind(&NativeViewportImpl::OnSurfaceConnectionCreated,
75 base::Unretained(this)));
sky 2014/08/26 23:16:32 Is it possible for 'this' to be deleted before the
jamesr 2014/08/26 23:17:22 Oh whoops, it is. I'll bind to a weak ptr
76 }
77 child_surface_id_ = surface_id.To<cc::SurfaceId>();
78 SubmitFrame();
79 }
80
62 void NativeViewportImpl::OnBoundsChanged(const gfx::Rect& bounds) { 81 void NativeViewportImpl::OnBoundsChanged(const gfx::Rect& bounds) {
82 if (bounds == bounds_)
83 return;
84 bounds_ = bounds;
63 client()->OnBoundsChanged(Rect::From(bounds)); 85 client()->OnBoundsChanged(Rect::From(bounds));
86 if (!surface_id_.is_null())
87 surface_->DestroySurface(SurfaceId::From(surface_id_));
88 if (!surface_id_allocator_)
89 return;
90 surface_id_ = surface_id_allocator_->GenerateId();
91 surface_->CreateSurface(SurfaceId::From(surface_id_),
92 Size::From(bounds_.size()));
93 SubmitFrame();
64 } 94 }
65 95
66 void NativeViewportImpl::OnAcceleratedWidgetAvailable( 96 void NativeViewportImpl::OnAcceleratedWidgetAvailable(
67 gfx::AcceleratedWidget widget) { 97 gfx::AcceleratedWidget widget) {
68 widget_ = widget; 98 widget_id_ = static_cast<uint64_t>(bit_cast<uintptr_t>(widget));
69 uintptr_t widget_ptr = bit_cast<uintptr_t>(widget); 99 // TODO(jamesr): Remove once everything is converted to surfaces.
70 client()->OnCreated(static_cast<uint64_t>(widget_ptr)); 100 client()->OnCreated(widget_id_);
101 if (surface_id_allocator_)
102 CreateViewportBoundSurface();
103 }
104
105 void NativeViewportImpl::CreateViewportBoundSurface() {
106 DCHECK(surface_id_.is_null());
107 CommandBufferPtr cb;
108 gpu_service_->CreateOnscreenGLES2Context(
109 widget_id_, Size::From(bounds_.size()), Get(&cb));
110
111 surface_id_ = surface_id_allocator_->GenerateId();
112 surface_->CreateGLES2BoundSurface(
113 cb.Pass(), SurfaceId::From(surface_id_), Size::From(bounds_.size()));
114
115 SubmitFrame();
116 }
117
118 void NativeViewportImpl::ReturnResources(Array<ReturnedResourcePtr> resources) {
119 // We never submit resources so we should never get any back.
120 DCHECK_EQ(0u, resources.size());
121 }
122 void NativeViewportImpl::OnSurfaceConnectionCreated(SurfacePtr surface,
123 uint32_t id_namespace) {
124 surface_ = surface.Pass();
125 surface_.set_client(this);
126 surface_id_allocator_.reset(new cc::SurfaceIdAllocator(id_namespace));
127 if (widget_id_)
128 CreateViewportBoundSurface();
129 }
130
131 void NativeViewportImpl::SubmitFrame() {
132 if (child_surface_id_.is_null() || surface_id_.is_null())
133 return;
134
jamesr 2014/08/26 23:05:50 the rest of this function is an unfortunately larg
135 SurfaceQuadStatePtr surface_quad_state = SurfaceQuadState::New();
136 surface_quad_state->surface = SurfaceId::From(child_surface_id_);
137
138 QuadPtr surface_quad = Quad::New();
139 surface_quad->material = Material::MATERIAL_SURFACE_CONTENT;
140 surface_quad->rect = Rect::From(bounds_);
141 surface_quad->opaque_rect = Rect::From(bounds_);
142 surface_quad->visible_rect = Rect::From(bounds_);
143 surface_quad->needs_blending = true;
144 surface_quad->shared_quad_state_index = 0;
145 surface_quad->surface_quad_state = surface_quad_state.Pass();
146
147 SharedQuadStatePtr sqs = SharedQuadState::New();
148 sqs->content_to_target_transform = Transform::From(gfx::Transform());
149 sqs->content_bounds = Size::From(bounds_.size());
150 sqs->visible_content_rect = Rect::From(bounds_);
151 sqs->clip_rect = Rect::From(bounds_);
152 sqs->is_clipped = false;
153 sqs->opacity = 1.0f;
154 sqs->blend_mode = SkXfermode::SK_XFERMODE_kSrcOver_Mode;
155 sqs->sorting_context_id = 1;
156
157 PassPtr pass = Pass::New();
158 pass->id = 1;
159 pass->output_rect = Rect::From(bounds_);
160 pass->damage_rect = Rect::From(bounds_);
161 pass->transform_to_root_target = Transform::From(gfx::Transform());
162 pass->has_transparent_background = false;
163 pass->quads.push_back(surface_quad.Pass());
164 pass->shared_quad_states.push_back(sqs.Pass());
165
166 FramePtr frame = Frame::New();
167 frame->passes.push_back(pass.Pass());
168 frame->resources.resize(0u);
169 surface_->SubmitFrame(SurfaceId::From(surface_id_), frame.Pass());
71 } 170 }
72 171
73 bool NativeViewportImpl::OnEvent(ui::Event* ui_event) { 172 bool NativeViewportImpl::OnEvent(ui::Event* ui_event) {
74 // Must not return early before updating capture. 173 // Must not return early before updating capture.
75 switch (ui_event->type()) { 174 switch (ui_event->type()) {
76 case ui::ET_MOUSE_PRESSED: 175 case ui::ET_MOUSE_PRESSED:
77 case ui::ET_TOUCH_PRESSED: 176 case ui::ET_TOUCH_PRESSED:
78 platform_viewport_->SetCapture(); 177 platform_viewport_->SetCapture();
79 break; 178 break;
80 case ui::ET_MOUSE_RELEASED: 179 case ui::ET_MOUSE_RELEASED:
(...skipping 18 matching lines...) Expand all
99 void NativeViewportImpl::OnDestroyed() { 198 void NativeViewportImpl::OnDestroyed() {
100 client()->OnDestroyed(); 199 client()->OnDestroyed();
101 } 200 }
102 201
103 void NativeViewportImpl::AckEvent() { 202 void NativeViewportImpl::AckEvent() {
104 waiting_for_event_ack_ = false; 203 waiting_for_event_ack_ = false;
105 } 204 }
106 205
107 } // namespace mojo 206 } // namespace mojo
108 207
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698