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

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

Issue 2675813002: Make LUTs independent of YUV in cc shaders (Closed)
Patch Set: compile fix Created 3 years, 10 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
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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 BlendMode blend_mode, 87 BlendMode blend_mode,
88 AAMode aa_mode, 88 AAMode aa_mode,
89 MaskMode mask_mode, 89 MaskMode mask_mode,
90 bool mask_for_background, 90 bool mask_for_background,
91 bool has_color_matrix); 91 bool has_color_matrix);
92 static ProgramKey VideoStream(TexCoordPrecision precision); 92 static ProgramKey VideoStream(TexCoordPrecision precision);
93 static ProgramKey YUVVideo(TexCoordPrecision precision, 93 static ProgramKey YUVVideo(TexCoordPrecision precision,
94 SamplerType sampler, 94 SamplerType sampler,
95 YUVAlphaTextureMode yuv_alpha_texture_mode, 95 YUVAlphaTextureMode yuv_alpha_texture_mode,
96 UVTextureMode uv_texture_mode, 96 UVTextureMode uv_texture_mode,
97 ColorConversionMode color_conversion_mode); 97 bool use_lut);
98 98
99 bool operator==(const ProgramKey& other) const; 99 bool operator==(const ProgramKey& other) const;
100 100
101 private: 101 private:
102 ProgramKey(); 102 ProgramKey();
103 friend struct ProgramKeyHash; 103 friend struct ProgramKeyHash;
104 friend class Program; 104 friend class Program;
105 105
106 ProgramType type_ = PROGRAM_TYPE_DEBUG_BORDER; 106 ProgramType type_ = PROGRAM_TYPE_DEBUG_BORDER;
107 TexCoordPrecision precision_ = TEX_COORD_PRECISION_NA; 107 TexCoordPrecision precision_ = TEX_COORD_PRECISION_NA;
108 SamplerType sampler_ = SAMPLER_TYPE_NA; 108 SamplerType sampler_ = SAMPLER_TYPE_NA;
109 BlendMode blend_mode_ = BLEND_MODE_NONE; 109 BlendMode blend_mode_ = BLEND_MODE_NONE;
110 AAMode aa_mode_ = NO_AA; 110 AAMode aa_mode_ = NO_AA;
111 SwizzleMode swizzle_mode_ = NO_SWIZZLE; 111 SwizzleMode swizzle_mode_ = NO_SWIZZLE;
112 bool is_opaque_ = false; 112 bool is_opaque_ = false;
113 113
114 PremultipliedAlphaMode premultiplied_alpha_ = PREMULTIPLIED_ALPHA; 114 PremultipliedAlphaMode premultiplied_alpha_ = PREMULTIPLIED_ALPHA;
115 bool has_background_color_ = false; 115 bool has_background_color_ = false;
116 116
117 MaskMode mask_mode_ = NO_MASK; 117 MaskMode mask_mode_ = NO_MASK;
118 bool mask_for_background_ = false; 118 bool mask_for_background_ = false;
119 bool has_color_matrix_ = false; 119 bool has_color_matrix_ = false;
120 bool has_resource_offset_ = false;
121 bool has_lut_ = false;
120 122
121 YUVAlphaTextureMode yuv_alpha_texture_mode_ = YUV_NO_ALPHA_TEXTURE; 123 YUVAlphaTextureMode yuv_alpha_texture_mode_ = YUV_NO_ALPHA_TEXTURE;
122 UVTextureMode uv_texture_mode_ = UV_TEXTURE_MODE_NA; 124 UVTextureMode uv_texture_mode_ = UV_TEXTURE_MODE_NA;
123
124 ColorConversionMode color_conversion_mode_ = COLOR_CONVERSION_MODE_NONE;
125 }; 125 };
126 126
127 struct ProgramKeyHash { 127 struct ProgramKeyHash {
128 size_t operator()(const ProgramKey& key) const { 128 size_t operator()(const ProgramKey& key) const {
129 return (static_cast<size_t>(key.type_) << 0) ^ 129 return (static_cast<size_t>(key.type_) << 0) ^
130 (static_cast<size_t>(key.precision_) << 3) ^ 130 (static_cast<size_t>(key.precision_) << 3) ^
131 (static_cast<size_t>(key.sampler_) << 6) ^ 131 (static_cast<size_t>(key.sampler_) << 6) ^
132 (static_cast<size_t>(key.blend_mode_) << 9) ^ 132 (static_cast<size_t>(key.blend_mode_) << 9) ^
133 (static_cast<size_t>(key.aa_mode_) << 15) ^ 133 (static_cast<size_t>(key.aa_mode_) << 15) ^
134 (static_cast<size_t>(key.swizzle_mode_) << 16) ^ 134 (static_cast<size_t>(key.swizzle_mode_) << 16) ^
135 (static_cast<size_t>(key.is_opaque_) << 17) ^ 135 (static_cast<size_t>(key.is_opaque_) << 17) ^
136 (static_cast<size_t>(key.premultiplied_alpha_) << 19) ^ 136 (static_cast<size_t>(key.premultiplied_alpha_) << 19) ^
137 (static_cast<size_t>(key.has_background_color_) << 20) ^ 137 (static_cast<size_t>(key.has_background_color_) << 20) ^
138 (static_cast<size_t>(key.mask_mode_) << 21) ^ 138 (static_cast<size_t>(key.mask_mode_) << 21) ^
139 (static_cast<size_t>(key.mask_for_background_) << 22) ^ 139 (static_cast<size_t>(key.mask_for_background_) << 22) ^
140 (static_cast<size_t>(key.has_color_matrix_) << 23) ^ 140 (static_cast<size_t>(key.has_color_matrix_) << 23) ^
141 (static_cast<size_t>(key.yuv_alpha_texture_mode_) << 24) ^ 141 (static_cast<size_t>(key.yuv_alpha_texture_mode_) << 24) ^
142 (static_cast<size_t>(key.uv_texture_mode_) << 25) ^ 142 (static_cast<size_t>(key.uv_texture_mode_) << 25) ^
143 (static_cast<size_t>(key.color_conversion_mode_) << 26); 143 (static_cast<size_t>(key.has_lut_) << 26) ^
144 (static_cast<size_t>(key.has_resource_offset_) << 27);
144 } 145 }
145 }; 146 };
146 147
147 class Program : public ProgramBindingBase { 148 class Program : public ProgramBindingBase {
148 public: 149 public:
149 Program() {} 150 Program() {}
150 151
151 void Initialize(ContextProvider* context_provider, const ProgramKey& key) { 152 void Initialize(ContextProvider* context_provider, const ProgramKey& key) {
152 // Set parameters that are common to all sub-classes. 153 // Set parameters that are common to all sub-classes.
153 vertex_shader_.aa_mode_ = key.aa_mode_; 154 vertex_shader_.aa_mode_ = key.aa_mode_;
154 fragment_shader_.aa_mode_ = key.aa_mode_; 155 fragment_shader_.aa_mode_ = key.aa_mode_;
155 fragment_shader_.blend_mode_ = key.blend_mode_; 156 fragment_shader_.blend_mode_ = key.blend_mode_;
156 fragment_shader_.tex_coord_precision_ = key.precision_; 157 fragment_shader_.tex_coord_precision_ = key.precision_;
157 fragment_shader_.sampler_type_ = key.sampler_; 158 fragment_shader_.sampler_type_ = key.sampler_;
158 fragment_shader_.swizzle_mode_ = key.swizzle_mode_; 159 fragment_shader_.swizzle_mode_ = key.swizzle_mode_;
159 fragment_shader_.premultiply_alpha_mode_ = key.premultiplied_alpha_; 160 fragment_shader_.premultiply_alpha_mode_ = key.premultiplied_alpha_;
160 fragment_shader_.mask_mode_ = key.mask_mode_; 161 fragment_shader_.mask_mode_ = key.mask_mode_;
161 fragment_shader_.mask_for_background_ = key.mask_for_background_; 162 fragment_shader_.mask_for_background_ = key.mask_for_background_;
163 fragment_shader_.has_color_matrix_ = key.has_color_matrix_;
164 fragment_shader_.has_resource_offset_ = key.has_resource_offset_;
165 fragment_shader_.has_lut_ = key.has_lut_;
162 166
163 switch (key.type_) { 167 switch (key.type_) {
164 case PROGRAM_TYPE_DEBUG_BORDER: 168 case PROGRAM_TYPE_DEBUG_BORDER:
165 InitializeDebugBorderProgram(); 169 InitializeDebugBorderProgram();
166 break; 170 break;
167 case PROGRAM_TYPE_SOLID_COLOR: 171 case PROGRAM_TYPE_SOLID_COLOR:
168 InitializeSolidColorProgram(key); 172 InitializeSolidColorProgram(key);
169 break; 173 break;
170 case PROGRAM_TYPE_TILE: 174 case PROGRAM_TYPE_TILE:
171 InitializeTileProgram(key); 175 InitializeTileProgram(key);
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 int uv_texture_location() const { 263 int uv_texture_location() const {
260 return fragment_shader_.uv_texture_location_; 264 return fragment_shader_.uv_texture_location_;
261 } 265 }
262 int a_texture_location() const { 266 int a_texture_location() const {
263 return fragment_shader_.a_texture_location_; 267 return fragment_shader_.a_texture_location_;
264 } 268 }
265 int lut_texture_location() const { 269 int lut_texture_location() const {
266 return fragment_shader_.lut_texture_location_; 270 return fragment_shader_.lut_texture_location_;
267 } 271 }
268 int lut_size_location() const { return fragment_shader_.lut_size_location_; } 272 int lut_size_location() const { return fragment_shader_.lut_size_location_; }
269 int yuv_matrix_location() const {
270 return fragment_shader_.yuv_matrix_location_;
271 }
272 int yuv_adj_location() const { return fragment_shader_.yuv_adj_location_; }
273 int ya_clamp_rect_location() const { 273 int ya_clamp_rect_location() const {
274 return fragment_shader_.ya_clamp_rect_location_; 274 return fragment_shader_.ya_clamp_rect_location_;
275 } 275 }
276 int uv_clamp_rect_location() const { 276 int uv_clamp_rect_location() const {
277 return fragment_shader_.uv_clamp_rect_location_; 277 return fragment_shader_.uv_clamp_rect_location_;
278 } 278 }
279 int resource_multiplier_location() const { 279 int resource_multiplier_location() const {
280 return fragment_shader_.resource_multiplier_location_; 280 return fragment_shader_.resource_multiplier_location_;
281 } 281 }
282 int resource_offset_location() const { 282 int resource_offset_location() const {
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 } else { 358 } else {
359 vertex_shader_.position_source_ = 359 vertex_shader_.position_source_ =
360 POSITION_SOURCE_ATTRIBUTE_INDEXED_UNIFORM; 360 POSITION_SOURCE_ATTRIBUTE_INDEXED_UNIFORM;
361 vertex_shader_.tex_coord_source_ = TEX_COORD_SOURCE_POSITION; 361 vertex_shader_.tex_coord_source_ = TEX_COORD_SOURCE_POSITION;
362 vertex_shader_.tex_coord_transform_ = TEX_COORD_TRANSFORM_TRANSLATED_VEC4; 362 vertex_shader_.tex_coord_transform_ = TEX_COORD_TRANSFORM_TRANSLATED_VEC4;
363 } 363 }
364 364
365 // Initialize fragment program. 365 // Initialize fragment program.
366 fragment_shader_.frag_color_mode_ = FRAG_COLOR_MODE_APPLY_BLEND_MODE; 366 fragment_shader_.frag_color_mode_ = FRAG_COLOR_MODE_APPLY_BLEND_MODE;
367 fragment_shader_.has_uniform_alpha_ = true; 367 fragment_shader_.has_uniform_alpha_ = true;
368 fragment_shader_.has_color_matrix_ = key.has_color_matrix_;
369 if (key.mask_mode_ == HAS_MASK) { 368 if (key.mask_mode_ == HAS_MASK) {
370 fragment_shader_.ignore_sampler_type_ = true; 369 fragment_shader_.ignore_sampler_type_ = true;
371 } else { 370 } else {
372 DCHECK(!key.mask_for_background_); 371 DCHECK(!key.mask_for_background_);
373 } 372 }
374 } 373 }
375 374
376 void InitializeVideoStreamProgram(const ProgramKey& key) { 375 void InitializeVideoStreamProgram(const ProgramKey& key) {
377 vertex_shader_.tex_coord_source_ = TEX_COORD_SOURCE_ATTRIBUTE; 376 vertex_shader_.tex_coord_source_ = TEX_COORD_SOURCE_ATTRIBUTE;
378 vertex_shader_.tex_coord_transform_ = TEX_COORD_TRANSFORM_MATRIX; 377 vertex_shader_.tex_coord_transform_ = TEX_COORD_TRANSFORM_MATRIX;
379 vertex_shader_.has_matrix_ = true; 378 vertex_shader_.has_matrix_ = true;
380 DCHECK_EQ(key.sampler_, SAMPLER_TYPE_EXTERNAL_OES); 379 DCHECK_EQ(key.sampler_, SAMPLER_TYPE_EXTERNAL_OES);
381 } 380 }
382 381
383 void InitializeYUVVideo(const ProgramKey& key) { 382 void InitializeYUVVideo(const ProgramKey& key) {
384 vertex_shader_.tex_coord_source_ = TEX_COORD_SOURCE_ATTRIBUTE; 383 vertex_shader_.tex_coord_source_ = TEX_COORD_SOURCE_ATTRIBUTE;
385 vertex_shader_.has_matrix_ = true; 384 vertex_shader_.has_matrix_ = true;
386 vertex_shader_.is_ya_uv_ = true; 385 vertex_shader_.is_ya_uv_ = true;
387 386
388 fragment_shader_.input_color_type_ = INPUT_COLOR_SOURCE_YUV_TEXTURES; 387 fragment_shader_.input_color_type_ = INPUT_COLOR_SOURCE_YUV_TEXTURES;
389 fragment_shader_.has_uniform_alpha_ = true; 388 fragment_shader_.has_uniform_alpha_ = true;
390 fragment_shader_.yuv_alpha_texture_mode_ = key.yuv_alpha_texture_mode_; 389 fragment_shader_.yuv_alpha_texture_mode_ = key.yuv_alpha_texture_mode_;
391 fragment_shader_.uv_texture_mode_ = key.uv_texture_mode_; 390 fragment_shader_.uv_texture_mode_ = key.uv_texture_mode_;
392 fragment_shader_.color_conversion_mode_ = key.color_conversion_mode_; 391 DCHECK(key.has_lut_ || key.has_color_matrix_);
393 } 392 }
394 393
395 void InitializeInternal(ContextProvider* context_provider) { 394 void InitializeInternal(ContextProvider* context_provider) {
396 DCHECK(context_provider); 395 DCHECK(context_provider);
397 DCHECK(!initialized_); 396 DCHECK(!initialized_);
398 397
399 if (IsContextLost(context_provider->ContextGL())) 398 if (IsContextLost(context_provider->ContextGL()))
400 return; 399 return;
401 400
402 if (!ProgramBindingBase::Init(context_provider->ContextGL(), 401 if (!ProgramBindingBase::Init(context_provider->ContextGL(),
(...skipping 20 matching lines...) Expand all
423 422
424 VertexShader vertex_shader_; 423 VertexShader vertex_shader_;
425 FragmentShader fragment_shader_; 424 FragmentShader fragment_shader_;
426 425
427 DISALLOW_COPY_AND_ASSIGN(Program); 426 DISALLOW_COPY_AND_ASSIGN(Program);
428 }; 427 };
429 428
430 } // namespace cc 429 } // namespace cc
431 430
432 #endif // CC_OUTPUT_PROGRAM_BINDING_H_ 431 #endif // CC_OUTPUT_PROGRAM_BINDING_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698