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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 DISALLOW_COPY_AND_ASSIGN(ProgramBindingBase); | 54 DISALLOW_COPY_AND_ASSIGN(ProgramBindingBase); |
55 }; | 55 }; |
56 | 56 |
57 enum ProgramType { | 57 enum ProgramType { |
58 PROGRAM_TYPE_DEBUG_BORDER, | 58 PROGRAM_TYPE_DEBUG_BORDER, |
59 PROGRAM_TYPE_SOLID_COLOR, | 59 PROGRAM_TYPE_SOLID_COLOR, |
60 PROGRAM_TYPE_TILE, | 60 PROGRAM_TYPE_TILE, |
61 PROGRAM_TYPE_TEXTURE, | 61 PROGRAM_TYPE_TEXTURE, |
62 PROGRAM_TYPE_RENDER_PASS, | 62 PROGRAM_TYPE_RENDER_PASS, |
63 PROGRAM_TYPE_VIDEO_STREAM, | 63 PROGRAM_TYPE_VIDEO_STREAM, |
| 64 PROGRAM_TYPE_YUV_VIDEO, |
64 }; | 65 }; |
65 | 66 |
66 class CC_EXPORT ProgramKey { | 67 class CC_EXPORT ProgramKey { |
67 public: | 68 public: |
68 ProgramKey(const ProgramKey& other); | 69 ProgramKey(const ProgramKey& other); |
69 ~ProgramKey(); | 70 ~ProgramKey(); |
70 | 71 |
71 static ProgramKey DebugBorder(); | 72 static ProgramKey DebugBorder(); |
72 static ProgramKey SolidColor(AAMode aa_mode); | 73 static ProgramKey SolidColor(AAMode aa_mode); |
73 static ProgramKey Tile(TexCoordPrecision precision, | 74 static ProgramKey Tile(TexCoordPrecision precision, |
74 SamplerType sampler, | 75 SamplerType sampler, |
75 AAMode aa_mode, | 76 AAMode aa_mode, |
76 SwizzleMode swizzle_mode, | 77 SwizzleMode swizzle_mode, |
77 bool is_opaque); | 78 bool is_opaque); |
78 static ProgramKey Texture(TexCoordPrecision precision, | 79 static ProgramKey Texture(TexCoordPrecision precision, |
79 SamplerType sampler, | 80 SamplerType sampler, |
80 PremultipliedAlphaMode premultiplied_alpha, | 81 PremultipliedAlphaMode premultiplied_alpha, |
81 bool has_background_color); | 82 bool has_background_color); |
82 | 83 |
83 // TODO(ccameron): Merge |mask_for_background| into MaskMode. | 84 // TODO(ccameron): Merge |mask_for_background| into MaskMode. |
84 static ProgramKey RenderPass(TexCoordPrecision precision, | 85 static ProgramKey RenderPass(TexCoordPrecision precision, |
85 SamplerType sampler, | 86 SamplerType sampler, |
86 BlendMode blend_mode, | 87 BlendMode blend_mode, |
87 AAMode aa_mode, | 88 AAMode aa_mode, |
88 MaskMode mask_mode, | 89 MaskMode mask_mode, |
89 bool mask_for_background, | 90 bool mask_for_background, |
90 bool has_color_matrix); | 91 bool has_color_matrix); |
91 static ProgramKey VideoStream(TexCoordPrecision precision); | 92 static ProgramKey VideoStream(TexCoordPrecision precision); |
| 93 static ProgramKey YUVVideo(TexCoordPrecision precision, |
| 94 SamplerType sampler, |
| 95 bool use_alpha_texture, |
| 96 bool use_nv12, |
| 97 bool use_color_lut); |
92 | 98 |
93 bool operator==(const ProgramKey& other) const; | 99 bool operator==(const ProgramKey& other) const; |
94 | 100 |
95 private: | 101 private: |
96 ProgramKey(); | 102 ProgramKey(); |
97 friend struct ProgramKeyHash; | 103 friend struct ProgramKeyHash; |
98 template <class VertexShader, class FragmentShader> | 104 friend class Program; |
99 friend class ProgramBinding; | |
100 | 105 |
101 ProgramType type_ = PROGRAM_TYPE_DEBUG_BORDER; | 106 ProgramType type_ = PROGRAM_TYPE_DEBUG_BORDER; |
102 TexCoordPrecision precision_ = TEX_COORD_PRECISION_NA; | 107 TexCoordPrecision precision_ = TEX_COORD_PRECISION_NA; |
103 SamplerType sampler_ = SAMPLER_TYPE_NA; | 108 SamplerType sampler_ = SAMPLER_TYPE_NA; |
104 BlendMode blend_mode_ = BLEND_MODE_NONE; | 109 BlendMode blend_mode_ = BLEND_MODE_NONE; |
105 AAMode aa_mode_ = NO_AA; | 110 AAMode aa_mode_ = NO_AA; |
106 SwizzleMode swizzle_mode_ = NO_SWIZZLE; | 111 SwizzleMode swizzle_mode_ = NO_SWIZZLE; |
107 bool is_opaque_ = false; | 112 bool is_opaque_ = false; |
108 | 113 |
109 PremultipliedAlphaMode premultiplied_alpha_ = PREMULTIPLIED_ALPHA; | 114 PremultipliedAlphaMode premultiplied_alpha_ = PREMULTIPLIED_ALPHA; |
110 bool has_background_color_ = false; | 115 bool has_background_color_ = false; |
111 | 116 |
112 MaskMode mask_mode_ = NO_MASK; | 117 MaskMode mask_mode_ = NO_MASK; |
113 bool mask_for_background_ = false; | 118 bool mask_for_background_ = false; |
114 bool has_color_matrix_ = false; | 119 bool has_color_matrix_ = false; |
| 120 |
| 121 bool use_alpha_texture_ = false; |
| 122 bool use_nv12_ = false; |
| 123 bool use_color_lut_ = false; |
115 }; | 124 }; |
116 | 125 |
117 struct ProgramKeyHash { | 126 struct ProgramKeyHash { |
118 size_t operator()(const ProgramKey& key) const { | 127 size_t operator()(const ProgramKey& key) const { |
119 return (static_cast<size_t>(key.type_) << 0) ^ | 128 return (static_cast<size_t>(key.type_) << 0) ^ |
120 (static_cast<size_t>(key.precision_) << 3) ^ | 129 (static_cast<size_t>(key.precision_) << 3) ^ |
121 (static_cast<size_t>(key.sampler_) << 6) ^ | 130 (static_cast<size_t>(key.sampler_) << 6) ^ |
122 (static_cast<size_t>(key.blend_mode_) << 9) ^ | 131 (static_cast<size_t>(key.blend_mode_) << 9) ^ |
123 (static_cast<size_t>(key.aa_mode_) << 15) ^ | 132 (static_cast<size_t>(key.aa_mode_) << 15) ^ |
124 (static_cast<size_t>(key.swizzle_mode_) << 16) ^ | 133 (static_cast<size_t>(key.swizzle_mode_) << 16) ^ |
125 (static_cast<size_t>(key.is_opaque_) << 17) ^ | 134 (static_cast<size_t>(key.is_opaque_) << 17) ^ |
126 (static_cast<size_t>(key.premultiplied_alpha_) << 19) ^ | 135 (static_cast<size_t>(key.premultiplied_alpha_) << 19) ^ |
127 (static_cast<size_t>(key.has_background_color_) << 20) ^ | 136 (static_cast<size_t>(key.has_background_color_) << 20) ^ |
128 (static_cast<size_t>(key.mask_mode_) << 21) ^ | 137 (static_cast<size_t>(key.mask_mode_) << 21) ^ |
129 (static_cast<size_t>(key.mask_for_background_) << 22) ^ | 138 (static_cast<size_t>(key.mask_for_background_) << 22) ^ |
130 (static_cast<size_t>(key.has_color_matrix_) << 23); | 139 (static_cast<size_t>(key.has_color_matrix_) << 23) ^ |
| 140 (static_cast<size_t>(key.use_alpha_texture_) << 24) ^ |
| 141 (static_cast<size_t>(key.use_nv12_) << 25) ^ |
| 142 (static_cast<size_t>(key.use_color_lut_) << 26); |
131 } | 143 } |
132 }; | 144 }; |
133 | 145 |
134 template <class VertexShader, class FragmentShader> | 146 class Program : public ProgramBindingBase { |
135 class ProgramBinding : public ProgramBindingBase { | |
136 public: | 147 public: |
137 ProgramBinding() {} | 148 Program() {} |
138 | 149 |
139 void Initialize(ContextProvider* context_provider, const ProgramKey& key) { | 150 void Initialize(ContextProvider* context_provider, const ProgramKey& key) { |
140 // Set parameters that are common to all sub-classes. | 151 // Set parameters that are common to all sub-classes. |
141 vertex_shader_.aa_mode_ = key.aa_mode_; | 152 vertex_shader_.aa_mode_ = key.aa_mode_; |
142 fragment_shader_.aa_mode_ = key.aa_mode_; | 153 fragment_shader_.aa_mode_ = key.aa_mode_; |
143 fragment_shader_.blend_mode_ = key.blend_mode_; | 154 fragment_shader_.blend_mode_ = key.blend_mode_; |
144 fragment_shader_.tex_coord_precision_ = key.precision_; | 155 fragment_shader_.tex_coord_precision_ = key.precision_; |
145 fragment_shader_.sampler_type_ = key.sampler_; | 156 fragment_shader_.sampler_type_ = key.sampler_; |
146 fragment_shader_.swizzle_mode_ = key.swizzle_mode_; | 157 fragment_shader_.swizzle_mode_ = key.swizzle_mode_; |
147 fragment_shader_.premultiply_alpha_mode_ = key.premultiplied_alpha_; | 158 fragment_shader_.premultiply_alpha_mode_ = key.premultiplied_alpha_; |
(...skipping 12 matching lines...) Expand all Loading... |
160 break; | 171 break; |
161 case PROGRAM_TYPE_TEXTURE: | 172 case PROGRAM_TYPE_TEXTURE: |
162 InitializeTextureProgram(key); | 173 InitializeTextureProgram(key); |
163 break; | 174 break; |
164 case PROGRAM_TYPE_RENDER_PASS: | 175 case PROGRAM_TYPE_RENDER_PASS: |
165 InitializeRenderPassProgram(key); | 176 InitializeRenderPassProgram(key); |
166 break; | 177 break; |
167 case PROGRAM_TYPE_VIDEO_STREAM: | 178 case PROGRAM_TYPE_VIDEO_STREAM: |
168 InitializeVideoStreamProgram(key); | 179 InitializeVideoStreamProgram(key); |
169 break; | 180 break; |
| 181 case PROGRAM_TYPE_YUV_VIDEO: |
| 182 InitializeYUVVideo(key); |
| 183 break; |
170 } | 184 } |
171 InitializeInternal(context_provider); | 185 InitializeInternal(context_provider); |
172 } | 186 } |
173 | 187 |
174 void InitializeVideoYUV(ContextProvider* context_provider, | |
175 TexCoordPrecision precision, | |
176 SamplerType sampler, | |
177 bool use_alpha_plane, | |
178 bool use_nv12, | |
179 bool use_color_lut) { | |
180 vertex_shader_.tex_coord_source_ = TEX_COORD_SOURCE_ATTRIBUTE; | |
181 vertex_shader_.has_matrix_ = true; | |
182 vertex_shader_.is_ya_uv_ = true; | |
183 | |
184 fragment_shader_.use_alpha_texture_ = use_alpha_plane; | |
185 fragment_shader_.use_nv12_ = use_nv12; | |
186 fragment_shader_.use_color_lut_ = use_color_lut; | |
187 fragment_shader_.tex_coord_precision_ = precision; | |
188 fragment_shader_.sampler_type_ = sampler; | |
189 | |
190 InitializeInternal(context_provider); | |
191 } | |
192 | |
193 const VertexShader& vertex_shader() const { return vertex_shader_; } | 188 const VertexShader& vertex_shader() const { return vertex_shader_; } |
194 const FragmentShader& fragment_shader() const { return fragment_shader_; } | 189 const FragmentShader& fragment_shader() const { return fragment_shader_; } |
195 | 190 |
196 // Functions for querying uniform locations. | 191 // Functions for querying uniform locations. |
197 int vertex_tex_transform_location() const { | 192 int vertex_tex_transform_location() const { |
198 return vertex_shader_.vertex_tex_transform_location_; | 193 return vertex_shader_.vertex_tex_transform_location_; |
199 } | 194 } |
200 int tex_matrix_location() const { | 195 int tex_matrix_location() const { |
201 return vertex_shader_.tex_matrix_location_; | 196 return vertex_shader_.tex_matrix_location_; |
202 } | 197 } |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 } | 239 } |
245 int mask_tex_coord_offset_location() const { | 240 int mask_tex_coord_offset_location() const { |
246 return fragment_shader_.mask_tex_coord_offset_location_; | 241 return fragment_shader_.mask_tex_coord_offset_location_; |
247 } | 242 } |
248 int color_matrix_location() const { | 243 int color_matrix_location() const { |
249 return fragment_shader_.color_matrix_location_; | 244 return fragment_shader_.color_matrix_location_; |
250 } | 245 } |
251 int color_offset_location() const { | 246 int color_offset_location() const { |
252 return fragment_shader_.color_offset_location_; | 247 return fragment_shader_.color_offset_location_; |
253 } | 248 } |
| 249 int y_texture_location() const { |
| 250 return fragment_shader_.y_texture_location_; |
| 251 } |
| 252 int u_texture_location() const { |
| 253 return fragment_shader_.u_texture_location_; |
| 254 } |
| 255 int v_texture_location() const { |
| 256 return fragment_shader_.v_texture_location_; |
| 257 } |
| 258 int uv_texture_location() const { |
| 259 return fragment_shader_.uv_texture_location_; |
| 260 } |
| 261 int a_texture_location() const { |
| 262 return fragment_shader_.a_texture_location_; |
| 263 } |
| 264 int lut_texture_location() const { |
| 265 return fragment_shader_.lut_texture_location_; |
| 266 } |
| 267 int yuv_matrix_location() const { |
| 268 return fragment_shader_.yuv_matrix_location_; |
| 269 } |
| 270 int yuv_adj_location() const { return fragment_shader_.yuv_adj_location_; } |
| 271 int ya_clamp_rect_location() const { |
| 272 return fragment_shader_.ya_clamp_rect_location_; |
| 273 } |
| 274 int uv_clamp_rect_location() const { |
| 275 return fragment_shader_.uv_clamp_rect_location_; |
| 276 } |
| 277 int resource_multiplier_location() const { |
| 278 return fragment_shader_.resource_multiplier_location_; |
| 279 } |
| 280 int resource_offset_location() const { |
| 281 return fragment_shader_.resource_offset_location_; |
| 282 } |
254 | 283 |
255 private: | 284 private: |
256 void InitializeDebugBorderProgram() { | 285 void InitializeDebugBorderProgram() { |
257 // Initialize vertex program. | 286 // Initialize vertex program. |
258 vertex_shader_.has_matrix_ = true; | 287 vertex_shader_.has_matrix_ = true; |
259 | 288 |
260 // Initialize fragment program. | 289 // Initialize fragment program. |
261 fragment_shader_.input_color_type_ = INPUT_COLOR_SOURCE_UNIFORM; | 290 fragment_shader_.input_color_type_ = INPUT_COLOR_SOURCE_UNIFORM; |
262 fragment_shader_.frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT; | 291 fragment_shader_.frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT; |
263 } | 292 } |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 fragment_shader_.ignore_sampler_type_ = true; | 368 fragment_shader_.ignore_sampler_type_ = true; |
340 } else { | 369 } else { |
341 DCHECK(!key.mask_for_background_); | 370 DCHECK(!key.mask_for_background_); |
342 } | 371 } |
343 } | 372 } |
344 | 373 |
345 void InitializeVideoStreamProgram(const ProgramKey& key) { | 374 void InitializeVideoStreamProgram(const ProgramKey& key) { |
346 vertex_shader_.tex_coord_source_ = TEX_COORD_SOURCE_ATTRIBUTE; | 375 vertex_shader_.tex_coord_source_ = TEX_COORD_SOURCE_ATTRIBUTE; |
347 vertex_shader_.tex_coord_transform_ = TEX_COORD_TRANSFORM_MATRIX; | 376 vertex_shader_.tex_coord_transform_ = TEX_COORD_TRANSFORM_MATRIX; |
348 vertex_shader_.has_matrix_ = true; | 377 vertex_shader_.has_matrix_ = true; |
| 378 DCHECK_EQ(key.sampler_, SAMPLER_TYPE_EXTERNAL_OES); |
| 379 } |
349 | 380 |
350 fragment_shader_.tex_coord_precision_ = key.precision_; | 381 void InitializeYUVVideo(const ProgramKey& key) { |
351 fragment_shader_.sampler_type_ = SAMPLER_TYPE_EXTERNAL_OES; | 382 vertex_shader_.tex_coord_source_ = TEX_COORD_SOURCE_ATTRIBUTE; |
352 fragment_shader_.frag_color_mode_ = FRAG_COLOR_MODE_DEFAULT; | 383 vertex_shader_.has_matrix_ = true; |
| 384 vertex_shader_.is_ya_uv_ = true; |
| 385 |
| 386 fragment_shader_.input_color_type_ = INPUT_COLOR_SOURCE_YUV_TEXTURES; |
| 387 fragment_shader_.use_alpha_texture_ = key.use_alpha_texture_; |
| 388 fragment_shader_.use_nv12_ = key.use_nv12_; |
| 389 fragment_shader_.use_color_lut_ = key.use_color_lut_; |
353 } | 390 } |
354 | 391 |
355 void InitializeInternal(ContextProvider* context_provider) { | 392 void InitializeInternal(ContextProvider* context_provider) { |
356 DCHECK(context_provider); | 393 DCHECK(context_provider); |
357 DCHECK(!initialized_); | 394 DCHECK(!initialized_); |
358 | 395 |
359 if (IsContextLost(context_provider->ContextGL())) | 396 if (IsContextLost(context_provider->ContextGL())) |
360 return; | 397 return; |
361 | 398 |
362 if (!ProgramBindingBase::Init(context_provider->ContextGL(), | 399 if (!ProgramBindingBase::Init(context_provider->ContextGL(), |
(...skipping 14 matching lines...) Expand all Loading... |
377 DCHECK(IsContextLost(context_provider->ContextGL())); | 414 DCHECK(IsContextLost(context_provider->ContextGL())); |
378 return; | 415 return; |
379 } | 416 } |
380 | 417 |
381 initialized_ = true; | 418 initialized_ = true; |
382 } | 419 } |
383 | 420 |
384 VertexShader vertex_shader_; | 421 VertexShader vertex_shader_; |
385 FragmentShader fragment_shader_; | 422 FragmentShader fragment_shader_; |
386 | 423 |
387 DISALLOW_COPY_AND_ASSIGN(ProgramBinding); | 424 DISALLOW_COPY_AND_ASSIGN(Program); |
388 }; | 425 }; |
389 | 426 |
390 typedef ProgramBinding<VertexShaderBase, FragmentShaderBase> Program; | |
391 | |
392 } // namespace cc | 427 } // namespace cc |
393 | 428 |
394 #endif // CC_OUTPUT_PROGRAM_BINDING_H_ | 429 #endif // CC_OUTPUT_PROGRAM_BINDING_H_ |
OLD | NEW |