| 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 texture2DRect(a_y_texture, v_texCoord).r, | 62 texture2DRect(a_y_texture, v_texCoord).r, |
| 63 texture2DRect(a_uv_texture, v_texCoord * 0.5).rg); | 63 texture2DRect(a_uv_texture, v_texCoord * 0.5).rg); |
| 64 gl_FragColor = vec4(yuv_matrix * (yuv + yuv_adj), 1.0); | 64 gl_FragColor = vec4(yuv_matrix * (yuv + yuv_adj), 1.0); |
| 65 } | 65 } |
| 66 ); | 66 ); |
| 67 // clang-format on | 67 // clang-format on |
| 68 | 68 |
| 69 bool ValidInternalFormat(unsigned internalformat) { | 69 bool ValidInternalFormat(unsigned internalformat) { |
| 70 switch (internalformat) { | 70 switch (internalformat) { |
| 71 case GL_RED: | 71 case GL_RED: |
| 72 case GL_BGR_EXT: |
| 72 case GL_BGRA_EXT: | 73 case GL_BGRA_EXT: |
| 73 case GL_RGB: | 74 case GL_RGB: |
| 74 case GL_RGB_YCBCR_420V_CHROMIUM: | 75 case GL_RGB_YCBCR_420V_CHROMIUM: |
| 75 case GL_RGB_YCBCR_422_CHROMIUM: | 76 case GL_RGB_YCBCR_422_CHROMIUM: |
| 76 case GL_RGBA: | 77 case GL_RGBA: |
| 77 return true; | 78 return true; |
| 78 default: | 79 default: |
| 79 return false; | 80 return false; |
| 80 } | 81 } |
| 81 } | 82 } |
| 82 | 83 |
| 83 bool ValidFormat(BufferFormat format) { | 84 bool ValidFormat(BufferFormat format) { |
| 84 switch (format) { | 85 switch (format) { |
| 85 case BufferFormat::R_8: | 86 case BufferFormat::R_8: |
| 86 case BufferFormat::BGRA_8888: | 87 case BufferFormat::BGRA_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: |
| 91 case BufferFormat::BGRX_8888: |
| 90 return true; | 92 return true; |
| 91 case BufferFormat::ATC: | 93 case BufferFormat::ATC: |
| 92 case BufferFormat::ATCIA: | 94 case BufferFormat::ATCIA: |
| 93 case BufferFormat::DXT1: | 95 case BufferFormat::DXT1: |
| 94 case BufferFormat::DXT5: | 96 case BufferFormat::DXT5: |
| 95 case BufferFormat::ETC1: | 97 case BufferFormat::ETC1: |
| 96 case BufferFormat::RGBA_4444: | 98 case BufferFormat::RGBA_4444: |
| 97 case BufferFormat::RGBX_8888: | 99 case BufferFormat::RGBX_8888: |
| 98 case BufferFormat::BGRX_8888: | |
| 99 case BufferFormat::YUV_420: | 100 case BufferFormat::YUV_420: |
| 100 return false; | 101 return false; |
| 101 } | 102 } |
| 102 | 103 |
| 103 NOTREACHED(); | 104 NOTREACHED(); |
| 104 return false; | 105 return false; |
| 105 } | 106 } |
| 106 | 107 |
| 107 GLenum TextureFormat(BufferFormat format) { | 108 GLenum TextureFormat(BufferFormat format) { |
| 108 switch (format) { | 109 switch (format) { |
| 109 case BufferFormat::R_8: | 110 case BufferFormat::R_8: |
| 110 return GL_RED; | 111 return GL_RED; |
| 111 case BufferFormat::BGRA_8888: | 112 case BufferFormat::BGRA_8888: |
| 112 case BufferFormat::RGBA_8888: | 113 case BufferFormat::RGBA_8888: |
| 114 case BufferFormat::BGRX_8888: |
| 113 return GL_RGBA; | 115 return GL_RGBA; |
| 114 case BufferFormat::UYVY_422: | 116 case BufferFormat::UYVY_422: |
| 115 return GL_RGB; | 117 return GL_RGB; |
| 116 case BufferFormat::YUV_420_BIPLANAR: | 118 case BufferFormat::YUV_420_BIPLANAR: |
| 117 return GL_RGB_YCBCR_420V_CHROMIUM; | 119 return GL_RGB_YCBCR_420V_CHROMIUM; |
| 118 case BufferFormat::ATC: | 120 case BufferFormat::ATC: |
| 119 case BufferFormat::ATCIA: | 121 case BufferFormat::ATCIA: |
| 120 case BufferFormat::DXT1: | 122 case BufferFormat::DXT1: |
| 121 case BufferFormat::DXT5: | 123 case BufferFormat::DXT5: |
| 122 case BufferFormat::ETC1: | 124 case BufferFormat::ETC1: |
| 123 case BufferFormat::RGBA_4444: | 125 case BufferFormat::RGBA_4444: |
| 124 case BufferFormat::RGBX_8888: | 126 case BufferFormat::RGBX_8888: |
| 125 case BufferFormat::BGRX_8888: | |
| 126 case BufferFormat::YUV_420: | 127 case BufferFormat::YUV_420: |
| 127 NOTREACHED(); | 128 NOTREACHED(); |
| 128 return 0; | 129 return 0; |
| 129 } | 130 } |
| 130 | 131 |
| 131 NOTREACHED(); | 132 NOTREACHED(); |
| 132 return 0; | 133 return 0; |
| 133 } | 134 } |
| 134 | 135 |
| 135 GLenum DataFormat(BufferFormat format) { | 136 GLenum DataFormat(BufferFormat format) { |
| 136 switch (format) { | 137 switch (format) { |
| 137 case BufferFormat::R_8: | 138 case BufferFormat::R_8: |
| 138 return GL_RED; | 139 return GL_RED; |
| 139 case BufferFormat::BGRA_8888: | 140 case BufferFormat::BGRA_8888: |
| 140 case BufferFormat::RGBA_8888: | 141 case BufferFormat::RGBA_8888: |
| 142 case BufferFormat::BGRX_8888: |
| 141 return GL_BGRA; | 143 return GL_BGRA; |
| 142 case BufferFormat::UYVY_422: | 144 case BufferFormat::UYVY_422: |
| 143 return GL_YCBCR_422_APPLE; | 145 return GL_YCBCR_422_APPLE; |
| 144 case BufferFormat::ATC: | 146 case BufferFormat::ATC: |
| 145 case BufferFormat::ATCIA: | 147 case BufferFormat::ATCIA: |
| 146 case BufferFormat::DXT1: | 148 case BufferFormat::DXT1: |
| 147 case BufferFormat::DXT5: | 149 case BufferFormat::DXT5: |
| 148 case BufferFormat::ETC1: | 150 case BufferFormat::ETC1: |
| 149 case BufferFormat::RGBA_4444: | 151 case BufferFormat::RGBA_4444: |
| 150 case BufferFormat::RGBX_8888: | 152 case BufferFormat::RGBX_8888: |
| 151 case BufferFormat::BGRX_8888: | |
| 152 case BufferFormat::YUV_420: | 153 case BufferFormat::YUV_420: |
| 153 case BufferFormat::YUV_420_BIPLANAR: | 154 case BufferFormat::YUV_420_BIPLANAR: |
| 154 NOTREACHED(); | 155 NOTREACHED(); |
| 155 return 0; | 156 return 0; |
| 156 } | 157 } |
| 157 | 158 |
| 158 NOTREACHED(); | 159 NOTREACHED(); |
| 159 return 0; | 160 return 0; |
| 160 } | 161 } |
| 161 | 162 |
| 162 GLenum DataType(BufferFormat format) { | 163 GLenum DataType(BufferFormat format) { |
| 163 switch (format) { | 164 switch (format) { |
| 164 case BufferFormat::R_8: | 165 case BufferFormat::R_8: |
| 165 return GL_UNSIGNED_BYTE; | 166 return GL_UNSIGNED_BYTE; |
| 166 case BufferFormat::BGRA_8888: | 167 case BufferFormat::BGRA_8888: |
| 167 case BufferFormat::RGBA_8888: | 168 case BufferFormat::RGBA_8888: |
| 169 case BufferFormat::BGRX_8888: |
| 168 return GL_UNSIGNED_INT_8_8_8_8_REV; | 170 return GL_UNSIGNED_INT_8_8_8_8_REV; |
| 169 case BufferFormat::UYVY_422: | 171 case BufferFormat::UYVY_422: |
| 170 return GL_UNSIGNED_SHORT_8_8_APPLE; | 172 return GL_UNSIGNED_SHORT_8_8_APPLE; |
| 171 break; | 173 break; |
| 172 case BufferFormat::ATC: | 174 case BufferFormat::ATC: |
| 173 case BufferFormat::ATCIA: | 175 case BufferFormat::ATCIA: |
| 174 case BufferFormat::DXT1: | 176 case BufferFormat::DXT1: |
| 175 case BufferFormat::DXT5: | 177 case BufferFormat::DXT5: |
| 176 case BufferFormat::ETC1: | 178 case BufferFormat::ETC1: |
| 177 case BufferFormat::RGBA_4444: | 179 case BufferFormat::RGBA_4444: |
| 178 case BufferFormat::RGBX_8888: | 180 case BufferFormat::RGBX_8888: |
| 179 case BufferFormat::BGRX_8888: | |
| 180 case BufferFormat::YUV_420: | 181 case BufferFormat::YUV_420: |
| 181 case BufferFormat::YUV_420_BIPLANAR: | 182 case BufferFormat::YUV_420_BIPLANAR: |
| 182 NOTREACHED(); | 183 NOTREACHED(); |
| 183 return 0; | 184 return 0; |
| 184 } | 185 } |
| 185 | 186 |
| 186 NOTREACHED(); | 187 NOTREACHED(); |
| 187 return 0; | 188 return 0; |
| 188 } | 189 } |
| 189 | 190 |
| 190 } // namespace | 191 } // namespace |
| 191 | 192 |
| 192 GLImageIOSurface::GLImageIOSurface(const gfx::Size& size, | 193 GLImageIOSurface::GLImageIOSurface(const gfx::Size& size, |
| 193 unsigned internalformat) | 194 unsigned internalformat) |
| 194 : size_(size), | 195 : size_(size), |
| 195 internalformat_(internalformat), | 196 internalformat_(internalformat), |
| 196 format_(BufferFormat::RGBA_8888) {} | 197 desired_internalformat_(internalformat), |
| 198 format_(BufferFormat::RGBA_8888) { |
| 199 if (internalformat == GL_BGR_EXT) |
| 200 internalformat_ = GL_BGRA_EXT; |
| 201 } |
| 197 | 202 |
| 198 GLImageIOSurface::~GLImageIOSurface() { | 203 GLImageIOSurface::~GLImageIOSurface() { |
| 199 DCHECK(thread_checker_.CalledOnValidThread()); | 204 DCHECK(thread_checker_.CalledOnValidThread()); |
| 200 DCHECK(!io_surface_); | 205 DCHECK(!io_surface_); |
| 201 } | 206 } |
| 202 | 207 |
| 203 bool GLImageIOSurface::Initialize(IOSurfaceRef io_surface, | 208 bool GLImageIOSurface::Initialize(IOSurfaceRef io_surface, |
| 204 gfx::GenericSharedMemoryId io_surface_id, | 209 gfx::GenericSharedMemoryId io_surface_id, |
| 205 BufferFormat format) { | 210 BufferFormat format) { |
| 206 DCHECK(thread_checker_.CalledOnValidThread()); | 211 DCHECK(thread_checker_.CalledOnValidThread()); |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, | 403 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, |
| 399 base::trace_event::MemoryAllocatorDump::kUnitsBytes, | 404 base::trace_event::MemoryAllocatorDump::kUnitsBytes, |
| 400 static_cast<uint64_t>(size_bytes)); | 405 static_cast<uint64_t>(size_bytes)); |
| 401 | 406 |
| 402 auto guid = | 407 auto guid = |
| 403 GetGenericSharedMemoryGUIDForTracing(process_tracing_id, io_surface_id_); | 408 GetGenericSharedMemoryGUIDForTracing(process_tracing_id, io_surface_id_); |
| 404 pmd->CreateSharedGlobalAllocatorDump(guid); | 409 pmd->CreateSharedGlobalAllocatorDump(guid); |
| 405 pmd->AddOwnershipEdge(dump->guid(), guid); | 410 pmd->AddOwnershipEdge(dump->guid(), guid); |
| 406 } | 411 } |
| 407 | 412 |
| 413 bool GLImageIOSurface::EmulatingRGB() const { |
| 414 return desired_internalformat_ == GL_BGR_EXT; |
| 415 } |
| 416 |
| 408 base::ScopedCFTypeRef<IOSurfaceRef> GLImageIOSurface::io_surface() { | 417 base::ScopedCFTypeRef<IOSurfaceRef> GLImageIOSurface::io_surface() { |
| 409 return io_surface_; | 418 return io_surface_; |
| 410 } | 419 } |
| 411 | 420 |
| 412 // static | 421 // static |
| 413 void GLImageIOSurface::SetLayerForWidget(gfx::AcceleratedWidget widget, | 422 void GLImageIOSurface::SetLayerForWidget(gfx::AcceleratedWidget widget, |
| 414 CALayer* layer) { | 423 CALayer* layer) { |
| 415 if (layer) | 424 if (layer) |
| 416 g_widget_to_layer_map.Pointer()->insert(std::make_pair(widget, layer)); | 425 g_widget_to_layer_map.Pointer()->insert(std::make_pair(widget, layer)); |
| 417 else | 426 else |
| 418 g_widget_to_layer_map.Pointer()->erase(widget); | 427 g_widget_to_layer_map.Pointer()->erase(widget); |
| 419 } | 428 } |
| 420 | 429 |
| 421 // static | 430 // static |
| 422 unsigned GLImageIOSurface::GetInternalFormatForTesting( | 431 unsigned GLImageIOSurface::GetInternalFormatForTesting( |
| 423 gfx::BufferFormat format) { | 432 gfx::BufferFormat format) { |
| 424 DCHECK(ValidFormat(format)); | 433 DCHECK(ValidFormat(format)); |
| 425 return TextureFormat(format); | 434 return TextureFormat(format); |
| 426 } | 435 } |
| 427 } // namespace gl | 436 } // namespace gl |
| OLD | NEW |