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.
5 #ifndef GPU_COMMAND_BUFFER_SERVICE_MAILBOX_MANAGER_H_
6 #define GPU_COMMAND_BUFFER_SERVICE_MAILBOX_MANAGER_H_
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"
18 #ifndef GL_MAILBOX_SIZE_CHROMIUM
19 #define GL_MAILBOX_SIZE_CHROMIUM 64
22 typedef signed char GLbyte
;
30 // Identifies a mailbox where a texture definition can be stored for
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.
33 struct GPU_EXPORT MailboxName
{
35 GLbyte key
[GL_MAILBOX_SIZE_CHROMIUM
/ 2];
36 GLbyte signature
[GL_MAILBOX_SIZE_CHROMIUM
/ 2];
39 // Manages resources scoped beyond the context or context group level.
40 class GPU_EXPORT MailboxManager
: public base::RefCounted
<MailboxManager
> {
44 // Generate a unique mailbox name signed with the manager's private key.
45 void GenerateMailboxName(MailboxName
* name
);
47 // Look up the texture definition from the named mailbox.
48 Texture
* ConsumeTexture(unsigned target
, const MailboxName
& name
);
50 // Put the texture into the named mailbox.
51 bool ProduceTexture(unsigned target
,
52 const MailboxName
& name
,
55 // Destroy any mailbox that reference the given texture.
56 void TextureDeleted(Texture
* texture
);
58 std::string
private_key() {
59 return std::string(private_key_
, sizeof(private_key_
));
63 friend class base::RefCounted
<MailboxManager
>;
67 void SignMailboxName(MailboxName
* name
);
68 bool IsMailboxNameValid(const MailboxName
& name
);
71 TargetName(unsigned target
, const MailboxName
& name
);
76 static bool TargetNameLess(const TargetName
& lhs
, const TargetName
& rhs
);
78 // This is a bidirectional map between mailbox and textures. We can have
79 // multiple mailboxes per texture, but one texture per mailbox. We keep an
80 // iterator in the MailboxToTextureMap to be able to manage changes to
81 // the TextureToMailboxMap efficiently.
82 typedef std::multimap
<Texture
*, TargetName
> TextureToMailboxMap
;
85 TextureToMailboxMap::iterator
,
86 std::pointer_to_binary_function
<
87 const TargetName
&, const TargetName
&, bool> > MailboxToTextureMap
;
89 char private_key_
[GL_MAILBOX_SIZE_CHROMIUM
/ 2];
91 MailboxToTextureMap mailbox_to_textures_
;
92 TextureToMailboxMap textures_to_mailboxes_
;
94 DISALLOW_COPY_AND_ASSIGN(MailboxManager
);
99 #endif // GPU_COMMAND_BUFFER_SERVICE_MAILBOX_MANAGER_H_