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

Side by Side Diff: content/common/gpu/client/gpu_memory_buffer_impl_shared_memory.cc

Issue 806653006: Update GPU memory buffers to use StrideInBytes internally. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use StrideInBytes Created 6 years 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "content/common/gpu/client/gpu_memory_buffer_impl_shared_memory.h" 5 #include "content/common/gpu/client/gpu_memory_buffer_impl_shared_memory.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/numerics/safe_math.h" 8 #include "base/numerics/safe_math.h"
9 #include "ui/gl/gl_bindings.h" 9 #include "ui/gl/gl_bindings.h"
10 10
(...skipping 17 matching lines...) Expand all
28 28
29 GpuMemoryBufferImplSharedMemory::~GpuMemoryBufferImplSharedMemory() { 29 GpuMemoryBufferImplSharedMemory::~GpuMemoryBufferImplSharedMemory() {
30 } 30 }
31 31
32 // static 32 // static
33 scoped_ptr<GpuMemoryBufferImpl> GpuMemoryBufferImplSharedMemory::Create( 33 scoped_ptr<GpuMemoryBufferImpl> GpuMemoryBufferImplSharedMemory::Create(
34 gfx::GpuMemoryBufferId id, 34 gfx::GpuMemoryBufferId id,
35 const gfx::Size& size, 35 const gfx::Size& size,
36 Format format) { 36 Format format) {
37 scoped_ptr<base::SharedMemory> shared_memory(new base::SharedMemory()); 37 scoped_ptr<base::SharedMemory> shared_memory(new base::SharedMemory());
38 if (!shared_memory->CreateAnonymous(size.GetArea() * BytesPerPixel(format))) 38 if (!shared_memory->CreateAnonymous(
39 StrideInBytes(size.width(), format) * size.height()))
39 return scoped_ptr<GpuMemoryBufferImpl>(); 40 return scoped_ptr<GpuMemoryBufferImpl>();
40 41
41 return make_scoped_ptr(new GpuMemoryBufferImplSharedMemory( 42 return make_scoped_ptr(new GpuMemoryBufferImplSharedMemory(
42 id, size, format, base::Bind(&Noop), shared_memory.Pass())); 43 id, size, format, base::Bind(&Noop), shared_memory.Pass()));
43 } 44 }
44 45
45 // static 46 // static
46 gfx::GpuMemoryBufferHandle 47 gfx::GpuMemoryBufferHandle
47 GpuMemoryBufferImplSharedMemory::AllocateForChildProcess( 48 GpuMemoryBufferImplSharedMemory::AllocateForChildProcess(
48 gfx::GpuMemoryBufferId id, 49 gfx::GpuMemoryBufferId id,
49 const gfx::Size& size, 50 const gfx::Size& size,
50 Format format, 51 Format format,
51 base::ProcessHandle child_process) { 52 base::ProcessHandle child_process) {
52 base::CheckedNumeric<int> buffer_size = size.width(); 53 base::CheckedNumeric<int> buffer_size = StrideInBytes(size.width(), format);
reveman 2014/12/18 18:49:56 Can a malicious renderer make this overflow? ie. w
christiank 2015/01/12 10:35:22 Should be fixed now that StrideInBytes uses Checke
53 buffer_size *= size.height(); 54 buffer_size *= size.height();
54 buffer_size *= BytesPerPixel(format);
55 if (!buffer_size.IsValid()) 55 if (!buffer_size.IsValid())
56 return gfx::GpuMemoryBufferHandle(); 56 return gfx::GpuMemoryBufferHandle();
57 57
58 base::SharedMemory shared_memory; 58 base::SharedMemory shared_memory;
59 if (!shared_memory.CreateAnonymous(buffer_size.ValueOrDie())) 59 if (!shared_memory.CreateAnonymous(buffer_size.ValueOrDie()))
60 return gfx::GpuMemoryBufferHandle(); 60 return gfx::GpuMemoryBufferHandle();
61 61
62 gfx::GpuMemoryBufferHandle handle; 62 gfx::GpuMemoryBufferHandle handle;
63 handle.type = gfx::SHARED_MEMORY_BUFFER; 63 handle.type = gfx::SHARED_MEMORY_BUFFER;
64 handle.id = id; 64 handle.id = id;
(...skipping 29 matching lines...) Expand all
94 case RGBX_8888: 94 case RGBX_8888:
95 return false; 95 return false;
96 } 96 }
97 97
98 NOTREACHED(); 98 NOTREACHED();
99 return false; 99 return false;
100 } 100 }
101 101
102 void* GpuMemoryBufferImplSharedMemory::Map() { 102 void* GpuMemoryBufferImplSharedMemory::Map() {
103 DCHECK(!mapped_); 103 DCHECK(!mapped_);
104 if (!shared_memory_->Map(size_.GetArea() * BytesPerPixel(format_))) 104 if (!shared_memory_->Map(
105 StrideInBytes(size_.width(), format_) * size_.height()))
105 return NULL; 106 return NULL;
106 mapped_ = true; 107 mapped_ = true;
107 return shared_memory_->memory(); 108 return shared_memory_->memory();
108 } 109 }
109 110
110 void GpuMemoryBufferImplSharedMemory::Unmap() { 111 void GpuMemoryBufferImplSharedMemory::Unmap() {
111 DCHECK(mapped_); 112 DCHECK(mapped_);
112 shared_memory_->Unmap(); 113 shared_memory_->Unmap();
113 mapped_ = false; 114 mapped_ = false;
114 } 115 }
115 116
116 uint32 GpuMemoryBufferImplSharedMemory::GetStride() const { 117 uint32 GpuMemoryBufferImplSharedMemory::GetStride() const {
117 return size_.width() * BytesPerPixel(format_); 118 return StrideInBytes(size_.width(), format_);
118 } 119 }
119 120
120 gfx::GpuMemoryBufferHandle GpuMemoryBufferImplSharedMemory::GetHandle() const { 121 gfx::GpuMemoryBufferHandle GpuMemoryBufferImplSharedMemory::GetHandle() const {
121 gfx::GpuMemoryBufferHandle handle; 122 gfx::GpuMemoryBufferHandle handle;
122 handle.type = gfx::SHARED_MEMORY_BUFFER; 123 handle.type = gfx::SHARED_MEMORY_BUFFER;
123 handle.id = id_; 124 handle.id = id_;
124 handle.handle = shared_memory_->handle(); 125 handle.handle = shared_memory_->handle();
125 return handle; 126 return handle;
126 } 127 }
127 128
128 } // namespace content 129 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698