OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 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 "ui/gl/gl_image_shm.h" |
| 6 |
| 7 #include "base/debug/trace_event.h" |
| 8 #include "base/process_util.h" |
| 9 #include "ui/gl/gl_bindings.h" |
| 10 |
| 11 namespace gfx { |
| 12 |
| 13 GLImageShm::GLImageShm(gfx::Size size) : size_(size) { |
| 14 } |
| 15 |
| 16 GLImageShm::~GLImageShm() { |
| 17 Destroy(); |
| 18 } |
| 19 |
| 20 bool GLImageShm::Initialize(gfx::GpuMemoryBufferHandle buffer) { |
| 21 if (!base::SharedMemory::IsHandleValid(buffer.handle)) |
| 22 return false; |
| 23 |
| 24 base::SharedMemory shared_memory(buffer.handle, true); |
| 25 |
| 26 // Duplicate the handle. |
| 27 base::SharedMemoryHandle duped_shared_memory_handle; |
| 28 if (!shared_memory.ShareToProcess(base::GetCurrentProcessHandle(), |
| 29 &duped_shared_memory_handle)) { |
| 30 DVLOG(0) << "Failed to duplicate shared memory handle."; |
| 31 return false; |
| 32 } |
| 33 |
| 34 shared_memory_.reset( |
| 35 new base::SharedMemory(duped_shared_memory_handle, true)); |
| 36 return true; |
| 37 } |
| 38 |
| 39 bool GLImageShm::BindTexImage() { |
| 40 TRACE_EVENT0("gpu", "GLImageShm::BindTexImage"); |
| 41 DCHECK(shared_memory_); |
| 42 |
| 43 const int kBytesPerPixel = 4; |
| 44 size_t size = size_.GetArea() * kBytesPerPixel; |
| 45 DCHECK(!shared_memory_->memory()); |
| 46 if (!shared_memory_->Map(size)) { |
| 47 DVLOG(0) << "Failed to map shared memory."; |
| 48 return false; |
| 49 } |
| 50 |
| 51 DCHECK(shared_memory_->memory()); |
| 52 glTexImage2D(GL_TEXTURE_2D, |
| 53 0, // mip level |
| 54 GL_RGBA8_OES, |
| 55 size_.width(), |
| 56 size_.height(), |
| 57 0, // border |
| 58 GL_BGRA, |
| 59 GL_UNSIGNED_BYTE, |
| 60 shared_memory_->memory()); |
| 61 |
| 62 shared_memory_->Unmap(); |
| 63 return true; |
| 64 } |
| 65 |
| 66 gfx::Size GLImageShm::GetSize() { |
| 67 return size_; |
| 68 } |
| 69 |
| 70 void GLImageShm::Destroy() { |
| 71 } |
| 72 |
| 73 void GLImageShm::ReleaseTexImage() { |
| 74 } |
| 75 |
| 76 } // namespace gfx |
OLD | NEW |