| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/exo/buffer.h" | 5 #include "components/exo/buffer.h" |
| 6 | 6 |
| 7 #include <GLES2/gl2.h> | 7 #include <GLES2/gl2.h> |
| 8 #include <GLES2/gl2ext.h> | 8 #include <GLES2/gl2ext.h> |
| 9 #include <GLES2/gl2extchromium.h> | 9 #include <GLES2/gl2extchromium.h> |
| 10 #include <stdint.h> | 10 #include <stdint.h> |
| (...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 // Note: This can fail if GPU acceleration has been disabled. | 421 // Note: This can fail if GPU acceleration has been disabled. |
| 422 scoped_refptr<cc::ContextProvider> context_provider = | 422 scoped_refptr<cc::ContextProvider> context_provider = |
| 423 context_factory->SharedMainThreadContextProvider(); | 423 context_factory->SharedMainThreadContextProvider(); |
| 424 if (!context_provider) { | 424 if (!context_provider) { |
| 425 DLOG(WARNING) << "Failed to acquire a context provider"; | 425 DLOG(WARNING) << "Failed to acquire a context provider"; |
| 426 resource->id = 0; | 426 resource->id = 0; |
| 427 resource->size = gfx::Size(); | 427 resource->size = gfx::Size(); |
| 428 return false; | 428 return false; |
| 429 } | 429 } |
| 430 | 430 |
| 431 // The reference to the CompositorFrameSinkHolder keeps it alive until a | |
| 432 // release callback is received. | |
| 433 compositor_frame_sink_holder_ = compositor_frame_sink_holder; | |
| 434 | |
| 435 resource->id = resource_id; | 431 resource->id = resource_id; |
| 436 resource->format = cc::RGBA_8888; | 432 resource->format = cc::RGBA_8888; |
| 437 resource->filter = GL_LINEAR; | 433 resource->filter = GL_LINEAR; |
| 438 resource->size = gpu_memory_buffer_->GetSize(); | 434 resource->size = gpu_memory_buffer_->GetSize(); |
| 439 | 435 |
| 440 // Create a new image texture for |gpu_memory_buffer_| with |texture_target_| | 436 // Create a new image texture for |gpu_memory_buffer_| with |texture_target_| |
| 441 // if one doesn't already exist. The contents of this buffer are copied to | 437 // if one doesn't already exist. The contents of this buffer are copied to |
| 442 // |texture| using a call to CopyTexImage. | 438 // |texture| using a call to CopyTexImage. |
| 443 if (!contents_texture_) { | 439 if (!contents_texture_) { |
| 444 contents_texture_ = base::MakeUnique<Texture>( | 440 contents_texture_ = base::MakeUnique<Texture>( |
| (...skipping 10 matching lines...) Expand all Loading... |
| 455 if (use_zero_copy_) { | 451 if (use_zero_copy_) { |
| 456 // This binds the latest contents of this buffer to |contents_texture|. | 452 // This binds the latest contents of this buffer to |contents_texture|. |
| 457 gpu::SyncToken sync_token = contents_texture->BindTexImage(); | 453 gpu::SyncToken sync_token = contents_texture->BindTexImage(); |
| 458 resource->mailbox_holder = gpu::MailboxHolder(contents_texture->mailbox(), | 454 resource->mailbox_holder = gpu::MailboxHolder(contents_texture->mailbox(), |
| 459 sync_token, texture_target_); | 455 sync_token, texture_target_); |
| 460 resource->is_overlay_candidate = is_overlay_candidate_; | 456 resource->is_overlay_candidate = is_overlay_candidate_; |
| 461 resource->buffer_format = gpu_memory_buffer_->GetFormat(); | 457 resource->buffer_format = gpu_memory_buffer_->GetFormat(); |
| 462 | 458 |
| 463 // The contents texture will be released when no longer used by the | 459 // The contents texture will be released when no longer used by the |
| 464 // compositor. | 460 // compositor. |
| 465 compositor_frame_sink_holder_->SetResourceReleaseCallback( | 461 compositor_frame_sink_holder->SetResourceReleaseCallback( |
| 466 resource_id, | 462 resource_id, |
| 467 base::Bind(&Buffer::Texture::ReleaseTexImage, | 463 base::Bind(&Buffer::Texture::ReleaseTexImage, |
| 468 base::Unretained(contents_texture), | 464 base::Unretained(contents_texture), |
| 469 base::Bind(&Buffer::ReleaseContentsTexture, AsWeakPtr(), | 465 base::Bind(&Buffer::ReleaseContentsTexture, AsWeakPtr(), |
| 470 base::Passed(&contents_texture_), | 466 base::Passed(&contents_texture_), |
| 471 release_contents_callback_.callback()))); | 467 release_contents_callback_.callback()))); |
| 472 return true; | 468 return true; |
| 473 } | 469 } |
| 474 | 470 |
| 475 // Create a mailbox texture that we copy the buffer contents to. | 471 // Create a mailbox texture that we copy the buffer contents to. |
| 476 if (!texture_) { | 472 if (!texture_) { |
| 477 texture_ = | 473 texture_ = |
| 478 base::MakeUnique<Texture>(context_factory, context_provider.get()); | 474 base::MakeUnique<Texture>(context_factory, context_provider.get()); |
| 479 } | 475 } |
| 480 Texture* texture = texture_.get(); | 476 Texture* texture = texture_.get(); |
| 481 | 477 |
| 482 // Copy the contents of |contents_texture| to |texture| and produce a | 478 // Copy the contents of |contents_texture| to |texture| and produce a |
| 483 // texture mailbox from the result in |texture|. The contents texture will | 479 // texture mailbox from the result in |texture|. The contents texture will |
| 484 // be released when copy has completed. | 480 // be released when copy has completed. |
| 485 gpu::SyncToken sync_token = contents_texture->CopyTexImage( | 481 gpu::SyncToken sync_token = contents_texture->CopyTexImage( |
| 486 texture, base::Bind(&Buffer::ReleaseContentsTexture, AsWeakPtr(), | 482 texture, base::Bind(&Buffer::ReleaseContentsTexture, AsWeakPtr(), |
| 487 base::Passed(&contents_texture_), | 483 base::Passed(&contents_texture_), |
| 488 release_contents_callback_.callback())); | 484 release_contents_callback_.callback())); |
| 489 resource->mailbox_holder = | 485 resource->mailbox_holder = |
| 490 gpu::MailboxHolder(texture->mailbox(), sync_token, GL_TEXTURE_2D); | 486 gpu::MailboxHolder(texture->mailbox(), sync_token, GL_TEXTURE_2D); |
| 491 resource->is_overlay_candidate = false; | 487 resource->is_overlay_candidate = false; |
| 492 | 488 |
| 493 // The mailbox texture will be released when no longer used by the | 489 // The mailbox texture will be released when no longer used by the |
| 494 // compositor. | 490 // compositor. |
| 495 compositor_frame_sink_holder_->SetResourceReleaseCallback( | 491 compositor_frame_sink_holder->SetResourceReleaseCallback( |
| 496 resource_id, | 492 resource_id, |
| 497 base::Bind(&Buffer::Texture::Release, base::Unretained(texture), | 493 base::Bind(&Buffer::Texture::Release, base::Unretained(texture), |
| 498 base::Bind(&Buffer::ReleaseTexture, AsWeakPtr(), | 494 base::Bind(&Buffer::ReleaseTexture, AsWeakPtr(), |
| 499 base::Passed(&texture_)))); | 495 base::Passed(&texture_)))); |
| 500 return true; | 496 return true; |
| 501 } | 497 } |
| 502 | 498 |
| 503 void Buffer::OnAttach() { | 499 void Buffer::OnAttach() { |
| 504 DLOG_IF(WARNING, attach_count_) | 500 DLOG_IF(WARNING, attach_count_) |
| 505 << "Reattaching a buffer that is already attached to another surface."; | 501 << "Reattaching a buffer that is already attached to another surface."; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 559 | 555 |
| 560 // Cancel callback to indicate that buffer has been released. | 556 // Cancel callback to indicate that buffer has been released. |
| 561 release_contents_callback_.Cancel(); | 557 release_contents_callback_.Cancel(); |
| 562 | 558 |
| 563 // Release buffer if not attached to surface. | 559 // Release buffer if not attached to surface. |
| 564 if (!attach_count_) | 560 if (!attach_count_) |
| 565 Release(); | 561 Release(); |
| 566 } | 562 } |
| 567 | 563 |
| 568 } // namespace exo | 564 } // namespace exo |
| OLD | NEW |