1// Copyright 2013 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 CC_RESOURCES_TEXTURE_MAILBOX_H_
6#define CC_RESOURCES_TEXTURE_MAILBOX_H_
7
8#include <string>
9
10#include "base/callback.h"
11#include "base/memory/shared_memory.h"
12#include "cc/base/cc_export.h"
13#include "gpu/command_buffer/common/mailbox.h"
14#include "ui/gfx/size.h"
15
16namespace cc {
17
18// TODO(skaslev, danakj) Rename this class more apropriately since now it
19// can hold a shared memory resource as well as a texture mailbox.
20class CC_EXPORT TextureMailbox {
21 public:
22  TextureMailbox();
23  explicit TextureMailbox(const std::string& mailbox_name);
24  explicit TextureMailbox(const gpu::Mailbox& mailbox_name);
25  TextureMailbox(const gpu::Mailbox& mailbox_name,
26                 unsigned sync_point);
27  TextureMailbox(const gpu::Mailbox& mailbox_name,
28                 unsigned texture_target,
29                 unsigned sync_point);
30  TextureMailbox(base::SharedMemory* shared_memory,
31                 gfx::Size size);
32
33  ~TextureMailbox();
34
35  bool IsValid() const { return IsTexture() || IsSharedMemory(); }
36  bool IsTexture() const { return !name_.IsZero(); }
37  bool IsSharedMemory() const { return shared_memory_ != NULL; }
38
39  bool Equals(const TextureMailbox&) const;
40  bool ContainsMailbox(const gpu::Mailbox&) const;
41  bool ContainsHandle(base::SharedMemoryHandle handle) const;
42
43  const int8* data() const { return name_.name; }
44  const gpu::Mailbox& name() const { return name_; }
45  void ResetSyncPoint() { sync_point_ = 0; }
46  unsigned target() const { return target_; }
47  unsigned sync_point() const { return sync_point_; }
48
49  base::SharedMemory* shared_memory() const { return shared_memory_; }
50  gfx::Size shared_memory_size() const { return shared_memory_size_; }
51  size_t shared_memory_size_in_bytes() const;
52
53  // TODO(danakj): ReleaseCallback should be separate from this class, and stop
54  // storing a TextureMailbox in ResourceProvider. Then we can remove this.
55  void SetName(const gpu::Mailbox& name);
56
57 private:
58  gpu::Mailbox name_;
59  unsigned target_;
60  unsigned sync_point_;
61  base::SharedMemory* shared_memory_;
62  gfx::Size shared_memory_size_;
63};
64
65}  // namespace cc
66
67#endif  // CC_RESOURCES_TEXTURE_MAILBOX_H_
68