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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 }; | 55 }; |
56 | 56 |
57 template <class VertexShader, class FragmentShader> | 57 template <class VertexShader, class FragmentShader> |
58 class ProgramBinding : public ProgramBindingBase { | 58 class ProgramBinding : public ProgramBindingBase { |
59 public: | 59 public: |
60 ProgramBinding() {} | 60 ProgramBinding() {} |
61 | 61 |
62 void Initialize(ContextProvider* context_provider, | 62 void Initialize(ContextProvider* context_provider, |
63 TexCoordPrecision precision, | 63 TexCoordPrecision precision, |
64 SamplerType sampler) { | 64 SamplerType sampler) { |
65 return Initialize( | 65 Initialize(context_provider, precision, sampler, BLEND_MODE_NONE, false); |
66 context_provider, precision, sampler, BLEND_MODE_NONE, false); | |
67 } | 66 } |
68 | 67 |
69 void Initialize(ContextProvider* context_provider, | 68 void Initialize(ContextProvider* context_provider, |
70 TexCoordPrecision precision, | 69 TexCoordPrecision precision, |
71 SamplerType sampler, | 70 SamplerType sampler, |
72 BlendMode blend_mode) { | 71 BlendMode blend_mode) { |
73 return Initialize( | 72 Initialize(context_provider, precision, sampler, blend_mode, false); |
74 context_provider, precision, sampler, blend_mode, false); | 73 } |
| 74 |
| 75 void InitializeVideoYUV(ContextProvider* context_provider, |
| 76 TexCoordPrecision precision, |
| 77 SamplerType sampler, |
| 78 bool use_alpha_plane, |
| 79 bool use_nv12, |
| 80 bool use_color_lut) { |
| 81 fragment_shader_.use_alpha_texture_ = use_alpha_plane; |
| 82 fragment_shader_.use_nv12_ = use_nv12; |
| 83 fragment_shader_.use_color_lut_ = use_color_lut; |
| 84 Initialize(context_provider, precision, sampler); |
75 } | 85 } |
76 | 86 |
77 void Initialize(ContextProvider* context_provider, | 87 void Initialize(ContextProvider* context_provider, |
78 TexCoordPrecision precision, | 88 TexCoordPrecision precision, |
79 SamplerType sampler, | 89 SamplerType sampler, |
80 BlendMode blend_mode, | 90 BlendMode blend_mode, |
81 bool mask_for_background) { | 91 bool mask_for_background) { |
| 92 vertex_shader_.SetSubclassProperties(); |
| 93 fragment_shader_.SetSubclassProperties(); |
| 94 fragment_shader_.blend_mode_ = blend_mode; |
| 95 fragment_shader_.mask_for_background_ = mask_for_background; |
| 96 fragment_shader_.tex_coord_precision_ = precision; |
| 97 fragment_shader_.sampler_type_ = sampler; |
| 98 InitializeInternal(context_provider); |
| 99 } |
| 100 |
| 101 const VertexShader& vertex_shader() const { return vertex_shader_; } |
| 102 const FragmentShader& fragment_shader() const { return fragment_shader_; } |
| 103 |
| 104 private: |
| 105 void InitializeInternal(ContextProvider* context_provider) { |
82 DCHECK(context_provider); | 106 DCHECK(context_provider); |
83 DCHECK(!initialized_); | 107 DCHECK(!initialized_); |
84 | 108 |
85 if (IsContextLost(context_provider->ContextGL())) | 109 if (IsContextLost(context_provider->ContextGL())) |
86 return; | 110 return; |
87 | 111 |
88 fragment_shader_.set_blend_mode(blend_mode); | 112 if (!ProgramBindingBase::Init(context_provider->ContextGL(), |
89 fragment_shader_.set_mask_for_background(mask_for_background); | 113 vertex_shader_.GetShaderString(), |
90 | 114 fragment_shader_.GetShaderString())) { |
91 if (!ProgramBindingBase::Init( | |
92 context_provider->ContextGL(), | |
93 vertex_shader_.GetShaderString(), | |
94 fragment_shader_.GetShaderString(precision, sampler))) { | |
95 DCHECK(IsContextLost(context_provider->ContextGL())); | 115 DCHECK(IsContextLost(context_provider->ContextGL())); |
96 return; | 116 return; |
97 } | 117 } |
98 | 118 |
99 int base_uniform_index = 0; | 119 int base_uniform_index = 0; |
100 vertex_shader_.Init(context_provider->ContextGL(), | 120 vertex_shader_.Init(context_provider->ContextGL(), |
101 program_, &base_uniform_index); | 121 program_, &base_uniform_index); |
102 fragment_shader_.Init(context_provider->ContextGL(), | 122 fragment_shader_.Init(context_provider->ContextGL(), |
103 program_, &base_uniform_index); | 123 program_, &base_uniform_index); |
104 | 124 |
105 // Link after binding uniforms | 125 // Link after binding uniforms |
106 if (!Link(context_provider->ContextGL())) { | 126 if (!Link(context_provider->ContextGL())) { |
107 DCHECK(IsContextLost(context_provider->ContextGL())); | 127 DCHECK(IsContextLost(context_provider->ContextGL())); |
108 return; | 128 return; |
109 } | 129 } |
110 | 130 |
111 initialized_ = true; | 131 initialized_ = true; |
112 } | 132 } |
113 | 133 |
114 const VertexShader& vertex_shader() const { return vertex_shader_; } | |
115 const FragmentShader& fragment_shader() const { return fragment_shader_; } | |
116 FragmentShader* mutable_fragment_shader() { return &fragment_shader_; } | |
117 | |
118 private: | |
119 VertexShader vertex_shader_; | 134 VertexShader vertex_shader_; |
120 FragmentShader fragment_shader_; | 135 FragmentShader fragment_shader_; |
121 | 136 |
122 DISALLOW_COPY_AND_ASSIGN(ProgramBinding); | 137 DISALLOW_COPY_AND_ASSIGN(ProgramBinding); |
123 }; | 138 }; |
124 | 139 |
125 } // namespace cc | 140 } // namespace cc |
126 | 141 |
127 #endif // CC_OUTPUT_PROGRAM_BINDING_H_ | 142 #endif // CC_OUTPUT_PROGRAM_BINDING_H_ |
OLD | NEW |