Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / cc / resources / texture_mailbox.cc
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 #include "cc/resources/texture_mailbox.h"
6
7 #include "base/logging.h"
8 #include "third_party/khronos/GLES2/gl2.h"
9
10 namespace cc {
11
12 TextureMailbox::TextureMailbox() : shared_memory_(NULL) {}
13
14 TextureMailbox::TextureMailbox(const gpu::MailboxHolder& mailbox_holder)
15     : mailbox_holder_(mailbox_holder), shared_memory_(NULL) {}
16
17 TextureMailbox::TextureMailbox(const gpu::Mailbox& mailbox,
18                                uint32 target,
19                                uint32 sync_point)
20     : mailbox_holder_(mailbox, target, sync_point), shared_memory_(NULL) {}
21
22 TextureMailbox::TextureMailbox(base::SharedMemory* shared_memory,
23                                const gfx::Size& size)
24     : shared_memory_(shared_memory), shared_memory_size_(size) {}
25
26 TextureMailbox::~TextureMailbox() {}
27
28 bool TextureMailbox::Equals(const TextureMailbox& other) const {
29   if (other.IsTexture()) {
30     return IsTexture() && !memcmp(mailbox_holder_.mailbox.name,
31                                   other.mailbox_holder_.mailbox.name,
32                                   sizeof(mailbox_holder_.mailbox.name));
33   } else if (other.IsSharedMemory()) {
34     return IsSharedMemory() &&
35            shared_memory_->handle() == other.shared_memory_->handle();
36   }
37
38   DCHECK(!other.IsValid());
39   return !IsValid();
40 }
41
42 size_t TextureMailbox::shared_memory_size_in_bytes() const {
43   return 4 * shared_memory_size_.GetArea();
44 }
45
46 }  // namespace cc