| 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_memory.h" | 5 #include "ui/gl/gl_image_memory.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/trace_event/trace_event.h" | 8 #include "base/trace_event/trace_event.h" |
| 9 #include "ui/gl/gl_bindings.h" | 9 #include "ui/gl/gl_bindings.h" |
| 10 #include "ui/gl/gl_surface_egl.h" |
| 10 #include "ui/gl/scoped_binders.h" | 11 #include "ui/gl/scoped_binders.h" |
| 11 | 12 |
| 12 #if defined(OS_WIN) || defined(USE_X11) || defined(OS_ANDROID) || \ | |
| 13 defined(USE_OZONE) | |
| 14 #include "ui/gl/gl_surface_egl.h" | |
| 15 #endif | |
| 16 | |
| 17 namespace gfx { | 13 namespace gfx { |
| 18 namespace { | 14 namespace { |
| 19 | 15 |
| 20 bool ValidInternalFormat(unsigned internalformat) { | 16 bool ValidInternalFormat(unsigned internalformat) { |
| 21 switch (internalformat) { | 17 switch (internalformat) { |
| 22 case GL_RGBA: | 18 case GL_RGBA: |
| 23 return true; | 19 return true; |
| 24 default: | 20 default: |
| 25 return false; | 21 return false; |
| 26 } | 22 } |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 | 117 |
| 122 } // namespace | 118 } // namespace |
| 123 | 119 |
| 124 GLImageMemory::GLImageMemory(const gfx::Size& size, unsigned internalformat) | 120 GLImageMemory::GLImageMemory(const gfx::Size& size, unsigned internalformat) |
| 125 : size_(size), | 121 : size_(size), |
| 126 internalformat_(internalformat), | 122 internalformat_(internalformat), |
| 127 memory_(NULL), | 123 memory_(NULL), |
| 128 format_(gfx::GpuMemoryBuffer::RGBA_8888), | 124 format_(gfx::GpuMemoryBuffer::RGBA_8888), |
| 129 in_use_(false), | 125 in_use_(false), |
| 130 target_(0), | 126 target_(0), |
| 131 need_do_bind_tex_image_(false) | 127 need_do_bind_tex_image_(false), |
| 132 #if defined(OS_WIN) || defined(USE_X11) || defined(OS_ANDROID) || \ | |
| 133 defined(USE_OZONE) | |
| 134 , | |
| 135 egl_texture_id_(0u), | 128 egl_texture_id_(0u), |
| 136 egl_image_(EGL_NO_IMAGE_KHR) | 129 egl_image_(EGL_NO_IMAGE_KHR) { |
| 137 #endif | |
| 138 { | |
| 139 } | 130 } |
| 140 | 131 |
| 141 GLImageMemory::~GLImageMemory() { | 132 GLImageMemory::~GLImageMemory() { |
| 142 #if defined(OS_WIN) || defined(USE_X11) || defined(OS_ANDROID) || \ | |
| 143 defined(USE_OZONE) | |
| 144 DCHECK_EQ(EGL_NO_IMAGE_KHR, egl_image_); | 133 DCHECK_EQ(EGL_NO_IMAGE_KHR, egl_image_); |
| 145 DCHECK_EQ(0u, egl_texture_id_); | 134 DCHECK_EQ(0u, egl_texture_id_); |
| 146 #endif | |
| 147 } | 135 } |
| 148 | 136 |
| 149 // static | 137 // static |
| 150 bool GLImageMemory::StrideInBytes(size_t width, | 138 bool GLImageMemory::StrideInBytes(size_t width, |
| 151 gfx::GpuMemoryBuffer::Format format, | 139 gfx::GpuMemoryBuffer::Format format, |
| 152 size_t* stride_in_bytes) { | 140 size_t* stride_in_bytes) { |
| 153 base::CheckedNumeric<size_t> s = width; | 141 base::CheckedNumeric<size_t> s = width; |
| 154 switch (format) { | 142 switch (format) { |
| 155 case gfx::GpuMemoryBuffer::ATCIA: | 143 case gfx::GpuMemoryBuffer::ATCIA: |
| 156 case gfx::GpuMemoryBuffer::DXT5: | 144 case gfx::GpuMemoryBuffer::DXT5: |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 DCHECK(memory); | 186 DCHECK(memory); |
| 199 DCHECK(!memory_); | 187 DCHECK(!memory_); |
| 200 DCHECK_IMPLIES(IsCompressedFormat(format), size_.width() % 4 == 0); | 188 DCHECK_IMPLIES(IsCompressedFormat(format), size_.width() % 4 == 0); |
| 201 DCHECK_IMPLIES(IsCompressedFormat(format), size_.height() % 4 == 0); | 189 DCHECK_IMPLIES(IsCompressedFormat(format), size_.height() % 4 == 0); |
| 202 memory_ = memory; | 190 memory_ = memory; |
| 203 format_ = format; | 191 format_ = format; |
| 204 return true; | 192 return true; |
| 205 } | 193 } |
| 206 | 194 |
| 207 void GLImageMemory::Destroy(bool have_context) { | 195 void GLImageMemory::Destroy(bool have_context) { |
| 208 #if defined(OS_WIN) || defined(USE_X11) || defined(OS_ANDROID) || \ | |
| 209 defined(USE_OZONE) | |
| 210 if (egl_image_ != EGL_NO_IMAGE_KHR) { | 196 if (egl_image_ != EGL_NO_IMAGE_KHR) { |
| 211 eglDestroyImageKHR(GLSurfaceEGL::GetHardwareDisplay(), egl_image_); | 197 eglDestroyImageKHR(GLSurfaceEGL::GetHardwareDisplay(), egl_image_); |
| 212 egl_image_ = EGL_NO_IMAGE_KHR; | 198 egl_image_ = EGL_NO_IMAGE_KHR; |
| 213 } | 199 } |
| 214 | 200 |
| 215 if (egl_texture_id_) { | 201 if (egl_texture_id_) { |
| 216 if (have_context) | 202 if (have_context) |
| 217 glDeleteTextures(1, &egl_texture_id_); | 203 glDeleteTextures(1, &egl_texture_id_); |
| 218 egl_texture_id_ = 0u; | 204 egl_texture_id_ = 0u; |
| 219 } | 205 } |
| 220 #endif | |
| 221 memory_ = NULL; | 206 memory_ = NULL; |
| 222 } | 207 } |
| 223 | 208 |
| 224 gfx::Size GLImageMemory::GetSize() { | 209 gfx::Size GLImageMemory::GetSize() { |
| 225 return size_; | 210 return size_; |
| 226 } | 211 } |
| 227 | 212 |
| 228 bool GLImageMemory::BindTexImage(unsigned target) { | 213 bool GLImageMemory::BindTexImage(unsigned target) { |
| 229 if (target_ && target_ != target) { | 214 if (target_ && target_ != target) { |
| 230 LOG(ERROR) << "GLImage can only be bound to one target"; | 215 LOG(ERROR) << "GLImage can only be bound to one target"; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 return false; | 278 return false; |
| 294 } | 279 } |
| 295 | 280 |
| 296 void GLImageMemory::DoBindTexImage(unsigned target) { | 281 void GLImageMemory::DoBindTexImage(unsigned target) { |
| 297 TRACE_EVENT0("gpu", "GLImageMemory::DoBindTexImage"); | 282 TRACE_EVENT0("gpu", "GLImageMemory::DoBindTexImage"); |
| 298 | 283 |
| 299 DCHECK(need_do_bind_tex_image_); | 284 DCHECK(need_do_bind_tex_image_); |
| 300 need_do_bind_tex_image_ = false; | 285 need_do_bind_tex_image_ = false; |
| 301 | 286 |
| 302 DCHECK(memory_); | 287 DCHECK(memory_); |
| 303 #if defined(OS_WIN) || defined(USE_X11) || defined(OS_ANDROID) || \ | |
| 304 defined(USE_OZONE) | |
| 305 if (target == GL_TEXTURE_EXTERNAL_OES) { | 288 if (target == GL_TEXTURE_EXTERNAL_OES) { |
| 306 if (egl_image_ == EGL_NO_IMAGE_KHR) { | 289 if (egl_image_ == EGL_NO_IMAGE_KHR) { |
| 307 DCHECK_EQ(0u, egl_texture_id_); | 290 DCHECK_EQ(0u, egl_texture_id_); |
| 308 glGenTextures(1, &egl_texture_id_); | 291 glGenTextures(1, &egl_texture_id_); |
| 309 | 292 |
| 310 { | 293 { |
| 311 ScopedTextureBinder texture_binder(GL_TEXTURE_2D, egl_texture_id_); | 294 ScopedTextureBinder texture_binder(GL_TEXTURE_2D, egl_texture_id_); |
| 312 | 295 |
| 313 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | 296 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 314 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 297 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 DataFormat(format_), | 349 DataFormat(format_), |
| 367 DataType(format_), | 350 DataType(format_), |
| 368 memory_); | 351 memory_); |
| 369 } | 352 } |
| 370 } | 353 } |
| 371 | 354 |
| 372 glEGLImageTargetTexture2DOES(target, egl_image_); | 355 glEGLImageTargetTexture2DOES(target, egl_image_); |
| 373 DCHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); | 356 DCHECK_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError()); |
| 374 return; | 357 return; |
| 375 } | 358 } |
| 376 #endif | |
| 377 | 359 |
| 378 DCHECK_NE(static_cast<GLenum>(GL_TEXTURE_EXTERNAL_OES), target); | 360 DCHECK_NE(static_cast<GLenum>(GL_TEXTURE_EXTERNAL_OES), target); |
| 379 if (IsCompressedFormat(format_)) { | 361 if (IsCompressedFormat(format_)) { |
| 380 glCompressedTexImage2D(target, | 362 glCompressedTexImage2D(target, |
| 381 0, // mip level | 363 0, // mip level |
| 382 TextureFormat(format_), size_.width(), | 364 TextureFormat(format_), size_.width(), |
| 383 size_.height(), | 365 size_.height(), |
| 384 0, // border | 366 0, // border |
| 385 SizeInBytes(size_, format_), memory_); | 367 SizeInBytes(size_, format_), memory_); |
| 386 } else { | 368 } else { |
| 387 glTexImage2D(target, | 369 glTexImage2D(target, |
| 388 0, // mip level | 370 0, // mip level |
| 389 TextureFormat(format_), | 371 TextureFormat(format_), |
| 390 size_.width(), | 372 size_.width(), |
| 391 size_.height(), | 373 size_.height(), |
| 392 0, // border | 374 0, // border |
| 393 DataFormat(format_), | 375 DataFormat(format_), |
| 394 DataType(format_), | 376 DataType(format_), |
| 395 memory_); | 377 memory_); |
| 396 } | 378 } |
| 397 } | 379 } |
| 398 | 380 |
| 399 } // namespace gfx | 381 } // namespace gfx |
| OLD | NEW |