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

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: add optional 'pool' reference while textures are in mailbox Created 7 years, 8 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 <algorithm>
8 #include <functional> 9 #include <functional>
9 #include <map> 10 #include <map>
10 11
11 #include "base/memory/linked_ptr.h" 12 #include "base/memory/linked_ptr.h"
12 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
13 #include "crypto/hmac.h" 14 #include "crypto/hmac.h"
14 #include "gpu/command_buffer/common/constants.h" 15 #include "gpu/command_buffer/common/constants.h"
16 #include "gpu/command_buffer/service/texture_definition.h"
15 #include "gpu/gpu_export.h" 17 #include "gpu/gpu_export.h"
16 18
17 // From gl2/gl2ext.h. 19 // From gl2/gl2ext.h.
18 #ifndef GL_MAILBOX_SIZE_CHROMIUM 20 #ifndef GL_MAILBOX_SIZE_CHROMIUM
19 #define GL_MAILBOX_SIZE_CHROMIUM 64 21 #define GL_MAILBOX_SIZE_CHROMIUM 64
20 #endif 22 #endif
21 23
22 typedef signed char GLbyte; 24 typedef signed char GLbyte;
23 25
24 namespace gpu { 26 namespace gpu {
25 namespace gles2 { 27 namespace gles2 {
26 28
27 class TextureDefinition;
28 class TextureManager;
29
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>,
40 public TextureDefinition::Observer,
41 private TextureDefinition::Client {
41 public: 42 public:
42 MailboxManager(); 43 MailboxManager();
43 44
44 // Generate a unique mailbox name signed with the manager's private key. 45 // Generate a unique mailbox name signed with the manager's private key.
45 void GenerateMailboxName(MailboxName* name); 46 void GenerateMailboxName(MailboxName* name);
46 47
47 // Remove the texture definition from the named mailbox and empty the mailbox. 48 // Remove the texture definition from the named mailbox and empty the mailbox.
48 TextureDefinition* ConsumeTexture(unsigned target, const MailboxName& name); 49 TextureDefinition* ConsumeTexture(unsigned target, const MailboxName& name);
49 50
51 enum TexturePoolType {
52 TEXTURE_POOL_NONE,
53 TEXTURE_POOL_FOR_SURFACE,
54 };
55
56 typedef std::pair<TexturePoolType, int> TexturePoolId;
57 static const TexturePoolId TexturePoolNone;
58
50 // Put the texture definition in the named mailbox. 59 // Put the texture definition in the named mailbox.
51 bool ProduceTexture(unsigned target, 60 bool ProduceTexture(unsigned target,
52 const MailboxName& name, 61 const MailboxName& name,
53 TextureDefinition* definition, 62 TextureDefinition* definition,
54 TextureManager* owner); 63 TexturePoolId pool);
55
56 // Destroy any texture definitions and mailboxes owned by the given texture
57 // manager.
58 void DestroyOwnedTextures(TextureManager* owner, bool have_context);
59 64
60 std::string private_key() { 65 std::string private_key() {
61 return std::string(private_key_, sizeof(private_key_)); 66 return std::string(private_key_, sizeof(private_key_));
62 } 67 }
63 68
69 // TextureDefinition::Observer implementation
70 virtual void OnDestroySharedTexture(const TextureDefinition* definition)
71 OVERRIDE;
72
73 void RemoveTexturesFromPool(TexturePoolId pool_id, bool have_context);
74
64 private: 75 private:
65 friend class base::RefCounted<MailboxManager>; 76 friend class base::RefCounted<MailboxManager>;
66 77
67 ~MailboxManager(); 78 ~MailboxManager();
68 79
69 void SignMailboxName(MailboxName* name); 80 void SignMailboxName(MailboxName* name);
70 bool IsMailboxNameValid(const MailboxName& name); 81 bool IsMailboxNameValid(const MailboxName& name);
71 82
72 struct TargetName { 83 struct TargetName {
73 TargetName(unsigned target, const MailboxName& name); 84 TargetName(unsigned target, const MailboxName& name);
74 unsigned target; 85 unsigned target;
75 MailboxName name; 86 MailboxName name;
76 }; 87 };
77 88
78 static bool TargetNameLess(const TargetName& lhs, const TargetName& rhs); 89 static bool TargetNameLess(const TargetName& lhs, const TargetName& rhs);
79 90
80 struct OwnedTextureDefinition { 91 struct MailboxTexture {
81 OwnedTextureDefinition(TextureDefinition* definition, 92 MailboxTexture(TextureDefinition* definition, TexturePoolId pool_id)
82 TextureManager* owner); 93 : definition(definition), pool_id(pool_id) {}
83 ~OwnedTextureDefinition(); 94 TextureDefinition* definition;
84 linked_ptr<TextureDefinition> definition; 95 TexturePoolId pool_id;
85 TextureManager* owner;
86 }; 96 };
87 97
88 typedef std::map< 98 typedef std::map<
89 TargetName, 99 TargetName,
90 OwnedTextureDefinition, 100 MailboxTexture,
91 std::pointer_to_binary_function< 101 std::pointer_to_binary_function<
92 const TargetName&, const TargetName&, bool> > TextureDefinitionMap; 102 const TargetName&, const TargetName&, bool> > TextureDefinitionMap;
93 103
94 char private_key_[GL_MAILBOX_SIZE_CHROMIUM / 2]; 104 char private_key_[GL_MAILBOX_SIZE_CHROMIUM / 2];
95 crypto::HMAC hmac_; 105 crypto::HMAC hmac_;
96 TextureDefinitionMap textures_; 106 TextureDefinitionMap textures_;
97 107
98 DISALLOW_COPY_AND_ASSIGN(MailboxManager); 108 DISALLOW_COPY_AND_ASSIGN(MailboxManager);
99 }; 109 };
100 } // namespage gles2 110 } // namespage gles2
101 } // namespace gpu 111 } // namespace gpu
102 112
103 #endif // GPU_COMMAND_BUFFER_SERVICE_MAILBOX_MANAGER_H_ 113 #endif // GPU_COMMAND_BUFFER_SERVICE_MAILBOX_MANAGER_H_
104 114
105 115
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/gles2_cmd_decoder_unittest.cc ('k') | gpu/command_buffer/service/mailbox_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698