• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #ifndef GPU_COMMAND_BUFFER_SERVICE_MAILBOX_MANAGER_H_
6 #define GPU_COMMAND_BUFFER_SERVICE_MAILBOX_MANAGER_H_
7 
8 #include <functional>
9 #include <map>
10 
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"
16 
17 typedef signed char GLbyte;
18 
19 namespace gpu {
20 namespace gles2 {
21 
22 class MailboxSynchronizer;
23 class Texture;
24 class TextureManager;
25 
26 // Manages resources scoped beyond the context or context group level.
27 class GPU_EXPORT MailboxManager : public base::RefCounted<MailboxManager> {
28  public:
29   MailboxManager();
30 
31   // Look up the texture definition from the named mailbox.
32   Texture* ConsumeTexture(unsigned target, const Mailbox& mailbox);
33 
34   // Put the texture into the named mailbox.
35   void ProduceTexture(unsigned target,
36                       const Mailbox& mailbox,
37                       Texture* texture);
38 
39   // Returns whether this manager synchronizes with other instances.
UsesSync()40   bool UsesSync() { return sync_ != NULL; }
41 
42   // Used with the MailboxSynchronizer to push/pull texture state to/from
43   // other manager instances.
44   void PushTextureUpdates();
45   void PullTextureUpdates();
46 
47   // Destroy any mailbox that reference the given texture.
48   void TextureDeleted(Texture* texture);
49 
50  private:
51   friend class base::RefCounted<MailboxManager>;
52   friend class MailboxSynchronizer;
53 
54   ~MailboxManager();
55 
56   struct TargetName {
57     TargetName(unsigned target, const Mailbox& mailbox);
58     unsigned target;
59     Mailbox mailbox;
60   };
61   void InsertTexture(TargetName target_name, Texture* texture);
62 
63   static bool TargetNameLess(const TargetName& lhs, const TargetName& rhs);
64 
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;
75 
76   MailboxToTextureMap mailbox_to_textures_;
77   TextureToMailboxMap textures_to_mailboxes_;
78 
79   MailboxSynchronizer* sync_;
80 
81   DISALLOW_COPY_AND_ASSIGN(MailboxManager);
82 };
83 }  // namespage gles2
84 }  // namespace gpu
85 
86 #endif  // GPU_COMMAND_BUFFER_SERVICE_MAILBOX_MANAGER_H_
87 
88