Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / gpu / command_buffer / service / mailbox_manager.h
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 Texture;
23 class TextureManager;
24
25 // Manages resources scoped beyond the context or context group level.
26 class GPU_EXPORT MailboxManager : public base::RefCounted<MailboxManager> {
27  public:
28   MailboxManager();
29
30   // Look up the texture definition from the named mailbox.
31   Texture* ConsumeTexture(unsigned target, const Mailbox& mailbox);
32
33   // Put the texture into the named mailbox.
34   void ProduceTexture(unsigned target,
35                       const Mailbox& mailbox,
36                       Texture* texture);
37
38   // Destroy any mailbox that reference the given texture.
39   void TextureDeleted(Texture* texture);
40
41  private:
42   friend class base::RefCounted<MailboxManager>;
43
44   ~MailboxManager();
45
46   struct TargetName {
47     TargetName(unsigned target, const Mailbox& mailbox);
48     unsigned target;
49     Mailbox mailbox;
50   };
51
52   static bool TargetNameLess(const TargetName& lhs, const TargetName& rhs);
53
54   // This is a bidirectional map between mailbox and textures. We can have
55   // multiple mailboxes per texture, but one texture per mailbox. We keep an
56   // iterator in the MailboxToTextureMap to be able to manage changes to
57   // the TextureToMailboxMap efficiently.
58   typedef std::multimap<Texture*, TargetName> TextureToMailboxMap;
59   typedef std::map<TargetName,
60                    TextureToMailboxMap::iterator,
61                    std::pointer_to_binary_function<const TargetName&,
62                                                    const TargetName&,
63                                                    bool> > MailboxToTextureMap;
64
65   MailboxToTextureMap mailbox_to_textures_;
66   TextureToMailboxMap textures_to_mailboxes_;
67
68   DISALLOW_COPY_AND_ASSIGN(MailboxManager);
69 };
70 }  // namespage gles2
71 }  // namespace gpu
72
73 #endif  // GPU_COMMAND_BUFFER_SERVICE_MAILBOX_MANAGER_H_
74