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" |
11 #include "gpu/command_buffer/service/program_manager.h" | 11 #include "gpu/command_buffer/service/program_manager.h" |
12 #include "gpu/command_buffer/service/renderbuffer_manager.h" | 12 #include "gpu/command_buffer/service/renderbuffer_manager.h" |
| 13 #include "ui/gl/dirty_texture_state.h" |
13 #include "ui/gl/gl_bindings.h" | 14 #include "ui/gl/gl_bindings.h" |
14 #include "ui/gl/gl_implementation.h" | 15 #include "ui/gl/gl_implementation.h" |
15 | 16 |
16 namespace gpu { | 17 namespace gpu { |
17 namespace gles2 { | 18 namespace gles2 { |
18 | 19 |
19 namespace { | 20 namespace { |
20 | 21 |
21 void EnableDisable(GLenum pname, bool enable) { | 22 void EnableDisable(GLenum pname, bool enable) { |
22 if (enable) { | 23 if (enable) { |
(...skipping 17 matching lines...) Expand all Loading... |
40 pack_reverse_row_order(false), | 41 pack_reverse_row_order(false), |
41 fbo_binding_for_scissor_workaround_dirty_(false), | 42 fbo_binding_for_scissor_workaround_dirty_(false), |
42 feature_info_(feature_info), | 43 feature_info_(feature_info), |
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( |
| 52 GLuint unit, const gfx::DirtyTextureState* dirty_texture_state) const { |
51 DCHECK_LT(unit, texture_units.size()); | 53 DCHECK_LT(unit, texture_units.size()); |
52 const TextureUnit& texture_unit = texture_units[unit]; | 54 const TextureUnit& texture_unit = texture_units[unit]; |
53 glActiveTexture(GL_TEXTURE0 + unit); | 55 glActiveTexture(GL_TEXTURE0 + unit); |
54 GLuint service_id = texture_unit.bound_texture_2d.get() | 56 if (!dirty_texture_state || |
55 ? texture_unit.bound_texture_2d->service_id() | 57 dirty_texture_state->IsBinding2DDirtyForUnit(unit)) { |
56 : 0; | 58 GLuint service_id = texture_unit.bound_texture_2d.get() |
57 glBindTexture(GL_TEXTURE_2D, service_id); | 59 ? texture_unit.bound_texture_2d->service_id() |
58 service_id = texture_unit.bound_texture_cube_map.get() | 60 : 0; |
59 ? texture_unit.bound_texture_cube_map->service_id() | 61 glBindTexture(GL_TEXTURE_2D, service_id); |
60 : 0; | 62 } |
61 glBindTexture(GL_TEXTURE_CUBE_MAP, service_id); | |
62 | 63 |
63 if (feature_info_->feature_flags().oes_egl_image_external) { | 64 if (!dirty_texture_state || |
64 service_id = texture_unit.bound_texture_external_oes.get() | 65 dirty_texture_state->IsBindingCubeMapDirtyForUnit(unit)) { |
65 ? texture_unit.bound_texture_external_oes->service_id() | 66 GLuint service_id = texture_unit.bound_texture_cube_map.get() |
66 : 0; | 67 ? texture_unit.bound_texture_cube_map->service_id() |
| 68 : 0; |
| 69 glBindTexture(GL_TEXTURE_CUBE_MAP, service_id); |
| 70 } |
| 71 |
| 72 if (feature_info_->feature_flags().oes_egl_image_external && |
| 73 (!dirty_texture_state || |
| 74 dirty_texture_state->IsBindingExternalOesDirtyForUnit(unit))) { |
| 75 GLuint service_id = |
| 76 texture_unit.bound_texture_external_oes.get() |
| 77 ? texture_unit.bound_texture_external_oes->service_id() |
| 78 : 0; |
67 glBindTexture(GL_TEXTURE_EXTERNAL_OES, service_id); | 79 glBindTexture(GL_TEXTURE_EXTERNAL_OES, service_id); |
68 } | 80 } |
69 | 81 |
70 if (feature_info_->feature_flags().arb_texture_rectangle) { | 82 if (feature_info_->feature_flags().arb_texture_rectangle && |
71 service_id = texture_unit.bound_texture_rectangle_arb.get() | 83 (!dirty_texture_state || |
72 ? texture_unit.bound_texture_rectangle_arb->service_id() | 84 dirty_texture_state->IsBindingRectangleArbDirtyForUnit(unit))) { |
73 : 0; | 85 GLuint service_id = |
| 86 texture_unit.bound_texture_rectangle_arb.get() |
| 87 ? texture_unit.bound_texture_rectangle_arb->service_id() |
| 88 : 0; |
74 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, service_id); | 89 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, service_id); |
75 } | 90 } |
76 } | 91 } |
77 | 92 |
78 void ContextState::RestoreBufferBindings() const { | 93 void ContextState::RestoreBufferBindings() const { |
79 if (vertex_attrib_manager.get()) { | 94 if (vertex_attrib_manager.get()) { |
80 Buffer* element_array_buffer = | 95 Buffer* element_array_buffer = |
81 vertex_attrib_manager->element_array_buffer(); | 96 vertex_attrib_manager->element_array_buffer(); |
82 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, | 97 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, |
83 element_array_buffer ? element_array_buffer->service_id() : 0); | 98 element_array_buffer ? element_array_buffer->service_id() : 0); |
(...skipping 10 matching lines...) Expand all Loading... |
94 } | 109 } |
95 | 110 |
96 void ContextState::RestoreProgramBindings() const { | 111 void ContextState::RestoreProgramBindings() const { |
97 glUseProgram(current_program.get() ? current_program->service_id() : 0); | 112 glUseProgram(current_program.get() ? current_program->service_id() : 0); |
98 } | 113 } |
99 | 114 |
100 void ContextState::RestoreActiveTexture() const { | 115 void ContextState::RestoreActiveTexture() const { |
101 glActiveTexture(GL_TEXTURE0 + active_texture_unit); | 116 glActiveTexture(GL_TEXTURE0 + active_texture_unit); |
102 } | 117 } |
103 | 118 |
104 void ContextState::RestoreAllTextureUnitBindings() const { | 119 void ContextState::RestoreAllTextureUnitBindings( |
| 120 const gfx::DirtyTextureState* dirty_texture_state) const { |
| 121 size_t texture_units_to_restore = |
| 122 dirty_texture_state ? |
| 123 dirty_texture_state->GetMaxTextureUnitIndex() + 1 |
| 124 : texture_units.size(); |
105 // Restore Texture state. | 125 // Restore Texture state. |
106 for (size_t ii = 0; ii < texture_units.size(); ++ii) { | 126 for (size_t ii = 0; ii < texture_units_to_restore; ++ii) { |
107 RestoreTextureUnitBindings(ii); | 127 RestoreTextureUnitBindings(ii, dirty_texture_state); |
108 } | 128 } |
109 RestoreActiveTexture(); | 129 RestoreActiveTexture(); |
110 } | 130 } |
111 | 131 |
112 void ContextState::RestoreAttribute(GLuint attrib_index) const { | 132 void ContextState::RestoreAttribute(GLuint attrib_index) const { |
113 const VertexAttrib* attrib = | 133 const VertexAttrib* attrib = |
114 vertex_attrib_manager->GetVertexAttrib(attrib_index); | 134 vertex_attrib_manager->GetVertexAttrib(attrib_index); |
115 const void* ptr = reinterpret_cast<const void*>(attrib->offset()); | 135 const void* ptr = reinterpret_cast<const void*>(attrib->offset()); |
116 Buffer* buffer = attrib->buffer(); | 136 Buffer* buffer = attrib->buffer(); |
117 glBindBuffer(GL_ARRAY_BUFFER, buffer ? buffer->service_id() : 0); | 137 glBindBuffer(GL_ARRAY_BUFFER, buffer ? buffer->service_id() : 0); |
(...skipping 14 matching lines...) Expand all Loading... |
132 } | 152 } |
133 } | 153 } |
134 glVertexAttrib4fv(attrib_index, attrib_values[attrib_index].v); | 154 glVertexAttrib4fv(attrib_index, attrib_values[attrib_index].v); |
135 } | 155 } |
136 | 156 |
137 void ContextState::RestoreGlobalState() const { | 157 void ContextState::RestoreGlobalState() const { |
138 InitCapabilities(); | 158 InitCapabilities(); |
139 InitState(); | 159 InitState(); |
140 } | 160 } |
141 | 161 |
142 void ContextState::RestoreState() const { | 162 void ContextState::RestoreState( |
143 RestoreAllTextureUnitBindings(); | 163 const gfx::DirtyTextureState* dirty_texture_state) const { |
| 164 RestoreAllTextureUnitBindings(dirty_texture_state); |
144 | 165 |
145 // Restore Attrib State | 166 // Restore Attrib State |
146 // TODO: This if should not be needed. RestoreState is getting called | 167 // TODO: This if should not be needed. RestoreState is getting called |
147 // before GLES2Decoder::Initialize which is a bug. | 168 // before GLES2Decoder::Initialize which is a bug. |
148 if (vertex_attrib_manager.get()) { | 169 if (vertex_attrib_manager.get()) { |
149 // TODO(gman): Move this restoration to VertexAttribManager. | 170 // TODO(gman): Move this restoration to VertexAttribManager. |
150 for (size_t attrib = 0; attrib < vertex_attrib_manager->num_attribs(); | 171 for (size_t attrib = 0; attrib < vertex_attrib_manager->num_attribs(); |
151 ++attrib) { | 172 ++attrib) { |
152 RestoreAttribute(attrib); | 173 RestoreAttribute(attrib); |
153 } | 174 } |
(...skipping 11 matching lines...) Expand all Loading... |
165 | 186 |
166 // Include the auto-generated part of this file. We split this because it means | 187 // 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 | 188 // 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. | 189 // instead of having to edit some template or the code generator. |
169 #include "gpu/command_buffer/service/context_state_impl_autogen.h" | 190 #include "gpu/command_buffer/service/context_state_impl_autogen.h" |
170 | 191 |
171 } // namespace gles2 | 192 } // namespace gles2 |
172 } // namespace gpu | 193 } // namespace gpu |
173 | 194 |
174 | 195 |
OLD | NEW |