Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Side by Side Diff: components/exo/buffer.cc

Issue 2584953002: exo::CompositorFrameSinkHolder's release callbacks hold ref (Closed)
Patch Set: Use ScopedClosureRunner Created 3 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
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(
462 base::Bind(&Buffer::Texture::ReleaseTexImage, base::Unretained(texture), 464 base::Bind(&Buffer::Texture::ReleaseTexImage, base::Unretained(texture),
463 base::Bind(&Buffer::ReleaseContentsTexture, AsWeakPtr(), 465 base::Bind(&Buffer::ReleaseContentsTexture, AsWeakPtr(),
464 base::Passed(&contents_texture_)))); 466 base::Passed(&contents_texture_),
467 (compositor_frame_sink_holder))));
reveman 2016/12/21 20:05:42 s/(compositor_frame_sink_holder)/compositor_frame_
Alex Z. 2016/12/21 22:35:33 Done.
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, base::Bind(&Buffer::ReleaseContentsTexture, AsWeakPtr(),
481 base::Passed(&contents_texture_))); 484 base::Passed(&contents_texture_), nullptr));
482 *texture_mailbox = 485 *texture_mailbox =
483 cc::TextureMailbox(texture->mailbox(), sync_token, GL_TEXTURE_2D, 486 cc::TextureMailbox(texture->mailbox(), sync_token, GL_TEXTURE_2D,
484 gpu_memory_buffer_->GetSize(), 487 gpu_memory_buffer_->GetSize(),
485 false /* is_overlay_candidate */, secure_output_only); 488 false /* is_overlay_candidate */, secure_output_only);
486 // 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
487 // compositor. 490 // compositor.
488 return cc::SingleReleaseCallback::Create( 491 return cc::SingleReleaseCallback::Create(base::Bind(
489 base::Bind(&Buffer::Texture::Release, base::Unretained(texture), 492 &Buffer::Texture::Release, base::Unretained(texture),
490 base::Bind(&Buffer::ReleaseTexture, AsWeakPtr(), 493 base::Bind(&Buffer::ReleaseTexture, AsWeakPtr(), base::Passed(&texture_),
491 base::Passed(&texture_)))); 494 (compositor_frame_sink_holder))));
492 } 495 }
493 496
494 void Buffer::OnAttach() { 497 void Buffer::OnAttach() {
495 DLOG_IF(WARNING, attach_count_ > 0u) 498 DLOG_IF(WARNING, attach_count_ > 0u)
496 << "Reattaching a buffer that is already attached to another surface."; 499 << "Reattaching a buffer that is already attached to another surface.";
497 attach_count_++; 500 attach_count_++;
498 } 501 }
499 502
500 void Buffer::OnDetach() { 503 void Buffer::OnDetach() {
501 DCHECK_GT(attach_count_, 0u); 504 DCHECK_GT(attach_count_, 0u);
(...skipping 27 matching lines...) Expand all
529 532
530 void Buffer::CheckReleaseCallback() { 533 void Buffer::CheckReleaseCallback() {
531 if (attach_count_ || use_count_) 534 if (attach_count_ || use_count_)
532 return; 535 return;
533 536
534 // Run release callback to notify the client that buffer has been released. 537 // Run release callback to notify the client that buffer has been released.
535 if (!release_callback_.is_null()) 538 if (!release_callback_.is_null())
536 release_callback_.Run(); 539 release_callback_.Run();
537 } 540 }
538 541
539 void Buffer::ReleaseTexture(std::unique_ptr<Texture> texture) { 542 void Buffer::ReleaseTexture(
543 std::unique_ptr<Texture> texture,
544 scoped_refptr<CompositorFrameSinkHolder> compositor_frame_sink_holder) {
540 texture_ = std::move(texture); 545 texture_ = std::move(texture);
541 } 546 }
542 547
543 void Buffer::ReleaseContentsTexture(std::unique_ptr<Texture> texture) { 548 void Buffer::ReleaseContentsTexture(
549 std::unique_ptr<Texture> texture,
550 scoped_refptr<CompositorFrameSinkHolder> compositor_frame_sink_holder) {
544 TRACE_EVENT0("exo", "Buffer::ReleaseContentsTexture"); 551 TRACE_EVENT0("exo", "Buffer::ReleaseContentsTexture");
545 552
546 contents_texture_ = std::move(texture); 553 contents_texture_ = std::move(texture);
547 Release(); 554 Release();
548 } 555 }
549 556
550 } // namespace exo 557 } // namespace exo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698