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

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

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

Powered by Google App Engine
This is Rietveld 408576698