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

Side by Side Diff: content/common/gpu/texture_image_transport_surface.cc

Issue 12440005: Use gpu::Mailbox in IPCs instead of std::string (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/common/gpu/texture_image_transport_surface.h" 5 #include "content/common/gpu/texture_image_transport_surface.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 return true; 207 return true;
208 208
209 if (!backbuffer_.service_id) { 209 if (!backbuffer_.service_id) {
210 LOG(ERROR) << "Swap without valid backing."; 210 LOG(ERROR) << "Swap without valid backing.";
211 return true; 211 return true;
212 } 212 }
213 213
214 DCHECK(backbuffer_.size == current_size_); 214 DCHECK(backbuffer_.size == current_size_);
215 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params; 215 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params;
216 params.size = backbuffer_.size; 216 params.size = backbuffer_.size;
217 const MailboxName& name = backbuffer_.mailbox_name; 217 params.mailbox_name = backbuffer_.mailbox_name;
218 params.mailbox_name.assign(
219 reinterpret_cast<const char*>(&name), sizeof(name));
220 218
221 glFlush(); 219 glFlush();
222 ProduceTexture(&backbuffer_); 220 ProduceTexture(&backbuffer_);
223 221
224 // Do not allow destruction while we are still waiting for a swap ACK, 222 // Do not allow destruction while we are still waiting for a swap ACK,
225 // so we do not leak a texture in the mailbox. 223 // so we do not leak a texture in the mailbox.
226 AddRef(); 224 AddRef();
227 225
228 helper_->SendAcceleratedSurfaceBuffersSwapped(params); 226 helper_->SendAcceleratedSurfaceBuffersSwapped(params);
229 227
(...skipping 19 matching lines...) Expand all
249 return true; 247 return true;
250 } 248 }
251 249
252 DCHECK(current_size_ == backbuffer_.size); 250 DCHECK(current_size_ == backbuffer_.size);
253 GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params params; 251 GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params params;
254 params.surface_size = backbuffer_.size; 252 params.surface_size = backbuffer_.size;
255 params.x = x; 253 params.x = x;
256 params.y = y; 254 params.y = y;
257 params.width = width; 255 params.width = width;
258 params.height = height; 256 params.height = height;
259 const MailboxName& name = backbuffer_.mailbox_name; 257 params.mailbox_name = backbuffer_.mailbox_name;
260 params.mailbox_name.assign(
261 reinterpret_cast<const char*>(&name), sizeof(name));
262 258
263 glFlush(); 259 glFlush();
264 ProduceTexture(&backbuffer_); 260 ProduceTexture(&backbuffer_);
265 261
266 // Do not allow destruction while we are still waiting for a swap ACK, 262 // Do not allow destruction while we are still waiting for a swap ACK,
267 // so we do not leak a texture in the mailbox. 263 // so we do not leak a texture in the mailbox.
268 AddRef(); 264 AddRef();
269 265
270 helper_->SendAcceleratedSurfacePostSubBuffer(params); 266 helper_->SendAcceleratedSurfacePostSubBuffer(params);
271 267
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 this, 305 this,
310 params.mailbox_name)); 306 params.mailbox_name));
311 } 307 }
312 308
313 // Careful, we might get deleted now if we were only waiting for 309 // Careful, we might get deleted now if we were only waiting for
314 // a final swap ACK. 310 // a final swap ACK.
315 Release(); 311 Release();
316 } 312 }
317 313
318 void TextureImageTransportSurface::BufferPresentedImpl( 314 void TextureImageTransportSurface::BufferPresentedImpl(
319 const std::string& mailbox_name) { 315 const gpu::Mailbox& mailbox_name) {
320 DCHECK(!backbuffer_.service_id); 316 DCHECK(!backbuffer_.service_id);
321 if (!mailbox_name.empty()) { 317 if (!mailbox_name.IsZero()) {
322 DCHECK(mailbox_name.length() == GL_MAILBOX_SIZE_CHROMIUM); 318 backbuffer_.mailbox_name = mailbox_name;
323 mailbox_name.copy(reinterpret_cast<char *>(&backbuffer_.mailbox_name),
324 sizeof(MailboxName));
325 ConsumeTexture(&backbuffer_); 319 ConsumeTexture(&backbuffer_);
326 } 320 }
327 321
328 if (stub_destroyed_ && backbuffer_.service_id) { 322 if (stub_destroyed_ && backbuffer_.service_id) {
329 // TODO(sievers): Remove this after changes to the mailbox to take ownership 323 // TODO(sievers): Remove this after changes to the mailbox to take ownership
330 // of the service ids. 324 // of the service ids.
331 DCHECK(context_.get() && surface_.get()); 325 DCHECK(context_.get() && surface_.get());
332 if (context_->MakeCurrent(surface_.get())) 326 if (context_->MakeCurrent(surface_.get()))
333 glDeleteTextures(1, &backbuffer_.service_id); 327 glDeleteTextures(1, &backbuffer_.service_id);
334 328
(...skipping 28 matching lines...) Expand all
363 void TextureImageTransportSurface::OnResizeViewACK() { 357 void TextureImageTransportSurface::OnResizeViewACK() {
364 NOTREACHED(); 358 NOTREACHED();
365 } 359 }
366 360
367 void TextureImageTransportSurface::ReleaseBackTexture() { 361 void TextureImageTransportSurface::ReleaseBackTexture() {
368 if (!backbuffer_.service_id) 362 if (!backbuffer_.service_id)
369 return; 363 return;
370 364
371 glDeleteTextures(1, &backbuffer_.service_id); 365 glDeleteTextures(1, &backbuffer_.service_id);
372 backbuffer_.service_id = 0; 366 backbuffer_.service_id = 0;
373 backbuffer_.mailbox_name = MailboxName(); 367 backbuffer_.mailbox_name = gpu::Mailbox();
374 glFlush(); 368 glFlush();
375 CHECK_GL_ERROR(); 369 CHECK_GL_ERROR();
376 } 370 }
377 371
378 void TextureImageTransportSurface::CreateBackTexture() { 372 void TextureImageTransportSurface::CreateBackTexture() {
379 // If |is_swap_buffers_pending| we are waiting for our backbuffer 373 // If |is_swap_buffers_pending| we are waiting for our backbuffer
380 // in the mailbox, so we shouldn't be reallocating it now. 374 // in the mailbox, so we shouldn't be reallocating it now.
381 DCHECK(!is_swap_buffers_pending_); 375 DCHECK(!is_swap_buffers_pending_);
382 376
383 if (backbuffer_.service_id && backbuffer_.size == current_size_) 377 if (backbuffer_.service_id && backbuffer_.size == current_size_)
(...skipping 10 matching lines...) Expand all
394 ->decoder() 388 ->decoder()
395 ->GetContextGroup() 389 ->GetContextGroup()
396 ->feature_info() 390 ->feature_info()
397 ->workarounds() 391 ->workarounds()
398 .delete_instead_of_resize_fbo) { 392 .delete_instead_of_resize_fbo) {
399 glDeleteTextures(1, &backbuffer_.service_id); 393 glDeleteTextures(1, &backbuffer_.service_id);
400 backbuffer_ = Texture(); 394 backbuffer_ = Texture();
401 } 395 }
402 396
403 if (!backbuffer_.service_id) { 397 if (!backbuffer_.service_id) {
398 gpu::Mailbox& name = backbuffer_.mailbox_name;
399 // This slot should be uninitialized.
400 DCHECK(name.IsZero());
401
404 MailboxName new_mailbox_name; 402 MailboxName new_mailbox_name;
405 MailboxName& name = backbuffer_.mailbox_name;
406 // This slot should be uninitialized.
407 DCHECK(!memcmp(&name, &new_mailbox_name, sizeof(MailboxName)));
408 mailbox_manager_->GenerateMailboxName(&new_mailbox_name); 403 mailbox_manager_->GenerateMailboxName(&new_mailbox_name);
409 name = new_mailbox_name; 404 name.SetName(new_mailbox_name.key);
410 glGenTextures(1, &backbuffer_.service_id); 405 glGenTextures(1, &backbuffer_.service_id);
411 } 406 }
412 407
413 backbuffer_.size = current_size_; 408 backbuffer_.size = current_size_;
414 409
415 { 410 {
416 ScopedTextureBinder texture_binder(backbuffer_.service_id); 411 ScopedTextureBinder texture_binder(backbuffer_.service_id);
417 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 412 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
418 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 413 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
419 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 414 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
(...skipping 22 matching lines...) Expand all
442 if (status != GL_FRAMEBUFFER_COMPLETE) { 437 if (status != GL_FRAMEBUFFER_COMPLETE) {
443 DLOG(FATAL) << "Framebuffer incomplete: " << status; 438 DLOG(FATAL) << "Framebuffer incomplete: " << status;
444 } 439 }
445 #endif 440 #endif
446 } 441 }
447 442
448 void TextureImageTransportSurface::ConsumeTexture(Texture* texture) { 443 void TextureImageTransportSurface::ConsumeTexture(Texture* texture) {
449 DCHECK(!texture->service_id); 444 DCHECK(!texture->service_id);
450 445
451 scoped_ptr<TextureDefinition> definition(mailbox_manager_->ConsumeTexture( 446 scoped_ptr<TextureDefinition> definition(mailbox_manager_->ConsumeTexture(
452 GL_TEXTURE_2D, texture->mailbox_name)); 447 GL_TEXTURE_2D, MailboxName(texture->mailbox_name)));
453 if (definition.get()) { 448 if (definition.get()) {
454 texture->service_id = definition->ReleaseServiceId(); 449 texture->service_id = definition->ReleaseServiceId();
455 texture->size = gfx::Size(definition->level_infos()[0][0].width, 450 texture->size = gfx::Size(definition->level_infos()[0][0].width,
456 definition->level_infos()[0][0].height); 451 definition->level_infos()[0][0].height);
457 } else { 452 } else {
458 texture->mailbox_name = MailboxName(); 453 texture->mailbox_name = gpu::Mailbox();
459 } 454 }
460 } 455 }
461 456
462 void TextureImageTransportSurface::ProduceTexture(Texture* texture) { 457 void TextureImageTransportSurface::ProduceTexture(Texture* texture) {
463 DCHECK(texture->service_id); 458 DCHECK(texture->service_id);
464 459
465 TextureManager* texture_manager = 460 TextureManager* texture_manager =
466 helper_->stub()->decoder()->GetContextGroup()->texture_manager(); 461 helper_->stub()->decoder()->GetContextGroup()->texture_manager();
467 DCHECK(texture->size.width() > 0 && texture->size.height() > 0); 462 DCHECK(texture->size.width() > 0 && texture->size.height() > 0);
468 TextureDefinition::LevelInfo info( 463 TextureDefinition::LevelInfo info(
(...skipping 13 matching lines...) Expand all
482 GL_CLAMP_TO_EDGE, 477 GL_CLAMP_TO_EDGE,
483 GL_NONE, 478 GL_NONE,
484 true, 479 true,
485 level_infos)); 480 level_infos));
486 // Pass NULL as |owner| here to avoid errors from glConsumeTextureCHROMIUM() 481 // Pass NULL as |owner| here to avoid errors from glConsumeTextureCHROMIUM()
487 // when the renderer context group goes away before the RWHV handles a pending 482 // when the renderer context group goes away before the RWHV handles a pending
488 // ACK. We avoid leaking a texture in the mailbox by waiting for the final ACK 483 // ACK. We avoid leaking a texture in the mailbox by waiting for the final ACK
489 // at which point we consume the correct texture back. 484 // at which point we consume the correct texture back.
490 bool success = mailbox_manager_->ProduceTexture( 485 bool success = mailbox_manager_->ProduceTexture(
491 GL_TEXTURE_2D, 486 GL_TEXTURE_2D,
492 texture->mailbox_name, 487 MailboxName(texture->mailbox_name),
493 definition.release(), 488 definition.release(),
494 NULL); 489 NULL);
495 DCHECK(success); 490 DCHECK(success);
496 texture->service_id = 0; 491 texture->service_id = 0;
497 texture->mailbox_name = MailboxName(); 492 texture->mailbox_name = gpu::Mailbox();
498 } 493 }
499 494
500 } // namespace content 495 } // namespace content
OLDNEW
« no previous file with comments | « content/common/gpu/texture_image_transport_surface.h ('k') | content/renderer/browser_plugin/browser_plugin.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698