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"
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"
24 // A thread-safe proxy that can be used to emulate texture sharing across
26 class MailboxSynchronizer
{
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
);
43 MailboxSynchronizer();
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
);
63 explicit TextureGroup(const TextureDefinition
& definition
);
66 TextureDefinition definition
;
67 std::set
<TargetName
> mailboxes
;
69 DISALLOW_COPY_AND_ASSIGN(TextureGroup
);
72 struct TextureVersion
{
73 explicit TextureVersion(linked_ptr
<TextureGroup
> group
);
77 linked_ptr
<TextureGroup
> group
;
79 typedef std::map
<Texture
*, TextureVersion
> TextureMap
;
82 linked_ptr
<TextureGroup
> GetGroupForMailboxLocked(
83 const TargetName
& target_name
);
84 void ReassociateMailboxLocked(
85 const TargetName
& target_name
,
87 void UpdateTextureLocked(Texture
* texture
, TextureVersion
& texture_version
);
89 DISALLOW_COPY_AND_ASSIGN(MailboxSynchronizer
);
95 #endif // GPU_COMMAND_BUFFER_SERVICE_MAILBOX_SYNCHRONIZER_H_