| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "gpu/command_buffer/service/image_factory.h" | 5 #include "gpu/command_buffer/common/gpu_memory_buffer_support.h" |
| 6 | 6 |
| 7 #include "base/logging.h" |
| 7 #include "gpu/command_buffer/common/capabilities.h" | 8 #include "gpu/command_buffer/common/capabilities.h" |
| 8 #include "ui/gl/gl_bindings.h" | 9 #include "ui/gl/gl_bindings.h" |
| 9 | 10 |
| 10 namespace gpu { | 11 namespace gpu { |
| 11 | 12 |
| 12 namespace { | 13 namespace { |
| 14 |
| 13 gfx::BufferFormat BufferFormatForInternalFormat(unsigned internalformat) { | 15 gfx::BufferFormat BufferFormatForInternalFormat(unsigned internalformat) { |
| 14 switch (internalformat) { | 16 switch (internalformat) { |
| 15 case GL_RED: | 17 case GL_RED: |
| 16 return gfx::BufferFormat::R_8; | 18 return gfx::BufferFormat::R_8; |
| 17 case GL_RGB: | 19 case GL_RGB: |
| 18 return gfx::BufferFormat::BGRX_8888; | 20 return gfx::BufferFormat::BGRX_8888; |
| 19 case GL_RGBA: | 21 case GL_RGBA: |
| 20 return gfx::BufferFormat::RGBA_8888; | 22 return gfx::BufferFormat::RGBA_8888; |
| 21 case GL_BGRA_EXT: | 23 case GL_BGRA_EXT: |
| 22 return gfx::BufferFormat::BGRA_8888; | 24 return gfx::BufferFormat::BGRA_8888; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 37 case GL_RGB_YCBCR_422_CHROMIUM: | 39 case GL_RGB_YCBCR_422_CHROMIUM: |
| 38 return gfx::BufferFormat::UYVY_422; | 40 return gfx::BufferFormat::UYVY_422; |
| 39 default: | 41 default: |
| 40 NOTREACHED(); | 42 NOTREACHED(); |
| 41 return gfx::BufferFormat::RGBA_8888; | 43 return gfx::BufferFormat::RGBA_8888; |
| 42 } | 44 } |
| 43 } | 45 } |
| 44 | 46 |
| 45 } // namespace | 47 } // namespace |
| 46 | 48 |
| 47 ImageFactory::ImageFactory() { | 49 gfx::BufferFormat DefaultBufferFormatForImageFormat(unsigned internalformat) { |
| 48 } | |
| 49 | |
| 50 ImageFactory::~ImageFactory() { | |
| 51 } | |
| 52 | |
| 53 // static | |
| 54 gfx::BufferFormat ImageFactory::DefaultBufferFormatForImageFormat( | |
| 55 unsigned internalformat) { | |
| 56 switch (internalformat) { | 50 switch (internalformat) { |
| 57 case GL_RGB: | 51 case GL_RGB: |
| 58 return gfx::BufferFormat::BGRX_8888; | 52 return gfx::BufferFormat::BGRX_8888; |
| 59 case GL_RGBA: | 53 case GL_RGBA: |
| 60 return gfx::BufferFormat::RGBA_8888; | 54 return gfx::BufferFormat::RGBA_8888; |
| 61 default: | 55 default: |
| 62 NOTREACHED(); | 56 NOTREACHED(); |
| 63 return gfx::BufferFormat::RGBA_8888; | 57 return gfx::BufferFormat::RGBA_8888; |
| 64 } | 58 } |
| 65 } | 59 } |
| 66 | 60 |
| 67 // static | 61 bool IsImageFormatCompatibleWithGpuMemoryBufferFormat( |
| 68 bool ImageFactory::IsImageFormatCompatibleWithGpuMemoryBufferFormat( | |
| 69 unsigned internalformat, | 62 unsigned internalformat, |
| 70 gfx::BufferFormat format) { | 63 gfx::BufferFormat format) { |
| 71 switch (format) { | 64 switch (format) { |
| 72 case gfx::BufferFormat::ATC: | 65 case gfx::BufferFormat::ATC: |
| 73 case gfx::BufferFormat::ATCIA: | 66 case gfx::BufferFormat::ATCIA: |
| 74 case gfx::BufferFormat::BGRA_8888: | 67 case gfx::BufferFormat::BGRA_8888: |
| 75 case gfx::BufferFormat::BGRX_8888: | 68 case gfx::BufferFormat::BGRX_8888: |
| 76 case gfx::BufferFormat::DXT1: | 69 case gfx::BufferFormat::DXT1: |
| 77 case gfx::BufferFormat::DXT5: | 70 case gfx::BufferFormat::DXT5: |
| 78 case gfx::BufferFormat::ETC1: | 71 case gfx::BufferFormat::ETC1: |
| 79 case gfx::BufferFormat::R_8: | 72 case gfx::BufferFormat::R_8: |
| 80 case gfx::BufferFormat::RGBA_8888: | 73 case gfx::BufferFormat::RGBA_8888: |
| 81 case gfx::BufferFormat::RGBX_8888: | 74 case gfx::BufferFormat::RGBX_8888: |
| 82 case gfx::BufferFormat::YUV_420: | 75 case gfx::BufferFormat::YUV_420: |
| 83 case gfx::BufferFormat::YUV_420_BIPLANAR: | 76 case gfx::BufferFormat::YUV_420_BIPLANAR: |
| 84 case gfx::BufferFormat::UYVY_422: | 77 case gfx::BufferFormat::UYVY_422: |
| 85 return format == BufferFormatForInternalFormat(internalformat); | 78 return format == BufferFormatForInternalFormat(internalformat); |
| 86 case gfx::BufferFormat::RGBA_4444: | 79 case gfx::BufferFormat::RGBA_4444: |
| 87 return internalformat == GL_RGBA; | 80 return internalformat == GL_RGBA; |
| 88 } | 81 } |
| 89 | 82 |
| 90 NOTREACHED(); | 83 NOTREACHED(); |
| 91 return false; | 84 return false; |
| 92 } | 85 } |
| 93 | 86 |
| 94 // static | 87 bool IsGpuMemoryBufferFormatSupported(gfx::BufferFormat format, |
| 95 bool ImageFactory::IsGpuMemoryBufferFormatSupported( | 88 const gpu::Capabilities& capabilities) { |
| 96 gfx::BufferFormat format, | |
| 97 const gpu::Capabilities& capabilities) { | |
| 98 switch (format) { | 89 switch (format) { |
| 99 case gfx::BufferFormat::ATC: | 90 case gfx::BufferFormat::ATC: |
| 100 case gfx::BufferFormat::ATCIA: | 91 case gfx::BufferFormat::ATCIA: |
| 101 return capabilities.texture_format_atc; | 92 return capabilities.texture_format_atc; |
| 102 case gfx::BufferFormat::BGRA_8888: | 93 case gfx::BufferFormat::BGRA_8888: |
| 103 case gfx::BufferFormat::BGRX_8888: | 94 case gfx::BufferFormat::BGRX_8888: |
| 104 return capabilities.texture_format_bgra8888; | 95 return capabilities.texture_format_bgra8888; |
| 105 case gfx::BufferFormat::DXT1: | 96 case gfx::BufferFormat::DXT1: |
| 106 return capabilities.texture_format_dxt1; | 97 return capabilities.texture_format_dxt1; |
| 107 case gfx::BufferFormat::DXT5: | 98 case gfx::BufferFormat::DXT5: |
| (...skipping 10 matching lines...) Expand all Loading... |
| 118 case gfx::BufferFormat::YUV_420: | 109 case gfx::BufferFormat::YUV_420: |
| 119 return true; | 110 return true; |
| 120 case gfx::BufferFormat::YUV_420_BIPLANAR: | 111 case gfx::BufferFormat::YUV_420_BIPLANAR: |
| 121 return capabilities.image_ycbcr_420v; | 112 return capabilities.image_ycbcr_420v; |
| 122 } | 113 } |
| 123 | 114 |
| 124 NOTREACHED(); | 115 NOTREACHED(); |
| 125 return false; | 116 return false; |
| 126 } | 117 } |
| 127 | 118 |
| 128 // static | 119 bool IsImageSizeValidForGpuMemoryBufferFormat(const gfx::Size& size, |
| 129 bool ImageFactory::IsImageSizeValidForGpuMemoryBufferFormat( | 120 gfx::BufferFormat format) { |
| 130 const gfx::Size& size, | |
| 131 gfx::BufferFormat format) { | |
| 132 switch (format) { | 121 switch (format) { |
| 133 case gfx::BufferFormat::ATC: | 122 case gfx::BufferFormat::ATC: |
| 134 case gfx::BufferFormat::ATCIA: | 123 case gfx::BufferFormat::ATCIA: |
| 135 case gfx::BufferFormat::DXT1: | 124 case gfx::BufferFormat::DXT1: |
| 136 case gfx::BufferFormat::DXT5: | 125 case gfx::BufferFormat::DXT5: |
| 137 case gfx::BufferFormat::ETC1: | 126 case gfx::BufferFormat::ETC1: |
| 138 // Compressed images must have a width and height that's evenly divisible | 127 // Compressed images must have a width and height that's evenly divisible |
| 139 // by the block size. | 128 // by the block size. |
| 140 return size.width() % 4 == 0 && size.height() % 4 == 0; | 129 return size.width() % 4 == 0 && size.height() % 4 == 0; |
| 141 case gfx::BufferFormat::R_8: | 130 case gfx::BufferFormat::R_8: |
| 142 case gfx::BufferFormat::RGBA_4444: | 131 case gfx::BufferFormat::RGBA_4444: |
| 143 case gfx::BufferFormat::RGBA_8888: | 132 case gfx::BufferFormat::RGBA_8888: |
| 144 case gfx::BufferFormat::RGBX_8888: | 133 case gfx::BufferFormat::RGBX_8888: |
| 145 case gfx::BufferFormat::BGRA_8888: | 134 case gfx::BufferFormat::BGRA_8888: |
| 146 case gfx::BufferFormat::BGRX_8888: | 135 case gfx::BufferFormat::BGRX_8888: |
| 147 return true; | 136 return true; |
| 148 case gfx::BufferFormat::YUV_420: | 137 case gfx::BufferFormat::YUV_420: |
| 149 case gfx::BufferFormat::YUV_420_BIPLANAR: | 138 case gfx::BufferFormat::YUV_420_BIPLANAR: |
| 150 // U and V planes are subsampled by a factor of 2. | 139 // U and V planes are subsampled by a factor of 2. |
| 151 return size.width() % 2 == 0 && size.height() % 2 == 0; | 140 return size.width() % 2 == 0 && size.height() % 2 == 0; |
| 152 case gfx::BufferFormat::UYVY_422: | 141 case gfx::BufferFormat::UYVY_422: |
| 153 return size.width() % 2 == 0; | 142 return size.width() % 2 == 0; |
| 154 } | 143 } |
| 155 | 144 |
| 156 NOTREACHED(); | 145 NOTREACHED(); |
| 157 return false; | 146 return false; |
| 158 } | 147 } |
| 159 | 148 |
| 160 } // namespace gpu | 149 } // namespace gpu |
| OLD | NEW |