summaryrefslogtreecommitdiffstats
path: root/cc/resources/texture_mailbox.h
blob: 4626dd366988b36095b4d9f09394eb2b84748844 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CC_RESOURCES_TEXTURE_MAILBOX_H_
#define CC_RESOURCES_TEXTURE_MAILBOX_H_

#include <string>

#include "base/callback.h"
#include "base/memory/shared_memory.h"
#include "cc/base/cc_export.h"
#include "gpu/command_buffer/common/mailbox_holder.h"
#include "ui/gfx/size.h"

namespace cc {

// TODO(skaslev, danakj) Rename this class more apropriately since now it
// can hold a shared memory resource as well as a texture mailbox.
class CC_EXPORT TextureMailbox {
 public:
  TextureMailbox();
  explicit TextureMailbox(const gpu::MailboxHolder& mailbox_holder);
  TextureMailbox(const gpu::Mailbox& mailbox, uint32 target, uint32 sync_point);
  TextureMailbox(base::SharedMemory* shared_memory, const gfx::Size& size);

  ~TextureMailbox();

  bool IsValid() const { return IsTexture() || IsSharedMemory(); }
  bool IsTexture() const { return !mailbox_holder_.mailbox.IsZero(); }
  bool IsSharedMemory() const { return shared_memory_ != NULL; }

  bool Equals(const TextureMailbox&) const;

  const gpu::Mailbox& mailbox() const { return mailbox_holder_.mailbox; }
  const int8* name() const { return mailbox().name; }
  uint32 target() const { return mailbox_holder_.texture_target; }
  uint32 sync_point() const { return mailbox_holder_.sync_point; }
  void set_sync_point(int32 sync_point) {
    mailbox_holder_.sync_point = sync_point;
  }

  bool allow_overlay() const { return allow_overlay_; }
  void set_allow_overlay(bool allow_overlay) { allow_overlay_ = allow_overlay; }

  base::SharedMemory* shared_memory() const { return shared_memory_; }
  gfx::Size shared_memory_size() const { return shared_memory_size_; }
  size_t SharedMemorySizeInBytes() const;

 private:
  gpu::MailboxHolder mailbox_holder_;
  base::SharedMemory* shared_memory_;
  gfx::Size shared_memory_size_;
  bool allow_overlay_;
};

}  // namespace cc

#endif  // CC_RESOURCES_TEXTURE_MAILBOX_H_