| Index: gpu/command_buffer/service/context_state.cc
|
| diff --git a/gpu/command_buffer/service/context_state.cc b/gpu/command_buffer/service/context_state.cc
|
| index 9942e9d249e3f071c353a68bf00dec794c17e581..7eaaa17805ab225a0aeba3d7ec5ef39a0422a777 100644
|
| --- a/gpu/command_buffer/service/context_state.cc
|
| +++ b/gpu/command_buffer/service/context_state.cc
|
| @@ -44,7 +44,84 @@ ContextState::ContextState(FeatureInfo* feature_info)
|
| ContextState::~ContextState() {
|
| }
|
|
|
| -void ContextState::RestoreState() const {
|
| +void ContextState::RestoreTextureUnitBindings(GLuint unit) const {
|
| + DCHECK_LT(unit, texture_units.size());
|
| + const TextureUnit& texture_unit = texture_units[unit];
|
| + glActiveTexture(GL_TEXTURE0 + unit);
|
| + GLuint service_id = texture_unit.bound_texture_2d ?
|
| + texture_unit.bound_texture_2d->service_id() : 0;
|
| + glBindTexture(GL_TEXTURE_2D, service_id);
|
| + service_id = texture_unit.bound_texture_cube_map ?
|
| + texture_unit.bound_texture_cube_map->service_id() : 0;
|
| + glBindTexture(GL_TEXTURE_CUBE_MAP, service_id);
|
| +
|
| + if (feature_info_->feature_flags().oes_egl_image_external) {
|
| + service_id = texture_unit.bound_texture_external_oes ?
|
| + texture_unit.bound_texture_external_oes->service_id() : 0;
|
| + glBindTexture(GL_TEXTURE_EXTERNAL_OES, service_id);
|
| + }
|
| +
|
| + if (feature_info_->feature_flags().arb_texture_rectangle) {
|
| + service_id = texture_unit.bound_texture_rectangle_arb ?
|
| + texture_unit.bound_texture_rectangle_arb->service_id() : 0;
|
| + glBindTexture(GL_TEXTURE_RECTANGLE_ARB, service_id);
|
| + }
|
| +}
|
| +
|
| +void ContextState::RestoreBufferBindings() const {
|
| + if (vertex_attrib_manager) {
|
| + BufferManager::BufferInfo* element_array_buffer =
|
| + vertex_attrib_manager->element_array_buffer();
|
| + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,
|
| + element_array_buffer ? element_array_buffer->service_id() : 0);
|
| + }
|
| + glBindBuffer(
|
| + GL_ARRAY_BUFFER,
|
| + bound_array_buffer ? bound_array_buffer->service_id() : 0);
|
| +}
|
| +
|
| +void ContextState::RestoreRenderbufferBindings() const {
|
| + // Restore Bindings
|
| + glBindRenderbufferEXT(
|
| + GL_RENDERBUFFER,
|
| + bound_renderbuffer ? bound_renderbuffer->service_id() : 0);
|
| +}
|
| +
|
| +void ContextState::RestoreProgramBindings() const {
|
| + glUseProgram(current_program ? current_program->service_id() : 0);
|
| +}
|
| +
|
| +void ContextState::RestoreActiveTexture() const {
|
| + glActiveTexture(GL_TEXTURE0 + active_texture_unit);
|
| +}
|
| +
|
| +void ContextState::RestoreAttribute(GLuint attrib) const {
|
| + const VertexAttribManager::VertexAttribInfo* info =
|
| + vertex_attrib_manager->GetVertexAttribInfo(attrib);
|
| + const void* ptr = reinterpret_cast<const void*>(info->offset());
|
| + BufferManager::BufferInfo* buffer_info = info->buffer();
|
| + glBindBuffer(
|
| + GL_ARRAY_BUFFER, buffer_info ? buffer_info->service_id() : 0);
|
| + glVertexAttribPointer(
|
| + attrib, info->size(), info->type(), info->normalized(),
|
| + info->gl_stride(), ptr);
|
| + if (info->divisor())
|
| + glVertexAttribDivisorANGLE(attrib, info->divisor());
|
| + // Never touch vertex attribute 0's state (in particular, never
|
| + // disable it) when running on desktop GL because it will never be
|
| + // re-enabled.
|
| + if (attrib != 0 ||
|
| + gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2) {
|
| + if (info->enabled()) {
|
| + glEnableVertexAttribArray(attrib);
|
| + } else {
|
| + glDisableVertexAttribArray(attrib);
|
| + }
|
| + }
|
| + glVertexAttrib4fv(attrib, attrib_values[attrib].v);
|
| +}
|
| +
|
| +void ContextState::RestoreGlobalState() const {
|
| InitCapabilities();
|
| InitState();
|
|
|
| @@ -54,31 +131,14 @@ void ContextState::RestoreState() const {
|
| glHint(GL_GENERATE_MIPMAP_HINT, hint_generate_mipmap);
|
| // TODO: If OES_standard_derivatives is available
|
| // restore GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES
|
| +}
|
|
|
| +void ContextState::RestoreState() const {
|
| // Restore Texture state.
|
| for (size_t ii = 0; ii < texture_units.size(); ++ii) {
|
| - const TextureUnit& texture_unit = texture_units[ii];
|
| - glActiveTexture(GL_TEXTURE0 + ii);
|
| - GLuint service_id = texture_unit.bound_texture_2d ?
|
| - texture_unit.bound_texture_2d->service_id() : 0;
|
| - glBindTexture(GL_TEXTURE_2D, service_id);
|
| - service_id = texture_unit.bound_texture_cube_map ?
|
| - texture_unit.bound_texture_cube_map->service_id() : 0;
|
| - glBindTexture(GL_TEXTURE_CUBE_MAP, service_id);
|
| -
|
| - if (feature_info_->feature_flags().oes_egl_image_external) {
|
| - service_id = texture_unit.bound_texture_external_oes ?
|
| - texture_unit.bound_texture_external_oes->service_id() : 0;
|
| - glBindTexture(GL_TEXTURE_EXTERNAL_OES, service_id);
|
| - }
|
| -
|
| - if (feature_info_->feature_flags().arb_texture_rectangle) {
|
| - service_id = texture_unit.bound_texture_rectangle_arb ?
|
| - texture_unit.bound_texture_rectangle_arb->service_id() : 0;
|
| - glBindTexture(GL_TEXTURE_RECTANGLE_ARB, service_id);
|
| - }
|
| + RestoreTextureUnitBindings(ii);
|
| }
|
| - glActiveTexture(GL_TEXTURE0 + active_texture_unit);
|
| + RestoreActiveTexture();
|
|
|
| // Restore Attrib State
|
| // TODO: This if should not be needed. RestoreState is getting called
|
| @@ -87,45 +147,12 @@ void ContextState::RestoreState() const {
|
| // TODO(gman): Move this restoration to VertexAttribManager.
|
| for (size_t attrib = 0; attrib < vertex_attrib_manager->num_attribs();
|
| ++attrib) {
|
| - const VertexAttribManager::VertexAttribInfo* info =
|
| - vertex_attrib_manager->GetVertexAttribInfo(attrib);
|
| - const void* ptr = reinterpret_cast<const void*>(info->offset());
|
| - BufferManager::BufferInfo* buffer_info = info->buffer();
|
| - glBindBuffer(
|
| - GL_ARRAY_BUFFER, buffer_info ? buffer_info->service_id() : 0);
|
| - glVertexAttribPointer(
|
| - attrib, info->size(), info->type(), info->normalized(),
|
| - info->gl_stride(), ptr);
|
| - if (info->divisor())
|
| - glVertexAttribDivisorANGLE(attrib, info->divisor());
|
| - // Never touch vertex attribute 0's state (in particular, never
|
| - // disable it) when running on desktop GL because it will never be
|
| - // re-enabled.
|
| - if (attrib != 0 ||
|
| - gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2) {
|
| - if (info->enabled()) {
|
| - glEnableVertexAttribArray(attrib);
|
| - } else {
|
| - glDisableVertexAttribArray(attrib);
|
| - }
|
| - }
|
| - glVertexAttrib4fv(attrib, attrib_values[attrib].v);
|
| + RestoreAttribute(attrib);
|
| }
|
| - BufferManager::BufferInfo* element_array_buffer =
|
| - vertex_attrib_manager->element_array_buffer();
|
| - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,
|
| - element_array_buffer ? element_array_buffer->service_id() : 0);
|
| }
|
|
|
| - // Restore Bindings
|
| - glBindBuffer(
|
| - GL_ARRAY_BUFFER,
|
| - bound_array_buffer ? bound_array_buffer->service_id() : 0);
|
| - glBindRenderbufferEXT(
|
| - GL_RENDERBUFFER,
|
| - bound_renderbuffer ? bound_renderbuffer->service_id() : 0);
|
| -
|
| - glUseProgram(current_program ? current_program->service_id() : 0);
|
| + RestoreRenderbufferBindings();
|
| + RestoreProgramBindings();
|
| }
|
|
|
| // Include the auto-generated part of this file. We split this because it means
|
|
|