| 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/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/mac/foundation_util.h" | 10 #include "base/mac/foundation_util.h" |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 return true; | 77 return true; |
| 78 default: | 78 default: |
| 79 return false; | 79 return false; |
| 80 } | 80 } |
| 81 } | 81 } |
| 82 | 82 |
| 83 bool ValidFormat(BufferFormat format) { | 83 bool ValidFormat(BufferFormat format) { |
| 84 switch (format) { | 84 switch (format) { |
| 85 case BufferFormat::R_8: | 85 case BufferFormat::R_8: |
| 86 case BufferFormat::BGRA_8888: | 86 case BufferFormat::BGRA_8888: |
| 87 case BufferFormat::BGRX_8888: |
| 87 case BufferFormat::RGBA_8888: | 88 case BufferFormat::RGBA_8888: |
| 88 case BufferFormat::UYVY_422: | 89 case BufferFormat::UYVY_422: |
| 89 case BufferFormat::YUV_420_BIPLANAR: | 90 case BufferFormat::YUV_420_BIPLANAR: |
| 90 return true; | 91 return true; |
| 91 case BufferFormat::ATC: | 92 case BufferFormat::ATC: |
| 92 case BufferFormat::ATCIA: | 93 case BufferFormat::ATCIA: |
| 93 case BufferFormat::DXT1: | 94 case BufferFormat::DXT1: |
| 94 case BufferFormat::DXT5: | 95 case BufferFormat::DXT5: |
| 95 case BufferFormat::ETC1: | 96 case BufferFormat::ETC1: |
| 96 case BufferFormat::RGBA_4444: | 97 case BufferFormat::RGBA_4444: |
| 97 case BufferFormat::RGBX_8888: | 98 case BufferFormat::RGBX_8888: |
| 98 case BufferFormat::BGRX_8888: | |
| 99 case BufferFormat::YUV_420: | 99 case BufferFormat::YUV_420: |
| 100 return false; | 100 return false; |
| 101 } | 101 } |
| 102 | 102 |
| 103 NOTREACHED(); | 103 NOTREACHED(); |
| 104 return false; | 104 return false; |
| 105 } | 105 } |
| 106 | 106 |
| 107 GLenum TextureFormat(BufferFormat format) { | 107 GLenum TextureFormat(BufferFormat format) { |
| 108 switch (format) { | 108 switch (format) { |
| 109 case BufferFormat::R_8: | 109 case BufferFormat::R_8: |
| 110 return GL_RED; | 110 return GL_RED; |
| 111 case BufferFormat::BGRA_8888: | 111 case BufferFormat::BGRA_8888: |
| 112 case BufferFormat::BGRX_8888: |
| 112 case BufferFormat::RGBA_8888: | 113 case BufferFormat::RGBA_8888: |
| 113 return GL_RGBA; | 114 return GL_RGBA; |
| 114 case BufferFormat::UYVY_422: | 115 case BufferFormat::UYVY_422: |
| 115 return GL_RGB; | 116 return GL_RGB; |
| 116 case BufferFormat::YUV_420_BIPLANAR: | 117 case BufferFormat::YUV_420_BIPLANAR: |
| 117 return GL_RGB_YCBCR_420V_CHROMIUM; | 118 return GL_RGB_YCBCR_420V_CHROMIUM; |
| 118 case BufferFormat::ATC: | 119 case BufferFormat::ATC: |
| 119 case BufferFormat::ATCIA: | 120 case BufferFormat::ATCIA: |
| 120 case BufferFormat::DXT1: | 121 case BufferFormat::DXT1: |
| 121 case BufferFormat::DXT5: | 122 case BufferFormat::DXT5: |
| 122 case BufferFormat::ETC1: | 123 case BufferFormat::ETC1: |
| 123 case BufferFormat::RGBA_4444: | 124 case BufferFormat::RGBA_4444: |
| 124 case BufferFormat::RGBX_8888: | 125 case BufferFormat::RGBX_8888: |
| 125 case BufferFormat::BGRX_8888: | |
| 126 case BufferFormat::YUV_420: | 126 case BufferFormat::YUV_420: |
| 127 NOTREACHED(); | 127 NOTREACHED(); |
| 128 return 0; | 128 return 0; |
| 129 } | 129 } |
| 130 | 130 |
| 131 NOTREACHED(); | 131 NOTREACHED(); |
| 132 return 0; | 132 return 0; |
| 133 } | 133 } |
| 134 | 134 |
| 135 GLenum DataFormat(BufferFormat format) { | 135 GLenum DataFormat(BufferFormat format) { |
| 136 switch (format) { | 136 switch (format) { |
| 137 case BufferFormat::R_8: | 137 case BufferFormat::R_8: |
| 138 return GL_RED; | 138 return GL_RED; |
| 139 case BufferFormat::BGRA_8888: | 139 case BufferFormat::BGRA_8888: |
| 140 case BufferFormat::BGRX_8888: |
| 140 case BufferFormat::RGBA_8888: | 141 case BufferFormat::RGBA_8888: |
| 141 return GL_BGRA; | 142 return GL_BGRA; |
| 142 case BufferFormat::UYVY_422: | 143 case BufferFormat::UYVY_422: |
| 143 return GL_YCBCR_422_APPLE; | 144 return GL_YCBCR_422_APPLE; |
| 144 case BufferFormat::ATC: | 145 case BufferFormat::ATC: |
| 145 case BufferFormat::ATCIA: | 146 case BufferFormat::ATCIA: |
| 146 case BufferFormat::DXT1: | 147 case BufferFormat::DXT1: |
| 147 case BufferFormat::DXT5: | 148 case BufferFormat::DXT5: |
| 148 case BufferFormat::ETC1: | 149 case BufferFormat::ETC1: |
| 149 case BufferFormat::RGBA_4444: | 150 case BufferFormat::RGBA_4444: |
| 150 case BufferFormat::RGBX_8888: | 151 case BufferFormat::RGBX_8888: |
| 151 case BufferFormat::BGRX_8888: | |
| 152 case BufferFormat::YUV_420: | 152 case BufferFormat::YUV_420: |
| 153 case BufferFormat::YUV_420_BIPLANAR: | 153 case BufferFormat::YUV_420_BIPLANAR: |
| 154 NOTREACHED(); | 154 NOTREACHED(); |
| 155 return 0; | 155 return 0; |
| 156 } | 156 } |
| 157 | 157 |
| 158 NOTREACHED(); | 158 NOTREACHED(); |
| 159 return 0; | 159 return 0; |
| 160 } | 160 } |
| 161 | 161 |
| 162 GLenum DataType(BufferFormat format) { | 162 GLenum DataType(BufferFormat format) { |
| 163 switch (format) { | 163 switch (format) { |
| 164 case BufferFormat::R_8: | 164 case BufferFormat::R_8: |
| 165 return GL_UNSIGNED_BYTE; | 165 return GL_UNSIGNED_BYTE; |
| 166 case BufferFormat::BGRA_8888: | 166 case BufferFormat::BGRA_8888: |
| 167 case BufferFormat::BGRX_8888: |
| 167 case BufferFormat::RGBA_8888: | 168 case BufferFormat::RGBA_8888: |
| 168 return GL_UNSIGNED_INT_8_8_8_8_REV; | 169 return GL_UNSIGNED_INT_8_8_8_8_REV; |
| 169 case BufferFormat::UYVY_422: | 170 case BufferFormat::UYVY_422: |
| 170 return GL_UNSIGNED_SHORT_8_8_APPLE; | 171 return GL_UNSIGNED_SHORT_8_8_APPLE; |
| 171 break; | 172 break; |
| 172 case BufferFormat::ATC: | 173 case BufferFormat::ATC: |
| 173 case BufferFormat::ATCIA: | 174 case BufferFormat::ATCIA: |
| 174 case BufferFormat::DXT1: | 175 case BufferFormat::DXT1: |
| 175 case BufferFormat::DXT5: | 176 case BufferFormat::DXT5: |
| 176 case BufferFormat::ETC1: | 177 case BufferFormat::ETC1: |
| 177 case BufferFormat::RGBA_4444: | 178 case BufferFormat::RGBA_4444: |
| 178 case BufferFormat::RGBX_8888: | 179 case BufferFormat::RGBX_8888: |
| 179 case BufferFormat::BGRX_8888: | |
| 180 case BufferFormat::YUV_420: | 180 case BufferFormat::YUV_420: |
| 181 case BufferFormat::YUV_420_BIPLANAR: | 181 case BufferFormat::YUV_420_BIPLANAR: |
| 182 NOTREACHED(); | 182 NOTREACHED(); |
| 183 return 0; | 183 return 0; |
| 184 } | 184 } |
| 185 | 185 |
| 186 NOTREACHED(); | 186 NOTREACHED(); |
| 187 return 0; | 187 return 0; |
| 188 } | 188 } |
| 189 | 189 |
| 190 // When an IOSurface is bound to a texture with internalformat "GL_RGB", many |
| 191 // OpenGL operations are broken. Therefore, never allow an IOSurface to be bound |
| 192 // with GL_RGB. https://crbug.com/595948. |
| 193 GLenum ConvertRequestedInternalFormat(GLenum internalformat) { |
| 194 if (internalformat == GL_RGB) |
| 195 return GL_RGBA; |
| 196 return internalformat; |
| 197 } |
| 198 |
| 190 } // namespace | 199 } // namespace |
| 191 | 200 |
| 192 GLImageIOSurface::GLImageIOSurface(const gfx::Size& size, | 201 GLImageIOSurface::GLImageIOSurface(const gfx::Size& size, |
| 193 unsigned internalformat) | 202 unsigned internalformat) |
| 194 : size_(size), | 203 : size_(size), |
| 195 internalformat_(internalformat), | 204 internalformat_(ConvertRequestedInternalFormat(internalformat)), |
| 205 client_internalformat_(internalformat), |
| 196 format_(BufferFormat::RGBA_8888) {} | 206 format_(BufferFormat::RGBA_8888) {} |
| 197 | 207 |
| 198 GLImageIOSurface::~GLImageIOSurface() { | 208 GLImageIOSurface::~GLImageIOSurface() { |
| 199 DCHECK(thread_checker_.CalledOnValidThread()); | 209 DCHECK(thread_checker_.CalledOnValidThread()); |
| 200 DCHECK(!io_surface_); | 210 DCHECK(!io_surface_); |
| 201 } | 211 } |
| 202 | 212 |
| 203 bool GLImageIOSurface::Initialize(IOSurfaceRef io_surface, | 213 bool GLImageIOSurface::Initialize(IOSurfaceRef io_surface, |
| 204 gfx::GenericSharedMemoryId io_surface_id, | 214 gfx::GenericSharedMemoryId io_surface_id, |
| 205 BufferFormat format) { | 215 BufferFormat format) { |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, | 408 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, |
| 399 base::trace_event::MemoryAllocatorDump::kUnitsBytes, | 409 base::trace_event::MemoryAllocatorDump::kUnitsBytes, |
| 400 static_cast<uint64_t>(size_bytes)); | 410 static_cast<uint64_t>(size_bytes)); |
| 401 | 411 |
| 402 auto guid = | 412 auto guid = |
| 403 GetGenericSharedMemoryGUIDForTracing(process_tracing_id, io_surface_id_); | 413 GetGenericSharedMemoryGUIDForTracing(process_tracing_id, io_surface_id_); |
| 404 pmd->CreateSharedGlobalAllocatorDump(guid); | 414 pmd->CreateSharedGlobalAllocatorDump(guid); |
| 405 pmd->AddOwnershipEdge(dump->guid(), guid); | 415 pmd->AddOwnershipEdge(dump->guid(), guid); |
| 406 } | 416 } |
| 407 | 417 |
| 418 bool GLImageIOSurface::EmulatingRGB() const { |
| 419 return client_internalformat_ == GL_RGB; |
| 420 } |
| 421 |
| 408 base::ScopedCFTypeRef<IOSurfaceRef> GLImageIOSurface::io_surface() { | 422 base::ScopedCFTypeRef<IOSurfaceRef> GLImageIOSurface::io_surface() { |
| 409 return io_surface_; | 423 return io_surface_; |
| 410 } | 424 } |
| 411 | 425 |
| 412 // static | 426 // static |
| 413 void GLImageIOSurface::SetLayerForWidget(gfx::AcceleratedWidget widget, | 427 void GLImageIOSurface::SetLayerForWidget(gfx::AcceleratedWidget widget, |
| 414 CALayer* layer) { | 428 CALayer* layer) { |
| 415 if (layer) | 429 if (layer) |
| 416 g_widget_to_layer_map.Pointer()->insert(std::make_pair(widget, layer)); | 430 g_widget_to_layer_map.Pointer()->insert(std::make_pair(widget, layer)); |
| 417 else | 431 else |
| 418 g_widget_to_layer_map.Pointer()->erase(widget); | 432 g_widget_to_layer_map.Pointer()->erase(widget); |
| 419 } | 433 } |
| 420 | 434 |
| 421 // static | 435 // static |
| 422 unsigned GLImageIOSurface::GetInternalFormatForTesting( | 436 unsigned GLImageIOSurface::GetInternalFormatForTesting( |
| 423 gfx::BufferFormat format) { | 437 gfx::BufferFormat format) { |
| 424 DCHECK(ValidFormat(format)); | 438 DCHECK(ValidFormat(format)); |
| 425 return TextureFormat(format); | 439 return TextureFormat(format); |
| 426 } | 440 } |
| 427 } // namespace gl | 441 } // namespace gl |
| OLD | NEW |