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

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

Issue 852283003: Revert of Update GPU memory buffers to use StrideInBytes internally. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 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
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 38 if (!shared_memory->CreateAnonymous(size.GetArea() * BytesPerPixel(format)))
39 size_t stride_in_bytes = 0;
40 if (!StrideInBytes(size.width(), format, &stride_in_bytes))
41 return scoped_ptr<GpuMemoryBufferImpl>();
42
43 base::CheckedNumeric<size_t> size_in_bytes = stride_in_bytes;
44 size_in_bytes *= size.height();
45 if (!size_in_bytes.IsValid())
46 return scoped_ptr<GpuMemoryBufferImpl>();
47
48 if (!shared_memory->CreateAnonymous(size_in_bytes.ValueOrDie()))
49 return scoped_ptr<GpuMemoryBufferImpl>(); 39 return scoped_ptr<GpuMemoryBufferImpl>();
50 40
51 return make_scoped_ptr(new GpuMemoryBufferImplSharedMemory( 41 return make_scoped_ptr(new GpuMemoryBufferImplSharedMemory(
52 id, size, format, base::Bind(&Noop), shared_memory.Pass())); 42 id, size, format, base::Bind(&Noop), shared_memory.Pass()));
53 } 43 }
54 44
55 // static 45 // static
56 gfx::GpuMemoryBufferHandle 46 gfx::GpuMemoryBufferHandle
57 GpuMemoryBufferImplSharedMemory::AllocateForChildProcess( 47 GpuMemoryBufferImplSharedMemory::AllocateForChildProcess(
58 gfx::GpuMemoryBufferId id, 48 gfx::GpuMemoryBufferId id,
59 const gfx::Size& size, 49 const gfx::Size& size,
60 Format format, 50 Format format,
61 base::ProcessHandle child_process) { 51 base::ProcessHandle child_process) {
62 size_t stride_in_bytes = 0; 52 base::CheckedNumeric<int> buffer_size = size.width();
63 if (!StrideInBytes(size.width(), format, &stride_in_bytes))
64 return gfx::GpuMemoryBufferHandle();
65
66 base::CheckedNumeric<int> buffer_size = stride_in_bytes;
67 buffer_size *= size.height(); 53 buffer_size *= size.height();
54 buffer_size *= BytesPerPixel(format);
68 if (!buffer_size.IsValid()) 55 if (!buffer_size.IsValid())
69 return gfx::GpuMemoryBufferHandle(); 56 return gfx::GpuMemoryBufferHandle();
70 57
71 base::SharedMemory shared_memory; 58 base::SharedMemory shared_memory;
72 if (!shared_memory.CreateAnonymous(buffer_size.ValueOrDie())) 59 if (!shared_memory.CreateAnonymous(buffer_size.ValueOrDie()))
73 return gfx::GpuMemoryBufferHandle(); 60 return gfx::GpuMemoryBufferHandle();
74 61
75 gfx::GpuMemoryBufferHandle handle; 62 gfx::GpuMemoryBufferHandle handle;
76 handle.type = gfx::SHARED_MEMORY_BUFFER; 63 handle.type = gfx::SHARED_MEMORY_BUFFER;
77 handle.id = id; 64 handle.id = id;
(...skipping 29 matching lines...) Expand all
107 case RGBX_8888: 94 case RGBX_8888:
108 return false; 95 return false;
109 } 96 }
110 97
111 NOTREACHED(); 98 NOTREACHED();
112 return false; 99 return false;
113 } 100 }
114 101
115 void* GpuMemoryBufferImplSharedMemory::Map() { 102 void* GpuMemoryBufferImplSharedMemory::Map() {
116 DCHECK(!mapped_); 103 DCHECK(!mapped_);
117 104 if (!shared_memory_->Map(size_.GetArea() * BytesPerPixel(format_)))
118 size_t stride_in_bytes = 0;
119 if (!StrideInBytes(size_.width(), format_, &stride_in_bytes))
120 return NULL;
121
122 base::CheckedNumeric<size_t> size_in_bytes = stride_in_bytes;
123 size_in_bytes *= size_.height();
124 if (!size_in_bytes.IsValid())
125 return NULL;
126
127 if (!shared_memory_->Map(size_in_bytes.ValueOrDie()))
128 return NULL; 105 return NULL;
129 mapped_ = true; 106 mapped_ = true;
130 return shared_memory_->memory(); 107 return shared_memory_->memory();
131 } 108 }
132 109
133 void GpuMemoryBufferImplSharedMemory::Unmap() { 110 void GpuMemoryBufferImplSharedMemory::Unmap() {
134 DCHECK(mapped_); 111 DCHECK(mapped_);
135 shared_memory_->Unmap(); 112 shared_memory_->Unmap();
136 mapped_ = false; 113 mapped_ = false;
137 } 114 }
138 115
139 uint32 GpuMemoryBufferImplSharedMemory::GetStride() const { 116 uint32 GpuMemoryBufferImplSharedMemory::GetStride() const {
140 size_t stride_in_bytes = 0; 117 return size_.width() * BytesPerPixel(format_);
141 DCHECK(StrideInBytes(size_.width(), format_, &stride_in_bytes));
142 return stride_in_bytes;
143 } 118 }
144 119
145 gfx::GpuMemoryBufferHandle GpuMemoryBufferImplSharedMemory::GetHandle() const { 120 gfx::GpuMemoryBufferHandle GpuMemoryBufferImplSharedMemory::GetHandle() const {
146 gfx::GpuMemoryBufferHandle handle; 121 gfx::GpuMemoryBufferHandle handle;
147 handle.type = gfx::SHARED_MEMORY_BUFFER; 122 handle.type = gfx::SHARED_MEMORY_BUFFER;
148 handle.id = id_; 123 handle.id = id_;
149 handle.handle = shared_memory_->handle(); 124 handle.handle = shared_memory_->handle();
150 return handle; 125 return handle;
151 } 126 }
152 127
153 } // namespace content 128 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698