Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(28)

Side by Side Diff: ui/gl/gl_image_shm.cc

Issue 301793003: During image destroy, delete textures only if we have a GL context. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move ImageManager destroy to GPUChannel + review comments Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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();
reveman 2014/06/02 16:45:29 nit: please be consistent with blank lines around
sohanjg 2014/06/03 05:48:33 Done.
117
109 #if defined(OS_WIN) || defined(USE_X11) || defined(OS_ANDROID) || \ 118 #if defined(OS_WIN) || defined(USE_X11) || defined(OS_ANDROID) || \
110 defined(USE_OZONE) 119 defined(USE_OZONE)
111 if (egl_image_ != EGL_NO_IMAGE_KHR) { 120 if (egl_image_ != EGL_NO_IMAGE_KHR) {
112 eglDestroyImageKHR(GLSurfaceEGL::GetHardwareDisplay(), egl_image_); 121 eglDestroyImageKHR(GLSurfaceEGL::GetHardwareDisplay(), egl_image_);
113 egl_image_ = EGL_NO_IMAGE_KHR; 122 egl_image_ = EGL_NO_IMAGE_KHR;
114 } 123 }
115 124
116 if (egl_texture_id_) { 125 if (egl_texture_id_) {
117 glDeleteTextures(1, &egl_texture_id_); 126 if (have_context)
127 glDeleteTextures(1, &egl_texture_id_);
118 egl_texture_id_ = 0u; 128 egl_texture_id_ = 0u;
119 } 129 }
120 #endif 130 #endif
121 } 131 }
122 132
123 gfx::Size GLImageShm::GetSize() { return size_; } 133 gfx::Size GLImageShm::GetSize() { return size_; }
124 134
125 bool GLImageShm::BindTexImage(unsigned target) { 135 bool GLImageShm::BindTexImage(unsigned target) {
126 TRACE_EVENT0("gpu", "GLImageShm::BindTexImage"); 136 TRACE_EVENT0("gpu", "GLImageShm::BindTexImage");
127 DCHECK(shared_memory_); 137 DCHECK(shared_memory_);
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 0, // border 212 0, // border
203 DataFormat(internalformat_), 213 DataFormat(internalformat_),
204 DataType(internalformat_), 214 DataType(internalformat_),
205 shared_memory_->memory()); 215 shared_memory_->memory());
206 216
207 shared_memory_->Unmap(); 217 shared_memory_->Unmap();
208 return true; 218 return true;
209 } 219 }
210 220
211 } // namespace gfx 221 } // namespace gfx
OLDNEW
« ui/gl/gl_image_glx.cc ('K') | « ui/gl/gl_image_shm.h ('k') | ui/gl/gl_image_stub.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698