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

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: Make ContextFactory pure; hold on to buffer reference 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 353 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 query_type_(query_type), 364 query_type_(query_type),
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 base::Closure* detach_callback) {
376 DCHECK(detach_callback->is_null());
375 // Non-client usage can only be allowed when the client is not allowed to 377 // Non-client usage can only be allowed when the client is not allowed to
376 // use the buffer. If the buffer has been released to the client then it 378 // 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. 379 // can no longer be used as the client might be writing to it.
378 if (!client_usage && !use_count_) 380 if (!client_usage && !use_count_)
379 return nullptr; 381 return nullptr;
380 382
381 DLOG_IF(WARNING, use_count_ && client_usage) 383 DLOG_IF(WARNING, use_count_ && client_usage)
382 << "Producing a texture mailbox for a buffer that has not been released"; 384 << "Producing a texture mailbox for a buffer that has not been released";
383 385
384 // Some clients think that they can reuse a buffer before it's released by 386 // Some clients think that they can reuse a buffer before it's released by
(...skipping 19 matching lines...) Expand all
404 scoped_refptr<cc::ContextProvider> context_provider = 406 scoped_refptr<cc::ContextProvider> context_provider =
405 aura::Env::GetInstance() 407 aura::Env::GetInstance()
406 ->context_factory() 408 ->context_factory()
407 ->SharedMainThreadContextProvider(); 409 ->SharedMainThreadContextProvider();
408 if (!context_provider) { 410 if (!context_provider) {
409 DLOG(WARNING) << "Failed to acquire a context provider"; 411 DLOG(WARNING) << "Failed to acquire a context provider";
410 Release(); // Decrements the use count 412 Release(); // Decrements the use count
411 return nullptr; 413 return nullptr;
412 } 414 }
413 415
416 // Add a callback to ensure this buffer isn't released while it's attached
417 // to a surface.
418 use_count_++;
419 *detach_callback = base::Bind(&Buffer::Release, AsWeakPtr());
420
414 // Create a new image texture for |gpu_memory_buffer_| with |texture_target_| 421 // Create a new image texture for |gpu_memory_buffer_| with |texture_target_|
415 // if one doesn't already exist. The contents of this buffer are copied to 422 // if one doesn't already exist. The contents of this buffer are copied to
416 // |texture| using a call to CopyTexImage. 423 // |texture| using a call to CopyTexImage.
417 if (!contents_texture_) { 424 if (!contents_texture_) {
418 contents_texture_ = base::WrapUnique( 425 contents_texture_ = base::WrapUnique(
419 new Texture(context_provider.get(), gpu_memory_buffer_.get(), 426 new Texture(context_provider.get(), gpu_memory_buffer_.get(),
420 texture_target_, query_type_)); 427 texture_target_, query_type_));
421 } 428 }
422 429
423 if (use_zero_copy_) { 430 if (use_zero_copy_) {
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 } 504 }
498 505
499 void Buffer::ReleaseContentsTexture(std::unique_ptr<Texture> texture) { 506 void Buffer::ReleaseContentsTexture(std::unique_ptr<Texture> texture) {
500 TRACE_EVENT0("exo", "Buffer::ReleaseContentsTexture"); 507 TRACE_EVENT0("exo", "Buffer::ReleaseContentsTexture");
501 508
502 contents_texture_ = std::move(texture); 509 contents_texture_ = std::move(texture);
503 Release(); 510 Release();
504 } 511 }
505 512
506 } // namespace exo 513 } // namespace exo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698