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