| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef GPU_COMMAND_BUFFER_SERVICE_MAILBOX_MANAGER_H_ | 5 #ifndef GPU_COMMAND_BUFFER_SERVICE_MAILBOX_MANAGER_H_ |
| 6 #define GPU_COMMAND_BUFFER_SERVICE_MAILBOX_MANAGER_H_ | 6 #define GPU_COMMAND_BUFFER_SERVICE_MAILBOX_MANAGER_H_ |
| 7 | 7 |
| 8 #include <functional> | 8 #include <functional> |
| 9 #include <map> | 9 #include <map> |
| 10 | 10 |
| 11 #include "base/memory/linked_ptr.h" | 11 #include "base/memory/linked_ptr.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "gpu/command_buffer/common/constants.h" | 13 #include "gpu/command_buffer/common/constants.h" |
| 14 #include "gpu/command_buffer/common/mailbox.h" | 14 #include "gpu/command_buffer/common/mailbox.h" |
| 15 #include "gpu/gpu_export.h" | 15 #include "gpu/gpu_export.h" |
| 16 | 16 |
| 17 typedef signed char GLbyte; | 17 typedef signed char GLbyte; |
| 18 | 18 |
| 19 namespace gpu { | 19 namespace gpu { |
| 20 namespace gles2 { | 20 namespace gles2 { |
| 21 | 21 |
| 22 class MailboxSynchronizer; |
| 22 class Texture; | 23 class Texture; |
| 23 class TextureManager; | 24 class TextureManager; |
| 24 | 25 |
| 25 // Manages resources scoped beyond the context or context group level. | 26 // Manages resources scoped beyond the context or context group level. |
| 26 class GPU_EXPORT MailboxManager : public base::RefCounted<MailboxManager> { | 27 class GPU_EXPORT MailboxManager : public base::RefCounted<MailboxManager> { |
| 27 public: | 28 public: |
| 28 MailboxManager(); | 29 MailboxManager(); |
| 29 | 30 |
| 30 // Look up the texture definition from the named mailbox. | 31 // Look up the texture definition from the named mailbox. |
| 31 Texture* ConsumeTexture(unsigned target, const Mailbox& mailbox); | 32 Texture* ConsumeTexture(unsigned target, const Mailbox& mailbox); |
| 32 | 33 |
| 33 // Put the texture into the named mailbox. | 34 // Put the texture into the named mailbox. |
| 34 void ProduceTexture(unsigned target, | 35 void ProduceTexture(unsigned target, |
| 35 const Mailbox& mailbox, | 36 const Mailbox& mailbox, |
| 36 Texture* texture); | 37 Texture* texture); |
| 37 | 38 |
| 39 // Returns whether this manager synchronizes with other instances. |
| 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 |
| 38 // Destroy any mailbox that reference the given texture. | 47 // Destroy any mailbox that reference the given texture. |
| 39 void TextureDeleted(Texture* texture); | 48 void TextureDeleted(Texture* texture); |
| 40 | 49 |
| 41 private: | 50 private: |
| 42 friend class base::RefCounted<MailboxManager>; | 51 friend class base::RefCounted<MailboxManager>; |
| 52 friend class MailboxSynchronizer; |
| 43 | 53 |
| 44 ~MailboxManager(); | 54 ~MailboxManager(); |
| 45 | 55 |
| 46 struct TargetName { | 56 struct TargetName { |
| 47 TargetName(unsigned target, const Mailbox& mailbox); | 57 TargetName(unsigned target, const Mailbox& mailbox); |
| 48 unsigned target; | 58 unsigned target; |
| 49 Mailbox mailbox; | 59 Mailbox mailbox; |
| 50 }; | 60 }; |
| 61 void InsertTexture(TargetName target_name, Texture* texture); |
| 51 | 62 |
| 52 static bool TargetNameLess(const TargetName& lhs, const TargetName& rhs); | 63 static bool TargetNameLess(const TargetName& lhs, const TargetName& rhs); |
| 53 | 64 |
| 54 // This is a bidirectional map between mailbox and textures. We can have | 65 // 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 | 66 // multiple mailboxes per texture, but one texture per mailbox. We keep an |
| 56 // iterator in the MailboxToTextureMap to be able to manage changes to | 67 // iterator in the MailboxToTextureMap to be able to manage changes to |
| 57 // the TextureToMailboxMap efficiently. | 68 // the TextureToMailboxMap efficiently. |
| 58 typedef std::multimap<Texture*, TargetName> TextureToMailboxMap; | 69 typedef std::multimap<Texture*, TargetName> TextureToMailboxMap; |
| 59 typedef std::map<TargetName, | 70 typedef std::map<TargetName, |
| 60 TextureToMailboxMap::iterator, | 71 TextureToMailboxMap::iterator, |
| 61 std::pointer_to_binary_function<const TargetName&, | 72 std::pointer_to_binary_function<const TargetName&, |
| 62 const TargetName&, | 73 const TargetName&, |
| 63 bool> > MailboxToTextureMap; | 74 bool> > MailboxToTextureMap; |
| 64 | 75 |
| 65 MailboxToTextureMap mailbox_to_textures_; | 76 MailboxToTextureMap mailbox_to_textures_; |
| 66 TextureToMailboxMap textures_to_mailboxes_; | 77 TextureToMailboxMap textures_to_mailboxes_; |
| 67 | 78 |
| 79 MailboxSynchronizer* sync_; |
| 80 |
| 68 DISALLOW_COPY_AND_ASSIGN(MailboxManager); | 81 DISALLOW_COPY_AND_ASSIGN(MailboxManager); |
| 69 }; | 82 }; |
| 70 } // namespage gles2 | 83 } // namespage gles2 |
| 71 } // namespace gpu | 84 } // namespace gpu |
| 72 | 85 |
| 73 #endif // GPU_COMMAND_BUFFER_SERVICE_MAILBOX_MANAGER_H_ | 86 #endif // GPU_COMMAND_BUFFER_SERVICE_MAILBOX_MANAGER_H_ |
| 74 | 87 |
| OLD | NEW |