OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_android_native_buffer.h" | 5 #include "ui/gl/gl_image_android_native_buffer.h" |
6 | 6 |
7 #include "ui/gl/gl_surface_egl.h" | 7 #include "ui/gl/gl_surface_egl.h" |
8 #include "ui/gl/scoped_binders.h" | 8 #include "ui/gl/scoped_binders.h" |
9 | 9 |
10 namespace gfx { | 10 namespace gfx { |
11 | 11 |
12 GLImageAndroidNativeBuffer::GLImageAndroidNativeBuffer(gfx::Size size) | 12 GLImageAndroidNativeBuffer::GLImageAndroidNativeBuffer(gfx::Size size) |
13 : GLImageEGL(size), | 13 : GLImageEGL(size), |
14 release_after_use_(false), | 14 release_after_use_(false), |
15 in_use_(false), | 15 in_use_(false), |
16 target_(0), | 16 target_(0), |
17 egl_image_for_unbind_(EGL_NO_IMAGE_KHR), | 17 egl_image_for_unbind_(EGL_NO_IMAGE_KHR), |
18 texture_id_for_unbind_(0) {} | 18 texture_id_for_unbind_(0) {} |
19 | 19 |
20 GLImageAndroidNativeBuffer::~GLImageAndroidNativeBuffer() { Destroy(); } | 20 GLImageAndroidNativeBuffer::~GLImageAndroidNativeBuffer() { |
21 DCHECK_EQ(EGL_NO_IMAGE_KHR, egl_image_); | |
22 DCHECK_EQ(0u, texture_id_for_unbind_); | |
23 } | |
21 | 24 |
22 bool GLImageAndroidNativeBuffer::Initialize(gfx::GpuMemoryBufferHandle buffer) { | 25 bool GLImageAndroidNativeBuffer::Initialize(gfx::GpuMemoryBufferHandle buffer) { |
23 DCHECK(buffer.native_buffer); | 26 DCHECK(buffer.native_buffer); |
24 | 27 |
25 EGLint attrs[] = {EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE}; | 28 EGLint attrs[] = {EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE}; |
26 return GLImageEGL::Initialize( | 29 return GLImageEGL::Initialize( |
27 EGL_NATIVE_BUFFER_ANDROID, buffer.native_buffer, attrs); | 30 EGL_NATIVE_BUFFER_ANDROID, buffer.native_buffer, attrs); |
28 } | 31 } |
29 | 32 |
30 void GLImageAndroidNativeBuffer::Destroy() { | 33 void GLImageAndroidNativeBuffer::Destroy(bool have_context) { |
31 if (egl_image_for_unbind_ != EGL_NO_IMAGE_KHR) { | 34 if (egl_image_for_unbind_ != EGL_NO_IMAGE_KHR) { |
32 eglDestroyImageKHR(GLSurfaceEGL::GetHardwareDisplay(), | 35 eglDestroyImageKHR(GLSurfaceEGL::GetHardwareDisplay(), |
33 egl_image_for_unbind_); | 36 egl_image_for_unbind_); |
34 egl_image_for_unbind_ = EGL_NO_IMAGE_KHR; | 37 egl_image_for_unbind_ = EGL_NO_IMAGE_KHR; |
35 } | 38 } |
39 | |
36 if (texture_id_for_unbind_) { | 40 if (texture_id_for_unbind_) { |
37 glDeleteTextures(1, &texture_id_for_unbind_); | 41 texture_id_for_unbind_ = 0u; |
38 texture_id_for_unbind_ = 0; | 42 if (have_context) |
43 glDeleteTextures(1, &texture_id_for_unbind_); | |
reveman
2014/05/31 05:05:06
doesn't work as you set texture_id_for_unbind_ to
sohanjg
2014/06/02 13:59:42
Done.
| |
39 } | 44 } |
40 | 45 |
41 GLImageEGL::Destroy(); | 46 GLImageEGL::Destroy(have_context); |
42 } | 47 } |
43 | 48 |
44 bool GLImageAndroidNativeBuffer::BindTexImage(unsigned target) { | 49 bool GLImageAndroidNativeBuffer::BindTexImage(unsigned target) { |
45 DCHECK_NE(EGL_NO_IMAGE_KHR, egl_image_); | 50 DCHECK_NE(EGL_NO_IMAGE_KHR, egl_image_); |
46 | 51 |
47 if (target == GL_TEXTURE_RECTANGLE_ARB) { | 52 if (target == GL_TEXTURE_RECTANGLE_ARB) { |
48 LOG(ERROR) << "EGLImage cannot be bound to TEXTURE_RECTANGLE_ARB target"; | 53 LOG(ERROR) << "EGLImage cannot be bound to TEXTURE_RECTANGLE_ARB target"; |
49 return false; | 54 return false; |
50 } | 55 } |
51 | 56 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
109 | 114 |
110 glEGLImageTargetTexture2DOES(target_, egl_image_for_unbind_); | 115 glEGLImageTargetTexture2DOES(target_, egl_image_for_unbind_); |
111 DCHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); | 116 DCHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
112 } | 117 } |
113 | 118 |
114 void GLImageAndroidNativeBuffer::SetReleaseAfterUse() { | 119 void GLImageAndroidNativeBuffer::SetReleaseAfterUse() { |
115 release_after_use_ = true; | 120 release_after_use_ = true; |
116 } | 121 } |
117 | 122 |
118 } // namespace gfx | 123 } // namespace gfx |
OLD | NEW |