Chromium Code Reviews| 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 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 391 bool use_zero_copy, | 392 bool use_zero_copy, |
| 392 bool is_overlay_candidate) | 393 bool is_overlay_candidate) |
| 393 : gpu_memory_buffer_(std::move(gpu_memory_buffer)), | 394 : gpu_memory_buffer_(std::move(gpu_memory_buffer)), |
| 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( |
|
reveman
2017/01/02 19:57:56
It doesn't make sense for this function to return
| |
| 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 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 14 matching lines...) Expand all Loading... | |
| 429 aura::Env::GetInstance()->context_factory(); | 431 aura::Env::GetInstance()->context_factory(); |
| 430 // Note: This can fail if GPU acceleration has been disabled. | 432 // Note: This can fail if GPU acceleration has been disabled. |
| 431 scoped_refptr<cc::ContextProvider> context_provider = | 433 scoped_refptr<cc::ContextProvider> context_provider = |
| 432 context_factory->SharedMainThreadContextProvider(); | 434 context_factory->SharedMainThreadContextProvider(); |
| 433 if (!context_provider) { | 435 if (!context_provider) { |
| 434 DLOG(WARNING) << "Failed to acquire a context provider"; | 436 DLOG(WARNING) << "Failed to acquire a context provider"; |
| 435 Release(); // Decrements the use count | 437 Release(); // Decrements the use count |
| 436 return nullptr; | 438 return nullptr; |
| 437 } | 439 } |
| 438 | 440 |
| 441 compositor_frame_sink_holder_ = compositor_frame_sink_holder; | |
|
reveman
2017/01/02 19:57:56
nit: short comment here saying something like: "We
| |
| 442 | |
| 439 // Create a new image texture for |gpu_memory_buffer_| with |texture_target_| | 443 // Create a new image texture for |gpu_memory_buffer_| with |texture_target_| |
| 440 // if one doesn't already exist. The contents of this buffer are copied to | 444 // if one doesn't already exist. The contents of this buffer are copied to |
| 441 // |texture| using a call to CopyTexImage. | 445 // |texture| using a call to CopyTexImage. |
| 442 if (!contents_texture_) { | 446 if (!contents_texture_) { |
| 443 contents_texture_ = base::MakeUnique<Texture>( | 447 contents_texture_ = base::MakeUnique<Texture>( |
| 444 context_factory, context_provider.get(), gpu_memory_buffer_.get(), | 448 context_factory, context_provider.get(), gpu_memory_buffer_.get(), |
| 445 texture_target_, query_type_); | 449 texture_target_, query_type_); |
| 446 } | 450 } |
| 447 | 451 |
| 448 if (use_zero_copy_) { | 452 if (use_zero_copy_) { |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 527 CheckReleaseCallback(); | 531 CheckReleaseCallback(); |
| 528 } | 532 } |
| 529 | 533 |
| 530 void Buffer::CheckReleaseCallback() { | 534 void Buffer::CheckReleaseCallback() { |
| 531 if (attach_count_ || use_count_) | 535 if (attach_count_ || use_count_) |
| 532 return; | 536 return; |
| 533 | 537 |
| 534 // Run release callback to notify the client that buffer has been released. | 538 // Run release callback to notify the client that buffer has been released. |
| 535 if (!release_callback_.is_null()) | 539 if (!release_callback_.is_null()) |
| 536 release_callback_.Run(); | 540 release_callback_.Run(); |
| 541 | |
| 542 compositor_frame_sink_holder_ = nullptr; | |
|
reveman
2017/01/02 19:57:56
Do we really need this here? Removing it would sol
| |
| 537 } | 543 } |
| 538 | 544 |
| 539 void Buffer::ReleaseTexture(std::unique_ptr<Texture> texture) { | 545 void Buffer::ReleaseTexture(std::unique_ptr<Texture> texture) { |
| 540 texture_ = std::move(texture); | 546 texture_ = std::move(texture); |
| 541 } | 547 } |
| 542 | 548 |
| 543 void Buffer::ReleaseContentsTexture(std::unique_ptr<Texture> texture) { | 549 void Buffer::ReleaseContentsTexture(std::unique_ptr<Texture> texture) { |
| 544 TRACE_EVENT0("exo", "Buffer::ReleaseContentsTexture"); | 550 TRACE_EVENT0("exo", "Buffer::ReleaseContentsTexture"); |
| 545 | 551 |
| 546 contents_texture_ = std::move(texture); | 552 contents_texture_ = std::move(texture); |
| 547 Release(); | 553 Release(); |
| 548 } | 554 } |
| 549 | 555 |
| 550 } // namespace exo | 556 } // namespace exo |
| OLD | NEW |