OLD | NEW |
---|---|
(Empty) | |
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 "content/common/gpu/client/gpu_memory_buffer_impl_shm.h" | |
6 | |
7 #include "base/logging.h" | |
8 | |
9 namespace content { | |
10 | |
11 GpuMemoryBufferImplShm::GpuMemoryBufferImplShm( | |
12 gfx::Size size, unsigned internalformat) | |
13 : GpuMemoryBufferImpl(size, internalformat) { | |
14 } | |
15 | |
16 GpuMemoryBufferImplShm::~GpuMemoryBufferImplShm() { | |
17 } | |
18 | |
19 bool GpuMemoryBufferImplShm::Initialize(gfx::GpuMemoryBufferHandle handle) { | |
20 if (!base::SharedMemory::IsHandleValid(handle.handle)) | |
21 return false; | |
22 shared_memory_.reset(new base::SharedMemory(handle.handle, false)); | |
23 DCHECK(!shared_memory_->memory()); | |
24 return true; | |
25 } | |
26 | |
27 bool GpuMemoryBufferImplShm::InitializeFromSharedMemory( | |
28 scoped_ptr<base::SharedMemory> shared_memory) { | |
29 shared_memory_ = shared_memory.Pass(); | |
30 DCHECK(!shared_memory_->memory()); | |
31 return true; | |
32 } | |
33 | |
34 void GpuMemoryBufferImplShm::Map(AccessMode mode, void** vaddr) { | |
Ken Russell (switch to Gerrit)
2013/12/03 22:36:13
How often are Map/Unmap expected to be called?
I
reveman
2013/12/04 02:00:31
Less frequently than the buffer is used for drawin
| |
35 DCHECK(!mapped_); | |
36 *vaddr = NULL; | |
37 if (!shared_memory_->Map(size_.GetArea() * BytesPerPixel(internalformat_))) | |
38 return; | |
39 *vaddr = shared_memory_->memory(); | |
40 mapped_ = true; | |
41 } | |
42 | |
43 void GpuMemoryBufferImplShm::Unmap() { | |
44 DCHECK(mapped_); | |
45 shared_memory_->Unmap(); | |
46 mapped_ = false; | |
47 } | |
48 | |
49 gfx::GpuMemoryBufferHandle GpuMemoryBufferImplShm::GetHandle() const { | |
50 gfx::GpuMemoryBufferHandle handle; | |
51 handle.type = gfx::SHARED_MEMORY_BUFFER; | |
52 handle.handle = shared_memory_->handle(); | |
53 return handle; | |
54 } | |
55 | |
56 } // namespace content | |
OLD | NEW |