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> |
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
432 if (!context_provider) { | 432 if (!context_provider) { |
433 DLOG(WARNING) << "Failed to acquire a context provider"; | 433 DLOG(WARNING) << "Failed to acquire a context provider"; |
434 Release(); // Decrements the use count | 434 Release(); // Decrements the use count |
435 return nullptr; | 435 return nullptr; |
436 } | 436 } |
437 | 437 |
438 // Create a new image texture for |gpu_memory_buffer_| with |texture_target_| | 438 // Create a new image texture for |gpu_memory_buffer_| with |texture_target_| |
439 // if one doesn't already exist. The contents of this buffer are copied to | 439 // if one doesn't already exist. The contents of this buffer are copied to |
440 // |texture| using a call to CopyTexImage. | 440 // |texture| using a call to CopyTexImage. |
441 if (!contents_texture_) { | 441 if (!contents_texture_) { |
442 contents_texture_ = base::WrapUnique( | 442 contents_texture_ = base::MakeUnique<Texture>( |
443 new Texture(context_factory, context_provider.get(), | 443 context_factory, context_provider.get(), gpu_memory_buffer_.get(), |
444 gpu_memory_buffer_.get(), texture_target_, query_type_)); | 444 texture_target_, query_type_); |
445 } | 445 } |
446 | 446 |
447 if (use_zero_copy_) { | 447 if (use_zero_copy_) { |
448 // Zero-copy means using the contents texture directly. | 448 // Zero-copy means using the contents texture directly. |
449 Texture* texture = contents_texture_.get(); | 449 Texture* texture = contents_texture_.get(); |
450 | 450 |
451 // This binds the latest contents of this buffer to |texture|. | 451 // This binds the latest contents of this buffer to |texture|. |
452 gpu::SyncToken sync_token = texture->BindTexImage(); | 452 gpu::SyncToken sync_token = texture->BindTexImage(); |
453 | 453 |
454 *texture_mailbox = | 454 *texture_mailbox = |
455 cc::TextureMailbox(texture->mailbox(), sync_token, texture_target_, | 455 cc::TextureMailbox(texture->mailbox(), sync_token, texture_target_, |
456 gpu_memory_buffer_->GetSize(), is_overlay_candidate_, | 456 gpu_memory_buffer_->GetSize(), is_overlay_candidate_, |
457 secure_output_only); | 457 secure_output_only); |
458 // The contents texture will be released when no longer used by the | 458 // The contents texture will be released when no longer used by the |
459 // compositor. | 459 // compositor. |
460 return cc::SingleReleaseCallback::Create( | 460 return cc::SingleReleaseCallback::Create( |
461 base::Bind(&Buffer::Texture::ReleaseTexImage, base::Unretained(texture), | 461 base::Bind(&Buffer::Texture::ReleaseTexImage, base::Unretained(texture), |
462 base::Bind(&Buffer::ReleaseContentsTexture, AsWeakPtr(), | 462 base::Bind(&Buffer::ReleaseContentsTexture, AsWeakPtr(), |
463 base::Passed(&contents_texture_)))); | 463 base::Passed(&contents_texture_)))); |
464 } | 464 } |
465 | 465 |
466 // Create a mailbox texture that we copy the buffer contents to. | 466 // Create a mailbox texture that we copy the buffer contents to. |
467 if (!texture_) { | 467 if (!texture_) { |
468 texture_ = | 468 texture_ = |
469 base::WrapUnique(new Texture(context_factory, context_provider.get())); | 469 base::MakeUnique<Texture>(context_factory, context_provider.get()); |
470 } | 470 } |
471 | 471 |
472 // Copy the contents of |contents_texture| to |texture| and produce a | 472 // Copy the contents of |contents_texture| to |texture| and produce a |
473 // texture mailbox from the result in |texture|. | 473 // texture mailbox from the result in |texture|. |
474 Texture* contents_texture = contents_texture_.get(); | 474 Texture* contents_texture = contents_texture_.get(); |
475 Texture* texture = texture_.get(); | 475 Texture* texture = texture_.get(); |
476 | 476 |
477 // The contents texture will be released when copy has completed. | 477 // The contents texture will be released when copy has completed. |
478 gpu::SyncToken sync_token = contents_texture->CopyTexImage( | 478 gpu::SyncToken sync_token = contents_texture->CopyTexImage( |
479 texture, base::Bind(&Buffer::ReleaseContentsTexture, AsWeakPtr(), | 479 texture, base::Bind(&Buffer::ReleaseContentsTexture, AsWeakPtr(), |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
540 } | 540 } |
541 | 541 |
542 void Buffer::ReleaseContentsTexture(std::unique_ptr<Texture> texture) { | 542 void Buffer::ReleaseContentsTexture(std::unique_ptr<Texture> texture) { |
543 TRACE_EVENT0("exo", "Buffer::ReleaseContentsTexture"); | 543 TRACE_EVENT0("exo", "Buffer::ReleaseContentsTexture"); |
544 | 544 |
545 contents_texture_ = std::move(texture); | 545 contents_texture_ = std::move(texture); |
546 Release(); | 546 Release(); |
547 } | 547 } |
548 | 548 |
549 } // namespace exo | 549 } // namespace exo |
OLD | NEW |