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

Side by Side Diff: content/renderer/browser_plugin/browser_plugin_compositing_helper.cc

Issue 19331002: Associate an id with the output surface to handle lost contexts (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix android, tests Created 7 years, 5 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "content/renderer/browser_plugin/browser_plugin_compositing_helper.h" 5 #include "content/renderer/browser_plugin/browser_plugin_compositing_helper.h"
6 6
7 #include "cc/layers/delegated_renderer_layer.h" 7 #include "cc/layers/delegated_renderer_layer.h"
8 #include "cc/layers/solid_color_layer.h" 8 #include "cc/layers/solid_color_layer.h"
9 #include "cc/layers/texture_layer.h" 9 #include "cc/layers/texture_layer.h"
10 #include "cc/output/context_provider.h" 10 #include "cc/output/context_provider.h"
11 #include "content/common/browser_plugin/browser_plugin_messages.h" 11 #include "content/common/browser_plugin/browser_plugin_messages.h"
12 #include "content/common/gpu/client/context_provider_command_buffer.h" 12 #include "content/common/gpu/client/context_provider_command_buffer.h"
13 #include "content/renderer/browser_plugin/browser_plugin_manager.h" 13 #include "content/renderer/browser_plugin/browser_plugin_manager.h"
14 #include "content/renderer/render_thread_impl.h" 14 #include "content/renderer/render_thread_impl.h"
15 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h" 15 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h"
16 #include "third_party/WebKit/public/web/WebPluginContainer.h" 16 #include "third_party/WebKit/public/web/WebPluginContainer.h"
17 #include "third_party/khronos/GLES2/gl2.h" 17 #include "third_party/khronos/GLES2/gl2.h"
18 #include "ui/gfx/size_conversions.h" 18 #include "ui/gfx/size_conversions.h"
19 #include "webkit/renderer/compositor_bindings/web_layer_impl.h" 19 #include "webkit/renderer/compositor_bindings/web_layer_impl.h"
20 20
21 namespace content { 21 namespace content {
22 22
23 BrowserPluginCompositingHelper::SwapBuffersInfo::SwapBuffersInfo() 23 BrowserPluginCompositingHelper::SwapBuffersInfo::SwapBuffersInfo()
24 : route_id(0), 24 : route_id(0),
25 output_surface_id(0),
25 host_id(0), 26 host_id(0),
26 software_frame_id(0), 27 software_frame_id(0),
27 shared_memory(NULL) { 28 shared_memory(NULL) {
28 } 29 }
29 30
30 BrowserPluginCompositingHelper::BrowserPluginCompositingHelper( 31 BrowserPluginCompositingHelper::BrowserPluginCompositingHelper(
31 WebKit::WebPluginContainer* container, 32 WebKit::WebPluginContainer* container,
32 BrowserPluginManager* manager, 33 BrowserPluginManager* manager,
33 int instance_id, 34 int instance_id,
34 int host_routing_id) 35 int host_routing_id)
35 : instance_id_(instance_id), 36 : instance_id_(instance_id),
36 host_routing_id_(host_routing_id), 37 host_routing_id_(host_routing_id),
37 last_route_id_(0), 38 last_route_id_(0),
39 last_output_surface_id_(0),
38 last_host_id_(0), 40 last_host_id_(0),
39 last_mailbox_valid_(false), 41 last_mailbox_valid_(false),
40 ack_pending_(true), 42 ack_pending_(true),
41 container_(container), 43 container_(container),
42 browser_plugin_manager_(manager) { 44 browser_plugin_manager_(manager) {
43 } 45 }
44 46
45 BrowserPluginCompositingHelper::~BrowserPluginCompositingHelper() { 47 BrowserPluginCompositingHelper::~BrowserPluginCompositingHelper() {
46 } 48 }
47 49
48 void BrowserPluginCompositingHelper::DidCommitCompositorFrame() { 50 void BrowserPluginCompositingHelper::DidCommitCompositorFrame() {
49 if (!delegated_layer_.get() || !ack_pending_) 51 if (!delegated_layer_.get() || !ack_pending_)
50 return; 52 return;
51 53
52 cc::CompositorFrameAck ack; 54 cc::CompositorFrameAck ack;
53 delegated_layer_->TakeUnusedResourcesForChildCompositor(&ack.resources); 55 delegated_layer_->TakeUnusedResourcesForChildCompositor(&ack.resources);
54 56
55 browser_plugin_manager_->Send( 57 browser_plugin_manager_->Send(
56 new BrowserPluginHostMsg_CompositorFrameACK( 58 new BrowserPluginHostMsg_CompositorFrameACK(
57 host_routing_id_, 59 host_routing_id_,
58 instance_id_, 60 instance_id_,
59 last_route_id_, 61 last_route_id_,
62 last_output_surface_id_,
60 last_host_id_, 63 last_host_id_,
61 ack)); 64 ack));
62 65
63 ack_pending_ = false; 66 ack_pending_ = false;
64 } 67 }
65 68
66 void BrowserPluginCompositingHelper::EnableCompositing(bool enable) { 69 void BrowserPluginCompositingHelper::EnableCompositing(bool enable) {
67 if (enable && !background_layer_.get()) { 70 if (enable && !background_layer_.get()) {
68 background_layer_ = cc::SolidColorLayer::Create(); 71 background_layer_ = cc::SolidColorLayer::Create();
69 background_layer_->SetMasksToBounds(true); 72 background_layer_->SetMasksToBounds(true);
(...skipping 26 matching lines...) Expand all
96 bool lost_resource) { 99 bool lost_resource) {
97 if (mailbox.type == SOFTWARE_COMPOSITOR_FRAME) { 100 if (mailbox.type == SOFTWARE_COMPOSITOR_FRAME) {
98 delete mailbox.shared_memory; 101 delete mailbox.shared_memory;
99 mailbox.shared_memory = NULL; 102 mailbox.shared_memory = NULL;
100 } else if (lost_resource) { 103 } else if (lost_resource) {
101 // Reset mailbox's name if the resource was lost. 104 // Reset mailbox's name if the resource was lost.
102 mailbox.name.SetZero(); 105 mailbox.name.SetZero();
103 } 106 }
104 107
105 // This means the GPU process crashed or guest crashed. 108 // This means the GPU process crashed or guest crashed.
106 if (last_host_id_ != mailbox.host_id || last_route_id_ != mailbox.route_id) 109 if (last_host_id_ != mailbox.host_id ||
110 last_output_surface_id_ != mailbox.output_surface_id ||
111 last_route_id_ != mailbox.route_id)
107 return; 112 return;
108 113
109 // We need to send an ACK to for every buffer sent to us. 114 // We need to send an ACK to for every buffer sent to us.
110 // However, if a buffer is freed up from 115 // However, if a buffer is freed up from
111 // the compositor in cases like switching back to SW mode without a new 116 // the compositor in cases like switching back to SW mode without a new
112 // buffer arriving, no ACK is needed. 117 // buffer arriving, no ACK is needed.
113 if (!ack_pending_) { 118 if (!ack_pending_) {
114 last_mailbox_valid_ = false; 119 last_mailbox_valid_ = false;
115 return; 120 return;
116 } 121 }
(...skipping 17 matching lines...) Expand all
134 ack.gl_frame_data.reset(new cc::GLFrameData()); 139 ack.gl_frame_data.reset(new cc::GLFrameData());
135 ack.gl_frame_data->mailbox = mailbox.name; 140 ack.gl_frame_data->mailbox = mailbox.name;
136 ack.gl_frame_data->size = mailbox.size; 141 ack.gl_frame_data->size = mailbox.size;
137 ack.gl_frame_data->sync_point = sync_point; 142 ack.gl_frame_data->sync_point = sync_point;
138 143
139 browser_plugin_manager_->Send( 144 browser_plugin_manager_->Send(
140 new BrowserPluginHostMsg_CompositorFrameACK( 145 new BrowserPluginHostMsg_CompositorFrameACK(
141 host_routing_id_, 146 host_routing_id_,
142 instance_id_, 147 instance_id_,
143 mailbox.route_id, 148 mailbox.route_id,
149 mailbox.output_surface_id,
144 mailbox.host_id, 150 mailbox.host_id,
145 ack)); 151 ack));
146 break; 152 break;
147 } 153 }
148 case SOFTWARE_COMPOSITOR_FRAME: { 154 case SOFTWARE_COMPOSITOR_FRAME: {
149 cc::CompositorFrameAck ack; 155 cc::CompositorFrameAck ack;
150 ack.last_software_frame_id = mailbox.software_frame_id; 156 ack.last_software_frame_id = mailbox.software_frame_id;
151 157
152 browser_plugin_manager_->Send( 158 browser_plugin_manager_->Send(
153 new BrowserPluginHostMsg_CompositorFrameACK( 159 new BrowserPluginHostMsg_CompositorFrameACK(
154 host_routing_id_, 160 host_routing_id_,
155 instance_id_, 161 instance_id_,
156 mailbox.route_id, 162 mailbox.route_id,
163 mailbox.output_surface_id,
157 mailbox.host_id, 164 mailbox.host_id,
158 ack)); 165 ack));
159 break; 166 break;
160 } 167 }
161 } 168 }
162 } 169 }
163 170
164 void BrowserPluginCompositingHelper::OnContainerDestroy() { 171 void BrowserPluginCompositingHelper::OnContainerDestroy() {
165 if (container_) 172 if (container_)
166 container_->setWebLayer(NULL); 173 container_->setWebLayer(NULL);
167 container_ = NULL; 174 container_ = NULL;
168 175
169 texture_layer_ = NULL; 176 texture_layer_ = NULL;
170 delegated_layer_ = NULL; 177 delegated_layer_ = NULL;
171 background_layer_ = NULL; 178 background_layer_ = NULL;
172 web_layer_.reset(); 179 web_layer_.reset();
173 } 180 }
174 181
175 void BrowserPluginCompositingHelper::OnBuffersSwappedPrivate( 182 void BrowserPluginCompositingHelper::OnBuffersSwappedPrivate(
176 const SwapBuffersInfo& mailbox, 183 const SwapBuffersInfo& mailbox,
177 unsigned sync_point, 184 unsigned sync_point,
178 float device_scale_factor) { 185 float device_scale_factor) {
179 DCHECK(!delegated_layer_.get()); 186 DCHECK(!delegated_layer_.get());
180 // If these mismatch, we are either just starting up, GPU process crashed or 187 // If these mismatch, we are either just starting up, GPU process crashed or
181 // guest renderer crashed. 188 // guest renderer crashed.
182 // In this case, we are communicating with a new image transport 189 // In this case, we are communicating with a new image transport
183 // surface and must ACK with the new ID's and an empty mailbox. 190 // surface and must ACK with the new ID's and an empty mailbox.
184 if (last_route_id_ != mailbox.route_id || last_host_id_ != mailbox.host_id) 191 if (last_route_id_ != mailbox.route_id ||
192 last_output_surface_id_ != mailbox.output_surface_id ||
193 last_host_id_ != mailbox.host_id)
185 last_mailbox_valid_ = false; 194 last_mailbox_valid_ = false;
186 195
187 last_route_id_ = mailbox.route_id; 196 last_route_id_ = mailbox.route_id;
197 last_output_surface_id_ = mailbox.output_surface_id;
188 last_host_id_ = mailbox.host_id; 198 last_host_id_ = mailbox.host_id;
189 199
190 ack_pending_ = true; 200 ack_pending_ = true;
191 // Browser plugin getting destroyed, do a fast ACK. 201 // Browser plugin getting destroyed, do a fast ACK.
192 if (!background_layer_.get()) { 202 if (!background_layer_.get()) {
193 MailboxReleased(mailbox, sync_point, false); 203 MailboxReleased(mailbox, sync_point, false);
194 return; 204 return;
195 } 205 }
196 206
197 if (!texture_layer_.get()) { 207 if (!texture_layer_.get()) {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 const gfx::Size& size, 261 const gfx::Size& size,
252 const std::string& mailbox_name, 262 const std::string& mailbox_name,
253 int gpu_route_id, 263 int gpu_route_id,
254 int gpu_host_id, 264 int gpu_host_id,
255 float device_scale_factor) { 265 float device_scale_factor) {
256 SwapBuffersInfo swap_info; 266 SwapBuffersInfo swap_info;
257 swap_info.name.SetName(reinterpret_cast<const int8*>(mailbox_name.data())); 267 swap_info.name.SetName(reinterpret_cast<const int8*>(mailbox_name.data()));
258 swap_info.type = TEXTURE_IMAGE_TRANSPORT; 268 swap_info.type = TEXTURE_IMAGE_TRANSPORT;
259 swap_info.size = size; 269 swap_info.size = size;
260 swap_info.route_id = gpu_route_id; 270 swap_info.route_id = gpu_route_id;
271 swap_info.output_surface_id = 0;
261 swap_info.host_id = gpu_host_id; 272 swap_info.host_id = gpu_host_id;
262 OnBuffersSwappedPrivate(swap_info, 0, device_scale_factor); 273 OnBuffersSwappedPrivate(swap_info, 0, device_scale_factor);
263 } 274 }
264 275
265 void BrowserPluginCompositingHelper::OnCompositorFrameSwapped( 276 void BrowserPluginCompositingHelper::OnCompositorFrameSwapped(
266 scoped_ptr<cc::CompositorFrame> frame, 277 scoped_ptr<cc::CompositorFrame> frame,
267 int route_id, 278 int route_id,
279 uint32 output_surface_id,
268 int host_id) { 280 int host_id) {
269 if (frame->gl_frame_data) { 281 if (frame->gl_frame_data) {
270 SwapBuffersInfo swap_info; 282 SwapBuffersInfo swap_info;
271 swap_info.name = frame->gl_frame_data->mailbox; 283 swap_info.name = frame->gl_frame_data->mailbox;
272 swap_info.type = GL_COMPOSITOR_FRAME; 284 swap_info.type = GL_COMPOSITOR_FRAME;
273 swap_info.size = frame->gl_frame_data->size; 285 swap_info.size = frame->gl_frame_data->size;
274 swap_info.route_id = route_id; 286 swap_info.route_id = route_id;
287 swap_info.output_surface_id = output_surface_id;
275 swap_info.host_id = host_id; 288 swap_info.host_id = host_id;
276 OnBuffersSwappedPrivate(swap_info, 289 OnBuffersSwappedPrivate(swap_info,
277 frame->gl_frame_data->sync_point, 290 frame->gl_frame_data->sync_point,
278 frame->metadata.device_scale_factor); 291 frame->metadata.device_scale_factor);
279 return; 292 return;
280 } 293 }
281 294
282 if (frame->software_frame_data) { 295 if (frame->software_frame_data) {
283 cc::SoftwareFrameData* frame_data = frame->software_frame_data.get(); 296 cc::SoftwareFrameData* frame_data = frame->software_frame_data.get();
284 297
285 SwapBuffersInfo swap_info; 298 SwapBuffersInfo swap_info;
286 swap_info.type = SOFTWARE_COMPOSITOR_FRAME; 299 swap_info.type = SOFTWARE_COMPOSITOR_FRAME;
287 swap_info.size = frame_data->size; 300 swap_info.size = frame_data->size;
288 swap_info.route_id = route_id; 301 swap_info.route_id = route_id;
302 swap_info.output_surface_id = output_surface_id;
289 swap_info.host_id = host_id; 303 swap_info.host_id = host_id;
290 swap_info.software_frame_id = frame_data->id; 304 swap_info.software_frame_id = frame_data->id;
291 305
292 scoped_ptr<base::SharedMemory> shared_memory( 306 scoped_ptr<base::SharedMemory> shared_memory(
293 new base::SharedMemory(frame_data->handle, true)); 307 new base::SharedMemory(frame_data->handle, true));
294 const size_t size_in_bytes = 4 * frame_data->size.GetArea(); 308 const size_t size_in_bytes = 4 * frame_data->size.GetArea();
295 if (!shared_memory->Map(size_in_bytes)) { 309 if (!shared_memory->Map(size_in_bytes)) {
296 LOG(ERROR) << "Failed to map shared memory of size " 310 LOG(ERROR) << "Failed to map shared memory of size "
297 << size_in_bytes; 311 << size_in_bytes;
298 // Send ACK right away. 312 // Send ACK right away.
(...skipping 21 matching lines...) Expand all
320 if (!frame_data) 334 if (!frame_data)
321 return; 335 return;
322 336
323 CheckSizeAndAdjustLayerBounds( 337 CheckSizeAndAdjustLayerBounds(
324 frame_data->render_pass_list.back()->output_rect.size(), 338 frame_data->render_pass_list.back()->output_rect.size(),
325 frame->metadata.device_scale_factor, 339 frame->metadata.device_scale_factor,
326 delegated_layer_.get()); 340 delegated_layer_.get());
327 341
328 delegated_layer_->SetFrameData(frame->delegated_frame_data.Pass()); 342 delegated_layer_->SetFrameData(frame->delegated_frame_data.Pass());
329 last_route_id_ = route_id; 343 last_route_id_ = route_id;
344 last_output_surface_id_ = output_surface_id;
330 last_host_id_ = host_id; 345 last_host_id_ = host_id;
331 ack_pending_ = true; 346 ack_pending_ = true;
332 } 347 }
333 348
334 void BrowserPluginCompositingHelper::UpdateVisibility(bool visible) { 349 void BrowserPluginCompositingHelper::UpdateVisibility(bool visible) {
335 if (texture_layer_.get()) 350 if (texture_layer_.get())
336 texture_layer_->SetIsDrawable(visible); 351 texture_layer_->SetIsDrawable(visible);
337 if (delegated_layer_.get()) 352 if (delegated_layer_.get())
338 delegated_layer_->SetIsDrawable(visible); 353 delegated_layer_->SetIsDrawable(visible);
339 } 354 }
340 355
341 } // namespace content 356 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/browser_plugin/browser_plugin_compositing_helper.h ('k') | content/renderer/gpu/compositor_output_surface.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698