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 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
457 contents_texture_ = base::MakeUnique<Texture>( | 457 contents_texture_ = base::MakeUnique<Texture>( |
458 context_factory, context_provider.get(), gpu_memory_buffer_.get(), | 458 context_factory, context_provider.get(), gpu_memory_buffer_.get(), |
459 texture_target_, query_type_); | 459 texture_target_, query_type_); |
460 } | 460 } |
461 | 461 |
462 if (use_zero_copy_) { | 462 if (use_zero_copy_) { |
463 // Zero-copy means using the contents texture directly. | 463 // Zero-copy means using the contents texture directly. |
464 Texture* texture = contents_texture_.get(); | 464 Texture* texture = contents_texture_.get(); |
465 | 465 |
466 // This binds the latest contents of this buffer to |texture|. | 466 // This binds the latest contents of this buffer to |texture|. |
467 resource->mailbox_holder = gpu::MailboxHolder( | 467 gpu::SyncToken sync_token = texture->BindTexImage(); |
468 texture->mailbox(), texture->BindTexImage(), texture_target_); | 468 resource->mailbox_holder = |
469 | 469 gpu::MailboxHolder(texture->mailbox(), sync_token, texture_target_); |
470 resource->is_overlay_candidate = is_overlay_candidate_; | 470 resource->is_overlay_candidate = is_overlay_candidate_; |
471 | 471 |
472 // The contents texture will be released when no longer used by the | 472 // The contents texture will be released when no longer used by the |
473 // compositor. | 473 // compositor. |
474 compositor_frame_sink_holder_->SetResourceReleaseCallback( | 474 compositor_frame_sink_holder_->SetResourceReleaseCallback( |
475 resource_id, | 475 resource_id, |
476 base::Bind(&Buffer::Texture::ReleaseTexImage, base::Unretained(texture), | 476 base::Bind(&Buffer::Texture::ReleaseTexImage, base::Unretained(texture), |
477 base::Bind(&Buffer::ReleaseContentsTexture, AsWeakPtr(), | 477 base::Bind(&Buffer::ReleaseContentsTexture, AsWeakPtr(), |
478 base::Passed(&contents_texture_)))); | 478 base::Passed(&contents_texture_)))); |
479 return true; | 479 return true; |
480 } | 480 } |
481 | 481 |
482 // Create a mailbox texture that we copy the buffer contents to. | 482 // Create a mailbox texture that we copy the buffer contents to. |
483 if (!texture_) { | 483 if (!texture_) { |
484 texture_ = | 484 texture_ = |
485 base::MakeUnique<Texture>(context_factory, context_provider.get()); | 485 base::MakeUnique<Texture>(context_factory, context_provider.get()); |
486 } | 486 } |
487 | 487 |
488 // Copy the contents of |contents_texture| to |texture| and produce a | 488 // Copy the contents of |contents_texture| to |texture| and produce a |
489 // texture mailbox from the result in |texture|. | 489 // texture mailbox from the result in |texture|. |
490 Texture* contents_texture = contents_texture_.get(); | 490 Texture* contents_texture = contents_texture_.get(); |
491 Texture* texture = texture_.get(); | 491 Texture* texture = texture_.get(); |
492 | 492 |
493 // The contents texture will be released when copy has completed. | 493 // The contents texture will be released when copy has completed. |
494 resource->mailbox_holder = gpu::MailboxHolder( | 494 gpu::SyncToken sync_token = contents_texture->CopyTexImage( |
495 texture->mailbox(), | 495 texture, base::Bind(&Buffer::ReleaseContentsTexture, AsWeakPtr(), |
496 contents_texture->CopyTexImage( | 496 base::Passed(&contents_texture_))); |
497 texture, base::Bind(&Buffer::ReleaseContentsTexture, AsWeakPtr(), | 497 resource->mailbox_holder = |
498 base::Passed(&contents_texture_))), | 498 gpu::MailboxHolder(texture->mailbox(), sync_token, GL_TEXTURE_2D); |
499 GL_TEXTURE_2D); | |
500 resource->is_overlay_candidate = false; | 499 resource->is_overlay_candidate = false; |
501 | 500 |
502 // The mailbox texture will be released when no longer used by the | 501 // The mailbox texture will be released when no longer used by the |
503 // compositor. | 502 // compositor. |
504 compositor_frame_sink_holder_->SetResourceReleaseCallback( | 503 compositor_frame_sink_holder_->SetResourceReleaseCallback( |
505 resource_id, | 504 resource_id, |
506 base::Bind(&Buffer::Texture::Release, base::Unretained(texture), | 505 base::Bind(&Buffer::Texture::Release, base::Unretained(texture), |
507 base::Bind(&Buffer::ReleaseTexture, AsWeakPtr(), | 506 base::Bind(&Buffer::ReleaseTexture, AsWeakPtr(), |
508 base::Passed(&texture_)))); | 507 base::Passed(&texture_)))); |
509 return true; | 508 return true; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
560 texture_ = std::move(texture); | 559 texture_ = std::move(texture); |
561 } | 560 } |
562 | 561 |
563 void Buffer::ReleaseContentsTexture(std::unique_ptr<Texture> texture) { | 562 void Buffer::ReleaseContentsTexture(std::unique_ptr<Texture> texture) { |
564 TRACE_EVENT0("exo", "Buffer::ReleaseContentsTexture"); | 563 TRACE_EVENT0("exo", "Buffer::ReleaseContentsTexture"); |
565 contents_texture_ = std::move(texture); | 564 contents_texture_ = std::move(texture); |
566 Release(); | 565 Release(); |
567 } | 566 } |
568 | 567 |
569 } // namespace exo | 568 } // namespace exo |
OLD | NEW |