| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "gpu/command_buffer/service/mailbox_manager.h" | 5 #include "gpu/command_buffer/service/mailbox_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> | |
| 8 | |
| 9 #include "base/rand_util.h" | 7 #include "base/rand_util.h" |
| 10 #include "crypto/hmac.h" | 8 #include "crypto/hmac.h" |
| 11 #include "gpu/command_buffer/service/gl_utils.h" | 9 #include "gpu/command_buffer/service/gl_utils.h" |
| 12 #include "gpu/command_buffer/service/texture_definition.h" | 10 #include "gpu/command_buffer/service/texture_definition.h" |
| 13 | 11 |
| 14 namespace gpu { | 12 namespace gpu { |
| 15 namespace gles2 { | 13 namespace gles2 { |
| 16 | 14 |
| 17 MailboxName::MailboxName() { | |
| 18 std::fill(key, key + sizeof(key), 0); | |
| 19 std::fill(signature, signature + sizeof(signature), 0); | |
| 20 } | |
| 21 | |
| 22 MailboxManager::MailboxManager() | 15 MailboxManager::MailboxManager() |
| 23 : hmac_(crypto::HMAC::SHA256), | 16 : hmac_(crypto::HMAC::SHA256), |
| 24 textures_(std::ptr_fun(&MailboxManager::TargetNameLess)) { | 17 textures_(std::ptr_fun(&MailboxManager::TargetNameLess)) { |
| 25 base::RandBytes(private_key_, sizeof(private_key_)); | 18 base::RandBytes(private_key_, sizeof(private_key_)); |
| 26 bool success = hmac_.Init( | 19 bool success = hmac_.Init( |
| 27 base::StringPiece(private_key_, sizeof(private_key_))); | 20 base::StringPiece(private_key_, sizeof(private_key_))); |
| 28 DCHECK(success); | 21 DCHECK(success); |
| 29 DCHECK(!IsMailboxNameValid(MailboxName())); | |
| 30 } | 22 } |
| 31 | 23 |
| 32 MailboxManager::~MailboxManager() { | 24 MailboxManager::~MailboxManager() { |
| 33 DCHECK(!textures_.size()); | |
| 34 } | 25 } |
| 35 | 26 |
| 36 void MailboxManager::GenerateMailboxName(MailboxName* name) { | 27 void MailboxManager::GenerateMailboxName(MailboxName* name) { |
| 37 base::RandBytes(name->key, sizeof(name->key)); | 28 base::RandBytes(name->key, sizeof(name->key)); |
| 38 SignMailboxName(name); | 29 SignMailboxName(name); |
| 39 } | 30 } |
| 40 | 31 |
| 41 TextureDefinition* MailboxManager::ConsumeTexture(unsigned target, | 32 TextureDefinition* MailboxManager::ConsumeTexture(unsigned target, |
| 42 const MailboxName& name) { | 33 const MailboxName& name) { |
| 43 if (!IsMailboxNameValid(name)) | 34 if (!IsMailboxNameValid(name)) |
| 44 return NULL; | 35 return NULL; |
| 45 | 36 |
| 46 TextureDefinitionMap::iterator it = | 37 TextureDefinitionMap::iterator it = |
| 47 textures_.find(TargetName(target, name)); | 38 textures_.find(TargetName(target, name)); |
| 48 if (it == textures_.end()) | 39 if (it == textures_.end()) { |
| 40 NOTREACHED(); |
| 49 return NULL; | 41 return NULL; |
| 42 } |
| 50 | 43 |
| 51 TextureDefinition* definition = it->second.definition.release(); | 44 TextureDefinition* definition = it->second.definition.release(); |
| 52 textures_.erase(it); | 45 textures_.erase(it); |
| 53 | 46 |
| 54 return definition; | 47 return definition; |
| 55 } | 48 } |
| 56 | 49 |
| 57 bool MailboxManager::ProduceTexture(unsigned target, | 50 bool MailboxManager::ProduceTexture(unsigned target, |
| 58 const MailboxName& name, | 51 const MailboxName& name, |
| 59 TextureDefinition* definition, | 52 TextureDefinition* definition, |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 TextureManager* owner) | 116 TextureManager* owner) |
| 124 : definition(definition), | 117 : definition(definition), |
| 125 owner(owner) { | 118 owner(owner) { |
| 126 } | 119 } |
| 127 | 120 |
| 128 MailboxManager::OwnedTextureDefinition::~OwnedTextureDefinition() { | 121 MailboxManager::OwnedTextureDefinition::~OwnedTextureDefinition() { |
| 129 } | 122 } |
| 130 | 123 |
| 131 } // namespace gles2 | 124 } // namespace gles2 |
| 132 } // namespace gpu | 125 } // namespace gpu |
| OLD | NEW |