Chromium Code Reviews| OLD | NEW | 
|---|---|
| 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 "ui/gl/gl_image_shm.h" | 5 #include "ui/gl/gl_image_shm.h" | 
| 6 | 6 | 
| 7 #include "base/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" | 
| 8 #include "base/process/process_handle.h" | 8 #include "base/process/process_handle.h" | 
| 9 #include "ui/gl/scoped_binders.h" | 9 #include "ui/gl/scoped_binders.h" | 
| 10 | 10 | 
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 72 internalformat_(internalformat) | 72 internalformat_(internalformat) | 
| 73 #if defined(OS_WIN) || defined(USE_X11) || defined(OS_ANDROID) || \ | 73 #if defined(OS_WIN) || defined(USE_X11) || defined(OS_ANDROID) || \ | 
| 74 defined(USE_OZONE) | 74 defined(USE_OZONE) | 
| 75 , | 75 , | 
| 76 egl_texture_id_(0u), | 76 egl_texture_id_(0u), | 
| 77 egl_image_(EGL_NO_IMAGE_KHR) | 77 egl_image_(EGL_NO_IMAGE_KHR) | 
| 78 #endif | 78 #endif | 
| 79 { | 79 { | 
| 80 } | 80 } | 
| 81 | 81 | 
| 82 GLImageShm::~GLImageShm() { Destroy(); } | 82 GLImageShm::~GLImageShm() { | 
| 
 
reveman
2014/06/02 14:34:47
Please add a DCHECK(!shared_memory_) here too.
 
sohanjg
2014/06/02 15:39:10
Done.
 
 | |
| 83 DCHECK_EQ(EGL_NO_IMAGE_KHR, egl_image_); | |
| 84 DCHECK_EQ(0u, egl_texture_id_); | |
| 
 
reveman
2014/06/02 14:34:47
These DCHECKs need to be ifdef-ed.
 
sohanjg
2014/06/02 15:39:10
Done.
 
 | |
| 85 } | |
| 83 | 86 | 
| 84 bool GLImageShm::Initialize(gfx::GpuMemoryBufferHandle buffer) { | 87 bool GLImageShm::Initialize(gfx::GpuMemoryBufferHandle buffer) { | 
| 85 if (!ValidFormat(internalformat_)) { | 88 if (!ValidFormat(internalformat_)) { | 
| 86 DVLOG(0) << "Invalid format: " << internalformat_; | 89 DVLOG(0) << "Invalid format: " << internalformat_; | 
| 87 return false; | 90 return false; | 
| 88 } | 91 } | 
| 89 | 92 | 
| 90 if (!base::SharedMemory::IsHandleValid(buffer.handle)) | 93 if (!base::SharedMemory::IsHandleValid(buffer.handle)) | 
| 91 return false; | 94 return false; | 
| 92 | 95 | 
| 93 base::SharedMemory shared_memory(buffer.handle, true); | 96 base::SharedMemory shared_memory(buffer.handle, true); | 
| 94 | 97 | 
| 95 // Duplicate the handle. | 98 // Duplicate the handle. | 
| 96 base::SharedMemoryHandle duped_shared_memory_handle; | 99 base::SharedMemoryHandle duped_shared_memory_handle; | 
| 97 if (!shared_memory.ShareToProcess(base::GetCurrentProcessHandle(), | 100 if (!shared_memory.ShareToProcess(base::GetCurrentProcessHandle(), | 
| 98 &duped_shared_memory_handle)) { | 101 &duped_shared_memory_handle)) { | 
| 99 DVLOG(0) << "Failed to duplicate shared memory handle."; | 102 DVLOG(0) << "Failed to duplicate shared memory handle."; | 
| 100 return false; | 103 return false; | 
| 101 } | 104 } | 
| 102 | 105 | 
| 103 shared_memory_.reset( | 106 shared_memory_.reset( | 
| 104 new base::SharedMemory(duped_shared_memory_handle, true)); | 107 new base::SharedMemory(duped_shared_memory_handle, true)); | 
| 105 return true; | 108 return true; | 
| 106 } | 109 } | 
| 107 | 110 | 
| 108 void GLImageShm::Destroy() { | 111 void GLImageShm::Destroy(bool have_context) { | 
| 109 #if defined(OS_WIN) || defined(USE_X11) || defined(OS_ANDROID) || \ | 112 #if defined(OS_WIN) || defined(USE_X11) || defined(OS_ANDROID) || \ | 
| 110 defined(USE_OZONE) | 113 defined(USE_OZONE) | 
| 111 if (egl_image_ != EGL_NO_IMAGE_KHR) { | 114 if (egl_image_ != EGL_NO_IMAGE_KHR) { | 
| 112 eglDestroyImageKHR(GLSurfaceEGL::GetHardwareDisplay(), egl_image_); | 115 eglDestroyImageKHR(GLSurfaceEGL::GetHardwareDisplay(), egl_image_); | 
| 113 egl_image_ = EGL_NO_IMAGE_KHR; | 116 egl_image_ = EGL_NO_IMAGE_KHR; | 
| 114 } | 117 } | 
| 115 | 118 | 
| 116 if (egl_texture_id_) { | 119 if (egl_texture_id_) { | 
| 117 glDeleteTextures(1, &egl_texture_id_); | 120 if (have_context) | 
| 121 glDeleteTextures(1, &egl_texture_id_); | |
| 118 egl_texture_id_ = 0u; | 122 egl_texture_id_ = 0u; | 
| 119 } | 123 } | 
| 120 #endif | 124 #endif | 
| 125 shared_memory_.reset(); | |
| 
 
reveman
2014/06/02 14:34:47
nit: move this above the ifdef
 
sohanjg
2014/06/02 15:39:10
Done.
 
 | |
| 121 } | 126 } | 
| 122 | 127 | 
| 123 gfx::Size GLImageShm::GetSize() { return size_; } | 128 gfx::Size GLImageShm::GetSize() { return size_; } | 
| 124 | 129 | 
| 125 bool GLImageShm::BindTexImage(unsigned target) { | 130 bool GLImageShm::BindTexImage(unsigned target) { | 
| 126 TRACE_EVENT0("gpu", "GLImageShm::BindTexImage"); | 131 TRACE_EVENT0("gpu", "GLImageShm::BindTexImage"); | 
| 127 DCHECK(shared_memory_); | 132 DCHECK(shared_memory_); | 
| 128 DCHECK(ValidFormat(internalformat_)); | 133 DCHECK(ValidFormat(internalformat_)); | 
| 129 | 134 | 
| 130 size_t size = size_.GetArea() * BytesPerPixel(internalformat_); | 135 size_t size = size_.GetArea() * BytesPerPixel(internalformat_); | 
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 202 0, // border | 207 0, // border | 
| 203 DataFormat(internalformat_), | 208 DataFormat(internalformat_), | 
| 204 DataType(internalformat_), | 209 DataType(internalformat_), | 
| 205 shared_memory_->memory()); | 210 shared_memory_->memory()); | 
| 206 | 211 | 
| 207 shared_memory_->Unmap(); | 212 shared_memory_->Unmap(); | 
| 208 return true; | 213 return true; | 
| 209 } | 214 } | 
| 210 | 215 | 
| 211 } // namespace gfx | 216 } // namespace gfx | 
| OLD | NEW |