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

Side by Side Diff: gpu/command_buffer/service/mailbox_manager.cc

Issue 12717013: Add reference-counting for mailbox textures. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 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 | Annotate | Revision Log
OLDNEW
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> 7 #include <algorithm>
8 8
9 #include "base/bind.h"
9 #include "base/rand_util.h" 10 #include "base/rand_util.h"
10 #include "crypto/hmac.h" 11 #include "crypto/hmac.h"
11 #include "gpu/command_buffer/service/gl_utils.h"
12 #include "gpu/command_buffer/service/texture_definition.h" 12 #include "gpu/command_buffer/service/texture_definition.h"
13 13
14 namespace gpu { 14 namespace gpu {
15 namespace gles2 { 15 namespace gles2 {
16 16
17 MailboxName::MailboxName() { 17 MailboxName::MailboxName() {
18 std::fill(key, key + sizeof(key), 0); 18 std::fill(key, key + sizeof(key), 0);
19 std::fill(signature, signature + sizeof(signature), 0); 19 std::fill(signature, signature + sizeof(signature), 0);
20 } 20 }
21 21
(...skipping 19 matching lines...) Expand all
41 TextureDefinition* MailboxManager::ConsumeTexture(unsigned target, 41 TextureDefinition* MailboxManager::ConsumeTexture(unsigned target,
42 const MailboxName& name) { 42 const MailboxName& name) {
43 if (!IsMailboxNameValid(name)) 43 if (!IsMailboxNameValid(name))
44 return NULL; 44 return NULL;
45 45
46 TextureDefinitionMap::iterator it = 46 TextureDefinitionMap::iterator it =
47 textures_.find(TargetName(target, name)); 47 textures_.find(TargetName(target, name));
48 if (it == textures_.end()) 48 if (it == textures_.end())
49 return NULL; 49 return NULL;
50 50
51 TextureDefinition* definition = it->second.definition.release(); 51 TextureDefinition* definition = it->second;
52 textures_.erase(it); 52 textures_.erase(it);
53 53
54 TextureDefinition::DestroyCallback cb;
55 definition->SetDestroyCallback(cb);
54 return definition; 56 return definition;
55 } 57 }
56 58
57 bool MailboxManager::ProduceTexture(unsigned target, 59 bool MailboxManager::ProduceTexture(unsigned target,
58 const MailboxName& name, 60 const MailboxName& name,
59 TextureDefinition* definition, 61 TextureDefinition* definition) {
60 TextureManager* owner) {
61 if (!IsMailboxNameValid(name)) 62 if (!IsMailboxNameValid(name))
62 return false; 63 return false;
63 64
64 TextureDefinitionMap::iterator it = 65 TextureDefinitionMap::iterator it =
65 textures_.find(TargetName(target, name)); 66 textures_.find(TargetName(target, name));
66 if (it != textures_.end()) { 67 if (it != textures_.end()) {
67 NOTREACHED(); 68 NOTREACHED();
68 GLuint service_id = it->second.definition->ReleaseServiceId(); 69 it->second = definition;
69 glDeleteTextures(1, &service_id);
70 it->second = OwnedTextureDefinition(definition, owner);
71 } else { 70 } else {
72 textures_.insert(std::make_pair( 71 textures_.insert(std::make_pair(TargetName(target, name), definition));
73 TargetName(target, name),
74 OwnedTextureDefinition(definition, owner)));
75 } 72 }
76 73
74 definition->SetDestroyCallback(base::Bind(
75 &MailboxManager::OnDestroyTexture, this));
77 return true; 76 return true;
78 } 77 }
79 78
80 void MailboxManager::DestroyOwnedTextures(TextureManager* owner, 79 void MailboxManager::OnDestroyTexture(TextureDefinition* definition) {
81 bool have_context) {
82 TextureDefinitionMap::iterator it = textures_.begin(); 80 TextureDefinitionMap::iterator it = textures_.begin();
83 while (it != textures_.end()) { 81 while (it != textures_.end()) {
84 TextureDefinitionMap::iterator current_it = it; 82 TextureDefinitionMap::iterator current_it = it;
85 ++it; 83 ++it;
86 if (current_it->second.owner == owner) { 84 if (current_it->second == definition)
87 GLuint service_id = current_it->second.definition->ReleaseServiceId();
88 if (have_context)
89 glDeleteTextures(1, &service_id);
90 textures_.erase(current_it); 85 textures_.erase(current_it);
91 }
92 } 86 }
93 } 87 }
94 88
95 void MailboxManager::SignMailboxName(MailboxName* name) { 89 void MailboxManager::SignMailboxName(MailboxName* name) {
96 bool success = hmac_.Sign( 90 bool success = hmac_.Sign(
97 base::StringPiece(reinterpret_cast<char*>(name->key), sizeof(name->key)), 91 base::StringPiece(reinterpret_cast<char*>(name->key), sizeof(name->key)),
98 reinterpret_cast<unsigned char*>(name->signature), 92 reinterpret_cast<unsigned char*>(name->signature),
99 sizeof(name->signature)); 93 sizeof(name->signature));
100 DCHECK(success); 94 DCHECK(success);
101 } 95 }
102 96
103 bool MailboxManager::IsMailboxNameValid(const MailboxName& name) { 97 bool MailboxManager::IsMailboxNameValid(const MailboxName& name) {
104 return hmac_.Verify( 98 return hmac_.Verify(
105 base::StringPiece(reinterpret_cast<const char*>(name.key), 99 base::StringPiece(reinterpret_cast<const char*>(name.key),
106 sizeof(name.key)), 100 sizeof(name.key)),
107 base::StringPiece(reinterpret_cast<const char*>(name.signature), 101 base::StringPiece(reinterpret_cast<const char*>(name.signature),
108 sizeof(name.signature))); 102 sizeof(name.signature)));
109 } 103 }
110 104
111 MailboxManager::TargetName::TargetName(unsigned target, const MailboxName& name) 105 MailboxManager::TargetName::TargetName(unsigned target, const MailboxName& name)
112 : target(target), 106 : target(target),
113 name(name) { 107 name(name) {
114 } 108 }
115 109
116 bool MailboxManager::TargetNameLess(const MailboxManager::TargetName& lhs, 110 bool MailboxManager::TargetNameLess(const MailboxManager::TargetName& lhs,
117 const MailboxManager::TargetName& rhs) { 111 const MailboxManager::TargetName& rhs) {
118 return memcmp(&lhs, &rhs, sizeof(lhs)) < 0; 112 return memcmp(&lhs, &rhs, sizeof(lhs)) < 0;
119 } 113 }
120 114
121 MailboxManager::OwnedTextureDefinition::OwnedTextureDefinition(
122 TextureDefinition* definition,
123 TextureManager* owner)
124 : definition(definition),
125 owner(owner) {
126 }
127
128 MailboxManager::OwnedTextureDefinition::~OwnedTextureDefinition() {
129 }
130
131 } // namespace gles2 115 } // namespace gles2
132 } // namespace gpu 116 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698