OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "gpu/command_buffer/service/gl_utils.h" |
| 6 #include "gpu/command_buffer/service/mailbox_manager.h" |
| 7 #include "gpu/command_buffer/service/texture_definition.h" |
| 8 |
| 9 namespace gpu { |
| 10 namespace gles2 { |
| 11 |
| 12 MailboxManager::MailboxManager() { |
| 13 } |
| 14 |
| 15 MailboxManager::~MailboxManager() { |
| 16 } |
| 17 |
| 18 TextureDefinition* MailboxManager::ConsumeTexture(unsigned target, |
| 19 const MailboxName& name) { |
| 20 TextureDefinitionMap::iterator it = |
| 21 textures_.find(TargetName(target, name)); |
| 22 if (it == textures_.end()) { |
| 23 NOTREACHED(); |
| 24 return NULL; |
| 25 } |
| 26 |
| 27 TextureDefinition* definition = it->second.definition.release(); |
| 28 textures_.erase(it); |
| 29 |
| 30 return definition; |
| 31 } |
| 32 |
| 33 void MailboxManager::ProduceTexture(unsigned target, |
| 34 const MailboxName& name, |
| 35 TextureDefinition* definition, |
| 36 TextureManager* owner) { |
| 37 TextureDefinitionMap::iterator it = |
| 38 textures_.find(TargetName(target, name)); |
| 39 if (it != textures_.end()) { |
| 40 NOTREACHED(); |
| 41 GLuint service_id = it->second.definition->ReleaseServiceId(); |
| 42 glDeleteTextures(1, &service_id); |
| 43 it->second = OwnedTextureDefinition(definition, owner); |
| 44 } else { |
| 45 textures_.insert(std::make_pair( |
| 46 TargetName(target, name), |
| 47 OwnedTextureDefinition(definition, owner))); |
| 48 } |
| 49 } |
| 50 |
| 51 void MailboxManager::DestroyOwnedTextures(TextureManager* owner, |
| 52 bool have_context) { |
| 53 TextureDefinitionMap::iterator it = textures_.begin(); |
| 54 while (it != textures_.end()) { |
| 55 if (it->second.owner == owner) { |
| 56 NOTREACHED(); |
| 57 GLuint service_id = it->second.definition->ReleaseServiceId(); |
| 58 if (have_context) |
| 59 glDeleteTextures(1, &service_id); |
| 60 it = textures_.erase(it); |
| 61 } else { |
| 62 ++it; |
| 63 } |
| 64 } |
| 65 } |
| 66 |
| 67 MailboxManager::TargetName::TargetName(unsigned target, const MailboxName& name) |
| 68 : target(target), |
| 69 name(name) { |
| 70 } |
| 71 |
| 72 size_t MailboxManager::TargetNameCompare::operator() ( |
| 73 const TargetName& value) const { |
| 74 size_t hash = value.target; |
| 75 for (int i = 0; i < arraysize(value.name.components); ++i) |
| 76 hash ^= value.name.components[i]; |
| 77 return hash; |
| 78 } |
| 79 |
| 80 int MailboxManager::TargetNameCompare::operator() ( |
| 81 const TargetName& lhs, |
| 82 const TargetName& rhs) const { |
| 83 return memcmp(&lhs, &rhs, sizeof(lhs)); |
| 84 } |
| 85 |
| 86 MailboxManager::OwnedTextureDefinition::OwnedTextureDefinition( |
| 87 TextureDefinition* definition, |
| 88 TextureManager* owner) |
| 89 : definition(definition), |
| 90 owner(owner) { |
| 91 } |
| 92 |
| 93 } // namespace gles2 |
| 94 } // namespace gpu |
OLD | NEW |