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> |
11 | 11 |
12 #include <algorithm> | 12 #include <algorithm> |
13 #include <utility> | 13 #include <utility> |
14 | 14 |
15 #include "base/callback_helpers.h" | 15 #include "base/callback_helpers.h" |
16 #include "base/logging.h" | 16 #include "base/logging.h" |
17 #include "base/macros.h" | 17 #include "base/macros.h" |
18 #include "base/memory/ptr_util.h" | 18 #include "base/memory/ptr_util.h" |
19 #include "base/memory/weak_ptr.h" | 19 #include "base/memory/weak_ptr.h" |
20 #include "base/threading/thread_task_runner_handle.h" | 20 #include "base/threading/thread_task_runner_handle.h" |
21 #include "base/time/time.h" | 21 #include "base/time/time.h" |
22 #include "base/trace_event/trace_event.h" | 22 #include "base/trace_event/trace_event.h" |
23 #include "base/trace_event/trace_event_argument.h" | 23 #include "base/trace_event/trace_event_argument.h" |
24 #include "cc/output/context_provider.h" | 24 #include "cc/output/context_provider.h" |
25 #include "cc/resources/single_release_callback.h" | 25 #include "cc/resources/single_release_callback.h" |
26 #include "cc/resources/texture_mailbox.h" | 26 #include "cc/resources/texture_mailbox.h" |
| 27 #include "components/exo/compositor_frame_sink_holder.h" |
27 #include "gpu/command_buffer/client/context_support.h" | 28 #include "gpu/command_buffer/client/context_support.h" |
28 #include "gpu/command_buffer/client/gles2_interface.h" | 29 #include "gpu/command_buffer/client/gles2_interface.h" |
29 #include "ui/aura/env.h" | 30 #include "ui/aura/env.h" |
30 #include "ui/compositor/compositor.h" | 31 #include "ui/compositor/compositor.h" |
31 #include "ui/gfx/gpu_memory_buffer.h" | 32 #include "ui/gfx/gpu_memory_buffer.h" |
32 | 33 |
33 namespace exo { | 34 namespace exo { |
34 namespace { | 35 namespace { |
35 | 36 |
36 // The amount of time before we wait for release queries using | 37 // The amount of time before we wait for release queries using |
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 texture_target_(texture_target), | 395 texture_target_(texture_target), |
395 query_type_(query_type), | 396 query_type_(query_type), |
396 use_zero_copy_(use_zero_copy), | 397 use_zero_copy_(use_zero_copy), |
397 is_overlay_candidate_(is_overlay_candidate) {} | 398 is_overlay_candidate_(is_overlay_candidate) {} |
398 | 399 |
399 Buffer::~Buffer() {} | 400 Buffer::~Buffer() {} |
400 | 401 |
401 std::unique_ptr<cc::SingleReleaseCallback> Buffer::ProduceTextureMailbox( | 402 std::unique_ptr<cc::SingleReleaseCallback> Buffer::ProduceTextureMailbox( |
402 cc::TextureMailbox* texture_mailbox, | 403 cc::TextureMailbox* texture_mailbox, |
403 bool secure_output_only, | 404 bool secure_output_only, |
404 bool client_usage) { | 405 bool client_usage, |
| 406 scoped_refptr<CompositorFrameSinkHolder> compositor_frame_sink_holder) { |
405 DCHECK(attach_count_); | 407 DCHECK(attach_count_); |
406 DLOG_IF(WARNING, use_count_ && client_usage) | 408 DLOG_IF(WARNING, use_count_ && client_usage) |
407 << "Producing a texture mailbox for a buffer that has not been released"; | 409 << "Producing a texture mailbox for a buffer that has not been released"; |
408 | 410 |
409 // Some clients think that they can reuse a buffer before it's released by | 411 // Some clients think that they can reuse a buffer before it's released by |
410 // performing a fast blit into the buffer. This behavior is bad as it prevents | 412 // performing a fast blit into the buffer. This behavior is bad as it prevents |
411 // the client from knowing when the buffer is actually released (e.g. the | 413 // the client from knowing when the buffer is actually released (e.g. the |
412 // release notification for the previous use of buffer can arrive after the | 414 // release notification for the previous use of buffer can arrive after the |
413 // buffer has been reused). We stop running the release callback when this | 415 // buffer has been reused). We stop running the release callback when this |
414 // type of behavior is detected as having the buffer always be busy will | 416 // type of behavior is detected as having the buffer always be busy will |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
451 | 453 |
452 // This binds the latest contents of this buffer to |texture|. | 454 // This binds the latest contents of this buffer to |texture|. |
453 gpu::SyncToken sync_token = texture->BindTexImage(); | 455 gpu::SyncToken sync_token = texture->BindTexImage(); |
454 | 456 |
455 *texture_mailbox = | 457 *texture_mailbox = |
456 cc::TextureMailbox(texture->mailbox(), sync_token, texture_target_, | 458 cc::TextureMailbox(texture->mailbox(), sync_token, texture_target_, |
457 gpu_memory_buffer_->GetSize(), is_overlay_candidate_, | 459 gpu_memory_buffer_->GetSize(), is_overlay_candidate_, |
458 secure_output_only); | 460 secure_output_only); |
459 // The contents texture will be released when no longer used by the | 461 // The contents texture will be released when no longer used by the |
460 // compositor. | 462 // compositor. |
461 return cc::SingleReleaseCallback::Create( | 463 return cc::SingleReleaseCallback::Create(base::Bind( |
462 base::Bind(&Buffer::Texture::ReleaseTexImage, base::Unretained(texture), | 464 &Buffer::Texture::ReleaseTexImage, base::Unretained(texture), |
463 base::Bind(&Buffer::ReleaseContentsTexture, AsWeakPtr(), | 465 base::Bind(&Buffer::ReleaseContentsTextureAndCompositorFrameSinkHolder, |
464 base::Passed(&contents_texture_)))); | 466 AsWeakPtr(), base::Passed(&contents_texture_), |
| 467 base::RetainedRef(compositor_frame_sink_holder)))); |
465 } | 468 } |
466 | 469 |
467 // Create a mailbox texture that we copy the buffer contents to. | 470 // Create a mailbox texture that we copy the buffer contents to. |
468 if (!texture_) { | 471 if (!texture_) { |
469 texture_ = | 472 texture_ = |
470 base::MakeUnique<Texture>(context_factory, context_provider.get()); | 473 base::MakeUnique<Texture>(context_factory, context_provider.get()); |
471 } | 474 } |
472 | 475 |
473 // Copy the contents of |contents_texture| to |texture| and produce a | 476 // Copy the contents of |contents_texture| to |texture| and produce a |
474 // texture mailbox from the result in |texture|. | 477 // texture mailbox from the result in |texture|. |
475 Texture* contents_texture = contents_texture_.get(); | 478 Texture* contents_texture = contents_texture_.get(); |
476 Texture* texture = texture_.get(); | 479 Texture* texture = texture_.get(); |
477 | 480 |
478 // The contents texture will be released when copy has completed. | 481 // The contents texture will be released when copy has completed. |
479 gpu::SyncToken sync_token = contents_texture->CopyTexImage( | 482 gpu::SyncToken sync_token = contents_texture->CopyTexImage( |
480 texture, base::Bind(&Buffer::ReleaseContentsTexture, AsWeakPtr(), | 483 texture, |
481 base::Passed(&contents_texture_))); | 484 base::Bind(&Buffer::ReleaseContentsTextureAndCompositorFrameSinkHolder, |
| 485 AsWeakPtr(), base::Passed(&contents_texture_), nullptr)); |
482 *texture_mailbox = | 486 *texture_mailbox = |
483 cc::TextureMailbox(texture->mailbox(), sync_token, GL_TEXTURE_2D, | 487 cc::TextureMailbox(texture->mailbox(), sync_token, GL_TEXTURE_2D, |
484 gpu_memory_buffer_->GetSize(), | 488 gpu_memory_buffer_->GetSize(), |
485 false /* is_overlay_candidate */, secure_output_only); | 489 false /* is_overlay_candidate */, secure_output_only); |
486 // The mailbox texture will be released when no longer used by the | 490 // The mailbox texture will be released when no longer used by the |
487 // compositor. | 491 // compositor. |
488 return cc::SingleReleaseCallback::Create( | 492 return cc::SingleReleaseCallback::Create( |
489 base::Bind(&Buffer::Texture::Release, base::Unretained(texture), | 493 base::Bind(&Buffer::Texture::Release, base::Unretained(texture), |
490 base::Bind(&Buffer::ReleaseTexture, AsWeakPtr(), | 494 base::Bind(&Buffer::ReleaseTextureAndCompositorFrameSinkHolder, |
491 base::Passed(&texture_)))); | 495 AsWeakPtr(), base::Passed(&texture_), |
| 496 base::RetainedRef(compositor_frame_sink_holder)))); |
492 } | 497 } |
493 | 498 |
494 void Buffer::OnAttach() { | 499 void Buffer::OnAttach() { |
495 DLOG_IF(WARNING, attach_count_ > 0u) | 500 DLOG_IF(WARNING, attach_count_ > 0u) |
496 << "Reattaching a buffer that is already attached to another surface."; | 501 << "Reattaching a buffer that is already attached to another surface."; |
497 attach_count_++; | 502 attach_count_++; |
498 } | 503 } |
499 | 504 |
500 void Buffer::OnDetach() { | 505 void Buffer::OnDetach() { |
501 DCHECK_GT(attach_count_, 0u); | 506 DCHECK_GT(attach_count_, 0u); |
(...skipping 27 matching lines...) Expand all Loading... |
529 | 534 |
530 void Buffer::CheckReleaseCallback() { | 535 void Buffer::CheckReleaseCallback() { |
531 if (attach_count_ || use_count_) | 536 if (attach_count_ || use_count_) |
532 return; | 537 return; |
533 | 538 |
534 // Run release callback to notify the client that buffer has been released. | 539 // Run release callback to notify the client that buffer has been released. |
535 if (!release_callback_.is_null()) | 540 if (!release_callback_.is_null()) |
536 release_callback_.Run(); | 541 release_callback_.Run(); |
537 } | 542 } |
538 | 543 |
| 544 void Buffer::ReleaseTextureAndCompositorFrameSinkHolder( |
| 545 std::unique_ptr<Texture> texture, |
| 546 CompositorFrameSinkHolder* compositor_frame_sink_holder) { |
| 547 ReleaseTexture(std::move(texture)); |
| 548 } |
| 549 |
539 void Buffer::ReleaseTexture(std::unique_ptr<Texture> texture) { | 550 void Buffer::ReleaseTexture(std::unique_ptr<Texture> texture) { |
540 texture_ = std::move(texture); | 551 texture_ = std::move(texture); |
541 } | 552 } |
542 | 553 |
| 554 void Buffer::ReleaseContentsTextureAndCompositorFrameSinkHolder( |
| 555 std::unique_ptr<Texture> texture, |
| 556 CompositorFrameSinkHolder* compositor_frame_sink_holder) { |
| 557 ReleaseContentsTexture(std::move(texture)); |
| 558 } |
| 559 |
543 void Buffer::ReleaseContentsTexture(std::unique_ptr<Texture> texture) { | 560 void Buffer::ReleaseContentsTexture(std::unique_ptr<Texture> texture) { |
544 TRACE_EVENT0("exo", "Buffer::ReleaseContentsTexture"); | 561 TRACE_EVENT0("exo", "Buffer::ReleaseContentsTexture"); |
545 | 562 |
546 contents_texture_ = std::move(texture); | 563 contents_texture_ = std::move(texture); |
547 Release(); | 564 Release(); |
548 } | 565 } |
549 | 566 |
550 } // namespace exo | 567 } // namespace exo |
OLD | NEW |