| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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_io_surface.h" | 5 #include "ui/gl/gl_image_io_surface.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 | 8 |
| 9 #include "base/callback_helpers.h" | 9 #include "base/callback_helpers.h" |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 return true; | 98 return true; |
| 99 default: | 99 default: |
| 100 return false; | 100 return false; |
| 101 } | 101 } |
| 102 } | 102 } |
| 103 | 103 |
| 104 bool ValidFormat(BufferFormat format) { | 104 bool ValidFormat(BufferFormat format) { |
| 105 switch (format) { | 105 switch (format) { |
| 106 case BufferFormat::R_8: | 106 case BufferFormat::R_8: |
| 107 case BufferFormat::BGRA_8888: | 107 case BufferFormat::BGRA_8888: |
| 108 case BufferFormat::BGRX_8888: |
| 108 case BufferFormat::RGBA_8888: | 109 case BufferFormat::RGBA_8888: |
| 109 case BufferFormat::UYVY_422: | 110 case BufferFormat::UYVY_422: |
| 110 case BufferFormat::YUV_420_BIPLANAR: | 111 case BufferFormat::YUV_420_BIPLANAR: |
| 111 return true; | 112 return true; |
| 112 case BufferFormat::ATC: | 113 case BufferFormat::ATC: |
| 113 case BufferFormat::ATCIA: | 114 case BufferFormat::ATCIA: |
| 114 case BufferFormat::DXT1: | 115 case BufferFormat::DXT1: |
| 115 case BufferFormat::DXT5: | 116 case BufferFormat::DXT5: |
| 116 case BufferFormat::ETC1: | 117 case BufferFormat::ETC1: |
| 117 case BufferFormat::RGBA_4444: | 118 case BufferFormat::RGBA_4444: |
| 118 case BufferFormat::RGBX_8888: | 119 case BufferFormat::RGBX_8888: |
| 119 case BufferFormat::BGRX_8888: | |
| 120 case BufferFormat::YUV_420: | 120 case BufferFormat::YUV_420: |
| 121 return false; | 121 return false; |
| 122 } | 122 } |
| 123 | 123 |
| 124 NOTREACHED(); | 124 NOTREACHED(); |
| 125 return false; | 125 return false; |
| 126 } | 126 } |
| 127 | 127 |
| 128 GLenum TextureFormat(BufferFormat format) { | 128 GLenum TextureFormat(BufferFormat format) { |
| 129 switch (format) { | 129 switch (format) { |
| 130 case BufferFormat::R_8: | 130 case BufferFormat::R_8: |
| 131 return GL_RED; | 131 return GL_RED; |
| 132 case BufferFormat::BGRA_8888: | 132 case BufferFormat::BGRA_8888: |
| 133 case BufferFormat::BGRX_8888: |
| 133 case BufferFormat::RGBA_8888: | 134 case BufferFormat::RGBA_8888: |
| 134 return GL_RGBA; | 135 return GL_RGBA; |
| 135 case BufferFormat::UYVY_422: | 136 case BufferFormat::UYVY_422: |
| 136 return GL_RGB; | 137 return GL_RGB; |
| 137 case BufferFormat::YUV_420_BIPLANAR: | 138 case BufferFormat::YUV_420_BIPLANAR: |
| 138 return GL_RGB_YCBCR_420V_CHROMIUM; | 139 return GL_RGB_YCBCR_420V_CHROMIUM; |
| 139 case BufferFormat::ATC: | 140 case BufferFormat::ATC: |
| 140 case BufferFormat::ATCIA: | 141 case BufferFormat::ATCIA: |
| 141 case BufferFormat::DXT1: | 142 case BufferFormat::DXT1: |
| 142 case BufferFormat::DXT5: | 143 case BufferFormat::DXT5: |
| 143 case BufferFormat::ETC1: | 144 case BufferFormat::ETC1: |
| 144 case BufferFormat::RGBA_4444: | 145 case BufferFormat::RGBA_4444: |
| 145 case BufferFormat::RGBX_8888: | 146 case BufferFormat::RGBX_8888: |
| 146 case BufferFormat::BGRX_8888: | |
| 147 case BufferFormat::YUV_420: | 147 case BufferFormat::YUV_420: |
| 148 NOTREACHED(); | 148 NOTREACHED(); |
| 149 return 0; | 149 return 0; |
| 150 } | 150 } |
| 151 | 151 |
| 152 NOTREACHED(); | 152 NOTREACHED(); |
| 153 return 0; | 153 return 0; |
| 154 } | 154 } |
| 155 | 155 |
| 156 GLenum DataFormat(BufferFormat format) { | 156 GLenum DataFormat(BufferFormat format) { |
| 157 switch (format) { | 157 switch (format) { |
| 158 case BufferFormat::R_8: | 158 case BufferFormat::R_8: |
| 159 return GL_RED; | 159 return GL_RED; |
| 160 case BufferFormat::BGRA_8888: | 160 case BufferFormat::BGRA_8888: |
| 161 case BufferFormat::BGRX_8888: |
| 161 case BufferFormat::RGBA_8888: | 162 case BufferFormat::RGBA_8888: |
| 162 return GL_BGRA; | 163 return GL_BGRA; |
| 163 case BufferFormat::UYVY_422: | 164 case BufferFormat::UYVY_422: |
| 164 return GL_YCBCR_422_APPLE; | 165 return GL_YCBCR_422_APPLE; |
| 165 case BufferFormat::ATC: | 166 case BufferFormat::ATC: |
| 166 case BufferFormat::ATCIA: | 167 case BufferFormat::ATCIA: |
| 167 case BufferFormat::DXT1: | 168 case BufferFormat::DXT1: |
| 168 case BufferFormat::DXT5: | 169 case BufferFormat::DXT5: |
| 169 case BufferFormat::ETC1: | 170 case BufferFormat::ETC1: |
| 170 case BufferFormat::RGBA_4444: | 171 case BufferFormat::RGBA_4444: |
| 171 case BufferFormat::RGBX_8888: | 172 case BufferFormat::RGBX_8888: |
| 172 case BufferFormat::BGRX_8888: | |
| 173 case BufferFormat::YUV_420: | 173 case BufferFormat::YUV_420: |
| 174 case BufferFormat::YUV_420_BIPLANAR: | 174 case BufferFormat::YUV_420_BIPLANAR: |
| 175 NOTREACHED(); | 175 NOTREACHED(); |
| 176 return 0; | 176 return 0; |
| 177 } | 177 } |
| 178 | 178 |
| 179 NOTREACHED(); | 179 NOTREACHED(); |
| 180 return 0; | 180 return 0; |
| 181 } | 181 } |
| 182 | 182 |
| 183 GLenum DataType(BufferFormat format) { | 183 GLenum DataType(BufferFormat format) { |
| 184 switch (format) { | 184 switch (format) { |
| 185 case BufferFormat::R_8: | 185 case BufferFormat::R_8: |
| 186 return GL_UNSIGNED_BYTE; | 186 return GL_UNSIGNED_BYTE; |
| 187 case BufferFormat::BGRA_8888: | 187 case BufferFormat::BGRA_8888: |
| 188 case BufferFormat::BGRX_8888: |
| 188 case BufferFormat::RGBA_8888: | 189 case BufferFormat::RGBA_8888: |
| 189 return GL_UNSIGNED_INT_8_8_8_8_REV; | 190 return GL_UNSIGNED_INT_8_8_8_8_REV; |
| 190 case BufferFormat::UYVY_422: | 191 case BufferFormat::UYVY_422: |
| 191 return GL_UNSIGNED_SHORT_8_8_APPLE; | 192 return GL_UNSIGNED_SHORT_8_8_APPLE; |
| 192 break; | 193 break; |
| 193 case BufferFormat::ATC: | 194 case BufferFormat::ATC: |
| 194 case BufferFormat::ATCIA: | 195 case BufferFormat::ATCIA: |
| 195 case BufferFormat::DXT1: | 196 case BufferFormat::DXT1: |
| 196 case BufferFormat::DXT5: | 197 case BufferFormat::DXT5: |
| 197 case BufferFormat::ETC1: | 198 case BufferFormat::ETC1: |
| 198 case BufferFormat::RGBA_4444: | 199 case BufferFormat::RGBA_4444: |
| 199 case BufferFormat::RGBX_8888: | 200 case BufferFormat::RGBX_8888: |
| 200 case BufferFormat::BGRX_8888: | |
| 201 case BufferFormat::YUV_420: | 201 case BufferFormat::YUV_420: |
| 202 case BufferFormat::YUV_420_BIPLANAR: | 202 case BufferFormat::YUV_420_BIPLANAR: |
| 203 NOTREACHED(); | 203 NOTREACHED(); |
| 204 return 0; | 204 return 0; |
| 205 } | 205 } |
| 206 | 206 |
| 207 NOTREACHED(); | 207 NOTREACHED(); |
| 208 return 0; | 208 return 0; |
| 209 } | 209 } |
| 210 | 210 |
| 211 // When an IOSurface is bound to a texture with internalformat "GL_RGB", many |
| 212 // OpenGL operations are broken. Therefore, never allow an IOSurface to be bound |
| 213 // with GL_RGB. https://crbug.com/595948. |
| 214 GLenum ConvertRequestedInternalFormat(GLenum internalformat) { |
| 215 if (internalformat == GL_RGB) |
| 216 return GL_RGBA; |
| 217 return internalformat; |
| 218 } |
| 219 |
| 211 } // namespace | 220 } // namespace |
| 212 | 221 |
| 213 class GLImageIOSurface::RGBConverter | 222 class GLImageIOSurface::RGBConverter |
| 214 : public base::RefCounted<GLImageIOSurface::RGBConverter> { | 223 : public base::RefCounted<GLImageIOSurface::RGBConverter> { |
| 215 public: | 224 public: |
| 216 static scoped_refptr<RGBConverter> GetForCurrentContext(); | 225 static scoped_refptr<RGBConverter> GetForCurrentContext(); |
| 217 bool CopyTexImage(IOSurfaceRef io_surface, const gfx::Size& size); | 226 bool CopyTexImage(IOSurfaceRef io_surface, const gfx::Size& size); |
| 218 | 227 |
| 219 private: | 228 private: |
| 220 friend class base::RefCounted<RGBConverter>; | 229 friend class base::RefCounted<RGBConverter>; |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 glUniform2f(size_location_, size.width(), size.height()); | 385 glUniform2f(size_location_, size.width(), size.height()); |
| 377 gfx::GLHelper::DrawQuad(vertex_buffer_); | 386 gfx::GLHelper::DrawQuad(vertex_buffer_); |
| 378 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, | 387 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, |
| 379 GL_TEXTURE_RECTANGLE_ARB, 0, 0); | 388 GL_TEXTURE_RECTANGLE_ARB, 0, 0); |
| 380 return true; | 389 return true; |
| 381 } | 390 } |
| 382 | 391 |
| 383 GLImageIOSurface::GLImageIOSurface(const gfx::Size& size, | 392 GLImageIOSurface::GLImageIOSurface(const gfx::Size& size, |
| 384 unsigned internalformat) | 393 unsigned internalformat) |
| 385 : size_(size), | 394 : size_(size), |
| 386 internalformat_(internalformat), | 395 internalformat_(ConvertRequestedInternalFormat(internalformat)), |
| 396 client_internalformat_(internalformat), |
| 387 format_(BufferFormat::RGBA_8888) {} | 397 format_(BufferFormat::RGBA_8888) {} |
| 388 | 398 |
| 389 GLImageIOSurface::~GLImageIOSurface() { | 399 GLImageIOSurface::~GLImageIOSurface() { |
| 390 DCHECK(thread_checker_.CalledOnValidThread()); | 400 DCHECK(thread_checker_.CalledOnValidThread()); |
| 391 DCHECK(!io_surface_); | 401 DCHECK(!io_surface_); |
| 392 } | 402 } |
| 393 | 403 |
| 394 bool GLImageIOSurface::Initialize(IOSurfaceRef io_surface, | 404 bool GLImageIOSurface::Initialize(IOSurfaceRef io_surface, |
| 395 gfx::GenericSharedMemoryId io_surface_id, | 405 gfx::GenericSharedMemoryId io_surface_id, |
| 396 BufferFormat format) { | 406 BufferFormat format) { |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 518 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, | 528 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, |
| 519 base::trace_event::MemoryAllocatorDump::kUnitsBytes, | 529 base::trace_event::MemoryAllocatorDump::kUnitsBytes, |
| 520 static_cast<uint64_t>(size_bytes)); | 530 static_cast<uint64_t>(size_bytes)); |
| 521 | 531 |
| 522 auto guid = | 532 auto guid = |
| 523 GetGenericSharedMemoryGUIDForTracing(process_tracing_id, io_surface_id_); | 533 GetGenericSharedMemoryGUIDForTracing(process_tracing_id, io_surface_id_); |
| 524 pmd->CreateSharedGlobalAllocatorDump(guid); | 534 pmd->CreateSharedGlobalAllocatorDump(guid); |
| 525 pmd->AddOwnershipEdge(dump->guid(), guid); | 535 pmd->AddOwnershipEdge(dump->guid(), guid); |
| 526 } | 536 } |
| 527 | 537 |
| 538 bool GLImageIOSurface::EmulatingRGB() const { |
| 539 return client_internalformat_ == GL_RGB; |
| 540 } |
| 541 |
| 528 base::ScopedCFTypeRef<IOSurfaceRef> GLImageIOSurface::io_surface() { | 542 base::ScopedCFTypeRef<IOSurfaceRef> GLImageIOSurface::io_surface() { |
| 529 return io_surface_; | 543 return io_surface_; |
| 530 } | 544 } |
| 531 | 545 |
| 532 base::ScopedCFTypeRef<CVPixelBufferRef> GLImageIOSurface::cv_pixel_buffer() { | 546 base::ScopedCFTypeRef<CVPixelBufferRef> GLImageIOSurface::cv_pixel_buffer() { |
| 533 return cv_pixel_buffer_; | 547 return cv_pixel_buffer_; |
| 534 } | 548 } |
| 535 | 549 |
| 536 // static | 550 // static |
| 537 unsigned GLImageIOSurface::GetInternalFormatForTesting( | 551 unsigned GLImageIOSurface::GetInternalFormatForTesting( |
| 538 gfx::BufferFormat format) { | 552 gfx::BufferFormat format) { |
| 539 DCHECK(ValidFormat(format)); | 553 DCHECK(ValidFormat(format)); |
| 540 return TextureFormat(format); | 554 return TextureFormat(format); |
| 541 } | 555 } |
| 542 } // namespace gl | 556 } // namespace gl |
| OLD | NEW |