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

Side by Side Diff: cc/program_binding.cc

Issue 11192030: cc: Switch to Chromium DCHECKs LOGs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebaseonenne Created 8 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « cc/program_binding.h ('k') | cc/proxy.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "config.h" 5 #include "config.h"
6 6
7 #include "cc/program_binding.h" 7 #include "cc/program_binding.h"
8 8
9 #include "CCRendererGL.h" // For the GLC() macro. 9 #include "CCRendererGL.h" // For the GLC() macro.
10 #include "GraphicsContext3D.h" 10 #include "GraphicsContext3D.h"
11 #include "base/debug/trace_event.h" 11 #include "base/debug/trace_event.h"
12 #include "cc/geometry_binding.h" 12 #include "cc/geometry_binding.h"
13 #include <public/WebGraphicsContext3D.h> 13 #include <public/WebGraphicsContext3D.h>
14 14
15 using WebKit::WebGraphicsContext3D; 15 using WebKit::WebGraphicsContext3D;
16 16
17 namespace cc { 17 namespace cc {
18 18
19 ProgramBindingBase::ProgramBindingBase() 19 ProgramBindingBase::ProgramBindingBase()
20 : m_program(0) 20 : m_program(0)
21 , m_vertexShaderId(0) 21 , m_vertexShaderId(0)
22 , m_fragmentShaderId(0) 22 , m_fragmentShaderId(0)
23 , m_initialized(false) 23 , m_initialized(false)
24 { 24 {
25 } 25 }
26 26
27 ProgramBindingBase::~ProgramBindingBase() 27 ProgramBindingBase::~ProgramBindingBase()
28 { 28 {
29 // If you hit these asserts, you initialized but forgot to call cleanup(). 29 // If you hit these asserts, you initialized but forgot to call cleanup().
30 ASSERT(!m_program); 30 DCHECK(!m_program);
31 ASSERT(!m_vertexShaderId); 31 DCHECK(!m_vertexShaderId);
32 ASSERT(!m_fragmentShaderId); 32 DCHECK(!m_fragmentShaderId);
33 ASSERT(!m_initialized); 33 DCHECK(!m_initialized);
34 } 34 }
35 35
36 static bool contextLost(WebGraphicsContext3D* context) 36 static bool contextLost(WebGraphicsContext3D* context)
37 { 37 {
38 return (context->getGraphicsResetStatusARB() != GraphicsContext3D::NO_ERROR) ; 38 return (context->getGraphicsResetStatusARB() != GraphicsContext3D::NO_ERROR) ;
39 } 39 }
40 40
41 41
42 void ProgramBindingBase::init(WebGraphicsContext3D* context, const std::string& vertexShader, const std::string& fragmentShader) 42 void ProgramBindingBase::init(WebGraphicsContext3D* context, const std::string& vertexShader, const std::string& fragmentShader)
43 { 43 {
44 TRACE_EVENT0("cc", "ProgramBindingBase::init"); 44 TRACE_EVENT0("cc", "ProgramBindingBase::init");
45 m_vertexShaderId = loadShader(context, GraphicsContext3D::VERTEX_SHADER, ver texShader); 45 m_vertexShaderId = loadShader(context, GraphicsContext3D::VERTEX_SHADER, ver texShader);
46 if (!m_vertexShaderId) { 46 if (!m_vertexShaderId) {
47 if (!contextLost(context)) 47 if (!contextLost(context))
48 LOG_ERROR("Failed to create vertex shader"); 48 LOG(ERROR) << "Failed to create vertex shader";
49 return; 49 return;
50 } 50 }
51 51
52 m_fragmentShaderId = loadShader(context, GraphicsContext3D::FRAGMENT_SHADER, fragmentShader); 52 m_fragmentShaderId = loadShader(context, GraphicsContext3D::FRAGMENT_SHADER, fragmentShader);
53 if (!m_fragmentShaderId) { 53 if (!m_fragmentShaderId) {
54 GLC(context, context->deleteShader(m_vertexShaderId)); 54 GLC(context, context->deleteShader(m_vertexShaderId));
55 m_vertexShaderId = 0; 55 m_vertexShaderId = 0;
56 if (!contextLost(context)) 56 if (!contextLost(context))
57 LOG_ERROR("Failed to create fragment shader"); 57 LOG(ERROR) << "Failed to create fragment shader";
58 return; 58 return;
59 } 59 }
60 60
61 m_program = createShaderProgram(context, m_vertexShaderId, m_fragmentShaderI d); 61 m_program = createShaderProgram(context, m_vertexShaderId, m_fragmentShaderI d);
62 ASSERT(m_program || contextLost(context)); 62 DCHECK(m_program || contextLost(context));
63 } 63 }
64 64
65 void ProgramBindingBase::link(WebGraphicsContext3D* context) 65 void ProgramBindingBase::link(WebGraphicsContext3D* context)
66 { 66 {
67 GLC(context, context->linkProgram(m_program)); 67 GLC(context, context->linkProgram(m_program));
68 cleanupShaders(context); 68 cleanupShaders(context);
69 #ifndef NDEBUG 69 #ifndef NDEBUG
70 int linked = 0; 70 int linked = 0;
71 GLC(context, context->getProgramiv(m_program, GraphicsContext3D::LINK_STATUS , &linked)); 71 GLC(context, context->getProgramiv(m_program, GraphicsContext3D::LINK_STATUS , &linked));
72 if (!linked) { 72 if (!linked) {
73 if (!contextLost(context)) 73 if (!contextLost(context))
74 LOG_ERROR("Failed to link shader program"); 74 LOG(ERROR) << "Failed to link shader program";
75 GLC(context, context->deleteProgram(m_program)); 75 GLC(context, context->deleteProgram(m_program));
76 return;
77 } 76 }
78 #endif 77 #endif
79 } 78 }
80 79
81 void ProgramBindingBase::cleanup(WebGraphicsContext3D* context) 80 void ProgramBindingBase::cleanup(WebGraphicsContext3D* context)
82 { 81 {
83 m_initialized = false; 82 m_initialized = false;
84 if (!m_program) 83 if (!m_program)
85 return; 84 return;
86 85
87 ASSERT(context); 86 DCHECK(context);
88 GLC(context, context->deleteProgram(m_program)); 87 GLC(context, context->deleteProgram(m_program));
89 m_program = 0; 88 m_program = 0;
90 89
91 cleanupShaders(context); 90 cleanupShaders(context);
92 } 91 }
93 92
94 unsigned ProgramBindingBase::loadShader(WebGraphicsContext3D* context, unsigned type, const std::string& shaderSource) 93 unsigned ProgramBindingBase::loadShader(WebGraphicsContext3D* context, unsigned type, const std::string& shaderSource)
95 { 94 {
96 unsigned shader = context->createShader(type); 95 unsigned shader = context->createShader(type);
97 if (!shader) 96 if (!shader)
98 return 0; 97 return 0;
99 GLC(context, context->shaderSource(shader, shaderSource.data())); 98 GLC(context, context->shaderSource(shader, shaderSource.data()));
100 GLC(context, context->compileShader(shader)); 99 GLC(context, context->compileShader(shader));
101 #ifndef NDEBUG 100 #ifndef NDEBUG
102 int compiled = 0; 101 int compiled = 0;
103 GLC(context, context->getShaderiv(shader, GraphicsContext3D::COMPILE_STATUS, &compiled)); 102 GLC(context, context->getShaderiv(shader, GraphicsContext3D::COMPILE_STATUS, &compiled));
104 if (!compiled) { 103 if (!compiled) {
105 GLC(context, context->deleteShader(shader)); 104 GLC(context, context->deleteShader(shader));
106 return 0; 105 return 0;
107 } 106 }
108 #endif 107 #endif
109 return shader; 108 return shader;
110 } 109 }
111 110
112 unsigned ProgramBindingBase::createShaderProgram(WebGraphicsContext3D* context, unsigned vertexShader, unsigned fragmentShader) 111 unsigned ProgramBindingBase::createShaderProgram(WebGraphicsContext3D* context, unsigned vertexShader, unsigned fragmentShader)
113 { 112 {
114 unsigned programObject = context->createProgram(); 113 unsigned programObject = context->createProgram();
115 if (!programObject) { 114 if (!programObject) {
116 if (!contextLost(context)) 115 if (!contextLost(context))
117 LOG_ERROR("Failed to create shader program"); 116 LOG(ERROR) << "Failed to create shader program";
118 return 0; 117 return 0;
119 } 118 }
120 119
121 GLC(context, context->attachShader(programObject, vertexShader)); 120 GLC(context, context->attachShader(programObject, vertexShader));
122 GLC(context, context->attachShader(programObject, fragmentShader)); 121 GLC(context, context->attachShader(programObject, fragmentShader));
123 122
124 // Bind the common attrib locations. 123 // Bind the common attrib locations.
125 GLC(context, context->bindAttribLocation(programObject, GeometryBinding::pos itionAttribLocation(), "a_position")); 124 GLC(context, context->bindAttribLocation(programObject, GeometryBinding::pos itionAttribLocation(), "a_position"));
126 GLC(context, context->bindAttribLocation(programObject, GeometryBinding::tex CoordAttribLocation(), "a_texCoord")); 125 GLC(context, context->bindAttribLocation(programObject, GeometryBinding::tex CoordAttribLocation(), "a_texCoord"));
127 126
128 return programObject; 127 return programObject;
129 } 128 }
130 129
131 void ProgramBindingBase::cleanupShaders(WebGraphicsContext3D* context) 130 void ProgramBindingBase::cleanupShaders(WebGraphicsContext3D* context)
132 { 131 {
133 if (m_vertexShaderId) { 132 if (m_vertexShaderId) {
134 GLC(context, context->deleteShader(m_vertexShaderId)); 133 GLC(context, context->deleteShader(m_vertexShaderId));
135 m_vertexShaderId = 0; 134 m_vertexShaderId = 0;
136 } 135 }
137 if (m_fragmentShaderId) { 136 if (m_fragmentShaderId) {
138 GLC(context, context->deleteShader(m_fragmentShaderId)); 137 GLC(context, context->deleteShader(m_fragmentShaderId));
139 m_fragmentShaderId = 0; 138 m_fragmentShaderId = 0;
140 } 139 }
141 } 140 }
142 141
143 } // namespace cc 142 } // namespace cc
OLDNEW
« no previous file with comments | « cc/program_binding.h ('k') | cc/proxy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698