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 "gpu/command_buffer/common/constants.h"
14 #include "gpu/command_buffer/common/mailbox.h"
15 #include "gpu/gpu_export.h"
17 typedef signed char GLbyte
;
22 class MailboxSynchronizer
;
26 // Manages resources scoped beyond the context or context group level.
27 class GPU_EXPORT MailboxManager
: public base::RefCounted
<MailboxManager
> {
31 // Look up the texture definition from the named mailbox.
32 Texture
* ConsumeTexture(unsigned target
, const Mailbox
& mailbox
);
34 // Put the texture into the named mailbox.
35 void ProduceTexture(unsigned target
,
36 const Mailbox
& mailbox
,
39 // Returns whether this manager synchronizes with other instances.
40 bool UsesSync() { return sync_
!= NULL
; }
42 // Used with the MailboxSynchronizer to push/pull texture state to/from
43 // other manager instances.
44 void PushTextureUpdates();
45 void PullTextureUpdates();
47 // Destroy any mailbox that reference the given texture.
48 void TextureDeleted(Texture
* texture
);
51 friend class base::RefCounted
<MailboxManager
>;
52 friend class MailboxSynchronizer
;
57 TargetName(unsigned target
, const Mailbox
& mailbox
);
61 void InsertTexture(TargetName target_name
, Texture
* texture
);
63 static bool TargetNameLess(const TargetName
& lhs
, const TargetName
& rhs
);
65 // This is a bidirectional map between mailbox and textures. We can have
66 // multiple mailboxes per texture, but one texture per mailbox. We keep an
67 // iterator in the MailboxToTextureMap to be able to manage changes to
68 // the TextureToMailboxMap efficiently.
69 typedef std::multimap
<Texture
*, TargetName
> TextureToMailboxMap
;
70 typedef std::map
<TargetName
,
71 TextureToMailboxMap::iterator
,
72 std::pointer_to_binary_function
<const TargetName
&,
74 bool> > MailboxToTextureMap
;
76 MailboxToTextureMap mailbox_to_textures_
;
77 TextureToMailboxMap textures_to_mailboxes_
;
79 MailboxSynchronizer
* sync_
;
81 DISALLOW_COPY_AND_ASSIGN(MailboxManager
);
86 #endif // GPU_COMMAND_BUFFER_SERVICE_MAILBOX_MANAGER_H_