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/gl_context.h" | |
reveman
2014/05/29 16:30:34
do we need this?
| |
9 #include "ui/gl/scoped_binders.h" | 10 #include "ui/gl/scoped_binders.h" |
10 | 11 |
11 #if defined(OS_WIN) || defined(USE_X11) || defined(OS_ANDROID) || \ | 12 #if defined(OS_WIN) || defined(USE_X11) || defined(OS_ANDROID) || \ |
12 defined(USE_OZONE) | 13 defined(USE_OZONE) |
13 #include "ui/gl/gl_surface_egl.h" | 14 #include "ui/gl/gl_surface_egl.h" |
14 #endif | 15 #endif |
15 | 16 |
16 namespace gfx { | 17 namespace gfx { |
17 | 18 |
18 namespace { | 19 namespace { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
72 internalformat_(internalformat) | 73 internalformat_(internalformat) |
73 #if defined(OS_WIN) || defined(USE_X11) || defined(OS_ANDROID) || \ | 74 #if defined(OS_WIN) || defined(USE_X11) || defined(OS_ANDROID) || \ |
74 defined(USE_OZONE) | 75 defined(USE_OZONE) |
75 , | 76 , |
76 egl_texture_id_(0u), | 77 egl_texture_id_(0u), |
77 egl_image_(EGL_NO_IMAGE_KHR) | 78 egl_image_(EGL_NO_IMAGE_KHR) |
78 #endif | 79 #endif |
79 { | 80 { |
80 } | 81 } |
81 | 82 |
82 GLImageShm::~GLImageShm() { Destroy(); } | 83 GLImageShm::~GLImageShm() { |
reveman
2014/05/29 16:30:34
Verify that Destroy has been called.
| |
84 } | |
83 | 85 |
84 bool GLImageShm::Initialize(gfx::GpuMemoryBufferHandle buffer) { | 86 bool GLImageShm::Initialize(gfx::GpuMemoryBufferHandle buffer) { |
85 if (!ValidFormat(internalformat_)) { | 87 if (!ValidFormat(internalformat_)) { |
86 DVLOG(0) << "Invalid format: " << internalformat_; | 88 DVLOG(0) << "Invalid format: " << internalformat_; |
87 return false; | 89 return false; |
88 } | 90 } |
89 | 91 |
90 if (!base::SharedMemory::IsHandleValid(buffer.handle)) | 92 if (!base::SharedMemory::IsHandleValid(buffer.handle)) |
91 return false; | 93 return false; |
92 | 94 |
93 base::SharedMemory shared_memory(buffer.handle, true); | 95 base::SharedMemory shared_memory(buffer.handle, true); |
94 | 96 |
95 // Duplicate the handle. | 97 // Duplicate the handle. |
96 base::SharedMemoryHandle duped_shared_memory_handle; | 98 base::SharedMemoryHandle duped_shared_memory_handle; |
97 if (!shared_memory.ShareToProcess(base::GetCurrentProcessHandle(), | 99 if (!shared_memory.ShareToProcess(base::GetCurrentProcessHandle(), |
98 &duped_shared_memory_handle)) { | 100 &duped_shared_memory_handle)) { |
99 DVLOG(0) << "Failed to duplicate shared memory handle."; | 101 DVLOG(0) << "Failed to duplicate shared memory handle."; |
100 return false; | 102 return false; |
101 } | 103 } |
102 | 104 |
103 shared_memory_.reset( | 105 shared_memory_.reset( |
104 new base::SharedMemory(duped_shared_memory_handle, true)); | 106 new base::SharedMemory(duped_shared_memory_handle, true)); |
105 return true; | 107 return true; |
106 } | 108 } |
107 | 109 |
108 void GLImageShm::Destroy() { | 110 void GLImageShm::Destroy(bool have_context) { |
109 #if defined(OS_WIN) || defined(USE_X11) || defined(OS_ANDROID) || \ | 111 #if defined(OS_WIN) || defined(USE_X11) || defined(OS_ANDROID) || \ |
110 defined(USE_OZONE) | 112 defined(USE_OZONE) |
111 if (egl_image_ != EGL_NO_IMAGE_KHR) { | 113 if (egl_image_ != EGL_NO_IMAGE_KHR) { |
112 eglDestroyImageKHR(GLSurfaceEGL::GetHardwareDisplay(), egl_image_); | 114 eglDestroyImageKHR(GLSurfaceEGL::GetHardwareDisplay(), egl_image_); |
113 egl_image_ = EGL_NO_IMAGE_KHR; | 115 egl_image_ = EGL_NO_IMAGE_KHR; |
114 } | 116 } |
115 | 117 |
116 if (egl_texture_id_) { | 118 if (egl_texture_id_ && have_context) { |
reveman
2014/05/29 16:30:34
I think you should set egl_texture_id_ to 0 even i
| |
117 glDeleteTextures(1, &egl_texture_id_); | 119 glDeleteTextures(1, &egl_texture_id_); |
118 egl_texture_id_ = 0u; | 120 egl_texture_id_ = 0u; |
119 } | 121 } |
120 #endif | 122 #endif |
reveman
2014/05/29 16:30:34
Please add shared_memory_.reset() to this function
| |
121 } | 123 } |
122 | 124 |
123 gfx::Size GLImageShm::GetSize() { return size_; } | 125 gfx::Size GLImageShm::GetSize() { return size_; } |
124 | 126 |
125 bool GLImageShm::BindTexImage(unsigned target) { | 127 bool GLImageShm::BindTexImage(unsigned target) { |
126 TRACE_EVENT0("gpu", "GLImageShm::BindTexImage"); | 128 TRACE_EVENT0("gpu", "GLImageShm::BindTexImage"); |
127 DCHECK(shared_memory_); | 129 DCHECK(shared_memory_); |
128 DCHECK(ValidFormat(internalformat_)); | 130 DCHECK(ValidFormat(internalformat_)); |
129 | 131 |
130 size_t size = size_.GetArea() * BytesPerPixel(internalformat_); | 132 size_t size = size_.GetArea() * BytesPerPixel(internalformat_); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
202 0, // border | 204 0, // border |
203 DataFormat(internalformat_), | 205 DataFormat(internalformat_), |
204 DataType(internalformat_), | 206 DataType(internalformat_), |
205 shared_memory_->memory()); | 207 shared_memory_->memory()); |
206 | 208 |
207 shared_memory_->Unmap(); | 209 shared_memory_->Unmap(); |
208 return true; | 210 return true; |
209 } | 211 } |
210 | 212 |
211 } // namespace gfx | 213 } // namespace gfx |
OLD | NEW |