Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / gpu / command_buffer / service / mailbox_manager.h
blobe1b36cb934e61b72af29a66c5e47fc5b53461343
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_
8 #include <functional>
9 #include <map>
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;
19 namespace gpu {
20 namespace gles2 {
22 class MailboxSynchronizer;
23 class Texture;
24 class TextureManager;
26 // Manages resources scoped beyond the context or context group level.
27 class GPU_EXPORT MailboxManager : public base::RefCounted<MailboxManager> {
28 public:
29 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,
37 Texture* texture);
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);
50 private:
51 friend class base::RefCounted<MailboxManager>;
52 friend class MailboxSynchronizer;
54 ~MailboxManager();
56 struct TargetName {
57 TargetName(unsigned target, const Mailbox& mailbox);
58 unsigned target;
59 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&,
73 const TargetName&,
74 bool> > MailboxToTextureMap;
76 MailboxToTextureMap mailbox_to_textures_;
77 TextureToMailboxMap textures_to_mailboxes_;
79 MailboxSynchronizer* sync_;
81 DISALLOW_COPY_AND_ASSIGN(MailboxManager);
83 } // namespage gles2
84 } // namespace gpu
86 #endif // GPU_COMMAND_BUFFER_SERVICE_MAILBOX_MANAGER_H_