Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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 Loading... | |
| 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 Loading... | |
| 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 Loading... | |
| 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); |
|
no sievers
2013/03/06 23:19:23
hmm, should MailboxName have an operator maybe?
piman
2013/03/07 01:48:02
cast operators are discouraged by the style guide.
| |
| 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 21 matching lines...) Expand all Loading... | |
| 441 GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER); | 436 GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER); |
| 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 |
| 446 MailboxName name; | |
|
no sievers
2013/03/06 23:19:23
Also maybe a constructor from gpu::Mailbox?
piman
2013/03/07 01:48:02
Done.
| |
| 447 memcpy(name.key, texture->mailbox_name.name, | |
| 448 sizeof(texture->mailbox_name.name)); | |
| 451 scoped_ptr<TextureDefinition> definition(mailbox_manager_->ConsumeTexture( | 449 scoped_ptr<TextureDefinition> definition(mailbox_manager_->ConsumeTexture( |
| 452 GL_TEXTURE_2D, texture->mailbox_name)); | 450 GL_TEXTURE_2D, name)); |
| 453 if (definition.get()) { | 451 if (definition.get()) { |
| 454 texture->service_id = definition->ReleaseServiceId(); | 452 texture->service_id = definition->ReleaseServiceId(); |
| 455 texture->size = gfx::Size(definition->level_infos()[0][0].width, | 453 texture->size = gfx::Size(definition->level_infos()[0][0].width, |
| 456 definition->level_infos()[0][0].height); | 454 definition->level_infos()[0][0].height); |
| 457 } else { | 455 } else { |
| 458 texture->mailbox_name = MailboxName(); | 456 texture->mailbox_name = gpu::Mailbox(); |
| 459 } | 457 } |
| 460 } | 458 } |
| 461 | 459 |
| 462 void TextureImageTransportSurface::ProduceTexture(Texture* texture) { | 460 void TextureImageTransportSurface::ProduceTexture(Texture* texture) { |
| 463 DCHECK(texture->service_id); | 461 DCHECK(texture->service_id); |
| 464 | 462 |
| 465 TextureManager* texture_manager = | 463 TextureManager* texture_manager = |
| 466 helper_->stub()->decoder()->GetContextGroup()->texture_manager(); | 464 helper_->stub()->decoder()->GetContextGroup()->texture_manager(); |
| 467 DCHECK(texture->size.width() > 0 && texture->size.height() > 0); | 465 DCHECK(texture->size.width() > 0 && texture->size.height() > 0); |
| 468 TextureDefinition::LevelInfo info( | 466 TextureDefinition::LevelInfo info( |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 480 GL_LINEAR, | 478 GL_LINEAR, |
| 481 GL_CLAMP_TO_EDGE, | 479 GL_CLAMP_TO_EDGE, |
| 482 GL_CLAMP_TO_EDGE, | 480 GL_CLAMP_TO_EDGE, |
| 483 GL_NONE, | 481 GL_NONE, |
| 484 true, | 482 true, |
| 485 level_infos)); | 483 level_infos)); |
| 486 // Pass NULL as |owner| here to avoid errors from glConsumeTextureCHROMIUM() | 484 // Pass NULL as |owner| here to avoid errors from glConsumeTextureCHROMIUM() |
| 487 // when the renderer context group goes away before the RWHV handles a pending | 485 // 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 | 486 // 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. | 487 // at which point we consume the correct texture back. |
| 488 MailboxName name; | |
| 489 memcpy(name.key, texture->mailbox_name.name, | |
| 490 sizeof(texture->mailbox_name.name)); | |
| 490 bool success = mailbox_manager_->ProduceTexture( | 491 bool success = mailbox_manager_->ProduceTexture( |
| 491 GL_TEXTURE_2D, | 492 GL_TEXTURE_2D, |
| 492 texture->mailbox_name, | 493 name, |
| 493 definition.release(), | 494 definition.release(), |
| 494 NULL); | 495 NULL); |
| 495 DCHECK(success); | 496 DCHECK(success); |
| 496 texture->service_id = 0; | 497 texture->service_id = 0; |
| 497 texture->mailbox_name = MailboxName(); | 498 texture->mailbox_name = gpu::Mailbox(); |
| 498 } | 499 } |
| 499 | 500 |
| 500 } // namespace content | 501 } // namespace content |
| OLD | NEW |