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

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

Issue 14188053: gpu: Change Produce/ConsumeTexture to allow texture sharing (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 6 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 Texture;
28 class TextureManager; 28 class TextureManager;
29 29
30 // Identifies a mailbox where a texture definition can be stored for 30 // Identifies a mailbox where a texture definition can be stored for
31 // transferring textures between contexts that are not in the same context 31 // 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. 32 // group. It is a random key signed with a hash of a private key.
33 struct GPU_EXPORT MailboxName { 33 struct GPU_EXPORT MailboxName {
34 MailboxName(); 34 MailboxName();
35 GLbyte key[GL_MAILBOX_SIZE_CHROMIUM / 2]; 35 GLbyte key[GL_MAILBOX_SIZE_CHROMIUM / 2];
36 GLbyte signature[GL_MAILBOX_SIZE_CHROMIUM / 2]; 36 GLbyte signature[GL_MAILBOX_SIZE_CHROMIUM / 2];
37 }; 37 };
38 38
39 // Manages resources scoped beyond the context or context group level. 39 // Manages resources scoped beyond the context or context group level.
40 class GPU_EXPORT MailboxManager : public base::RefCounted<MailboxManager> { 40 class GPU_EXPORT MailboxManager : public base::RefCounted<MailboxManager> {
41 public: 41 public:
42 MailboxManager(); 42 MailboxManager();
43 43
44 // Generate a unique mailbox name signed with the manager's private key. 44 // Generate a unique mailbox name signed with the manager's private key.
45 void GenerateMailboxName(MailboxName* name); 45 void GenerateMailboxName(MailboxName* name);
46 46
47 // Remove the texture definition from the named mailbox and empty the mailbox. 47 // Look up the texture definition from the named mailbox.
48 TextureDefinition* ConsumeTexture(unsigned target, const MailboxName& name); 48 Texture* ConsumeTexture(unsigned target, const MailboxName& name);
49 49
50 // Put the texture definition in the named mailbox. 50 // Put the texture into the named mailbox.
51 bool ProduceTexture(unsigned target, 51 bool ProduceTexture(unsigned target,
52 const MailboxName& name, 52 const MailboxName& name,
53 TextureDefinition* definition, 53 Texture* texture);
54 TextureManager* owner);
55 54
56 // Destroy any texture definitions and mailboxes owned by the given texture 55 // Destroy any mailbox that reference the given texture.
57 // manager. 56 void TextureDeleted(Texture* texture);
58 void DestroyOwnedTextures(TextureManager* owner, bool have_context);
59 57
60 std::string private_key() { 58 std::string private_key() {
61 return std::string(private_key_, sizeof(private_key_)); 59 return std::string(private_key_, sizeof(private_key_));
62 } 60 }
63 61
64 private: 62 private:
65 friend class base::RefCounted<MailboxManager>; 63 friend class base::RefCounted<MailboxManager>;
66 64
67 ~MailboxManager(); 65 ~MailboxManager();
68 66
69 void SignMailboxName(MailboxName* name); 67 void SignMailboxName(MailboxName* name);
70 bool IsMailboxNameValid(const MailboxName& name); 68 bool IsMailboxNameValid(const MailboxName& name);
71 69
72 struct TargetName { 70 struct TargetName {
73 TargetName(unsigned target, const MailboxName& name); 71 TargetName(unsigned target, const MailboxName& name);
74 unsigned target; 72 unsigned target;
75 MailboxName name; 73 MailboxName name;
76 }; 74 };
77 75
78 static bool TargetNameLess(const TargetName& lhs, const TargetName& rhs); 76 static bool TargetNameLess(const TargetName& lhs, const TargetName& rhs);
79 77
80 struct OwnedTextureDefinition { 78 // This is a bidirectional map between mailbox and textures. We can have
81 OwnedTextureDefinition(TextureDefinition* definition, 79 // multiple mailboxes per texture, but one texture per mailbox. We keep an
82 TextureManager* owner); 80 // iterator in the MailboxToTextureMap to be able to manage changes to
83 ~OwnedTextureDefinition(); 81 // the TextureToMailboxMap efficiently.
84 linked_ptr<TextureDefinition> definition; 82 typedef std::multimap<Texture*, TargetName> TextureToMailboxMap;
85 TextureManager* owner;
86 };
87
88 typedef std::map< 83 typedef std::map<
89 TargetName, 84 TargetName,
90 OwnedTextureDefinition, 85 TextureToMailboxMap::iterator,
91 std::pointer_to_binary_function< 86 std::pointer_to_binary_function<
92 const TargetName&, const TargetName&, bool> > TextureDefinitionMap; 87 const TargetName&, const TargetName&, bool> > MailboxToTextureMap;
93 88
94 char private_key_[GL_MAILBOX_SIZE_CHROMIUM / 2]; 89 char private_key_[GL_MAILBOX_SIZE_CHROMIUM / 2];
95 crypto::HMAC hmac_; 90 crypto::HMAC hmac_;
96 TextureDefinitionMap textures_; 91 MailboxToTextureMap mailbox_to_textures_;
92 TextureToMailboxMap textures_to_mailboxes_;
97 93
98 DISALLOW_COPY_AND_ASSIGN(MailboxManager); 94 DISALLOW_COPY_AND_ASSIGN(MailboxManager);
99 }; 95 };
100 } // namespage gles2 96 } // namespage gles2
101 } // namespace gpu 97 } // namespace gpu
102 98
103 #endif // GPU_COMMAND_BUFFER_SERVICE_MAILBOX_MANAGER_H_ 99 #endif // GPU_COMMAND_BUFFER_SERVICE_MAILBOX_MANAGER_H_
104 100
105 101
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.cc ('k') | gpu/command_buffer/service/mailbox_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698