Chromium Code Reviews| 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/scoped_binders.h" | 10 #include "ui/gl/scoped_binders.h" |
| 11 | 11 |
| 12 #if defined(OS_WIN) || defined(USE_X11) || defined(OS_ANDROID) || \ | 12 #if defined(OS_WIN) || defined(USE_X11) || defined(OS_ANDROID) || \ |
| 13 defined(USE_OZONE) | 13 defined(USE_OZONE) |
| 14 #include "ui/gl/gl_surface_egl.h" | 14 #include "ui/gl/gl_surface_egl.h" |
| 15 #endif | 15 #endif |
| 16 | 16 |
| 17 namespace gfx { | 17 namespace gfx { |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 20 bool ValidInternalFormat(unsigned internalformat) { | 20 bool ValidInternalFormat(unsigned internalformat) { |
| 21 switch (internalformat) { | 21 switch (internalformat) { |
| 22 case GL_R8: | |
| 22 case GL_RGBA: | 23 case GL_RGBA: |
| 23 case GL_BGRA_EXT: | 24 case GL_BGRA_EXT: |
| 24 return true; | 25 return true; |
| 25 default: | 26 default: |
| 26 return false; | 27 return false; |
| 27 } | 28 } |
| 28 } | 29 } |
| 29 | 30 |
| 30 bool ValidFormat(gfx::GpuMemoryBuffer::Format format) { | 31 bool ValidFormat(gfx::GpuMemoryBuffer::Format format) { |
| 31 switch (format) { | 32 switch (format) { |
| 32 case gfx::GpuMemoryBuffer::ATC: | 33 case gfx::GpuMemoryBuffer::ATC: |
| 33 case gfx::GpuMemoryBuffer::ATCIA: | 34 case gfx::GpuMemoryBuffer::ATCIA: |
| 34 case gfx::GpuMemoryBuffer::DXT1: | 35 case gfx::GpuMemoryBuffer::DXT1: |
| 35 case gfx::GpuMemoryBuffer::DXT5: | 36 case gfx::GpuMemoryBuffer::DXT5: |
| 36 case gfx::GpuMemoryBuffer::ETC1: | 37 case gfx::GpuMemoryBuffer::ETC1: |
| 38 case gfx::GpuMemoryBuffer::R_8: | |
| 37 case gfx::GpuMemoryBuffer::RGBA_8888: | 39 case gfx::GpuMemoryBuffer::RGBA_8888: |
| 38 case gfx::GpuMemoryBuffer::BGRA_8888: | 40 case gfx::GpuMemoryBuffer::BGRA_8888: |
| 39 return true; | 41 return true; |
| 40 case gfx::GpuMemoryBuffer::RGBX_8888: | 42 case gfx::GpuMemoryBuffer::RGBX_8888: |
| 41 return false; | 43 return false; |
| 42 } | 44 } |
| 43 | 45 |
| 44 NOTREACHED(); | 46 NOTREACHED(); |
| 45 return false; | 47 return false; |
| 46 } | 48 } |
| 47 | 49 |
| 48 bool IsCompressedFormat(gfx::GpuMemoryBuffer::Format format) { | 50 bool IsCompressedFormat(gfx::GpuMemoryBuffer::Format format) { |
| 49 switch (format) { | 51 switch (format) { |
| 50 case gfx::GpuMemoryBuffer::ATC: | 52 case gfx::GpuMemoryBuffer::ATC: |
| 51 case gfx::GpuMemoryBuffer::ATCIA: | 53 case gfx::GpuMemoryBuffer::ATCIA: |
| 52 case gfx::GpuMemoryBuffer::DXT1: | 54 case gfx::GpuMemoryBuffer::DXT1: |
| 53 case gfx::GpuMemoryBuffer::DXT5: | 55 case gfx::GpuMemoryBuffer::DXT5: |
| 54 case gfx::GpuMemoryBuffer::ETC1: | 56 case gfx::GpuMemoryBuffer::ETC1: |
| 55 return true; | 57 return true; |
| 58 case gfx::GpuMemoryBuffer::R_8: | |
| 56 case gfx::GpuMemoryBuffer::RGBA_8888: | 59 case gfx::GpuMemoryBuffer::RGBA_8888: |
| 57 case gfx::GpuMemoryBuffer::BGRA_8888: | 60 case gfx::GpuMemoryBuffer::BGRA_8888: |
| 58 case gfx::GpuMemoryBuffer::RGBX_8888: | 61 case gfx::GpuMemoryBuffer::RGBX_8888: |
| 59 return false; | 62 return false; |
| 60 } | 63 } |
| 61 | 64 |
| 62 NOTREACHED(); | 65 NOTREACHED(); |
| 63 return false; | 66 return false; |
| 64 } | 67 } |
| 65 | 68 |
| 66 GLenum TextureFormat(gfx::GpuMemoryBuffer::Format format) { | 69 GLenum TextureFormat(gfx::GpuMemoryBuffer::Format format) { |
| 67 switch (format) { | 70 switch (format) { |
| 68 case gfx::GpuMemoryBuffer::ATC: | 71 case gfx::GpuMemoryBuffer::ATC: |
| 69 return GL_ATC_RGB_AMD; | 72 return GL_ATC_RGB_AMD; |
| 70 case gfx::GpuMemoryBuffer::ATCIA: | 73 case gfx::GpuMemoryBuffer::ATCIA: |
| 71 return GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD; | 74 return GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD; |
| 72 case gfx::GpuMemoryBuffer::DXT1: | 75 case gfx::GpuMemoryBuffer::DXT1: |
| 73 return GL_COMPRESSED_RGB_S3TC_DXT1_EXT; | 76 return GL_COMPRESSED_RGB_S3TC_DXT1_EXT; |
| 74 case gfx::GpuMemoryBuffer::DXT5: | 77 case gfx::GpuMemoryBuffer::DXT5: |
| 75 return GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; | 78 return GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; |
| 76 case gfx::GpuMemoryBuffer::ETC1: | 79 case gfx::GpuMemoryBuffer::ETC1: |
| 77 return GL_ETC1_RGB8_OES; | 80 return GL_ETC1_RGB8_OES; |
| 81 case gfx::GpuMemoryBuffer::R_8: | |
| 82 return GL_RED; | |
| 78 case gfx::GpuMemoryBuffer::RGBA_8888: | 83 case gfx::GpuMemoryBuffer::RGBA_8888: |
| 79 return GL_RGBA; | 84 return GL_RGBA; |
| 80 case gfx::GpuMemoryBuffer::BGRA_8888: | 85 case gfx::GpuMemoryBuffer::BGRA_8888: |
| 81 return GL_BGRA_EXT; | 86 return GL_BGRA_EXT; |
| 82 case gfx::GpuMemoryBuffer::RGBX_8888: | 87 case gfx::GpuMemoryBuffer::RGBX_8888: |
| 83 NOTREACHED(); | 88 NOTREACHED(); |
| 84 return 0; | 89 return 0; |
| 85 } | 90 } |
| 86 | 91 |
| 87 NOTREACHED(); | 92 NOTREACHED(); |
| 88 return 0; | 93 return 0; |
| 89 } | 94 } |
| 90 | 95 |
| 91 GLenum DataFormat(gfx::GpuMemoryBuffer::Format format) { | 96 GLenum DataFormat(gfx::GpuMemoryBuffer::Format format) { |
| 92 return TextureFormat(format); | 97 return TextureFormat(format); |
| 93 } | 98 } |
| 94 | 99 |
| 95 GLenum DataType(gfx::GpuMemoryBuffer::Format format) { | 100 GLenum DataType(gfx::GpuMemoryBuffer::Format format) { |
| 96 switch (format) { | 101 switch (format) { |
| 97 case gfx::GpuMemoryBuffer::RGBA_8888: | 102 case gfx::GpuMemoryBuffer::RGBA_8888: |
| 98 case gfx::GpuMemoryBuffer::BGRA_8888: | 103 case gfx::GpuMemoryBuffer::BGRA_8888: |
| 104 case gfx::GpuMemoryBuffer::R_8: | |
| 99 return GL_UNSIGNED_BYTE; | 105 return GL_UNSIGNED_BYTE; |
| 100 case gfx::GpuMemoryBuffer::ATC: | 106 case gfx::GpuMemoryBuffer::ATC: |
| 101 case gfx::GpuMemoryBuffer::ATCIA: | 107 case gfx::GpuMemoryBuffer::ATCIA: |
| 102 case gfx::GpuMemoryBuffer::DXT1: | 108 case gfx::GpuMemoryBuffer::DXT1: |
| 103 case gfx::GpuMemoryBuffer::DXT5: | 109 case gfx::GpuMemoryBuffer::DXT5: |
| 104 case gfx::GpuMemoryBuffer::ETC1: | 110 case gfx::GpuMemoryBuffer::ETC1: |
| 105 case gfx::GpuMemoryBuffer::RGBX_8888: | 111 case gfx::GpuMemoryBuffer::RGBX_8888: |
| 106 NOTREACHED(); | 112 NOTREACHED(); |
| 107 return 0; | 113 return 0; |
| 108 } | 114 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 144 defined(USE_OZONE) | 150 defined(USE_OZONE) |
| 145 DCHECK_EQ(EGL_NO_IMAGE_KHR, egl_image_); | 151 DCHECK_EQ(EGL_NO_IMAGE_KHR, egl_image_); |
| 146 DCHECK_EQ(0u, egl_texture_id_); | 152 DCHECK_EQ(0u, egl_texture_id_); |
| 147 #endif | 153 #endif |
| 148 } | 154 } |
| 149 | 155 |
| 150 // static | 156 // static |
| 151 bool GLImageMemory::StrideInBytes(size_t width, | 157 bool GLImageMemory::StrideInBytes(size_t width, |
| 152 gfx::GpuMemoryBuffer::Format format, | 158 gfx::GpuMemoryBuffer::Format format, |
| 153 size_t* stride_in_bytes) { | 159 size_t* stride_in_bytes) { |
| 154 base::CheckedNumeric<size_t> s = width; | 160 base::CheckedNumeric<size_t> checked_stride = width; |
| 155 switch (format) { | 161 switch (format) { |
| 156 case gfx::GpuMemoryBuffer::ATCIA: | 162 case GpuMemoryBuffer::R_8: |
|
reveman
2015/04/07 23:28:03
nit: I prefer if you save gfx:: prefix removal to
Daniele Castagna
2015/04/08 01:00:28
Done.
| |
| 157 case gfx::GpuMemoryBuffer::DXT5: | 163 checked_stride += 3; |
| 164 if (!checked_stride.IsValid()) | |
| 165 return false; | |
| 166 *stride_in_bytes = checked_stride.ValueOrDie() & ~0x3; | |
| 167 return true; | |
| 168 case GpuMemoryBuffer::ATCIA: | |
| 169 case GpuMemoryBuffer::DXT5: | |
| 158 *stride_in_bytes = width; | 170 *stride_in_bytes = width; |
| 159 return true; | 171 return true; |
| 160 case gfx::GpuMemoryBuffer::ATC: | 172 case GpuMemoryBuffer::ATC: |
| 161 case gfx::GpuMemoryBuffer::DXT1: | 173 case GpuMemoryBuffer::DXT1: |
| 162 case gfx::GpuMemoryBuffer::ETC1: | 174 case GpuMemoryBuffer::ETC1: |
| 163 DCHECK_EQ(width % 2, 0U); | 175 DCHECK_EQ(width % 2, 0u); |
| 164 s /= 2; | 176 *stride_in_bytes = width / 2; |
| 165 if (!s.IsValid()) | 177 return true; |
| 178 case GpuMemoryBuffer::RGBA_8888: | |
| 179 case GpuMemoryBuffer::RGBX_8888: | |
| 180 case GpuMemoryBuffer::BGRA_8888: | |
| 181 checked_stride *= 4; | |
| 182 if (!checked_stride.IsValid()) | |
| 166 return false; | 183 return false; |
| 167 | 184 *stride_in_bytes = checked_stride.ValueOrDie(); |
| 168 *stride_in_bytes = s.ValueOrDie(); | |
| 169 return true; | 185 return true; |
| 170 case gfx::GpuMemoryBuffer::RGBA_8888: | |
| 171 case gfx::GpuMemoryBuffer::BGRA_8888: | |
| 172 s *= 4; | |
| 173 if (!s.IsValid()) | |
| 174 return false; | |
| 175 | |
| 176 *stride_in_bytes = s.ValueOrDie(); | |
| 177 return true; | |
| 178 case gfx::GpuMemoryBuffer::RGBX_8888: | |
| 179 NOTREACHED(); | |
| 180 return false; | |
| 181 } | 186 } |
| 182 | |
| 183 NOTREACHED(); | 187 NOTREACHED(); |
| 184 return false; | 188 return false; |
| 185 } | 189 } |
| 186 | 190 |
| 187 bool GLImageMemory::Initialize(const unsigned char* memory, | 191 bool GLImageMemory::Initialize(const unsigned char* memory, |
| 188 gfx::GpuMemoryBuffer::Format format) { | 192 gfx::GpuMemoryBuffer::Format format) { |
| 189 if (!ValidInternalFormat(internalformat_)) { | 193 if (!ValidInternalFormat(internalformat_)) { |
| 190 LOG(ERROR) << "Invalid internalformat: " << internalformat_; | 194 LOG(ERROR) << "Invalid internalformat: " << internalformat_; |
| 191 return false; | 195 return false; |
| 192 } | 196 } |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 348 } else { | 352 } else { |
| 349 ScopedTextureBinder texture_binder(GL_TEXTURE_2D, egl_texture_id_); | 353 ScopedTextureBinder texture_binder(GL_TEXTURE_2D, egl_texture_id_); |
| 350 | 354 |
| 351 if (IsCompressedFormat(format_)) { | 355 if (IsCompressedFormat(format_)) { |
| 352 glCompressedTexSubImage2D(GL_TEXTURE_2D, | 356 glCompressedTexSubImage2D(GL_TEXTURE_2D, |
| 353 0, // mip level | 357 0, // mip level |
| 354 0, // x-offset | 358 0, // x-offset |
| 355 0, // y-offset | 359 0, // y-offset |
| 356 size_.width(), size_.height(), | 360 size_.width(), size_.height(), |
| 357 DataFormat(format_), | 361 DataFormat(format_), |
| 358 SizeInBytes(size_, format_), | 362 SizeInBytes(size_, format_), memory_); |
| 359 memory_); | |
| 360 } else { | 363 } else { |
| 361 glTexSubImage2D(GL_TEXTURE_2D, | 364 glTexSubImage2D(GL_TEXTURE_2D, |
| 362 0, // mip level | 365 0, // mip level |
| 363 0, // x-offset | 366 0, // x-offset |
| 364 0, // y-offset | 367 0, // y-offset |
| 365 size_.width(), | 368 size_.width(), |
| 366 size_.height(), | 369 size_.height(), |
| 367 DataFormat(format_), | 370 DataFormat(format_), |
| 368 DataType(format_), | 371 DataType(format_), |
| 369 memory_); | 372 memory_); |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 391 size_.width(), | 394 size_.width(), |
| 392 size_.height(), | 395 size_.height(), |
| 393 0, // border | 396 0, // border |
| 394 DataFormat(format_), | 397 DataFormat(format_), |
| 395 DataType(format_), | 398 DataType(format_), |
| 396 memory_); | 399 memory_); |
| 397 } | 400 } |
| 398 } | 401 } |
| 399 | 402 |
| 400 } // namespace gfx | 403 } // namespace gfx |
| OLD | NEW |