Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/texture_manager.h" | 5 #include "gpu/command_buffer/service/texture_manager.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 1832 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1843 return NULL; | 1843 return NULL; |
| 1844 } | 1844 } |
| 1845 | 1845 |
| 1846 GLsizei TextureManager::ComputeMipMapCount(GLenum target, | 1846 GLsizei TextureManager::ComputeMipMapCount(GLenum target, |
| 1847 GLsizei width, | 1847 GLsizei width, |
| 1848 GLsizei height, | 1848 GLsizei height, |
| 1849 GLsizei depth) { | 1849 GLsizei depth) { |
| 1850 switch (target) { | 1850 switch (target) { |
| 1851 case GL_TEXTURE_EXTERNAL_OES: | 1851 case GL_TEXTURE_EXTERNAL_OES: |
| 1852 return 1; | 1852 return 1; |
| 1853 case GL_TEXTURE_3D: | |
| 1854 return 1 + | |
| 1855 base::bits::Log2Floor(std::max(std::max(width, height), depth)); | |
| 1853 default: | 1856 default: |
| 1854 return 1 + | 1857 return 1 + |
| 1855 base::bits::Log2Floor(std::max(std::max(width, height), depth)); | 1858 base::bits::Log2Floor(std::max(width, height)); |
| 1856 } | 1859 } |
| 1857 } | 1860 } |
| 1858 | 1861 |
| 1859 void TextureManager::SetLevelImage(TextureRef* ref, | 1862 void TextureManager::SetLevelImage(TextureRef* ref, |
| 1860 GLenum target, | 1863 GLenum target, |
| 1861 GLint level, | 1864 GLint level, |
| 1862 gl::GLImage* image, | 1865 gl::GLImage* image, |
| 1863 Texture::ImageState state) { | 1866 Texture::ImageState state) { |
| 1864 DCHECK(ref); | 1867 DCHECK(ref); |
| 1865 ref->texture()->SetLevelImage(target, level, image, state); | 1868 ref->texture()->SetLevelImage(target, level, image, state); |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2120 function_name, texture_ref, args); | 2123 function_name, texture_ref, args); |
| 2121 } | 2124 } |
| 2122 | 2125 |
| 2123 bool TextureManager::ValidateTexSubImage(ContextState* state, | 2126 bool TextureManager::ValidateTexSubImage(ContextState* state, |
| 2124 const char* function_name, | 2127 const char* function_name, |
| 2125 const DoTexSubImageArguments& args, | 2128 const DoTexSubImageArguments& args, |
| 2126 TextureRef** texture_ref) { | 2129 TextureRef** texture_ref) { |
| 2127 ErrorState* error_state = state->GetErrorState(); | 2130 ErrorState* error_state = state->GetErrorState(); |
| 2128 const Validators* validators = feature_info_->validators(); | 2131 const Validators* validators = feature_info_->validators(); |
| 2129 | 2132 |
| 2130 if (!validators->texture_target.IsValid(args.target)) { | 2133 if ((args.command_type == DoTexSubImageArguments::kTexSubImage2D && |
| 2134 !validators->texture_target.IsValid(args.target)) || | |
| 2135 (args.command_type == DoTexSubImageArguments::kTexSubImage3D && | |
| 2136 !validators->texture_3_d_target.IsValid(args.target))) { | |
| 2131 ERRORSTATE_SET_GL_ERROR_INVALID_ENUM(error_state, function_name, | 2137 ERRORSTATE_SET_GL_ERROR_INVALID_ENUM(error_state, function_name, |
| 2132 args.target, "target"); | 2138 args.target, "target"); |
| 2133 return false; | 2139 return false; |
| 2134 } | 2140 } |
| 2135 if (args.width < 0) { | 2141 if (args.width < 0) { |
| 2136 ERRORSTATE_SET_GL_ERROR(error_state, GL_INVALID_VALUE, function_name, | 2142 ERRORSTATE_SET_GL_ERROR(error_state, GL_INVALID_VALUE, function_name, |
| 2137 "width < 0"); | 2143 "width < 0"); |
| 2138 return false; | 2144 return false; |
| 2139 } | 2145 } |
| 2140 if (args.height < 0) { | 2146 if (args.height < 0) { |
| 2141 ERRORSTATE_SET_GL_ERROR(error_state, GL_INVALID_VALUE, function_name, | 2147 ERRORSTATE_SET_GL_ERROR(error_state, GL_INVALID_VALUE, function_name, |
| 2142 "height < 0"); | 2148 "height < 0"); |
| 2143 return false; | 2149 return false; |
| 2144 } | 2150 } |
| 2151 if (args.depth < 0) { | |
| 2152 ERRORSTATE_SET_GL_ERROR(error_state, GL_INVALID_VALUE, function_name, | |
| 2153 "depth < 0"); | |
| 2154 return false; | |
| 2155 } | |
| 2145 TextureRef* local_texture_ref = GetTextureInfoForTarget(state, args.target); | 2156 TextureRef* local_texture_ref = GetTextureInfoForTarget(state, args.target); |
| 2146 if (!local_texture_ref) { | 2157 if (!local_texture_ref) { |
| 2147 ERRORSTATE_SET_GL_ERROR(error_state, GL_INVALID_OPERATION, function_name, | 2158 ERRORSTATE_SET_GL_ERROR(error_state, GL_INVALID_OPERATION, function_name, |
| 2148 "unknown texture for target"); | 2159 "unknown texture for target"); |
| 2149 return false; | 2160 return false; |
| 2150 } | 2161 } |
| 2151 Texture* texture = local_texture_ref->texture(); | 2162 Texture* texture = local_texture_ref->texture(); |
| 2152 GLenum current_type = 0; | 2163 GLenum current_type = 0; |
| 2153 GLenum internal_format = 0; | 2164 GLenum internal_format = 0; |
| 2154 if (!texture->GetLevelType(args.target, args.level, ¤t_type, | 2165 if (!texture->GetLevelType(args.target, args.level, ¤t_type, |
| 2155 &internal_format)) { | 2166 &internal_format)) { |
| 2156 ERRORSTATE_SET_GL_ERROR(error_state, GL_INVALID_OPERATION, function_name, | 2167 ERRORSTATE_SET_GL_ERROR(error_state, GL_INVALID_OPERATION, function_name, |
| 2157 "level does not exist."); | 2168 "level does not exist."); |
| 2158 return false; | 2169 return false; |
| 2159 } | 2170 } |
| 2160 if (!ValidateTextureParameters(error_state, function_name, args.format, | 2171 if (!ValidateTextureParameters(error_state, function_name, args.format, |
| 2161 args.type, internal_format, args.level)) { | 2172 args.type, internal_format, args.level)) { |
| 2162 return false; | 2173 return false; |
| 2163 } | 2174 } |
| 2164 if (args.type != current_type && !feature_info_->IsES3Enabled()) { | 2175 if (args.type != current_type && !feature_info_->IsES3Enabled()) { |
| 2176 // It isn't explicitly required in the ES2 spec, but some drivers (for | |
| 2177 // example, Linux NVIDIA) generates an error. It is better to be | |
| 2178 // consistent across drivers. | |
| 2165 ERRORSTATE_SET_GL_ERROR(error_state, GL_INVALID_OPERATION, function_name, | 2179 ERRORSTATE_SET_GL_ERROR(error_state, GL_INVALID_OPERATION, function_name, |
| 2166 "type does not match type of texture."); | 2180 "type does not match type of texture."); |
| 2167 return false; | 2181 return false; |
| 2168 } | 2182 } |
| 2169 if (!texture->ValidForTexture(args.target, args.level, args.xoffset, | 2183 if (!texture->ValidForTexture(args.target, args.level, |
| 2170 args.yoffset, 0, args.width, args.height, 1)) { | 2184 args.xoffset, args.yoffset, args.zoffset, |
| 2185 args.width, args.height, args.depth)) { | |
| 2171 ERRORSTATE_SET_GL_ERROR(error_state, GL_INVALID_VALUE, function_name, | 2186 ERRORSTATE_SET_GL_ERROR(error_state, GL_INVALID_VALUE, function_name, |
| 2172 "bad dimensions."); | 2187 "bad dimensions."); |
| 2173 return false; | 2188 return false; |
| 2174 } | 2189 } |
| 2175 if ((GLES2Util::GetChannelsForFormat(args.format) & | 2190 if ((GLES2Util::GetChannelsForFormat(args.format) & |
| 2176 (GLES2Util::kDepth | GLES2Util::kStencil)) != 0 && | 2191 (GLES2Util::kDepth | GLES2Util::kStencil)) != 0 && |
| 2177 !feature_info_->IsES3Enabled()) { | 2192 !feature_info_->IsES3Enabled()) { |
| 2178 ERRORSTATE_SET_GL_ERROR( | 2193 ERRORSTATE_SET_GL_ERROR( |
| 2179 error_state, GL_INVALID_OPERATION, function_name, | 2194 error_state, GL_INVALID_OPERATION, function_name, |
| 2180 "can not supply data for depth or stencil textures"); | 2195 "can not supply data for depth or stencil textures"); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 2194 const DoTexSubImageArguments& args) { | 2209 const DoTexSubImageArguments& args) { |
| 2195 ErrorState* error_state = state->GetErrorState(); | 2210 ErrorState* error_state = state->GetErrorState(); |
| 2196 TextureRef* texture_ref; | 2211 TextureRef* texture_ref; |
| 2197 if (!ValidateTexSubImage(state, function_name, args, &texture_ref)) { | 2212 if (!ValidateTexSubImage(state, function_name, args, &texture_ref)) { |
| 2198 return; | 2213 return; |
| 2199 } | 2214 } |
| 2200 | 2215 |
| 2201 Texture* texture = texture_ref->texture(); | 2216 Texture* texture = texture_ref->texture(); |
| 2202 GLsizei tex_width = 0; | 2217 GLsizei tex_width = 0; |
| 2203 GLsizei tex_height = 0; | 2218 GLsizei tex_height = 0; |
| 2219 GLsizei tex_depth = 0; | |
| 2204 bool ok = texture->GetLevelSize(args.target, args.level, &tex_width, | 2220 bool ok = texture->GetLevelSize(args.target, args.level, &tex_width, |
| 2205 &tex_height, nullptr); | 2221 &tex_height, &tex_depth); |
| 2206 DCHECK(ok); | 2222 DCHECK(ok); |
| 2207 if (args.xoffset != 0 || args.yoffset != 0 || args.width != tex_width || | 2223 if (args.xoffset != 0 || args.yoffset != 0 || args.zoffset != 0 || |
| 2208 args.height != tex_height) { | 2224 args.width != tex_width || args.height != tex_height || |
| 2225 args.depth != tex_depth) { | |
| 2226 // TODO(zmo): Upgrade to 3D. | |
|
Ken Russell (switch to Gerrit)
2016/02/11 01:30:17
What will happen here if this code path is taken f
piman
2016/02/11 02:00:22
Yeah, the clearing logic is incomplete for 3D:
- o
| |
| 2209 gfx::Rect cleared_rect; | 2227 gfx::Rect cleared_rect; |
| 2210 if (CombineAdjacentRects( | 2228 if (CombineAdjacentRects( |
| 2211 texture->GetLevelClearedRect(args.target, args.level), | 2229 texture->GetLevelClearedRect(args.target, args.level), |
| 2212 gfx::Rect(args.xoffset, args.yoffset, args.width, args.height), | 2230 gfx::Rect(args.xoffset, args.yoffset, args.width, args.height), |
| 2213 &cleared_rect)) { | 2231 &cleared_rect)) { |
| 2214 DCHECK_GE(cleared_rect.size().GetArea(), | 2232 DCHECK_GE(cleared_rect.size().GetArea(), |
| 2215 texture->GetLevelClearedRect(args.target, args.level) | 2233 texture->GetLevelClearedRect(args.target, args.level) |
| 2216 .size() | 2234 .size() |
| 2217 .GetArea()); | 2235 .GetArea()); |
| 2218 SetLevelClearedRect(texture_ref, args.target, args.level, cleared_rect); | 2236 SetLevelClearedRect(texture_ref, args.target, args.level, cleared_rect); |
| 2219 } else { | 2237 } else { |
| 2220 // Otherwise clear part of texture level that is not already cleared. | 2238 // Otherwise clear part of texture level that is not already cleared. |
| 2221 if (!ClearTextureLevel(decoder, texture_ref, args.target, args.level)) { | 2239 if (!ClearTextureLevel(decoder, texture_ref, args.target, args.level)) { |
| 2222 ERRORSTATE_SET_GL_ERROR(error_state, GL_OUT_OF_MEMORY, | 2240 ERRORSTATE_SET_GL_ERROR(error_state, GL_OUT_OF_MEMORY, |
| 2223 "glTexSubImage2D", "dimensions too big"); | 2241 function_name, "dimensions too big"); |
| 2224 return; | 2242 return; |
| 2225 } | 2243 } |
| 2226 } | 2244 } |
| 2227 ScopedTextureUploadTimer timer(texture_state); | 2245 ScopedTextureUploadTimer timer(texture_state); |
| 2228 glTexSubImage2D(args.target, args.level, args.xoffset, args.yoffset, | 2246 if (args.command_type == DoTexSubImageArguments::kTexSubImage3D) { |
| 2229 args.width, args.height, AdjustTexFormat(args.format), | 2247 glTexSubImage3D(args.target, args.level, args.xoffset, args.yoffset, |
| 2230 args.type, args.pixels); | 2248 args.zoffset, args.width, args.height, args.depth, |
| 2231 return; | 2249 AdjustTexFormat(args.format), args.type, args.pixels); |
| 2250 } else { | |
| 2251 glTexSubImage2D(args.target, args.level, args.xoffset, args.yoffset, | |
| 2252 args.width, args.height, AdjustTexFormat(args.format), | |
| 2253 args.type, args.pixels); | |
| 2254 return; | |
| 2255 } | |
| 2232 } | 2256 } |
| 2233 | 2257 |
| 2234 if (!texture_state->texsubimage_faster_than_teximage && | 2258 if (!texture_state->texsubimage_faster_than_teximage && |
| 2235 !texture->IsImmutable() && !texture->HasImages()) { | 2259 !texture->IsImmutable() && !texture->HasImages()) { |
| 2236 ScopedTextureUploadTimer timer(texture_state); | 2260 ScopedTextureUploadTimer timer(texture_state); |
| 2237 GLenum internal_format; | 2261 GLenum internal_format; |
| 2238 GLenum tex_type; | 2262 GLenum tex_type; |
| 2239 texture->GetLevelType(args.target, args.level, &tex_type, &internal_format); | 2263 texture->GetLevelType(args.target, args.level, &tex_type, &internal_format); |
| 2240 // NOTE: In OpenGL ES 2.0 border is always zero. If that changes we'll need | 2264 // NOTE: In OpenGL ES 2/3 border is always zero. If that changes we'll need |
| 2241 // to look it up. | 2265 // to look it up. |
| 2242 glTexImage2D(args.target, args.level, internal_format, args.width, | 2266 if (args.command_type == DoTexSubImageArguments::kTexSubImage3D) { |
| 2243 args.height, 0, AdjustTexFormat(args.format), args.type, | 2267 glTexImage3D(args.target, args.level, internal_format, args.width, |
| 2244 args.pixels); | 2268 args.height, args.depth, 0, AdjustTexFormat(args.format), |
| 2269 args.type, args.pixels); | |
| 2270 } else { | |
| 2271 glTexImage2D(args.target, args.level, internal_format, args.width, | |
| 2272 args.height, 0, AdjustTexFormat(args.format), args.type, | |
| 2273 args.pixels); | |
| 2274 } | |
| 2245 } else { | 2275 } else { |
| 2246 ScopedTextureUploadTimer timer(texture_state); | 2276 ScopedTextureUploadTimer timer(texture_state); |
| 2247 glTexSubImage2D(args.target, args.level, args.xoffset, args.yoffset, | 2277 if (args.command_type == DoTexSubImageArguments::kTexSubImage3D) { |
| 2248 args.width, args.height, AdjustTexFormat(args.format), | 2278 glTexSubImage3D(args.target, args.level, args.xoffset, args.yoffset, |
| 2249 args.type, args.pixels); | 2279 args.zoffset, args.width, args.height, args.depth, |
| 2280 AdjustTexFormat(args.format), args.type, args.pixels); | |
| 2281 } else { | |
| 2282 glTexSubImage2D(args.target, args.level, args.xoffset, args.yoffset, | |
| 2283 args.width, args.height, AdjustTexFormat(args.format), | |
| 2284 args.type, args.pixels); | |
| 2285 } | |
| 2250 } | 2286 } |
| 2251 SetLevelCleared(texture_ref, args.target, args.level, true); | 2287 SetLevelCleared(texture_ref, args.target, args.level, true); |
| 2252 return; | 2288 return; |
| 2253 } | 2289 } |
| 2254 | 2290 |
| 2255 GLenum TextureManager::AdjustTexFormat(GLenum format) const { | 2291 GLenum TextureManager::AdjustTexFormat(GLenum format) const { |
| 2256 // TODO(bajones): GLES 3 allows for internal format and format to differ. | 2292 // TODO(bajones): GLES 3 allows for internal format and format to differ. |
| 2257 // This logic may need to change as a result. | 2293 // This logic may need to change as a result. |
| 2258 if (gfx::GetGLImplementation() == gfx::kGLImplementationDesktopGL) { | 2294 if (gfx::GetGLImplementation() == gfx::kGLImplementationDesktopGL) { |
| 2259 if (format == GL_SRGB_EXT) | 2295 if (format == GL_SRGB_EXT) |
| (...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2706 uint32_t TextureManager::GetServiceIdGeneration() const { | 2742 uint32_t TextureManager::GetServiceIdGeneration() const { |
| 2707 return current_service_id_generation_; | 2743 return current_service_id_generation_; |
| 2708 } | 2744 } |
| 2709 | 2745 |
| 2710 void TextureManager::IncrementServiceIdGeneration() { | 2746 void TextureManager::IncrementServiceIdGeneration() { |
| 2711 current_service_id_generation_++; | 2747 current_service_id_generation_++; |
| 2712 } | 2748 } |
| 2713 | 2749 |
| 2714 } // namespace gles2 | 2750 } // namespace gles2 |
| 2715 } // namespace gpu | 2751 } // namespace gpu |
| OLD | NEW |