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

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

Issue 2083853002: exo: Recreate Surface resources on context lost. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix deps Created 4 years, 6 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>
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 use_zero_copy_(use_zero_copy), 365 use_zero_copy_(use_zero_copy),
366 is_overlay_candidate_(is_overlay_candidate), 366 is_overlay_candidate_(is_overlay_candidate),
367 use_count_(0) {} 367 use_count_(0) {}
368 368
369 Buffer::~Buffer() {} 369 Buffer::~Buffer() {}
370 370
371 std::unique_ptr<cc::SingleReleaseCallback> Buffer::ProduceTextureMailbox( 371 std::unique_ptr<cc::SingleReleaseCallback> Buffer::ProduceTextureMailbox(
372 cc::TextureMailbox* texture_mailbox, 372 cc::TextureMailbox* texture_mailbox,
373 bool secure_output_only, 373 bool secure_output_only,
374 bool client_usage) { 374 bool client_usage) {
375 // Non-client usage can only be allowed when the client is not allowed to 375 DCHECK(attach_count_);
376 // use the buffer. If the buffer has been released to the client then it
377 // can no longer be used as the client might be writing to it.
378 if (!client_usage && !use_count_)
379 return nullptr;
380
381 DLOG_IF(WARNING, use_count_ && client_usage) 376 DLOG_IF(WARNING, use_count_ && client_usage)
382 << "Producing a texture mailbox for a buffer that has not been released"; 377 << "Producing a texture mailbox for a buffer that has not been released";
383 378
384 // Some clients think that they can reuse a buffer before it's released by 379 // Some clients think that they can reuse a buffer before it's released by
385 // performing a fast blit into the buffer. This behavior is bad as it prevents 380 // performing a fast blit into the buffer. This behavior is bad as it prevents
386 // the client from knowing when the buffer is actually released (e.g. the 381 // the client from knowing when the buffer is actually released (e.g. the
387 // release notification for the previous use of buffer can arrive after the 382 // release notification for the previous use of buffer can arrive after the
388 // buffer has been reused). We stop running the release callback when this 383 // buffer has been reused). We stop running the release callback when this
389 // type of behavior is detected as having the buffer always be busy will 384 // type of behavior is detected as having the buffer always be busy will
390 // result in fewer drawing artifacts. 385 // result in fewer drawing artifacts.
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 gpu_memory_buffer_->GetSize(), gfx::GpuMemoryBufferId(), 452 gpu_memory_buffer_->GetSize(), gfx::GpuMemoryBufferId(),
458 false /* is_overlay_candidate */, secure_output_only); 453 false /* is_overlay_candidate */, secure_output_only);
459 // The mailbox texture will be released when no longer used by the 454 // The mailbox texture will be released when no longer used by the
460 // compositor. 455 // compositor.
461 return cc::SingleReleaseCallback::Create( 456 return cc::SingleReleaseCallback::Create(
462 base::Bind(&Buffer::Texture::Release, base::Unretained(texture), 457 base::Bind(&Buffer::Texture::Release, base::Unretained(texture),
463 base::Bind(&Buffer::ReleaseTexture, AsWeakPtr(), 458 base::Bind(&Buffer::ReleaseTexture, AsWeakPtr(),
464 base::Passed(&texture_)))); 459 base::Passed(&texture_))));
465 } 460 }
466 461
462 void Buffer::OnDetach() {
463 DCHECK_GT(attach_count_, 0u);
464 --attach_count_;
465 CheckReleaseCallback();
466 }
467
467 gfx::Size Buffer::GetSize() const { 468 gfx::Size Buffer::GetSize() const {
468 return gpu_memory_buffer_->GetSize(); 469 return gpu_memory_buffer_->GetSize();
469 } 470 }
470 471
471 std::unique_ptr<base::trace_event::TracedValue> Buffer::AsTracedValue() const { 472 std::unique_ptr<base::trace_event::TracedValue> Buffer::AsTracedValue() const {
472 std::unique_ptr<base::trace_event::TracedValue> value( 473 std::unique_ptr<base::trace_event::TracedValue> value(
473 new base::trace_event::TracedValue()); 474 new base::trace_event::TracedValue());
474 gfx::Size size = gpu_memory_buffer_->GetSize(); 475 gfx::Size size = gpu_memory_buffer_->GetSize();
475 value->SetInteger("width", size.width()); 476 value->SetInteger("width", size.width());
476 value->SetInteger("height", size.height()); 477 value->SetInteger("height", size.height());
477 value->SetInteger("format", 478 value->SetInteger("format",
478 static_cast<int>(gpu_memory_buffer_->GetFormat())); 479 static_cast<int>(gpu_memory_buffer_->GetFormat()));
479 return value; 480 return value;
480 } 481 }
481 482
482 //////////////////////////////////////////////////////////////////////////////// 483 ////////////////////////////////////////////////////////////////////////////////
483 // Buffer, private: 484 // Buffer, private:
484 485
485 void Buffer::Release() { 486 void Buffer::Release() {
486 DCHECK_GT(use_count_, 0u); 487 DCHECK_GT(use_count_, 0u);
487 if (--use_count_) 488 --use_count_;
489 CheckReleaseCallback();
490 }
491
492 void Buffer::CheckReleaseCallback() {
493 if (attach_count_ || use_count_)
488 return; 494 return;
489 495
490 // Run release callback to notify the client that buffer has been released. 496 // Run release callback to notify the client that buffer has been released.
491 if (!release_callback_.is_null()) 497 if (!release_callback_.is_null())
492 release_callback_.Run(); 498 release_callback_.Run();
493 } 499 }
494 500
495 void Buffer::ReleaseTexture(std::unique_ptr<Texture> texture) { 501 void Buffer::ReleaseTexture(std::unique_ptr<Texture> texture) {
496 texture_ = std::move(texture); 502 texture_ = std::move(texture);
497 } 503 }
498 504
499 void Buffer::ReleaseContentsTexture(std::unique_ptr<Texture> texture) { 505 void Buffer::ReleaseContentsTexture(std::unique_ptr<Texture> texture) {
500 TRACE_EVENT0("exo", "Buffer::ReleaseContentsTexture"); 506 TRACE_EVENT0("exo", "Buffer::ReleaseContentsTexture");
501 507
502 contents_texture_ = std::move(texture); 508 contents_texture_ = std::move(texture);
503 Release(); 509 Release();
504 } 510 }
505 511
506 } // namespace exo 512 } // namespace exo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698