Add a helper method GetInfoForTarget() to TextureUnit.
In addition to eliminating some redundant code, this fixes a bug in
RestoreStateForTextures() where the texture being restored was assumed to be
either bound_texture_2d or bound_texture_cube_map.
BUG=533617
Review URL: https://codereview.chromium.org/1529343002
Cr-Commit-Position: refs/heads/master@{#365722}
diff --git a/gpu/command_buffer/service/context_state.h b/gpu/command_buffer/service/context_state.h
index 911879e..7a44edc5 100644
--- a/gpu/command_buffer/service/context_state.h
+++ b/gpu/command_buffer/service/context_state.h
@@ -80,6 +80,26 @@
NOTREACHED();
return NULL;
}
+
+ scoped_refptr<TextureRef>& GetInfoForTarget(GLenum target) {
+ switch (target) {
+ case GL_TEXTURE_2D:
+ return bound_texture_2d;
+ case GL_TEXTURE_CUBE_MAP:
+ return bound_texture_cube_map;
+ case GL_TEXTURE_EXTERNAL_OES:
+ return bound_texture_external_oes;
+ case GL_TEXTURE_RECTANGLE_ARB:
+ return bound_texture_rectangle_arb;
+ case GL_TEXTURE_3D:
+ return bound_texture_3d;
+ case GL_TEXTURE_2D_ARRAY:
+ return bound_texture_2d_array;
+ }
+
+ NOTREACHED();
+ return bound_texture_2d;
+ }
};
class GPU_EXPORT Vec4 {
diff --git a/gpu/command_buffer/service/gles2_cmd_decoder.cc b/gpu/command_buffer/service/gles2_cmd_decoder.cc
index 32493e6..a3e5d6b3 100644
--- a/gpu/command_buffer/service/gles2_cmd_decoder.cc
+++ b/gpu/command_buffer/service/gles2_cmd_decoder.cc
@@ -2113,24 +2113,7 @@
static void RestoreCurrentTextureBindings(ContextState* state, GLenum target) {
TextureUnit& info = state->texture_units[0];
GLuint last_id;
- scoped_refptr<TextureRef> texture_ref;
- switch (target) {
- case GL_TEXTURE_2D:
- texture_ref = info.bound_texture_2d;
- break;
- case GL_TEXTURE_CUBE_MAP:
- texture_ref = info.bound_texture_cube_map;
- break;
- case GL_TEXTURE_EXTERNAL_OES:
- texture_ref = info.bound_texture_external_oes;
- break;
- case GL_TEXTURE_RECTANGLE_ARB:
- texture_ref = info.bound_texture_rectangle_arb;
- break;
- default:
- NOTREACHED();
- break;
- }
+ scoped_refptr<TextureRef>& texture_ref = info.GetInfoForTarget(target);
if (texture_ref.get()) {
last_id = texture_ref->service_id();
} else {
@@ -4904,29 +4887,7 @@
TextureUnit& unit = state_.texture_units[state_.active_texture_unit];
unit.bind_target = target;
- switch (target) {
- case GL_TEXTURE_2D:
- unit.bound_texture_2d = texture_ref;
- break;
- case GL_TEXTURE_CUBE_MAP:
- unit.bound_texture_cube_map = texture_ref;
- break;
- case GL_TEXTURE_EXTERNAL_OES:
- unit.bound_texture_external_oes = texture_ref;
- break;
- case GL_TEXTURE_RECTANGLE_ARB:
- unit.bound_texture_rectangle_arb = texture_ref;
- break;
- case GL_TEXTURE_3D:
- unit.bound_texture_3d = texture_ref;
- break;
- case GL_TEXTURE_2D_ARRAY:
- unit.bound_texture_2d_array = texture_ref;
- break;
- default:
- NOTREACHED(); // Validation should prevent us getting here.
- break;
- }
+ unit.GetInfoForTarget(target) = texture_ref;
}
void GLES2DecoderImpl::DoBindSampler(GLuint unit, GLuint client_id) {
@@ -7707,9 +7668,8 @@
if (!texture_ref || !texture_manager()->CanRender(texture_ref)) {
glActiveTexture(GL_TEXTURE0 + texture_unit_index);
// Get the texture_ref info that was previously bound here.
- texture_ref = texture_unit.bind_target == GL_TEXTURE_2D
- ? texture_unit.bound_texture_2d.get()
- : texture_unit.bound_texture_cube_map.get();
+ texture_ref =
+ texture_unit.GetInfoForTarget(texture_unit.bind_target).get();
glBindTexture(texture_unit.bind_target,
texture_ref ? texture_ref->service_id() : 0);
continue;
@@ -14059,23 +14019,7 @@
TextureUnit& unit = state_.texture_units[state_.active_texture_unit];
unit.bind_target = target;
- switch (target) {
- case GL_TEXTURE_2D:
- unit.bound_texture_2d = texture_ref;
- break;
- case GL_TEXTURE_CUBE_MAP:
- unit.bound_texture_cube_map = texture_ref;
- break;
- case GL_TEXTURE_EXTERNAL_OES:
- unit.bound_texture_external_oes = texture_ref;
- break;
- case GL_TEXTURE_RECTANGLE_ARB:
- unit.bound_texture_rectangle_arb = texture_ref;
- break;
- default:
- NOTREACHED(); // Validation should prevent us getting here.
- break;
- }
+ unit.GetInfoForTarget(target) = texture_ref;
}
void GLES2DecoderImpl::EnsureTextureForClientId(