Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(41)

Side by Side Diff: gpu/command_buffer/service/texture_manager.cc

Issue 1426903002: gpu: Make glTexSubImage2D work with GL_SRGB_ALPHA on OpenGL (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 1987 matching lines...) Expand 10 before | Expand all | Expand 10 after
1998 DoTexImage(texture_state, state->GetErrorState(), framebuffer_state, 1998 DoTexImage(texture_state, state->GetErrorState(), framebuffer_state,
1999 function_name, texture_ref, new_args); 1999 function_name, texture_ref, new_args);
2000 } 2000 }
2001 return; 2001 return;
2002 } 2002 }
2003 2003
2004 DoTexImage(texture_state, state->GetErrorState(), framebuffer_state, 2004 DoTexImage(texture_state, state->GetErrorState(), framebuffer_state,
2005 function_name, texture_ref, args); 2005 function_name, texture_ref, args);
2006 } 2006 }
2007 2007
2008 bool TextureManager::ValidateTexSubImage(ContextState* state,
2009 const char* function_name,
2010 const DoTexSubImageArguments& args,
2011 TextureRef** texture_ref) {
2012 ErrorState* error_state = state->GetErrorState();
2013 const Validators* validators = feature_info_->validators();
2014
2015 if (!validators->texture_target.IsValid(args.target)) {
2016 ERRORSTATE_SET_GL_ERROR_INVALID_ENUM(error_state, function_name,
2017 args.target, "target");
2018 return false;
2019 }
2020 // TODO(ccameron): Add a separate texture from |texture_target| for
2021 // [Compressed]Tex[Sub]Image2D and related functions.
2022 // http://crbug.com/536854
2023 if (args.target == GL_TEXTURE_RECTANGLE_ARB) {
2024 ERRORSTATE_SET_GL_ERROR_INVALID_ENUM(error_state, function_name,
2025 args.target, "target");
2026 return false;
2027 }
2028 if (args.width < 0) {
2029 ERRORSTATE_SET_GL_ERROR(error_state, GL_INVALID_VALUE, function_name,
2030 "width < 0");
2031 return false;
2032 }
2033 if (args.height < 0) {
2034 ERRORSTATE_SET_GL_ERROR(error_state, GL_INVALID_VALUE, function_name,
2035 "height < 0");
2036 return false;
2037 }
2038 TextureRef* local_texture_ref = GetTextureInfoForTarget(state, args.target);
2039 if (!local_texture_ref) {
2040 ERRORSTATE_SET_GL_ERROR(error_state, GL_INVALID_OPERATION, function_name,
2041 "unknown texture for target");
2042 return false;
2043 }
2044 Texture* texture = local_texture_ref->texture();
2045 GLenum current_type = 0;
2046 GLenum internal_format = 0;
2047 if (!texture->GetLevelType(args.target, args.level, &current_type,
2048 &internal_format)) {
2049 ERRORSTATE_SET_GL_ERROR(error_state, GL_INVALID_OPERATION, function_name,
2050 "level does not exist.");
2051 return false;
2052 }
2053 if (!ValidateTextureParameters(error_state, function_name, args.format,
2054 args.type, internal_format, args.level)) {
2055 return false;
2056 }
2057 if (args.type != current_type && !feature_info_->IsES3Enabled()) {
2058 ERRORSTATE_SET_GL_ERROR(error_state, GL_INVALID_OPERATION, function_name,
2059 "type does not match type of texture.");
2060 return false;
2061 }
2062 if (!texture->ValidForTexture(args.target, args.level, args.xoffset,
2063 args.yoffset, 0, args.width, args.height, 1)) {
2064 ERRORSTATE_SET_GL_ERROR(error_state, GL_INVALID_VALUE, function_name,
2065 "bad dimensions.");
2066 return false;
2067 }
2068 if ((GLES2Util::GetChannelsForFormat(args.format) &
2069 (GLES2Util::kDepth | GLES2Util::kStencil)) != 0 &&
2070 !feature_info_->IsES3Enabled()) {
2071 ERRORSTATE_SET_GL_ERROR(
2072 error_state, GL_INVALID_OPERATION, function_name,
2073 "can not supply data for depth or stencil textures");
2074 return false;
2075 }
2076 DCHECK(args.pixels);
2077 *texture_ref = local_texture_ref;
2078 return true;
2079 }
2080
2081 void TextureManager::ValidateAndDoTexSubImage(
2082 GLES2Decoder* decoder,
2083 DecoderTextureState* texture_state,
2084 ContextState* state,
2085 DecoderFramebufferState* framebuffer_state,
2086 const char* function_name,
2087 const DoTexSubImageArguments& args) {
2088 ErrorState* error_state = state->GetErrorState();
2089 TextureRef* texture_ref;
2090 if (!ValidateTexSubImage(state, function_name, args, &texture_ref)) {
2091 return;
2092 }
2093
2094 Texture* texture = texture_ref->texture();
2095 GLsizei tex_width = 0;
2096 GLsizei tex_height = 0;
2097 bool ok = texture->GetLevelSize(args.target, args.level, &tex_width,
2098 &tex_height, nullptr);
2099 DCHECK(ok);
2100 if (args.xoffset != 0 || args.yoffset != 0 || args.width != tex_width ||
2101 args.height != tex_height) {
2102 gfx::Rect cleared_rect;
2103 if (CombineAdjacentRects(
2104 texture->GetLevelClearedRect(args.target, args.level),
2105 gfx::Rect(args.xoffset, args.yoffset, args.width, args.height),
2106 &cleared_rect)) {
2107 DCHECK_GE(cleared_rect.size().GetArea(),
2108 texture->GetLevelClearedRect(args.target, args.level)
2109 .size()
2110 .GetArea());
2111 SetLevelClearedRect(texture_ref, args.target, args.level, cleared_rect);
2112 } else {
2113 // Otherwise clear part of texture level that is not already cleared.
2114 if (!ClearTextureLevel(decoder, texture_ref, args.target, args.level)) {
2115 ERRORSTATE_SET_GL_ERROR(error_state, GL_OUT_OF_MEMORY,
2116 "glTexSubImage2D", "dimensions too big");
2117 return;
2118 }
2119 }
2120 ScopedTextureUploadTimer timer(texture_state);
2121 glTexSubImage2D(args.target, args.level, args.xoffset, args.yoffset,
2122 args.width, args.height, AdjustTexFormat(args.format),
2123 args.type, args.pixels);
2124 return;
2125 }
2126
2127 if (!texture_state->texsubimage_faster_than_teximage &&
2128 !texture->IsImmutable() && !texture->HasImages()) {
2129 ScopedTextureUploadTimer timer(texture_state);
2130 GLenum internal_format;
2131 GLenum tex_type;
2132 texture->GetLevelType(args.target, args.level, &tex_type, &internal_format);
2133 // NOTE: In OpenGL ES 2.0 border is always zero. If that changes we'll need
2134 // to look it up.
2135 glTexImage2D(args.target, args.level, internal_format, args.width,
2136 args.height, 0, AdjustTexFormat(args.format), args.type,
2137 args.pixels);
2138 } else {
2139 ScopedTextureUploadTimer timer(texture_state);
2140 glTexSubImage2D(args.target, args.level, args.xoffset, args.yoffset,
2141 args.width, args.height, AdjustTexFormat(args.format),
2142 args.type, args.pixels);
2143 }
2144 SetLevelCleared(texture_ref, args.target, args.level, true);
2145 return;
2146 }
2147
2008 GLenum TextureManager::AdjustTexFormat(GLenum format) const { 2148 GLenum TextureManager::AdjustTexFormat(GLenum format) const {
2009 // TODO(bajones): GLES 3 allows for internal format and format to differ. 2149 // TODO(bajones): GLES 3 allows for internal format and format to differ.
2010 // This logic may need to change as a result. 2150 // This logic may need to change as a result.
2011 if (gfx::GetGLImplementation() == gfx::kGLImplementationDesktopGL) { 2151 if (gfx::GetGLImplementation() == gfx::kGLImplementationDesktopGL) {
2012 if (format == GL_SRGB_EXT) 2152 if (format == GL_SRGB_EXT)
2013 return GL_RGB; 2153 return GL_RGB;
2014 if (format == GL_SRGB_ALPHA_EXT) 2154 if (format == GL_SRGB_ALPHA_EXT)
2015 return GL_RGBA; 2155 return GL_RGBA;
2016 } 2156 }
2017 return format; 2157 return format;
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
2085 GLenum error = ERRORSTATE_PEEK_GL_ERROR(error_state, function_name); 2225 GLenum error = ERRORSTATE_PEEK_GL_ERROR(error_state, function_name);
2086 if (error == GL_NO_ERROR) { 2226 if (error == GL_NO_ERROR) {
2087 SetLevelInfo( 2227 SetLevelInfo(
2088 texture_ref, args.target, args.level, args.internal_format, args.width, 2228 texture_ref, args.target, args.level, args.internal_format, args.width,
2089 args.height, args.depth, args.border, args.format, args.type, 2229 args.height, args.depth, args.border, args.format, args.type,
2090 args.pixels != NULL ? gfx::Rect(args.width, args.height) : gfx::Rect()); 2230 args.pixels != NULL ? gfx::Rect(args.width, args.height) : gfx::Rect());
2091 texture_state->tex_image_failed = false; 2231 texture_state->tex_image_failed = false;
2092 } 2232 }
2093 } 2233 }
2094 2234
2235 bool TextureManager::CombineAdjacentRects(const gfx::Rect& rect1,
2236 const gfx::Rect& rect2,
2237 gfx::Rect* result) {
2238 // Return |rect2| if |rect1| is empty or |rect2| contains |rect1|.
2239 if (rect1.IsEmpty() || rect2.Contains(rect1)) {
2240 *result = rect2;
2241 return true;
2242 }
2243
2244 // Return |rect1| if |rect2| is empty or |rect1| contains |rect2|.
2245 if (rect2.IsEmpty() || rect1.Contains(rect2)) {
2246 *result = rect1;
2247 return true;
2248 }
2249
2250 // Return the union of |rect1| and |rect2| if they share an edge.
2251 if (rect1.SharesEdgeWith(rect2)) {
2252 *result = gfx::UnionRects(rect1, rect2);
2253 return true;
2254 }
2255
2256 // Return false if it's not possible to combine |rect1| and |rect2|.
2257 return false;
2258 }
2259
2095 ScopedTextureUploadTimer::ScopedTextureUploadTimer( 2260 ScopedTextureUploadTimer::ScopedTextureUploadTimer(
2096 DecoderTextureState* texture_state) 2261 DecoderTextureState* texture_state)
2097 : texture_state_(texture_state), 2262 : texture_state_(texture_state),
2098 begin_time_(base::TimeTicks::Now()) { 2263 begin_time_(base::TimeTicks::Now()) {
2099 } 2264 }
2100 2265
2101 ScopedTextureUploadTimer::~ScopedTextureUploadTimer() { 2266 ScopedTextureUploadTimer::~ScopedTextureUploadTimer() {
2102 texture_state_->texture_upload_count++; 2267 texture_state_->texture_upload_count++;
2103 texture_state_->total_texture_upload_time += 2268 texture_state_->total_texture_upload_time +=
2104 base::TimeTicks::Now() - begin_time_; 2269 base::TimeTicks::Now() - begin_time_;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
2163 pmd->AddOwnershipEdge(client_guid, service_guid, importance); 2328 pmd->AddOwnershipEdge(client_guid, service_guid, importance);
2164 2329
2165 // Dump all sub-levels held by the texture. They will appear below the main 2330 // Dump all sub-levels held by the texture. They will appear below the main
2166 // gl/textures/client_X/texture_Y dump. 2331 // gl/textures/client_X/texture_Y dump.
2167 ref->texture()->DumpLevelMemory(pmd, memory_tracker_->ClientTracingId(), 2332 ref->texture()->DumpLevelMemory(pmd, memory_tracker_->ClientTracingId(),
2168 dump_name); 2333 dump_name);
2169 } 2334 }
2170 2335
2171 } // namespace gles2 2336 } // namespace gles2
2172 } // namespace gpu 2337 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698