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