blob: 9bf242e1d7c897e44b4c0f904d0ec54b29cf87cc [file] [log] [blame]
James Robinson646469d2014-10-03 15:33:28 -07001// 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"
James Robinson646469d2014-10-03 15:33:28 -07009
10namespace cc {
11
Etienne Membrivesb1556b32014-12-16 13:56:09 +010012TextureMailbox::TextureMailbox() : shared_bitmap_(NULL) {
13}
James Robinson646469d2014-10-03 15:33:28 -070014
15TextureMailbox::TextureMailbox(const gpu::MailboxHolder& mailbox_holder)
16 : mailbox_holder_(mailbox_holder),
Etienne Membrivesb1556b32014-12-16 13:56:09 +010017 shared_bitmap_(NULL),
James Robinson1027bc12014-12-04 14:51:42 -080018 allow_overlay_(false),
Etienne Membrivesb1556b32014-12-16 13:56:09 +010019 nearest_neighbor_(false) {
20}
James Robinson646469d2014-10-03 15:33:28 -070021
22TextureMailbox::TextureMailbox(const gpu::Mailbox& mailbox,
23 uint32 target,
24 uint32 sync_point)
25 : mailbox_holder_(mailbox, target, sync_point),
Etienne Membrivesb1556b32014-12-16 13:56:09 +010026 shared_bitmap_(NULL),
James Robinson1027bc12014-12-04 14:51:42 -080027 allow_overlay_(false),
Etienne Membrivesb1556b32014-12-16 13:56:09 +010028 nearest_neighbor_(false) {
29}
James Robinson646469d2014-10-03 15:33:28 -070030
Etienne Membrivesb1556b32014-12-16 13:56:09 +010031TextureMailbox::TextureMailbox(SharedBitmap* shared_bitmap,
James Robinson646469d2014-10-03 15:33:28 -070032 const gfx::Size& size)
Etienne Membrivesb1556b32014-12-16 13:56:09 +010033 : shared_bitmap_(shared_bitmap),
James Robinson646469d2014-10-03 15:33:28 -070034 shared_memory_size_(size),
James Robinson1027bc12014-12-04 14:51:42 -080035 allow_overlay_(false),
36 nearest_neighbor_(false) {
James Robinson646469d2014-10-03 15:33:28 -070037 // If an embedder of cc gives an invalid TextureMailbox, we should crash
38 // here to identify the offender.
39 CHECK(SharedBitmap::VerifySizeInBytes(shared_memory_size_));
40}
41
42TextureMailbox::~TextureMailbox() {}
43
44bool TextureMailbox::Equals(const TextureMailbox& other) const {
45 if (other.IsTexture()) {
46 return IsTexture() && !memcmp(mailbox_holder_.mailbox.name,
47 other.mailbox_holder_.mailbox.name,
48 sizeof(mailbox_holder_.mailbox.name));
49 } else if (other.IsSharedMemory()) {
Etienne Membrivesb1556b32014-12-16 13:56:09 +010050 return IsSharedMemory() && (shared_bitmap_ == other.shared_bitmap_);
James Robinson646469d2014-10-03 15:33:28 -070051 }
52
53 DCHECK(!other.IsValid());
54 return !IsValid();
55}
56
57size_t TextureMailbox::SharedMemorySizeInBytes() const {
58 // UncheckedSizeInBytes is okay because we VerifySizeInBytes in the
59 // constructor and the field is immutable.
60 return SharedBitmap::UncheckedSizeInBytes(shared_memory_size_);
61}
62
63} // namespace cc