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/context_state.h" | 5 #include "gpu/command_buffer/service/context_state.h" |
6 | 6 |
7 #include "gpu/command_buffer/common/gles2_cmd_utils.h" | 7 #include "gpu/command_buffer/common/gles2_cmd_utils.h" |
8 #include "gpu/command_buffer/service/buffer_manager.h" | 8 #include "gpu/command_buffer/service/buffer_manager.h" |
9 #include "gpu/command_buffer/service/error_state.h" | 9 #include "gpu/command_buffer/service/error_state.h" |
10 #include "gpu/command_buffer/service/framebuffer_manager.h" | 10 #include "gpu/command_buffer/service/framebuffer_manager.h" |
(...skipping 22 matching lines...) Expand all Loading... | |
33 } | 33 } |
34 | 34 |
35 TextureUnit::~TextureUnit() { | 35 TextureUnit::~TextureUnit() { |
36 } | 36 } |
37 | 37 |
38 ContextState::ContextState(FeatureInfo* feature_info, Logger* logger) | 38 ContextState::ContextState(FeatureInfo* feature_info, Logger* logger) |
39 : active_texture_unit(0), | 39 : active_texture_unit(0), |
40 pack_reverse_row_order(false), | 40 pack_reverse_row_order(false), |
41 fbo_binding_for_scissor_workaround_dirty_(false), | 41 fbo_binding_for_scissor_workaround_dirty_(false), |
42 feature_info_(feature_info), | 42 feature_info_(feature_info), |
43 max_active_texture_unit_(0), | |
43 error_state_(ErrorState::Create(logger)) { | 44 error_state_(ErrorState::Create(logger)) { |
44 Initialize(); | 45 Initialize(); |
45 } | 46 } |
46 | 47 |
47 ContextState::~ContextState() { | 48 ContextState::~ContextState() { |
48 } | 49 } |
49 | 50 |
50 void ContextState::RestoreTextureUnitBindings(GLuint unit) const { | 51 void ContextState::RestoreTextureUnitBindings(GLuint unit) const { |
51 DCHECK_LT(unit, texture_units.size()); | 52 DCHECK_LT(unit, texture_units.size()); |
52 const TextureUnit& texture_unit = texture_units[unit]; | 53 const TextureUnit& texture_unit = texture_units[unit]; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
94 } | 95 } |
95 | 96 |
96 void ContextState::RestoreProgramBindings() const { | 97 void ContextState::RestoreProgramBindings() const { |
97 glUseProgram(current_program.get() ? current_program->service_id() : 0); | 98 glUseProgram(current_program.get() ? current_program->service_id() : 0); |
98 } | 99 } |
99 | 100 |
100 void ContextState::RestoreActiveTexture() const { | 101 void ContextState::RestoreActiveTexture() const { |
101 glActiveTexture(GL_TEXTURE0 + active_texture_unit); | 102 glActiveTexture(GL_TEXTURE0 + active_texture_unit); |
102 } | 103 } |
103 | 104 |
104 void ContextState::RestoreAllTextureUnitBindings() const { | 105 void ContextState::RestoreAllTextureUnitBindings( |
106 const ContextState* prev_state) const { | |
107 size_t units_to_restore = texture_units.size(); | |
boliu
2013/12/18 19:55:11
Should this be max_active_texture_unit_?
| |
108 if (prev_state) { | |
109 // Only restore units that have been modified by both contexts. | |
110 units_to_restore = std::max(prev_state->max_active_texture_unit_, | |
111 max_active_texture_unit_) + 1; | |
no sievers
2013/12/18 19:36:20
Do we really need |max_active_texture_unit_| which
kaanb
2013/12/18 19:43:56
Having max_active_texture_unit_ is useful as it re
boliu
2013/12/18 19:55:11
Just diffing against prev_state would be great for
Ken Russell (switch to Gerrit)
2013/12/18 20:09:44
Reducing the number of loop iterations is a premat
| |
112 } | |
113 | |
105 // Restore Texture state. | 114 // Restore Texture state. |
106 for (size_t ii = 0; ii < texture_units.size(); ++ii) { | 115 for (size_t ii = 0; ii < units_to_restore; ++ii) { |
107 RestoreTextureUnitBindings(ii); | 116 RestoreTextureUnitBindings(ii); |
108 } | 117 } |
109 RestoreActiveTexture(); | 118 RestoreActiveTexture(); |
110 } | 119 } |
111 | 120 |
112 void ContextState::RestoreAttribute(GLuint attrib_index) const { | 121 void ContextState::RestoreAttribute(GLuint attrib_index) const { |
113 const VertexAttrib* attrib = | 122 const VertexAttrib* attrib = |
114 vertex_attrib_manager->GetVertexAttrib(attrib_index); | 123 vertex_attrib_manager->GetVertexAttrib(attrib_index); |
115 const void* ptr = reinterpret_cast<const void*>(attrib->offset()); | 124 const void* ptr = reinterpret_cast<const void*>(attrib->offset()); |
116 Buffer* buffer = attrib->buffer(); | 125 Buffer* buffer = attrib->buffer(); |
(...skipping 15 matching lines...) Expand all Loading... | |
132 } | 141 } |
133 } | 142 } |
134 glVertexAttrib4fv(attrib_index, attrib_values[attrib_index].v); | 143 glVertexAttrib4fv(attrib_index, attrib_values[attrib_index].v); |
135 } | 144 } |
136 | 145 |
137 void ContextState::RestoreGlobalState() const { | 146 void ContextState::RestoreGlobalState() const { |
138 InitCapabilities(); | 147 InitCapabilities(); |
139 InitState(); | 148 InitState(); |
140 } | 149 } |
141 | 150 |
142 void ContextState::RestoreState() const { | 151 void ContextState::RestoreState(const ContextState* prev_state) const { |
143 RestoreAllTextureUnitBindings(); | 152 RestoreAllTextureUnitBindings(prev_state); |
144 | 153 |
145 // Restore Attrib State | 154 // Restore Attrib State |
146 // TODO: This if should not be needed. RestoreState is getting called | 155 // TODO: This if should not be needed. RestoreState is getting called |
147 // before GLES2Decoder::Initialize which is a bug. | 156 // before GLES2Decoder::Initialize which is a bug. |
148 if (vertex_attrib_manager.get()) { | 157 if (vertex_attrib_manager.get()) { |
149 // TODO(gman): Move this restoration to VertexAttribManager. | 158 // TODO(gman): Move this restoration to VertexAttribManager. |
150 for (size_t attrib = 0; attrib < vertex_attrib_manager->num_attribs(); | 159 for (size_t attrib = 0; attrib < vertex_attrib_manager->num_attribs(); |
151 ++attrib) { | 160 ++attrib) { |
152 RestoreAttribute(attrib); | 161 RestoreAttribute(attrib); |
153 } | 162 } |
(...skipping 11 matching lines...) Expand all Loading... | |
165 | 174 |
166 // Include the auto-generated part of this file. We split this because it means | 175 // Include the auto-generated part of this file. We split this because it means |
167 // we can easily edit the non-auto generated parts right here in this file | 176 // we can easily edit the non-auto generated parts right here in this file |
168 // instead of having to edit some template or the code generator. | 177 // instead of having to edit some template or the code generator. |
169 #include "gpu/command_buffer/service/context_state_impl_autogen.h" | 178 #include "gpu/command_buffer/service/context_state_impl_autogen.h" |
170 | 179 |
171 } // namespace gles2 | 180 } // namespace gles2 |
172 } // namespace gpu | 181 } // namespace gpu |
173 | 182 |
174 | 183 |
OLD | NEW |