| Index: gpu/command_buffer/service/mailbox_manager.cc
|
| diff --git a/gpu/command_buffer/service/mailbox_manager.cc b/gpu/command_buffer/service/mailbox_manager.cc
|
| index 90193934f3a4dd40ba797266978847b653241e69..eeebb8e46388f8a894faf4a4919d252d0271eb7e 100644
|
| --- a/gpu/command_buffer/service/mailbox_manager.cc
|
| +++ b/gpu/command_buffer/service/mailbox_manager.cc
|
| @@ -4,12 +4,11 @@
|
|
|
| #include "gpu/command_buffer/service/mailbox_manager.h"
|
|
|
| -#include <algorithm>
|
| +#include <utility>
|
|
|
| +#include "base/bind.h"
|
| #include "base/rand_util.h"
|
| #include "crypto/hmac.h"
|
| -#include "gpu/command_buffer/service/gl_utils.h"
|
| -#include "gpu/command_buffer/service/texture_definition.h"
|
|
|
| namespace gpu {
|
| namespace gles2 {
|
| @@ -19,6 +18,9 @@ MailboxName::MailboxName() {
|
| std::fill(signature, signature + sizeof(signature), 0);
|
| }
|
|
|
| +const MailboxManager::TexturePoolId MailboxManager::TexturePoolNone =
|
| + std::make_pair(TEXTURE_POOL_NONE, 0);
|
| +
|
| MailboxManager::MailboxManager()
|
| : hmac_(crypto::HMAC::SHA256),
|
| textures_(std::ptr_fun(&MailboxManager::TargetNameLess)) {
|
| @@ -48,45 +50,67 @@ TextureDefinition* MailboxManager::ConsumeTexture(unsigned target,
|
| if (it == textures_.end())
|
| return NULL;
|
|
|
| - TextureDefinition* definition = it->second.definition.release();
|
| + TextureDefinition* definition = it->second.definition;
|
| + TexturePoolId pool_id = it->second.pool_id;
|
| +
|
| + if (pool_id != TexturePoolNone)
|
| + StartSharedTextureTransfer(definition);
|
| +
|
| textures_.erase(it);
|
|
|
| + definition->RemoveObserver(this);
|
| return definition;
|
| }
|
|
|
| bool MailboxManager::ProduceTexture(unsigned target,
|
| const MailboxName& name,
|
| TextureDefinition* definition,
|
| - TextureManager* owner) {
|
| + TexturePoolId pool_id) {
|
| if (!IsMailboxNameValid(name))
|
| return false;
|
|
|
| TextureDefinitionMap::iterator it =
|
| textures_.find(TargetName(target, name));
|
| + MailboxTexture texture(definition, pool_id);
|
| if (it != textures_.end()) {
|
| NOTREACHED();
|
| - GLuint service_id = it->second.definition->ReleaseServiceId();
|
| - glDeleteTextures(1, &service_id);
|
| - it->second = OwnedTextureDefinition(definition, owner);
|
| + it->second = texture;
|
| } else {
|
| - textures_.insert(std::make_pair(
|
| - TargetName(target, name),
|
| - OwnedTextureDefinition(definition, owner)));
|
| + textures_.insert(std::make_pair(TargetName(target, name), texture));
|
| }
|
|
|
| + if (pool_id != TexturePoolNone)
|
| + StartUsingSharedTexture(definition);
|
| +
|
| + definition->AddObserver(this);
|
| return true;
|
| }
|
|
|
| -void MailboxManager::DestroyOwnedTextures(TextureManager* owner,
|
| - bool have_context) {
|
| +void MailboxManager::OnDestroySharedTexture(
|
| + const TextureDefinition* definition) {
|
| TextureDefinitionMap::iterator it = textures_.begin();
|
| + bool found = false;
|
| while (it != textures_.end()) {
|
| TextureDefinitionMap::iterator current_it = it;
|
| ++it;
|
| - if (current_it->second.owner == owner) {
|
| - GLuint service_id = current_it->second.definition->ReleaseServiceId();
|
| - if (have_context)
|
| - glDeleteTextures(1, &service_id);
|
| + if (current_it->second.definition == definition) {
|
| + DCHECK(!found);
|
| + textures_.erase(current_it);
|
| + found = true;
|
| + }
|
| + }
|
| + DCHECK(found);
|
| +}
|
| +
|
| +void MailboxManager::RemoveTexturesFromPool(TexturePoolId pool_id,
|
| + bool have_context) {
|
| + DCHECK(pool_id != TexturePoolNone);
|
| + TextureDefinitionMap::iterator it = textures_.begin();
|
| + while (it != textures_.end()) {
|
| + TextureDefinitionMap::iterator current_it = it;
|
| + ++it;
|
| + if (current_it->second.pool_id == pool_id) {
|
| + StopUsingSharedTexture(current_it->second.definition, have_context);
|
| textures_.erase(current_it);
|
| }
|
| }
|
| @@ -118,15 +142,5 @@ bool MailboxManager::TargetNameLess(const MailboxManager::TargetName& lhs,
|
| return memcmp(&lhs, &rhs, sizeof(lhs)) < 0;
|
| }
|
|
|
| -MailboxManager::OwnedTextureDefinition::OwnedTextureDefinition(
|
| - TextureDefinition* definition,
|
| - TextureManager* owner)
|
| - : definition(definition),
|
| - owner(owner) {
|
| -}
|
| -
|
| -MailboxManager::OwnedTextureDefinition::~OwnedTextureDefinition() {
|
| -}
|
| -
|
| } // namespace gles2
|
| } // namespace gpu
|
|
|