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 #ifndef GPU_COMMAND_BUFFER_SERVICE_MAILBOX_MANAGER_H_ |
| 6 #define GPU_COMMAND_BUFFER_SERVICE_MAILBOX_MANAGER_H_ |
| 7 |
| 8 #include <functional> |
| 9 #include <map> |
| 10 |
| 11 #include "base/memory/linked_ptr.h" |
| 12 #include "base/memory/ref_counted.h" |
| 13 #include "crypto/hmac.h" |
| 14 #include "gpu/command_buffer/common/constants.h" |
| 15 #include "gpu/gpu_export.h" |
| 16 |
| 17 #ifndef GL_MAILBOX_SIZE_CHROMIUM |
| 18 #define GL_MAILBOX_SIZE_CHROMIUM 64 |
| 19 #endif |
| 20 |
| 21 typedef signed char GLbyte; |
| 22 |
| 23 namespace gpu { |
| 24 namespace gles2 { |
| 25 |
| 26 class TextureDefinition; |
| 27 class TextureManager; |
| 28 |
| 29 // Identifies a mailbox where a texture definition can be stored for |
| 30 // transferring textures between contexts that are not in the same context |
| 31 // group. It is a random key signed with a hash of a private key. |
| 32 struct MailboxName { |
| 33 GLbyte key[GL_MAILBOX_SIZE_CHROMIUM / 2]; |
| 34 GLbyte signature[GL_MAILBOX_SIZE_CHROMIUM / 2]; |
| 35 }; |
| 36 |
| 37 // Manages resources scoped beyond the context or context group level. |
| 38 class GPU_EXPORT MailboxManager : public base::RefCounted<MailboxManager> { |
| 39 public: |
| 40 MailboxManager(); |
| 41 |
| 42 // Generate a unique mailbox name signed with the manager's private key. |
| 43 void GenerateMailboxName(MailboxName* name); |
| 44 |
| 45 // Remove the texture definition from the named mailbox and empty the mailbox. |
| 46 TextureDefinition* ConsumeTexture(unsigned target, const MailboxName& name); |
| 47 |
| 48 // Put the texture definition in the named mailbox. |
| 49 bool ProduceTexture(unsigned target, |
| 50 const MailboxName& name, |
| 51 TextureDefinition* definition, |
| 52 TextureManager* owner); |
| 53 |
| 54 // Destroy any texture definitions and mailboxes owned by the given texture |
| 55 // manager. |
| 56 void DestroyOwnedTextures(TextureManager* owner, bool have_context); |
| 57 |
| 58 private: |
| 59 friend class base::RefCounted<MailboxManager>; |
| 60 |
| 61 ~MailboxManager(); |
| 62 |
| 63 void SignMailboxName(MailboxName* name); |
| 64 bool IsMailboxNameValid(const MailboxName& name); |
| 65 |
| 66 struct TargetName { |
| 67 TargetName(unsigned target, const MailboxName& name); |
| 68 unsigned target; |
| 69 MailboxName name; |
| 70 }; |
| 71 |
| 72 static bool TargetNameLess(TargetName lhs, TargetName rhs); |
| 73 |
| 74 struct OwnedTextureDefinition { |
| 75 OwnedTextureDefinition(TextureDefinition* definition, |
| 76 TextureManager* owner); |
| 77 ~OwnedTextureDefinition(); |
| 78 linked_ptr<TextureDefinition> definition; |
| 79 TextureManager* owner; |
| 80 }; |
| 81 |
| 82 typedef std::map< |
| 83 TargetName, |
| 84 OwnedTextureDefinition, |
| 85 std::pointer_to_binary_function<TargetName, TargetName, bool> > |
| 86 TextureDefinitionMap; |
| 87 |
| 88 crypto::HMAC hmac_; |
| 89 TextureDefinitionMap textures_; |
| 90 |
| 91 DISALLOW_COPY_AND_ASSIGN(MailboxManager); |
| 92 }; |
| 93 } // namespage gles2 |
| 94 } // namespace gpu |
| 95 |
| 96 #endif // GPU_COMMAND_BUFFER_SERVICE_MAILBOX_MANAGER_H_ |
| 97 |
| 98 |
OLD | NEW |