| 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 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 texture_target_, query_type_)); | 411 texture_target_, query_type_)); |
| 412 } | 412 } |
| 413 | 413 |
| 414 if (use_zero_copy_) { | 414 if (use_zero_copy_) { |
| 415 // Zero-copy means using the contents texture directly. | 415 // Zero-copy means using the contents texture directly. |
| 416 Texture* texture = contents_texture_.get(); | 416 Texture* texture = contents_texture_.get(); |
| 417 | 417 |
| 418 // This binds the latest contents of this buffer to |texture|. | 418 // This binds the latest contents of this buffer to |texture|. |
| 419 gpu::SyncToken sync_token = texture->BindTexImage(); | 419 gpu::SyncToken sync_token = texture->BindTexImage(); |
| 420 | 420 |
| 421 *texture_mailbox = | 421 *texture_mailbox = cc::TextureMailbox( |
| 422 cc::TextureMailbox(texture->mailbox(), sync_token, texture_target_, | 422 texture->mailbox(), sync_token, texture_target_, |
| 423 gpu_memory_buffer_->GetSize(), is_overlay_candidate_, | 423 gpu_memory_buffer_->GetSize(), gfx::GpuMemoryBufferHandle(), |
| 424 secure_output_only); | 424 is_overlay_candidate_, secure_output_only); |
| 425 // The contents texture will be released when no longer used by the | 425 // The contents texture will be released when no longer used by the |
| 426 // compositor. | 426 // compositor. |
| 427 return cc::SingleReleaseCallback::Create( | 427 return cc::SingleReleaseCallback::Create( |
| 428 base::Bind(&Buffer::Texture::ReleaseTexImage, base::Unretained(texture), | 428 base::Bind(&Buffer::Texture::ReleaseTexImage, base::Unretained(texture), |
| 429 base::Bind(&Buffer::ReleaseContentsTexture, AsWeakPtr(), | 429 base::Bind(&Buffer::ReleaseContentsTexture, AsWeakPtr(), |
| 430 base::Passed(&contents_texture_)))); | 430 base::Passed(&contents_texture_)))); |
| 431 } | 431 } |
| 432 | 432 |
| 433 // Create a mailbox texture that we copy the buffer contents to. | 433 // Create a mailbox texture that we copy the buffer contents to. |
| 434 if (!texture_) | 434 if (!texture_) |
| 435 texture_ = base::WrapUnique(new Texture(context_provider.get())); | 435 texture_ = base::WrapUnique(new Texture(context_provider.get())); |
| 436 | 436 |
| 437 // Copy the contents of |contents_texture| to |texture| and produce a | 437 // Copy the contents of |contents_texture| to |texture| and produce a |
| 438 // texture mailbox from the result in |texture|. | 438 // texture mailbox from the result in |texture|. |
| 439 Texture* contents_texture = contents_texture_.get(); | 439 Texture* contents_texture = contents_texture_.get(); |
| 440 Texture* texture = texture_.get(); | 440 Texture* texture = texture_.get(); |
| 441 | 441 |
| 442 // The contents texture will be released when copy has completed. | 442 // The contents texture will be released when copy has completed. |
| 443 gpu::SyncToken sync_token = contents_texture->CopyTexImage( | 443 gpu::SyncToken sync_token = contents_texture->CopyTexImage( |
| 444 texture, base::Bind(&Buffer::ReleaseContentsTexture, AsWeakPtr(), | 444 texture, base::Bind(&Buffer::ReleaseContentsTexture, AsWeakPtr(), |
| 445 base::Passed(&contents_texture_))); | 445 base::Passed(&contents_texture_))); |
| 446 *texture_mailbox = | 446 *texture_mailbox = cc::TextureMailbox( |
| 447 cc::TextureMailbox(texture->mailbox(), sync_token, GL_TEXTURE_2D, | 447 texture->mailbox(), sync_token, GL_TEXTURE_2D, |
| 448 gpu_memory_buffer_->GetSize(), | 448 gpu_memory_buffer_->GetSize(), gfx::GpuMemoryBufferHandle(), |
| 449 false /* is_overlay_candidate */, secure_output_only); | 449 false /* is_overlay_candidate */, secure_output_only); |
| 450 // The mailbox texture will be released when no longer used by the | 450 // The mailbox texture will be released when no longer used by the |
| 451 // compositor. | 451 // compositor. |
| 452 return cc::SingleReleaseCallback::Create( | 452 return cc::SingleReleaseCallback::Create( |
| 453 base::Bind(&Buffer::Texture::Release, base::Unretained(texture), | 453 base::Bind(&Buffer::Texture::Release, base::Unretained(texture), |
| 454 base::Bind(&Buffer::ReleaseTexture, AsWeakPtr(), | 454 base::Bind(&Buffer::ReleaseTexture, AsWeakPtr(), |
| 455 base::Passed(&texture_)))); | 455 base::Passed(&texture_)))); |
| 456 } | 456 } |
| 457 | 457 |
| 458 gfx::Size Buffer::GetSize() const { | 458 gfx::Size Buffer::GetSize() const { |
| 459 return gpu_memory_buffer_->GetSize(); | 459 return gpu_memory_buffer_->GetSize(); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 488 } | 488 } |
| 489 | 489 |
| 490 void Buffer::ReleaseContentsTexture(std::unique_ptr<Texture> texture) { | 490 void Buffer::ReleaseContentsTexture(std::unique_ptr<Texture> texture) { |
| 491 TRACE_EVENT0("exo", "Buffer::ReleaseContentsTexture"); | 491 TRACE_EVENT0("exo", "Buffer::ReleaseContentsTexture"); |
| 492 | 492 |
| 493 contents_texture_ = std::move(texture); | 493 contents_texture_ = std::move(texture); |
| 494 Release(); | 494 Release(); |
| 495 } | 495 } |
| 496 | 496 |
| 497 } // namespace exo | 497 } // namespace exo |
| OLD | NEW |