Home | History | Annotate | Download | only in service
      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 // From gl2/gl2ext.h.
     18 #ifndef GL_MAILBOX_SIZE_CHROMIUM
     19 #define GL_MAILBOX_SIZE_CHROMIUM 64
     20 #endif
     21 
     22 typedef signed char GLbyte;
     23 
     24 namespace gpu {
     25 namespace gles2 {
     26 
     27 class MailboxSynchronizer;
     28 class Texture;
     29 class TextureManager;
     30 
     31 // Manages resources scoped beyond the context or context group level.
     32 class GPU_EXPORT MailboxManager : public base::RefCounted<MailboxManager> {
     33  public:
     34   MailboxManager();
     35 
     36   // Generate a unique unguessable mailbox name.
     37   void GenerateMailbox(Mailbox* mailbox);
     38 
     39   // Look up the texture definition from the named mailbox.
     40   Texture* ConsumeTexture(unsigned target, const Mailbox& mailbox);
     41 
     42   // Put the texture into the named mailbox.
     43   void ProduceTexture(unsigned target,
     44                       const Mailbox& mailbox,
     45                       Texture* texture);
     46 
     47   // Returns whether this manager synchronizes with other instances.
     48   bool UsesSync() { return sync_ != NULL; }
     49 
     50   // Used with the MailboxSynchronizer to push/pull texture state to/from
     51   // other manager instances.
     52   void PushTextureUpdates();
     53   void PullTextureUpdates();
     54 
     55   // Destroy any mailbox that reference the given texture.
     56   void TextureDeleted(Texture* texture);
     57 
     58  private:
     59   friend class base::RefCounted<MailboxManager>;
     60   friend class MailboxSynchronizer;
     61 
     62   ~MailboxManager();
     63 
     64   struct TargetName {
     65     TargetName(unsigned target, const Mailbox& mailbox);
     66     unsigned target;
     67     Mailbox mailbox;
     68   };
     69   void InsertTexture(TargetName target_name, Texture* texture);
     70 
     71   static bool TargetNameLess(const TargetName& lhs, const TargetName& rhs);
     72 
     73   // This is a bidirectional map between mailbox and textures. We can have
     74   // multiple mailboxes per texture, but one texture per mailbox. We keep an
     75   // iterator in the MailboxToTextureMap to be able to manage changes to
     76   // the TextureToMailboxMap efficiently.
     77   typedef std::multimap<Texture*, TargetName> TextureToMailboxMap;
     78   typedef std::map<
     79       TargetName,
     80       TextureToMailboxMap::iterator,
     81       std::pointer_to_binary_function<
     82           const TargetName&, const TargetName&, bool> > MailboxToTextureMap;
     83 
     84   MailboxToTextureMap mailbox_to_textures_;
     85   TextureToMailboxMap textures_to_mailboxes_;
     86 
     87   MailboxSynchronizer* sync_;
     88 
     89   DISALLOW_COPY_AND_ASSIGN(MailboxManager);
     90 };
     91 }  // namespage gles2
     92 }  // namespace gpu
     93 
     94 #endif  // GPU_COMMAND_BUFFER_SERVICE_MAILBOX_MANAGER_H_
     95 
     96 
     97