OLD | NEW |
---|---|
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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
47 | 47 |
48 unsigned program_; | 48 unsigned program_; |
49 unsigned vertex_shader_id_; | 49 unsigned vertex_shader_id_; |
50 unsigned fragment_shader_id_; | 50 unsigned fragment_shader_id_; |
51 bool initialized_; | 51 bool initialized_; |
52 | 52 |
53 private: | 53 private: |
54 DISALLOW_COPY_AND_ASSIGN(ProgramBindingBase); | 54 DISALLOW_COPY_AND_ASSIGN(ProgramBindingBase); |
55 }; | 55 }; |
56 | 56 |
57 enum ProgramType { | |
58 PROGRAM_TYPE_DEBUG_BORDER, | |
59 PROGRAM_TYPE_SOLID_COLOR, | |
60 PROGRAM_TYPE_TILE, | |
61 PROGRAM_TYPE_TEXTURE, | |
62 PROGRAM_TYPE_RENDER_PASS, | |
63 PROGRAM_TYPE_VIDEO_STREAM, | |
64 }; | |
65 | |
66 class CC_EXPORT ProgramKey { | |
67 public: | |
68 ProgramKey(const ProgramKey& other); | |
69 ~ProgramKey(); | |
70 | |
71 static ProgramKey DebugBorder(); | |
72 static ProgramKey SolidColor(AAMode aa_mode); | |
73 static ProgramKey Tile(TexCoordPrecision precision, | |
74 SamplerType sampler, | |
75 AAMode aa_mode, | |
76 SwizzleMode swizzle_mode, | |
77 OpacityMode opacity_mode); | |
78 static ProgramKey Texture(TexCoordPrecision precision, | |
79 SamplerType sampler, | |
80 PremultipliedAlphaMode premultiplied_alpha, | |
81 bool has_background_color); | |
82 | |
83 // TODO(ccameron): Merge |mask_for_background| into MaskMode. | |
84 static ProgramKey RenderPass(TexCoordPrecision precision, | |
85 SamplerType sampler, | |
86 BlendMode blend_mode, | |
87 AAMode aa_mode, | |
88 MaskMode mask_mode, | |
89 bool mask_for_background, | |
90 bool has_color_matrix); | |
91 static ProgramKey VideoStream(TexCoordPrecision precision); | |
92 | |
93 bool operator==(const ProgramKey& other) const; | |
94 | |
95 private: | |
96 ProgramKey(); | |
97 friend struct ProgramKeyHash; | |
98 template <class FragmentShader> | |
99 friend class ProgramBinding; | |
100 | |
101 ProgramType type_ = PROGRAM_TYPE_DEBUG_BORDER; | |
102 TexCoordPrecision precision_ = TEX_COORD_PRECISION_NA; | |
103 SamplerType sampler_ = SAMPLER_TYPE_NA; | |
104 BlendMode blend_mode_ = BLEND_MODE_NONE; | |
105 AAMode aa_mode_ = NO_AA; | |
106 SwizzleMode swizzle_mode_ = NO_SWIZZLE; | |
107 OpacityMode opacity_mode_ = NOT_OPAQUE; | |
108 | |
109 PremultipliedAlphaMode premultiplied_alpha_ = PREMULTIPLIED_ALPHA; | |
110 bool has_background_color_ = false; | |
111 | |
112 MaskMode mask_mode_ = NO_MASK; | |
113 bool mask_for_background_ = false; | |
114 bool has_color_matrix_ = false; | |
115 }; | |
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.opacity_mode_) << 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 | |
57 template <class FragmentShader> | 134 template <class FragmentShader> |
58 class ProgramBinding : public ProgramBindingBase { | 135 class ProgramBinding : public ProgramBindingBase { |
59 public: | 136 public: |
60 ProgramBinding() {} | 137 ProgramBinding() {} |
61 | 138 |
62 void InitializeDebugBorderProgram(ContextProvider* context_provider) { | 139 void Initialize(ContextProvider* context_provider, const ProgramKey& key) { |
63 vertex_shader_.has_matrix_ = true; | 140 switch (key.type_) { |
64 | 141 case PROGRAM_TYPE_DEBUG_BORDER: |
65 fragment_shader_.input_color_type_ = INPUT_COLOR_SOURCE_UNIFORM; | 142 InitializeDebugBorderProgram(); |
66 fragment_shader_.frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT; | 143 break; |
67 | 144 case PROGRAM_TYPE_SOLID_COLOR: |
145 InitializeSolidColorProgram(key); | |
146 break; | |
147 case PROGRAM_TYPE_TILE: | |
148 InitializeTileProgram(key); | |
149 break; | |
150 case PROGRAM_TYPE_TEXTURE: | |
151 InitializeTextureProgram(key); | |
152 break; | |
153 case PROGRAM_TYPE_RENDER_PASS: | |
154 InitializeRenderPassProgram(key); | |
155 break; | |
156 case PROGRAM_TYPE_VIDEO_STREAM: | |
157 InitializeVideoStreamProgram(key); | |
158 break; | |
159 } | |
68 InitializeInternal(context_provider); | 160 InitializeInternal(context_provider); |
69 } | 161 } |
70 | 162 |
71 void InitializeSolidColorProgram(ContextProvider* context_provider, | 163 private: |
ccameron
2017/01/05 10:32:27
This "public then private then public again" schem
| |
72 bool use_aa) { | 164 void InitializeDebugBorderProgram() { |
165 vertex_shader_.has_matrix_ = true; | |
166 fragment_shader_.input_color_type_ = INPUT_COLOR_SOURCE_UNIFORM; | |
167 fragment_shader_.frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT; | |
168 } | |
169 | |
170 void InitializeSolidColorProgram(const ProgramKey& key) { | |
73 vertex_shader_.position_source_ = POSITION_SOURCE_ATTRIBUTE_INDEXED_UNIFORM; | 171 vertex_shader_.position_source_ = POSITION_SOURCE_ATTRIBUTE_INDEXED_UNIFORM; |
74 vertex_shader_.has_matrix_ = true; | 172 vertex_shader_.has_matrix_ = true; |
75 #if defined(OS_ANDROID) | 173 #if defined(OS_ANDROID) |
76 vertex_shader_.has_dummy_variables_ = true; | 174 vertex_shader_.has_dummy_variables_ = true; |
77 #endif | 175 #endif |
78 vertex_shader_.has_aa_ = use_aa; | |
79 | 176 |
80 fragment_shader_.input_color_type_ = INPUT_COLOR_SOURCE_UNIFORM; | 177 fragment_shader_.input_color_type_ = INPUT_COLOR_SOURCE_UNIFORM; |
81 fragment_shader_.frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT; | 178 fragment_shader_.frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT; |
82 fragment_shader_.has_aa_ = use_aa; | |
83 | 179 |
84 InitializeInternal(context_provider); | 180 if (key.aa_mode_ == USE_AA) { |
181 vertex_shader_.has_aa_ = true; | |
182 fragment_shader_.has_aa_ = true; | |
183 } | |
85 } | 184 } |
86 | 185 |
87 void InitializeTileProgram(ContextProvider* context_provider, | 186 void InitializeTileProgram(const ProgramKey& key) { |
88 TexCoordPrecision precision, | |
89 SamplerType sampler, | |
90 AAMode aa_mode, | |
91 SwizzleMode swizzle_mode, | |
92 OpacityMode opacity_mode) { | |
93 vertex_shader_.position_source_ = POSITION_SOURCE_ATTRIBUTE_INDEXED_UNIFORM; | 187 vertex_shader_.position_source_ = POSITION_SOURCE_ATTRIBUTE_INDEXED_UNIFORM; |
94 vertex_shader_.tex_coord_source_ = TEX_COORD_SOURCE_ATTRIBUTE; | 188 vertex_shader_.tex_coord_source_ = TEX_COORD_SOURCE_ATTRIBUTE; |
95 vertex_shader_.tex_coord_transform_ = TEX_COORD_TRANSFORM_VEC4; | 189 vertex_shader_.tex_coord_transform_ = TEX_COORD_TRANSFORM_VEC4; |
96 vertex_shader_.has_matrix_ = true; | 190 vertex_shader_.has_matrix_ = true; |
97 fragment_shader_.tex_coord_precision_ = precision; | 191 fragment_shader_.tex_coord_precision_ = key.precision_; |
98 fragment_shader_.sampler_type_ = sampler; | 192 fragment_shader_.sampler_type_ = key.sampler_; |
99 if (swizzle_mode == DO_SWIZZLE) | 193 if (key.swizzle_mode_ == DO_SWIZZLE) |
100 fragment_shader_.has_swizzle_ = true; | 194 fragment_shader_.has_swizzle_ = true; |
101 if (aa_mode == USE_AA) { | 195 if (key.aa_mode_ == USE_AA) { |
102 vertex_shader_.has_aa_ = true; | 196 vertex_shader_.has_aa_ = true; |
103 fragment_shader_.has_aa_ = true; | 197 fragment_shader_.has_aa_ = true; |
104 fragment_shader_.has_rgba_fragment_tex_transform_ = true; | 198 fragment_shader_.has_rgba_fragment_tex_transform_ = true; |
105 } | 199 } |
106 | 200 |
107 if (opacity_mode == IS_OPAQUE) { | 201 if (key.opacity_mode_ == IS_OPAQUE) { |
108 fragment_shader_.frag_color_mode_ = FRAG_COLOR_MODE_OPAQUE; | 202 fragment_shader_.frag_color_mode_ = FRAG_COLOR_MODE_OPAQUE; |
109 } else { | 203 } else { |
110 fragment_shader_.has_uniform_alpha_ = true; | 204 fragment_shader_.has_uniform_alpha_ = true; |
111 // TODO(ccameron): Determine if we can always use FRAG_COLOR_MODE_DEFAULT | 205 // TODO(ccameron): Determine if we can always use FRAG_COLOR_MODE_DEFAULT |
112 // here. | 206 // here. |
113 if (aa_mode == NO_AA && swizzle_mode == NO_SWIZZLE) | 207 if (key.aa_mode_ == NO_AA && key.swizzle_mode_ == NO_SWIZZLE) |
114 fragment_shader_.frag_color_mode_ = FRAG_COLOR_MODE_APPLY_BLEND_MODE; | 208 fragment_shader_.frag_color_mode_ = FRAG_COLOR_MODE_APPLY_BLEND_MODE; |
115 else | 209 else |
116 fragment_shader_.frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT; | 210 fragment_shader_.frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT; |
117 } | 211 } |
118 | |
119 InitializeInternal(context_provider); | |
120 } | 212 } |
121 | 213 |
122 void InitializeTextureProgram(ContextProvider* context_provider, | 214 void InitializeTextureProgram(const ProgramKey& key) { |
123 TexCoordPrecision precision, | |
124 SamplerType sampler, | |
125 PremultipliedAlphaMode premultiplied_alpha, | |
126 bool has_background_color) { | |
127 vertex_shader_.tex_coord_source_ = TEX_COORD_SOURCE_ATTRIBUTE; | 215 vertex_shader_.tex_coord_source_ = TEX_COORD_SOURCE_ATTRIBUTE; |
128 vertex_shader_.tex_coord_transform_ = TEX_COORD_TRANSFORM_VEC4; | 216 vertex_shader_.tex_coord_transform_ = TEX_COORD_TRANSFORM_VEC4; |
129 vertex_shader_.has_matrix_ = true; | 217 vertex_shader_.has_matrix_ = true; |
130 vertex_shader_.has_vertex_opacity_ = true; | 218 vertex_shader_.has_vertex_opacity_ = true; |
131 vertex_shader_.use_uniform_arrays_ = true; | 219 vertex_shader_.use_uniform_arrays_ = true; |
132 fragment_shader_.tex_coord_precision_ = precision; | 220 fragment_shader_.tex_coord_precision_ = key.precision_; |
133 fragment_shader_.sampler_type_ = sampler; | 221 fragment_shader_.sampler_type_ = key.sampler_; |
134 fragment_shader_.frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT; | 222 fragment_shader_.frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT; |
135 fragment_shader_.has_varying_alpha_ = true; | 223 fragment_shader_.has_varying_alpha_ = true; |
136 if (premultiplied_alpha == NON_PREMULTIPLIED_ALPHA) | 224 if (key.premultiplied_alpha_ == NON_PREMULTIPLIED_ALPHA) |
137 fragment_shader_.has_premultiply_alpha_ = true; | 225 fragment_shader_.has_premultiply_alpha_ = true; |
138 fragment_shader_.has_background_color_ = has_background_color; | 226 fragment_shader_.has_background_color_ = key.has_background_color_; |
139 InitializeInternal(context_provider); | |
140 } | 227 } |
141 | 228 |
142 // TODO(ccameron): Merge |mask_for_background| into MaskMode. | 229 void InitializeRenderPassProgram(const ProgramKey& key) { |
143 void InitializeRenderPassProgram(ContextProvider* context_provider, | |
144 TexCoordPrecision precision, | |
145 SamplerType sampler, | |
146 BlendMode blend_mode, | |
147 AAMode aa_mode, | |
148 MaskMode mask_mode, | |
149 bool mask_for_background, | |
150 bool has_color_matrix) { | |
151 vertex_shader_.has_matrix_ = true; | 230 vertex_shader_.has_matrix_ = true; |
152 if (aa_mode == NO_AA) { | 231 if (key.aa_mode_ == NO_AA) { |
153 vertex_shader_.tex_coord_source_ = TEX_COORD_SOURCE_ATTRIBUTE; | 232 vertex_shader_.tex_coord_source_ = TEX_COORD_SOURCE_ATTRIBUTE; |
154 vertex_shader_.tex_coord_transform_ = TEX_COORD_TRANSFORM_VEC4; | 233 vertex_shader_.tex_coord_transform_ = TEX_COORD_TRANSFORM_VEC4; |
155 vertex_shader_.has_vertex_opacity_ = true; | 234 vertex_shader_.has_vertex_opacity_ = true; |
156 vertex_shader_.use_uniform_arrays_ = true; | 235 vertex_shader_.use_uniform_arrays_ = true; |
157 } else { | 236 } else { |
158 vertex_shader_.position_source_ = | 237 vertex_shader_.position_source_ = |
159 POSITION_SOURCE_ATTRIBUTE_INDEXED_UNIFORM; | 238 POSITION_SOURCE_ATTRIBUTE_INDEXED_UNIFORM; |
160 vertex_shader_.tex_coord_source_ = TEX_COORD_SOURCE_POSITION; | 239 vertex_shader_.tex_coord_source_ = TEX_COORD_SOURCE_POSITION; |
161 vertex_shader_.tex_coord_transform_ = TEX_COORD_TRANSFORM_TRANSLATED_VEC4; | 240 vertex_shader_.tex_coord_transform_ = TEX_COORD_TRANSFORM_TRANSLATED_VEC4; |
162 vertex_shader_.has_aa_ = true; | 241 vertex_shader_.has_aa_ = true; |
163 fragment_shader_.has_aa_ = true; | 242 fragment_shader_.has_aa_ = true; |
164 } | 243 } |
165 | 244 |
166 fragment_shader_.tex_coord_precision_ = precision; | 245 fragment_shader_.tex_coord_precision_ = key.precision_; |
167 fragment_shader_.sampler_type_ = sampler; | 246 fragment_shader_.sampler_type_ = key.sampler_; |
168 fragment_shader_.blend_mode_ = blend_mode; | 247 fragment_shader_.blend_mode_ = key.blend_mode_; |
169 fragment_shader_.frag_color_mode_ = FRAG_COLOR_MODE_APPLY_BLEND_MODE; | 248 fragment_shader_.frag_color_mode_ = FRAG_COLOR_MODE_APPLY_BLEND_MODE; |
170 fragment_shader_.has_uniform_alpha_ = true; | 249 fragment_shader_.has_uniform_alpha_ = true; |
171 fragment_shader_.mask_for_background_ = mask_for_background; | 250 fragment_shader_.mask_for_background_ = key.mask_for_background_; |
172 fragment_shader_.has_color_matrix_ = has_color_matrix; | 251 fragment_shader_.has_color_matrix_ = key.has_color_matrix_; |
173 if (mask_mode == HAS_MASK) { | 252 if (key.mask_mode_ == HAS_MASK) { |
174 fragment_shader_.has_mask_sampler_ = true; | 253 fragment_shader_.has_mask_sampler_ = true; |
175 fragment_shader_.ignore_sampler_type_ = true; | 254 fragment_shader_.ignore_sampler_type_ = true; |
176 } else { | 255 } else { |
177 DCHECK(!mask_for_background); | 256 DCHECK(!key.mask_for_background_); |
178 } | 257 } |
179 | |
180 InitializeInternal(context_provider); | |
181 } | 258 } |
182 | 259 |
183 void InitializeVideoStreamProgram(ContextProvider* context_provider, | 260 void InitializeVideoStreamProgram(const ProgramKey& key) { |
184 TexCoordPrecision precision) { | |
185 vertex_shader_.tex_coord_source_ = TEX_COORD_SOURCE_ATTRIBUTE; | 261 vertex_shader_.tex_coord_source_ = TEX_COORD_SOURCE_ATTRIBUTE; |
186 vertex_shader_.tex_coord_transform_ = TEX_COORD_TRANSFORM_MATRIX; | 262 vertex_shader_.tex_coord_transform_ = TEX_COORD_TRANSFORM_MATRIX; |
187 vertex_shader_.has_matrix_ = true; | 263 vertex_shader_.has_matrix_ = true; |
188 | 264 |
189 fragment_shader_.tex_coord_precision_ = precision; | 265 fragment_shader_.tex_coord_precision_ = key.precision_; |
190 fragment_shader_.sampler_type_ = SAMPLER_TYPE_EXTERNAL_OES; | 266 fragment_shader_.sampler_type_ = SAMPLER_TYPE_EXTERNAL_OES; |
191 fragment_shader_.frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT; | 267 fragment_shader_.frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT; |
192 | |
193 InitializeInternal(context_provider); | |
194 } | 268 } |
195 | 269 |
270 public: | |
196 void InitializeVideoYUVProgram(ContextProvider* context_provider, | 271 void InitializeVideoYUVProgram(ContextProvider* context_provider, |
197 TexCoordPrecision precision, | 272 TexCoordPrecision precision, |
198 SamplerType sampler, | 273 SamplerType sampler, |
199 bool use_alpha_plane, | 274 bool use_alpha_plane, |
200 bool use_nv12, | 275 bool use_nv12, |
201 bool use_color_lut) { | 276 bool use_color_lut) { |
202 vertex_shader_.tex_coord_source_ = TEX_COORD_SOURCE_ATTRIBUTE; | 277 vertex_shader_.tex_coord_source_ = TEX_COORD_SOURCE_ATTRIBUTE; |
203 vertex_shader_.has_matrix_ = true; | 278 vertex_shader_.has_matrix_ = true; |
204 vertex_shader_.is_ya_uv_ = true; | 279 vertex_shader_.is_ya_uv_ = true; |
205 | 280 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
245 | 320 |
246 VertexShaderBase vertex_shader_; | 321 VertexShaderBase vertex_shader_; |
247 FragmentShader fragment_shader_; | 322 FragmentShader fragment_shader_; |
248 | 323 |
249 DISALLOW_COPY_AND_ASSIGN(ProgramBinding); | 324 DISALLOW_COPY_AND_ASSIGN(ProgramBinding); |
250 }; | 325 }; |
251 | 326 |
252 } // namespace cc | 327 } // namespace cc |
253 | 328 |
254 #endif // CC_OUTPUT_PROGRAM_BINDING_H_ | 329 #endif // CC_OUTPUT_PROGRAM_BINDING_H_ |
OLD | NEW |