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() { |
| 83 DCHECK(!shared_memory_); |
| 84 #if defined(OS_WIN) || defined(USE_X11) || defined(OS_ANDROID) || \ |
| 85 defined(USE_OZONE) |
| 86 DCHECK_EQ(EGL_NO_IMAGE_KHR, egl_image_); |
| 87 DCHECK_EQ(0u, egl_texture_id_); |
| 88 #endif |
| 89 } |
83 | 90 |
84 bool GLImageShm::Initialize(gfx::GpuMemoryBufferHandle buffer) { | 91 bool GLImageShm::Initialize(gfx::GpuMemoryBufferHandle buffer) { |
85 if (!ValidFormat(internalformat_)) { | 92 if (!ValidFormat(internalformat_)) { |
86 DVLOG(0) << "Invalid format: " << internalformat_; | 93 DVLOG(0) << "Invalid format: " << internalformat_; |
87 return false; | 94 return false; |
88 } | 95 } |
89 | 96 |
90 if (!base::SharedMemory::IsHandleValid(buffer.handle)) | 97 if (!base::SharedMemory::IsHandleValid(buffer.handle)) |
91 return false; | 98 return false; |
92 | 99 |
93 base::SharedMemory shared_memory(buffer.handle, true); | 100 base::SharedMemory shared_memory(buffer.handle, true); |
94 | 101 |
95 // Duplicate the handle. | 102 // Duplicate the handle. |
96 base::SharedMemoryHandle duped_shared_memory_handle; | 103 base::SharedMemoryHandle duped_shared_memory_handle; |
97 if (!shared_memory.ShareToProcess(base::GetCurrentProcessHandle(), | 104 if (!shared_memory.ShareToProcess(base::GetCurrentProcessHandle(), |
98 &duped_shared_memory_handle)) { | 105 &duped_shared_memory_handle)) { |
99 DVLOG(0) << "Failed to duplicate shared memory handle."; | 106 DVLOG(0) << "Failed to duplicate shared memory handle."; |
100 return false; | 107 return false; |
101 } | 108 } |
102 | 109 |
103 shared_memory_.reset( | 110 shared_memory_.reset( |
104 new base::SharedMemory(duped_shared_memory_handle, true)); | 111 new base::SharedMemory(duped_shared_memory_handle, true)); |
105 return true; | 112 return true; |
106 } | 113 } |
107 | 114 |
108 void GLImageShm::Destroy() { | 115 void GLImageShm::Destroy(bool have_context) { |
| 116 shared_memory_.reset(); |
109 #if defined(OS_WIN) || defined(USE_X11) || defined(OS_ANDROID) || \ | 117 #if defined(OS_WIN) || defined(USE_X11) || defined(OS_ANDROID) || \ |
110 defined(USE_OZONE) | 118 defined(USE_OZONE) |
111 if (egl_image_ != EGL_NO_IMAGE_KHR) { | 119 if (egl_image_ != EGL_NO_IMAGE_KHR) { |
112 eglDestroyImageKHR(GLSurfaceEGL::GetHardwareDisplay(), egl_image_); | 120 eglDestroyImageKHR(GLSurfaceEGL::GetHardwareDisplay(), egl_image_); |
113 egl_image_ = EGL_NO_IMAGE_KHR; | 121 egl_image_ = EGL_NO_IMAGE_KHR; |
114 } | 122 } |
115 | 123 |
116 if (egl_texture_id_) { | 124 if (egl_texture_id_) { |
117 glDeleteTextures(1, &egl_texture_id_); | 125 if (have_context) |
| 126 glDeleteTextures(1, &egl_texture_id_); |
118 egl_texture_id_ = 0u; | 127 egl_texture_id_ = 0u; |
119 } | 128 } |
120 #endif | 129 #endif |
121 } | 130 } |
122 | 131 |
123 gfx::Size GLImageShm::GetSize() { return size_; } | 132 gfx::Size GLImageShm::GetSize() { return size_; } |
124 | 133 |
125 bool GLImageShm::BindTexImage(unsigned target) { | 134 bool GLImageShm::BindTexImage(unsigned target) { |
126 TRACE_EVENT0("gpu", "GLImageShm::BindTexImage"); | 135 TRACE_EVENT0("gpu", "GLImageShm::BindTexImage"); |
127 DCHECK(shared_memory_); | 136 DCHECK(shared_memory_); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 0, // border | 211 0, // border |
203 DataFormat(internalformat_), | 212 DataFormat(internalformat_), |
204 DataType(internalformat_), | 213 DataType(internalformat_), |
205 shared_memory_->memory()); | 214 shared_memory_->memory()); |
206 | 215 |
207 shared_memory_->Unmap(); | 216 shared_memory_->Unmap(); |
208 return true; | 217 return true; |
209 } | 218 } |
210 | 219 |
211 } // namespace gfx | 220 } // namespace gfx |
OLD | NEW |