Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(26)

Side by Side Diff: cc/resources/texture_mailbox.cc

Issue 221523003: cc: Remove all usage of GetArea() from production code in cc (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: getarea: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « cc/resources/texture_mailbox.h ('k') | content/browser/renderer_host/software_frame_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/resources/texture_mailbox.h" 5 #include "cc/resources/texture_mailbox.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "cc/resources/shared_bitmap.h"
8 #include "third_party/khronos/GLES2/gl2.h" 9 #include "third_party/khronos/GLES2/gl2.h"
9 10
10 namespace cc { 11 namespace cc {
11 12
12 TextureMailbox::TextureMailbox() : shared_memory_(NULL) {} 13 TextureMailbox::TextureMailbox() : shared_memory_(NULL) {}
13 14
14 TextureMailbox::TextureMailbox(const gpu::MailboxHolder& mailbox_holder) 15 TextureMailbox::TextureMailbox(const gpu::MailboxHolder& mailbox_holder)
15 : mailbox_holder_(mailbox_holder), 16 : mailbox_holder_(mailbox_holder),
16 shared_memory_(NULL), 17 shared_memory_(NULL),
17 allow_overlay_(false) {} 18 allow_overlay_(false) {}
18 19
19 TextureMailbox::TextureMailbox(const gpu::Mailbox& mailbox, 20 TextureMailbox::TextureMailbox(const gpu::Mailbox& mailbox,
20 uint32 target, 21 uint32 target,
21 uint32 sync_point) 22 uint32 sync_point)
22 : mailbox_holder_(mailbox, target, sync_point), 23 : mailbox_holder_(mailbox, target, sync_point),
23 shared_memory_(NULL), 24 shared_memory_(NULL),
24 allow_overlay_(false) {} 25 allow_overlay_(false) {}
25 26
26 TextureMailbox::TextureMailbox(base::SharedMemory* shared_memory, 27 TextureMailbox::TextureMailbox(base::SharedMemory* shared_memory,
27 const gfx::Size& size) 28 const gfx::Size& size)
28 : shared_memory_(shared_memory), 29 : shared_memory_(shared_memory),
29 shared_memory_size_(size), 30 shared_memory_size_(size),
30 allow_overlay_(false) { 31 allow_overlay_(false) {
31 // If an embedder of cc gives an invalid TextureMailbox, we should crash 32 // If an embedder of cc gives an invalid TextureMailbox, we should crash
32 // safely rather than overflow. 33 // here to identify the offender.
33 CHECK(CheckedSharedMemorySizeInBytes().IsValid()); 34 CHECK(SharedBitmap::VerifySizeInBytes(shared_memory_size_));
34 } 35 }
35 36
36 TextureMailbox::~TextureMailbox() {} 37 TextureMailbox::~TextureMailbox() {}
37 38
38 bool TextureMailbox::Equals(const TextureMailbox& other) const { 39 bool TextureMailbox::Equals(const TextureMailbox& other) const {
39 if (other.IsTexture()) { 40 if (other.IsTexture()) {
40 return IsTexture() && !memcmp(mailbox_holder_.mailbox.name, 41 return IsTexture() && !memcmp(mailbox_holder_.mailbox.name,
41 other.mailbox_holder_.mailbox.name, 42 other.mailbox_holder_.mailbox.name,
42 sizeof(mailbox_holder_.mailbox.name)); 43 sizeof(mailbox_holder_.mailbox.name));
43 } else if (other.IsSharedMemory()) { 44 } else if (other.IsSharedMemory()) {
44 return IsSharedMemory() && 45 return IsSharedMemory() &&
45 shared_memory_->handle() == other.shared_memory_->handle(); 46 shared_memory_->handle() == other.shared_memory_->handle();
46 } 47 }
47 48
48 DCHECK(!other.IsValid()); 49 DCHECK(!other.IsValid());
49 return !IsValid(); 50 return !IsValid();
50 } 51 }
51 52
52 size_t TextureMailbox::SharedMemorySizeInBytes() const { 53 size_t TextureMailbox::SharedMemorySizeInBytes() const {
53 size_t bytes_per_pixel = 4; 54 // UncheckedSizeInBytes is okay because we VerifySizeInBytes in the
54 size_t width = shared_memory_size_.width(); 55 // constructor and the field is immutable.
55 size_t height = shared_memory_size_.height(); 56 return SharedBitmap::UncheckedSizeInBytes(shared_memory_size_);
56 return bytes_per_pixel * width * height;
57 }
58
59 base::CheckedNumeric<size_t> TextureMailbox::CheckedSharedMemorySizeInBytes()
60 const {
61 return base::CheckedNumeric<size_t>(4) *
62 base::CheckedNumeric<size_t>(shared_memory_size_.width()) *
63 base::CheckedNumeric<size_t>(shared_memory_size_.height());
64 } 57 }
65 58
66 } // namespace cc 59 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resources/texture_mailbox.h ('k') | content/browser/renderer_host/software_frame_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698