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 ProgramBinding_h | 5 #ifndef ProgramBinding_h |
6 #define ProgramBinding_h | 6 #define ProgramBinding_h |
7 | 7 |
8 #if USE(ACCELERATED_COMPOSITING) | 8 #if USE(ACCELERATED_COMPOSITING) |
9 | 9 |
10 #include <string> | 10 #include <string> |
11 | 11 |
| 12 #include "base/logging.h" |
| 13 |
12 namespace WebKit { | 14 namespace WebKit { |
13 class WebGraphicsContext3D; | 15 class WebGraphicsContext3D; |
14 } | 16 } |
15 | 17 |
16 namespace cc { | 18 namespace cc { |
17 | 19 |
18 class ProgramBindingBase { | 20 class ProgramBindingBase { |
19 public: | 21 public: |
20 ProgramBindingBase(); | 22 ProgramBindingBase(); |
21 ~ProgramBindingBase(); | 23 ~ProgramBindingBase(); |
22 | 24 |
23 void init(WebKit::WebGraphicsContext3D*, const std::string& vertexShader, co
nst std::string& fragmentShader); | 25 void init(WebKit::WebGraphicsContext3D*, const std::string& vertexShader, co
nst std::string& fragmentShader); |
24 void link(WebKit::WebGraphicsContext3D*); | 26 void link(WebKit::WebGraphicsContext3D*); |
25 void cleanup(WebKit::WebGraphicsContext3D*); | 27 void cleanup(WebKit::WebGraphicsContext3D*); |
26 | 28 |
27 unsigned program() const { ASSERT(m_initialized); return m_program; } | 29 unsigned program() const { DCHECK(m_initialized); return m_program; } |
28 bool initialized() const { return m_initialized; } | 30 bool initialized() const { return m_initialized; } |
29 | 31 |
30 protected: | 32 protected: |
31 | 33 |
32 unsigned loadShader(WebKit::WebGraphicsContext3D*, unsigned type, const std:
:string& shaderSource); | 34 unsigned loadShader(WebKit::WebGraphicsContext3D*, unsigned type, const std:
:string& shaderSource); |
33 unsigned createShaderProgram(WebKit::WebGraphicsContext3D*, unsigned vertexS
hader, unsigned fragmentShader); | 35 unsigned createShaderProgram(WebKit::WebGraphicsContext3D*, unsigned vertexS
hader, unsigned fragmentShader); |
34 void cleanupShaders(WebKit::WebGraphicsContext3D*); | 36 void cleanupShaders(WebKit::WebGraphicsContext3D*); |
35 | 37 |
36 unsigned m_program; | 38 unsigned m_program; |
37 unsigned m_vertexShaderId; | 39 unsigned m_vertexShaderId; |
38 unsigned m_fragmentShaderId; | 40 unsigned m_fragmentShaderId; |
39 bool m_initialized; | 41 bool m_initialized; |
40 }; | 42 }; |
41 | 43 |
42 template<class VertexShader, class FragmentShader> | 44 template<class VertexShader, class FragmentShader> |
43 class ProgramBinding : public ProgramBindingBase { | 45 class ProgramBinding : public ProgramBindingBase { |
44 public: | 46 public: |
45 explicit ProgramBinding(WebKit::WebGraphicsContext3D* context) | 47 explicit ProgramBinding(WebKit::WebGraphicsContext3D* context) |
46 { | 48 { |
47 ProgramBindingBase::init(context, m_vertexShader.getShaderString(), m_fr
agmentShader.getShaderString()); | 49 ProgramBindingBase::init(context, m_vertexShader.getShaderString(), m_fr
agmentShader.getShaderString()); |
48 } | 50 } |
49 | 51 |
50 void initialize(WebKit::WebGraphicsContext3D* context, bool usingBindUniform
) | 52 void initialize(WebKit::WebGraphicsContext3D* context, bool usingBindUniform
) |
51 { | 53 { |
52 ASSERT(context); | 54 DCHECK(context); |
53 ASSERT(m_program); | 55 DCHECK(m_program); |
54 ASSERT(!m_initialized); | 56 DCHECK(!m_initialized); |
55 | 57 |
56 // Need to bind uniforms before linking | 58 // Need to bind uniforms before linking |
57 if (!usingBindUniform) | 59 if (!usingBindUniform) |
58 link(context); | 60 link(context); |
59 | 61 |
60 int baseUniformIndex = 0; | 62 int baseUniformIndex = 0; |
61 m_vertexShader.init(context, m_program, usingBindUniform, &baseUniformIn
dex); | 63 m_vertexShader.init(context, m_program, usingBindUniform, &baseUniformIn
dex); |
62 m_fragmentShader.init(context, m_program, usingBindUniform, &baseUniform
Index); | 64 m_fragmentShader.init(context, m_program, usingBindUniform, &baseUniform
Index); |
63 | 65 |
64 // Link after binding uniforms | 66 // Link after binding uniforms |
(...skipping 10 matching lines...) Expand all Loading... |
75 | 77 |
76 VertexShader m_vertexShader; | 78 VertexShader m_vertexShader; |
77 FragmentShader m_fragmentShader; | 79 FragmentShader m_fragmentShader; |
78 }; | 80 }; |
79 | 81 |
80 } // namespace cc | 82 } // namespace cc |
81 | 83 |
82 #endif // USE(ACCELERATED_COMPOSITING) | 84 #endif // USE(ACCELERATED_COMPOSITING) |
83 | 85 |
84 #endif | 86 #endif |
OLD | NEW |