Handle account removal correctly on all platforms.
[chromium-blink-merge.git] / gpu / command_buffer / service / mailbox_synchronizer.h
bloba845963bbbf74c67c6f2b0198c4c2ec7719e6981
1 // Copyright 2014 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_SYNCHRONIZER_H_
6 #define GPU_COMMAND_BUFFER_SERVICE_MAILBOX_SYNCHRONIZER_H_
8 #include "gpu/command_buffer/common/mailbox.h"
10 #include <map>
11 #include <set>
13 #include "base/memory/linked_ptr.h"
14 #include "base/synchronization/lock.h"
15 #include "gpu/command_buffer/service/texture_definition.h"
16 #include "gpu/gpu_export.h"
18 namespace gpu {
19 namespace gles2 {
21 class MailboxManager;
22 class Texture;
24 // A thread-safe proxy that can be used to emulate texture sharing across
25 // share-groups.
26 class MailboxSynchronizer {
27 public:
28 ~MailboxSynchronizer();
30 GPU_EXPORT static bool Initialize();
31 GPU_EXPORT static void Terminate();
32 static MailboxSynchronizer* GetInstance();
34 // Create a texture from a globally visible mailbox.
35 Texture* CreateTextureFromMailbox(unsigned target, const Mailbox& mailbox);
37 void PushTextureUpdates(MailboxManager* manager);
38 void PullTextureUpdates(MailboxManager* manager);
40 void TextureDeleted(Texture* texture);
42 private:
43 MailboxSynchronizer();
45 struct TargetName {
46 TargetName(unsigned target, const Mailbox& mailbox);
47 bool operator<(const TargetName& rhs) const {
48 return memcmp(this, &rhs, sizeof(rhs)) < 0;
50 bool operator!=(const TargetName& rhs) const {
51 return memcmp(this, &rhs, sizeof(rhs)) != 0;
53 bool operator==(const TargetName& rhs) const {
54 return !operator!=(rhs);
56 unsigned target;
57 Mailbox mailbox;
60 base::Lock lock_;
62 struct TextureGroup {
63 explicit TextureGroup(const TextureDefinition& definition);
64 ~TextureGroup();
66 TextureDefinition definition;
67 std::set<TargetName> mailboxes;
68 private:
69 DISALLOW_COPY_AND_ASSIGN(TextureGroup);
72 struct TextureVersion {
73 explicit TextureVersion(linked_ptr<TextureGroup> group);
74 ~TextureVersion();
76 unsigned int version;
77 linked_ptr<TextureGroup> group;
79 typedef std::map<Texture*, TextureVersion> TextureMap;
80 TextureMap textures_;
82 linked_ptr<TextureGroup> GetGroupForMailboxLocked(
83 const TargetName& target_name);
84 void ReassociateMailboxLocked(
85 const TargetName& target_name,
86 TextureGroup* group);
87 void UpdateTextureLocked(Texture* texture, TextureVersion& texture_version);
89 DISALLOW_COPY_AND_ASSIGN(MailboxSynchronizer);
92 } // namespage gles2
93 } // namespace gpu
95 #endif // GPU_COMMAND_BUFFER_SERVICE_MAILBOX_SYNCHRONIZER_H_