Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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_egl.h" | 5 #include "ui/gl/gl_image_egl.h" |
| 6 | 6 |
| 7 #include "ui/gl/gl_bindings.h" | 7 #include "ui/gl/gl_bindings.h" |
| 8 #include "ui/gl/gl_surface_egl.h" | 8 #include "ui/gl/gl_surface_egl.h" |
| 9 | 9 |
| 10 namespace gfx { | 10 namespace gfx { |
| 11 | 11 |
| 12 GLImageEGL::GLImageEGL(gfx::Size size) | 12 GLImageEGL::GLImageEGL(gfx::Size size) |
| 13 : egl_image_(EGL_NO_IMAGE_KHR), | 13 : egl_image_(EGL_NO_IMAGE_KHR), |
| 14 size_(size), | 14 size_(size), |
| 15 release_after_use_(false), | 15 release_after_use_(false), |
| 16 in_use_(false), | 16 in_use_(false), |
| 17 target_(0) { | 17 target_(0) { |
| 18 } | 18 } |
| 19 | 19 |
| 20 GLImageEGL::~GLImageEGL() { | 20 GLImageEGL::~GLImageEGL() { |
| 21 Destroy(); | 21 Destroy(); |
| 22 } | 22 } |
| 23 | 23 |
| 24 bool GLImageEGL::Initialize(gfx::GpuMemoryBufferHandle buffer) { | 24 bool GLImageEGL::Initialize(gfx::GpuMemoryBufferHandle buffer) { |
| 25 buffer_ = buffer; | |
| 25 DCHECK(buffer.native_buffer); | 26 DCHECK(buffer.native_buffer); |
| 26 EGLint attrs[] = { | 27 EGLint attrs[] = { |
| 27 EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, | 28 EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, |
| 28 EGL_NONE, | 29 EGL_NONE, |
| 29 }; | 30 }; |
| 30 egl_image_ = eglCreateImageKHR( | 31 egl_image_ = eglCreateImageKHR(GLSurfaceEGL::GetHardwareDisplay(), |
| 31 GLSurfaceEGL::GetHardwareDisplay(), | 32 EGL_NO_CONTEXT, |
| 32 EGL_NO_CONTEXT, | 33 EGL_NATIVE_PIXMAP_KHR, |
|
rjkroege
2014/01/10 19:14:04
won't this change break something?
| |
| 33 EGL_NATIVE_BUFFER_ANDROID, | 34 buffer.native_buffer, |
| 34 buffer.native_buffer, | 35 attrs); |
| 35 attrs); | |
| 36 | 36 |
| 37 if (egl_image_ == EGL_NO_IMAGE_KHR) { | 37 if (egl_image_ == EGL_NO_IMAGE_KHR) { |
| 38 EGLint error = eglGetError(); | 38 EGLint error = eglGetError(); |
| 39 LOG(ERROR) << "Error creating EGLImage: " << error; | 39 LOG(ERROR) << "Error creating EGLImage: " << error; |
| 40 return false; | 40 return false; |
| 41 } | 41 } |
| 42 | 42 |
| 43 return true; | 43 return true; |
| 44 } | 44 } |
| 45 | 45 |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 73 return false; | 73 return false; |
| 74 } | 74 } |
| 75 | 75 |
| 76 if (target_ && target_ != target) { | 76 if (target_ && target_ != target) { |
| 77 LOG(ERROR) << "EGLImage can only be bound to one target"; | 77 LOG(ERROR) << "EGLImage can only be bound to one target"; |
| 78 return false; | 78 return false; |
| 79 } | 79 } |
| 80 target_ = target; | 80 target_ = target; |
| 81 | 81 |
| 82 // Defer ImageTargetTexture2D if not currently in use. | 82 // Defer ImageTargetTexture2D if not currently in use. |
| 83 if (!in_use_) | 83 /*if (!in_use_) { |
| 84 return true; | 84 return true; |
| 85 }*/ | |
| 85 | 86 |
| 86 glEGLImageTargetTexture2DOES(target_, egl_image_); | 87 glEGLImageTargetTexture2DOES(target_, egl_image_); |
| 87 DCHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); | 88 DCHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
| 88 return true; | 89 return true; |
| 89 } | 90 } |
| 90 | 91 |
| 91 void GLImageEGL::ReleaseTexImage(unsigned target) { | 92 void GLImageEGL::ReleaseTexImage(unsigned target) { |
| 92 // Nothing to do here as image is released after each use or there is no need | 93 // Nothing to do here as image is released after each use or there is no need |
| 93 // to release image. | 94 // to release image. |
| 94 } | 95 } |
| 95 | 96 |
| 96 void GLImageEGL::WillUseTexImage() { | 97 void GLImageEGL::WillUseTexImage() { |
| 97 DCHECK(egl_image_); | 98 /*DCHECK(egl_image_); |
|
rjkroege
2014/01/10 19:14:04
you've had to remove this because the surfaces in
| |
| 98 DCHECK(!in_use_); | 99 //DCHECK(!in_use_); |
| 99 in_use_ = true; | 100 in_use_ = true; |
| 100 glEGLImageTargetTexture2DOES(target_, egl_image_); | 101 glEGLImageTargetTexture2DOES(target_, egl_image_); |
| 101 DCHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); | 102 DCHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());*/ |
| 102 } | 103 } |
| 103 | 104 |
| 104 void GLImageEGL::DidUseTexImage() { | 105 void GLImageEGL::DidUseTexImage() { |
| 105 DCHECK(in_use_); | 106 // DCHECK(in_use_); |
| 106 in_use_ = false; | 107 /*in_use_ = false; |
| 107 | 108 |
| 108 if (!release_after_use_) | 109 if (!release_after_use_) |
| 109 return; | 110 return; |
| 110 | 111 |
| 111 char zero[4] = { 0, }; | 112 char zero[4] = { 0, }; |
| 112 glTexImage2D(target_, | 113 glTexImage2D(target_, |
| 113 0, | 114 0, |
| 114 GL_RGBA, | 115 GL_RGBA, |
| 115 1, | 116 1, |
| 116 1, | 117 1, |
| 117 0, | 118 0, |
| 118 GL_RGBA, | 119 GL_RGBA, |
| 119 GL_UNSIGNED_BYTE, | 120 GL_UNSIGNED_BYTE, |
| 120 &zero); | 121 &zero);*/ |
| 121 } | 122 } |
| 122 | 123 |
| 123 void GLImageEGL::SetReleaseAfterUse() { | 124 void GLImageEGL::SetReleaseAfterUse() { |
| 124 release_after_use_ = true; | 125 release_after_use_ = true; |
| 125 } | 126 } |
| 126 | 127 |
| 127 } // namespace gfx | 128 } // namespace gfx |
| OLD | NEW |