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(const gfx::Size& size) | 12 GLImageAndroidNativeBuffer::GLImageAndroidNativeBuffer(const 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 | 20 |
21 GLImageAndroidNativeBuffer::~GLImageAndroidNativeBuffer() { Destroy(); } | 21 GLImageAndroidNativeBuffer::~GLImageAndroidNativeBuffer() { |
22 DCHECK_EQ(EGL_NO_IMAGE_KHR, egl_image_); | |
23 DCHECK_EQ(0u, texture_id_for_unbind_); | |
24 } | |
22 | 25 |
23 bool GLImageAndroidNativeBuffer::Initialize(EGLClientBuffer native_buffer) { | 26 bool GLImageAndroidNativeBuffer::Initialize(EGLClientBuffer native_buffer) { |
24 EGLint attrs[] = {EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE}; | 27 EGLint attrs[] = {EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE}; |
25 return GLImageEGL::Initialize( | 28 return GLImageEGL::Initialize( |
26 EGL_NATIVE_BUFFER_ANDROID, native_buffer, attrs); | 29 EGL_NATIVE_BUFFER_ANDROID, native_buffer, attrs); |
27 } | 30 } |
28 | 31 |
29 void GLImageAndroidNativeBuffer::Destroy() { | 32 void GLImageAndroidNativeBuffer::Destroy(bool have_context) { |
30 if (egl_image_for_unbind_ != EGL_NO_IMAGE_KHR) { | 33 if (egl_image_for_unbind_ != EGL_NO_IMAGE_KHR) { |
31 eglDestroyImageKHR(GLSurfaceEGL::GetHardwareDisplay(), | 34 eglDestroyImageKHR(GLSurfaceEGL::GetHardwareDisplay(), |
32 egl_image_for_unbind_); | 35 egl_image_for_unbind_); |
33 egl_image_for_unbind_ = EGL_NO_IMAGE_KHR; | 36 egl_image_for_unbind_ = EGL_NO_IMAGE_KHR; |
34 } | 37 } |
38 | |
35 if (texture_id_for_unbind_) { | 39 if (texture_id_for_unbind_) { |
36 glDeleteTextures(1, &texture_id_for_unbind_); | 40 if (have_context) |
37 texture_id_for_unbind_ = 0; | 41 glDeleteTextures(1, &texture_id_for_unbind_); |
42 texture_id_for_unbind_ = 0u; | |
38 } | 43 } |
39 | 44 |
40 GLImageEGL::Destroy(); | 45 GLImageEGL::Destroy(have_context); |
41 } | 46 } |
42 | 47 |
43 bool GLImageAndroidNativeBuffer::BindTexImage(unsigned target) { | 48 bool GLImageAndroidNativeBuffer::BindTexImage(unsigned target) { |
44 DCHECK_NE(EGL_NO_IMAGE_KHR, egl_image_); | 49 if (egl_image_ == EGL_NO_IMAGE_KHR) { |
50 LOG(ERROR) << "Uninitialized image cannot be bound to texture"; | |
51 return false; | |
52 } | |
reveman
2014/07/25 19:00:23
Hm, maybe all these should be DCHECKs after all. I
sohanjg
2014/07/26 10:42:23
Done.
| |
45 | 53 |
46 if (target == GL_TEXTURE_RECTANGLE_ARB) { | 54 if (target == GL_TEXTURE_RECTANGLE_ARB) { |
47 LOG(ERROR) << "EGLImage cannot be bound to TEXTURE_RECTANGLE_ARB target"; | 55 LOG(ERROR) << "EGLImage cannot be bound to TEXTURE_RECTANGLE_ARB target"; |
48 return false; | 56 return false; |
49 } | 57 } |
50 | 58 |
51 if (target_ && target_ != target) { | 59 if (target_ && target_ != target) { |
52 LOG(ERROR) << "EGLImage can only be bound to one target"; | 60 LOG(ERROR) << "EGLImage can only be bound to one target"; |
53 return false; | 61 return false; |
54 } | 62 } |
55 target_ = target; | 63 target_ = target; |
56 | 64 |
57 // Defer ImageTargetTexture2D if not currently in use. | 65 // Defer ImageTargetTexture2D if not currently in use. |
58 if (!in_use_) | 66 if (!in_use_) |
59 return true; | 67 return true; |
60 | 68 |
61 glEGLImageTargetTexture2DOES(target_, egl_image_); | 69 glEGLImageTargetTexture2DOES(target_, egl_image_); |
62 DCHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); | 70 DCHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
63 return true; | 71 return true; |
64 } | 72 } |
65 | 73 |
66 void GLImageAndroidNativeBuffer::WillUseTexImage() { | 74 void GLImageAndroidNativeBuffer::WillUseTexImage() { |
67 DCHECK(egl_image_); | 75 if (egl_image_ == EGL_NO_IMAGE_KHR) { |
reveman
2014/07/25 19:00:23
Let's make this DCHECK_NE(EGL_NO_IMAGE_KHR, egl_im
sohanjg
2014/07/26 10:42:23
Done.
| |
76 LOG(ERROR) << "Uninitialized image cannot be used to bind to texture"; | |
77 return; | |
78 } | |
68 DCHECK(!in_use_); | 79 DCHECK(!in_use_); |
69 in_use_ = true; | 80 in_use_ = true; |
70 glEGLImageTargetTexture2DOES(target_, egl_image_); | 81 glEGLImageTargetTexture2DOES(target_, egl_image_); |
71 DCHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); | 82 DCHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
72 } | 83 } |
73 | 84 |
74 void GLImageAndroidNativeBuffer::DidUseTexImage() { | 85 void GLImageAndroidNativeBuffer::DidUseTexImage() { |
86 if (egl_image_ == EGL_NO_IMAGE_KHR) { | |
reveman
2014/07/25 19:00:23
DCHECK_NE(EGL_NO_IMAGE_KHR, egl_image_) instead
sohanjg
2014/07/26 10:42:23
Done.
| |
87 LOG(ERROR) | |
88 << "Uninitialized image cannot be used while unbinding to texture"; | |
89 return; | |
90 } | |
75 DCHECK(in_use_); | 91 DCHECK(in_use_); |
76 in_use_ = false; | 92 in_use_ = false; |
77 | 93 |
78 if (!release_after_use_) | 94 if (!release_after_use_) |
79 return; | 95 return; |
80 | 96 |
81 if (egl_image_for_unbind_ == EGL_NO_IMAGE_KHR) { | 97 if (egl_image_for_unbind_ == EGL_NO_IMAGE_KHR) { |
82 DCHECK_EQ(0u, texture_id_for_unbind_); | 98 DCHECK_EQ(0u, texture_id_for_unbind_); |
83 glGenTextures(1, &texture_id_for_unbind_); | 99 glGenTextures(1, &texture_id_for_unbind_); |
84 | 100 |
(...skipping 23 matching lines...) Expand all Loading... | |
108 | 124 |
109 glEGLImageTargetTexture2DOES(target_, egl_image_for_unbind_); | 125 glEGLImageTargetTexture2DOES(target_, egl_image_for_unbind_); |
110 DCHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); | 126 DCHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
111 } | 127 } |
112 | 128 |
113 void GLImageAndroidNativeBuffer::SetReleaseAfterUse() { | 129 void GLImageAndroidNativeBuffer::SetReleaseAfterUse() { |
114 release_after_use_ = true; | 130 release_after_use_ = true; |
115 } | 131 } |
116 | 132 |
117 } // namespace gfx | 133 } // namespace gfx |
OLD | NEW |