• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "cc/resources/shared_bitmap.h"
9 #include "third_party/khronos/GLES2/gl2.h"
10 
11 namespace cc {
12 
TextureMailbox()13 TextureMailbox::TextureMailbox() : shared_memory_(NULL) {}
14 
TextureMailbox(const gpu::MailboxHolder & mailbox_holder)15 TextureMailbox::TextureMailbox(const gpu::MailboxHolder& mailbox_holder)
16     : mailbox_holder_(mailbox_holder),
17       shared_memory_(NULL),
18       allow_overlay_(false) {}
19 
TextureMailbox(const gpu::Mailbox & mailbox,uint32 target,uint32 sync_point)20 TextureMailbox::TextureMailbox(const gpu::Mailbox& mailbox,
21                                uint32 target,
22                                uint32 sync_point)
23     : mailbox_holder_(mailbox, target, sync_point),
24       shared_memory_(NULL),
25       allow_overlay_(false) {}
26 
TextureMailbox(base::SharedMemory * shared_memory,const gfx::Size & size)27 TextureMailbox::TextureMailbox(base::SharedMemory* shared_memory,
28                                const gfx::Size& size)
29     : shared_memory_(shared_memory),
30       shared_memory_size_(size),
31       allow_overlay_(false) {
32   // If an embedder of cc gives an invalid TextureMailbox, we should crash
33   // here to identify the offender.
34   CHECK(SharedBitmap::VerifySizeInBytes(shared_memory_size_));
35 }
36 
~TextureMailbox()37 TextureMailbox::~TextureMailbox() {}
38 
Equals(const TextureMailbox & other) const39 bool TextureMailbox::Equals(const TextureMailbox& other) const {
40   if (other.IsTexture()) {
41     return IsTexture() && !memcmp(mailbox_holder_.mailbox.name,
42                                   other.mailbox_holder_.mailbox.name,
43                                   sizeof(mailbox_holder_.mailbox.name));
44   } else if (other.IsSharedMemory()) {
45     return IsSharedMemory() &&
46            shared_memory_->handle() == other.shared_memory_->handle();
47   }
48 
49   DCHECK(!other.IsValid());
50   return !IsValid();
51 }
52 
SharedMemorySizeInBytes() const53 size_t TextureMailbox::SharedMemorySizeInBytes() const {
54   // UncheckedSizeInBytes is okay because we VerifySizeInBytes in the
55   // constructor and the field is immutable.
56   return SharedBitmap::UncheckedSizeInBytes(shared_memory_size_);
57 }
58 
59 }  // namespace cc
60