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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 Initialize(); | 46 Initialize(); |
47 } | 47 } |
48 | 48 |
49 ContextState::~ContextState() { | 49 ContextState::~ContextState() { |
50 } | 50 } |
51 | 51 |
52 void ContextState::RestoreTextureUnitBindings(GLuint unit) const { | 52 void ContextState::RestoreTextureUnitBindings(GLuint unit) const { |
53 DCHECK_LT(unit, texture_units.size()); | 53 DCHECK_LT(unit, texture_units.size()); |
54 const TextureUnit& texture_unit = texture_units[unit]; | 54 const TextureUnit& texture_unit = texture_units[unit]; |
55 glActiveTexture(GL_TEXTURE0 + unit); | 55 glActiveTexture(GL_TEXTURE0 + unit); |
56 GLuint service_id = texture_unit.bound_texture_2d ? | 56 GLuint service_id = texture_unit.bound_texture_2d.get() |
57 texture_unit.bound_texture_2d->service_id() : 0; | 57 ? texture_unit.bound_texture_2d->service_id() |
| 58 : 0; |
58 glBindTexture(GL_TEXTURE_2D, service_id); | 59 glBindTexture(GL_TEXTURE_2D, service_id); |
59 service_id = texture_unit.bound_texture_cube_map ? | 60 service_id = texture_unit.bound_texture_cube_map.get() |
60 texture_unit.bound_texture_cube_map->service_id() : 0; | 61 ? texture_unit.bound_texture_cube_map->service_id() |
| 62 : 0; |
61 glBindTexture(GL_TEXTURE_CUBE_MAP, service_id); | 63 glBindTexture(GL_TEXTURE_CUBE_MAP, service_id); |
62 | 64 |
63 if (feature_info_->feature_flags().oes_egl_image_external) { | 65 if (feature_info_->feature_flags().oes_egl_image_external) { |
64 service_id = texture_unit.bound_texture_external_oes ? | 66 service_id = texture_unit.bound_texture_external_oes.get() |
65 texture_unit.bound_texture_external_oes->service_id() : 0; | 67 ? texture_unit.bound_texture_external_oes->service_id() |
| 68 : 0; |
66 glBindTexture(GL_TEXTURE_EXTERNAL_OES, service_id); | 69 glBindTexture(GL_TEXTURE_EXTERNAL_OES, service_id); |
67 } | 70 } |
68 | 71 |
69 if (feature_info_->feature_flags().arb_texture_rectangle) { | 72 if (feature_info_->feature_flags().arb_texture_rectangle) { |
70 service_id = texture_unit.bound_texture_rectangle_arb ? | 73 service_id = texture_unit.bound_texture_rectangle_arb.get() |
71 texture_unit.bound_texture_rectangle_arb->service_id() : 0; | 74 ? texture_unit.bound_texture_rectangle_arb->service_id() |
| 75 : 0; |
72 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, service_id); | 76 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, service_id); |
73 } | 77 } |
74 } | 78 } |
75 | 79 |
76 void ContextState::RestoreBufferBindings() const { | 80 void ContextState::RestoreBufferBindings() const { |
77 if (vertex_attrib_manager) { | 81 if (vertex_attrib_manager.get()) { |
78 Buffer* element_array_buffer = | 82 Buffer* element_array_buffer = |
79 vertex_attrib_manager->element_array_buffer(); | 83 vertex_attrib_manager->element_array_buffer(); |
80 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, | 84 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, |
81 element_array_buffer ? element_array_buffer->service_id() : 0); | 85 element_array_buffer ? element_array_buffer->service_id() : 0); |
82 } | 86 } |
83 glBindBuffer( | 87 glBindBuffer(GL_ARRAY_BUFFER, |
84 GL_ARRAY_BUFFER, | 88 bound_array_buffer.get() ? bound_array_buffer->service_id() : 0); |
85 bound_array_buffer ? bound_array_buffer->service_id() : 0); | |
86 } | 89 } |
87 | 90 |
88 void ContextState::RestoreRenderbufferBindings() const { | 91 void ContextState::RestoreRenderbufferBindings() const { |
89 // Restore Bindings | 92 // Restore Bindings |
90 glBindRenderbufferEXT( | 93 glBindRenderbufferEXT( |
91 GL_RENDERBUFFER, | 94 GL_RENDERBUFFER, |
92 bound_renderbuffer ? bound_renderbuffer->service_id() : 0); | 95 bound_renderbuffer.get() ? bound_renderbuffer->service_id() : 0); |
93 } | 96 } |
94 | 97 |
95 void ContextState::RestoreProgramBindings() const { | 98 void ContextState::RestoreProgramBindings() const { |
96 glUseProgram(current_program ? current_program->service_id() : 0); | 99 glUseProgram(current_program.get() ? current_program->service_id() : 0); |
97 } | 100 } |
98 | 101 |
99 void ContextState::RestoreActiveTexture() const { | 102 void ContextState::RestoreActiveTexture() const { |
100 glActiveTexture(GL_TEXTURE0 + active_texture_unit); | 103 glActiveTexture(GL_TEXTURE0 + active_texture_unit); |
101 } | 104 } |
102 | 105 |
103 void ContextState::RestoreAllTextureUnitBindings() const { | 106 void ContextState::RestoreAllTextureUnitBindings() const { |
104 // Restore Texture state. | 107 // Restore Texture state. |
105 for (size_t ii = 0; ii < texture_units.size(); ++ii) { | 108 for (size_t ii = 0; ii < texture_units.size(); ++ii) { |
106 RestoreTextureUnitBindings(ii); | 109 RestoreTextureUnitBindings(ii); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 glPixelStorei(GL_PACK_ALIGNMENT, pack_alignment); | 143 glPixelStorei(GL_PACK_ALIGNMENT, pack_alignment); |
141 glPixelStorei(GL_UNPACK_ALIGNMENT, unpack_alignment); | 144 glPixelStorei(GL_UNPACK_ALIGNMENT, unpack_alignment); |
142 } | 145 } |
143 | 146 |
144 void ContextState::RestoreState() const { | 147 void ContextState::RestoreState() const { |
145 RestoreAllTextureUnitBindings(); | 148 RestoreAllTextureUnitBindings(); |
146 | 149 |
147 // Restore Attrib State | 150 // Restore Attrib State |
148 // TODO: This if should not be needed. RestoreState is getting called | 151 // TODO: This if should not be needed. RestoreState is getting called |
149 // before GLES2Decoder::Initialize which is a bug. | 152 // before GLES2Decoder::Initialize which is a bug. |
150 if (vertex_attrib_manager) { | 153 if (vertex_attrib_manager.get()) { |
151 // TODO(gman): Move this restoration to VertexAttribManager. | 154 // TODO(gman): Move this restoration to VertexAttribManager. |
152 for (size_t attrib = 0; attrib < vertex_attrib_manager->num_attribs(); | 155 for (size_t attrib = 0; attrib < vertex_attrib_manager->num_attribs(); |
153 ++attrib) { | 156 ++attrib) { |
154 RestoreAttribute(attrib); | 157 RestoreAttribute(attrib); |
155 } | 158 } |
156 } | 159 } |
157 | 160 |
158 RestoreBufferBindings(); | 161 RestoreBufferBindings(); |
159 RestoreRenderbufferBindings(); | 162 RestoreRenderbufferBindings(); |
160 RestoreProgramBindings(); | 163 RestoreProgramBindings(); |
161 RestoreGlobalState(); | 164 RestoreGlobalState(); |
162 } | 165 } |
163 | 166 |
164 ErrorState* ContextState::GetErrorState() { | 167 ErrorState* ContextState::GetErrorState() { |
165 return error_state_.get(); | 168 return error_state_.get(); |
166 } | 169 } |
167 | 170 |
168 // Include the auto-generated part of this file. We split this because it means | 171 // Include the auto-generated part of this file. We split this because it means |
169 // we can easily edit the non-auto generated parts right here in this file | 172 // we can easily edit the non-auto generated parts right here in this file |
170 // instead of having to edit some template or the code generator. | 173 // instead of having to edit some template or the code generator. |
171 #include "gpu/command_buffer/service/context_state_impl_autogen.h" | 174 #include "gpu/command_buffer/service/context_state_impl_autogen.h" |
172 | 175 |
173 } // namespace gles2 | 176 } // namespace gles2 |
174 } // namespace gpu | 177 } // namespace gpu |
175 | 178 |
176 | 179 |
OLD | NEW |