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 <algorithm> | 7 #include <algorithm> |
8 #include <set> | 8 #include <set> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 1954 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1965 DecoderTextureState* texture_state, | 1965 DecoderTextureState* texture_state, |
1966 ContextState* state, | 1966 ContextState* state, |
1967 DecoderFramebufferState* framebuffer_state, | 1967 DecoderFramebufferState* framebuffer_state, |
1968 const char* function_name, | 1968 const char* function_name, |
1969 const DoTexImageArguments& args) { | 1969 const DoTexImageArguments& args) { |
1970 TextureRef* texture_ref; | 1970 TextureRef* texture_ref; |
1971 if (!ValidateTexImage(state, function_name, args, &texture_ref)) { | 1971 if (!ValidateTexImage(state, function_name, args, &texture_ref)) { |
1972 return; | 1972 return; |
1973 } | 1973 } |
1974 | 1974 |
| 1975 // ValidateTexImage is passed already. |
| 1976 Texture* texture = texture_ref->texture(); |
| 1977 bool need_cube_map_workaround = |
| 1978 texture->target() == GL_TEXTURE_CUBE_MAP && |
| 1979 (texture_state->force_cube_complete || |
| 1980 (texture_state->force_cube_map_positive_x_allocation && |
| 1981 args.target != GL_TEXTURE_CUBE_MAP_POSITIVE_X)); |
| 1982 if (need_cube_map_workaround) { |
| 1983 std::vector<GLenum> undefined_faces; |
| 1984 if (texture_state->force_cube_complete) { |
| 1985 int width = 0; |
| 1986 int height = 0; |
| 1987 for (unsigned i = 0; i < 6; i++) { |
| 1988 bool defined = |
| 1989 texture->GetLevelSize(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, |
| 1990 args.level, &width, &height, nullptr); |
| 1991 if (!defined || GL_TEXTURE_CUBE_MAP_POSITIVE_X + i == args.target) |
| 1992 undefined_faces.push_back(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i); |
| 1993 } |
| 1994 } else if (texture_state->force_cube_map_positive_x_allocation && |
| 1995 args.target != GL_TEXTURE_CUBE_MAP_POSITIVE_X) { |
| 1996 int width = 0; |
| 1997 int height = 0; |
| 1998 if (!texture->GetLevelSize(GL_TEXTURE_CUBE_MAP_POSITIVE_X, args.level, |
| 1999 &width, &height, nullptr)) { |
| 2000 undefined_faces.push_back(GL_TEXTURE_CUBE_MAP_POSITIVE_X); |
| 2001 } |
| 2002 undefined_faces.push_back(args.target); |
| 2003 } |
| 2004 |
| 2005 DCHECK(undefined_faces.size()); |
| 2006 if (!memory_tracker_managed_->EnsureGPUMemoryAvailable( |
| 2007 undefined_faces.size() * args.pixels_size)) { |
| 2008 ERRORSTATE_SET_GL_ERROR(state->GetErrorState(), GL_OUT_OF_MEMORY, |
| 2009 function_name, "out of memory"); |
| 2010 return; |
| 2011 } |
| 2012 DoTexImageArguments new_args = args; |
| 2013 scoped_ptr<char[]> zero(new char[args.pixels_size]); |
| 2014 memset(zero.get(), 0, args.pixels_size); |
| 2015 for (GLenum face : undefined_faces) { |
| 2016 new_args.target = face; |
| 2017 if (face == args.target) { |
| 2018 new_args.pixels = args.pixels; |
| 2019 } else { |
| 2020 new_args.pixels = zero.get(); |
| 2021 } |
| 2022 DoTexImage(texture_state, state->GetErrorState(), framebuffer_state, |
| 2023 function_name, texture_ref, new_args); |
| 2024 } |
| 2025 return; |
| 2026 } |
| 2027 |
1975 DoTexImage(texture_state, state->GetErrorState(), framebuffer_state, | 2028 DoTexImage(texture_state, state->GetErrorState(), framebuffer_state, |
1976 function_name, texture_ref, args); | 2029 function_name, texture_ref, args); |
1977 } | 2030 } |
1978 | 2031 |
1979 GLenum TextureManager::AdjustTexFormat(GLenum format) const { | 2032 GLenum TextureManager::AdjustTexFormat(GLenum format) const { |
1980 // TODO(bajones): GLES 3 allows for internal format and format to differ. | 2033 // TODO(bajones): GLES 3 allows for internal format and format to differ. |
1981 // This logic may need to change as a result. | 2034 // This logic may need to change as a result. |
1982 if (gfx::GetGLImplementation() == gfx::kGLImplementationDesktopGL) { | 2035 if (gfx::GetGLImplementation() == gfx::kGLImplementationDesktopGL) { |
1983 if (format == GL_SRGB_EXT) | 2036 if (format == GL_SRGB_EXT) |
1984 return GL_RGB; | 2037 return GL_RGB; |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2134 pmd->AddOwnershipEdge(client_guid, service_guid, importance); | 2187 pmd->AddOwnershipEdge(client_guid, service_guid, importance); |
2135 | 2188 |
2136 // Dump all sub-levels held by the texture. They will appear below the main | 2189 // Dump all sub-levels held by the texture. They will appear below the main |
2137 // gl/textures/client_X/texture_Y dump. | 2190 // gl/textures/client_X/texture_Y dump. |
2138 ref->texture()->DumpLevelMemory(pmd, memory_tracker_->ClientTracingId(), | 2191 ref->texture()->DumpLevelMemory(pmd, memory_tracker_->ClientTracingId(), |
2139 dump_name); | 2192 dump_name); |
2140 } | 2193 } |
2141 | 2194 |
2142 } // namespace gles2 | 2195 } // namespace gles2 |
2143 } // namespace gpu | 2196 } // namespace gpu |
OLD | NEW |