Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: cc/output/program_binding.h

Issue 2613903002: The great shader refactor: Move all programs to a common cache (Closed)
Patch Set: Incorporate review feedback Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/output/gl_renderer_unittest.cc ('k') | cc/output/shader.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2011 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 #ifndef CC_OUTPUT_PROGRAM_BINDING_H_ 5 #ifndef CC_OUTPUT_PROGRAM_BINDING_H_
6 #define CC_OUTPUT_PROGRAM_BINDING_H_ 6 #define CC_OUTPUT_PROGRAM_BINDING_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 bool is_opaque_ = false; 107 bool is_opaque_ = false;
108 108
109 PremultipliedAlphaMode premultiplied_alpha_ = PREMULTIPLIED_ALPHA; 109 PremultipliedAlphaMode premultiplied_alpha_ = PREMULTIPLIED_ALPHA;
110 bool has_background_color_ = false; 110 bool has_background_color_ = false;
111 111
112 MaskMode mask_mode_ = NO_MASK; 112 MaskMode mask_mode_ = NO_MASK;
113 bool mask_for_background_ = false; 113 bool mask_for_background_ = false;
114 bool has_color_matrix_ = false; 114 bool has_color_matrix_ = false;
115 }; 115 };
116 116
117 struct ProgramKeyHash {
118 size_t operator()(const ProgramKey& key) const {
119 return (static_cast<size_t>(key.type_) << 0) ^
120 (static_cast<size_t>(key.precision_) << 3) ^
121 (static_cast<size_t>(key.sampler_) << 6) ^
122 (static_cast<size_t>(key.blend_mode_) << 9) ^
123 (static_cast<size_t>(key.aa_mode_) << 15) ^
124 (static_cast<size_t>(key.swizzle_mode_) << 16) ^
125 (static_cast<size_t>(key.is_opaque_) << 17) ^
126 (static_cast<size_t>(key.premultiplied_alpha_) << 19) ^
127 (static_cast<size_t>(key.has_background_color_) << 20) ^
128 (static_cast<size_t>(key.mask_mode_) << 21) ^
129 (static_cast<size_t>(key.mask_for_background_) << 22) ^
130 (static_cast<size_t>(key.has_color_matrix_) << 23);
131 }
132 };
133
117 template <class VertexShader, class FragmentShader> 134 template <class VertexShader, class FragmentShader>
118 class ProgramBinding : public ProgramBindingBase { 135 class ProgramBinding : public ProgramBindingBase {
119 public: 136 public:
120 ProgramBinding() {} 137 ProgramBinding() {}
121 138
122 void Initialize(ContextProvider* context_provider, const ProgramKey& key) { 139 void Initialize(ContextProvider* context_provider, const ProgramKey& key) {
123 // Set parameters that are common to all sub-classes. 140 // Set parameters that are common to all sub-classes.
124 vertex_shader_.aa_mode_ = key.aa_mode_; 141 vertex_shader_.aa_mode_ = key.aa_mode_;
125 fragment_shader_.aa_mode_ = key.aa_mode_; 142 fragment_shader_.aa_mode_ = key.aa_mode_;
126 fragment_shader_.blend_mode_ = key.blend_mode_; 143 fragment_shader_.blend_mode_ = key.blend_mode_;
(...skipping 17 matching lines...) Expand all
144 case PROGRAM_TYPE_TEXTURE: 161 case PROGRAM_TYPE_TEXTURE:
145 InitializeTextureProgram(key); 162 InitializeTextureProgram(key);
146 break; 163 break;
147 case PROGRAM_TYPE_RENDER_PASS: 164 case PROGRAM_TYPE_RENDER_PASS:
148 InitializeRenderPassProgram(key); 165 InitializeRenderPassProgram(key);
149 break; 166 break;
150 case PROGRAM_TYPE_VIDEO_STREAM: 167 case PROGRAM_TYPE_VIDEO_STREAM:
151 InitializeVideoStreamProgram(key); 168 InitializeVideoStreamProgram(key);
152 break; 169 break;
153 } 170 }
154 fragment_shader_.CheckSubclassProperties();
155 vertex_shader_.CheckSubclassProperties();
156 InitializeInternal(context_provider); 171 InitializeInternal(context_provider);
157 } 172 }
158 173
159 void InitializeVideoYUV(ContextProvider* context_provider, 174 void InitializeVideoYUV(ContextProvider* context_provider,
160 TexCoordPrecision precision, 175 TexCoordPrecision precision,
161 SamplerType sampler, 176 SamplerType sampler,
162 bool use_alpha_plane, 177 bool use_alpha_plane,
163 bool use_nv12, 178 bool use_nv12,
164 bool use_color_lut) { 179 bool use_color_lut) {
165 vertex_shader_.tex_coord_source_ = TEX_COORD_SOURCE_ATTRIBUTE; 180 vertex_shader_.tex_coord_source_ = TEX_COORD_SOURCE_ATTRIBUTE;
166 vertex_shader_.has_matrix_ = true; 181 vertex_shader_.has_matrix_ = true;
167 vertex_shader_.is_ya_uv_ = true; 182 vertex_shader_.is_ya_uv_ = true;
168 183
169 fragment_shader_.use_alpha_texture_ = use_alpha_plane; 184 fragment_shader_.use_alpha_texture_ = use_alpha_plane;
170 fragment_shader_.use_nv12_ = use_nv12; 185 fragment_shader_.use_nv12_ = use_nv12;
171 fragment_shader_.use_color_lut_ = use_color_lut; 186 fragment_shader_.use_color_lut_ = use_color_lut;
172 fragment_shader_.tex_coord_precision_ = precision; 187 fragment_shader_.tex_coord_precision_ = precision;
173 fragment_shader_.sampler_type_ = sampler; 188 fragment_shader_.sampler_type_ = sampler;
174 189
175 fragment_shader_.CheckSubclassProperties();
176 vertex_shader_.CheckSubclassProperties();
177 InitializeInternal(context_provider); 190 InitializeInternal(context_provider);
178 } 191 }
179 192
180 const VertexShader& vertex_shader() const { return vertex_shader_; } 193 const VertexShader& vertex_shader() const { return vertex_shader_; }
181 const FragmentShader& fragment_shader() const { return fragment_shader_; } 194 const FragmentShader& fragment_shader() const { return fragment_shader_; }
182 195
183 private: 196 private:
184 void InitializeDebugBorderProgram() { 197 void InitializeDebugBorderProgram() {
185 // Initialize vertex program. 198 // Initialize vertex program.
186 vertex_shader_.has_matrix_ = true; 199 vertex_shader_.has_matrix_ = true;
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 321
309 initialized_ = true; 322 initialized_ = true;
310 } 323 }
311 324
312 VertexShader vertex_shader_; 325 VertexShader vertex_shader_;
313 FragmentShader fragment_shader_; 326 FragmentShader fragment_shader_;
314 327
315 DISALLOW_COPY_AND_ASSIGN(ProgramBinding); 328 DISALLOW_COPY_AND_ASSIGN(ProgramBinding);
316 }; 329 };
317 330
331 typedef ProgramBinding<VertexShaderBase, FragmentShaderBase> Program;
332
318 } // namespace cc 333 } // namespace cc
319 334
320 #endif // CC_OUTPUT_PROGRAM_BINDING_H_ 335 #endif // CC_OUTPUT_PROGRAM_BINDING_H_
OLDNEW
« no previous file with comments | « cc/output/gl_renderer_unittest.cc ('k') | cc/output/shader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698