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

Side by Side Diff: cc/program_binding.cc

Issue 11196014: Revert "cc: Switch to Chromium DCHECKs LOGs" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 "TraceEvent.h" 11 #include "TraceEvent.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 DCHECK(!m_program); 30 ASSERT(!m_program);
31 DCHECK(!m_vertexShaderId); 31 ASSERT(!m_vertexShaderId);
32 DCHECK(!m_fragmentShaderId); 32 ASSERT(!m_fragmentShaderId);
33 DCHECK(!m_initialized); 33 ASSERT(!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 DCHECK(m_program || contextLost(context)); 62 ASSERT(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 #if CC_DCHECK_ENABLED() 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;
76 } 77 }
77 #endif 78 #endif
78 } 79 }
79 80
80 void ProgramBindingBase::cleanup(WebGraphicsContext3D* context) 81 void ProgramBindingBase::cleanup(WebGraphicsContext3D* context)
81 { 82 {
82 m_initialized = false; 83 m_initialized = false;
83 if (!m_program) 84 if (!m_program)
84 return; 85 return;
85 86
86 DCHECK(context); 87 ASSERT(context);
87 GLC(context, context->deleteProgram(m_program)); 88 GLC(context, context->deleteProgram(m_program));
88 m_program = 0; 89 m_program = 0;
89 90
90 cleanupShaders(context); 91 cleanupShaders(context);
91 } 92 }
92 93
93 unsigned ProgramBindingBase::loadShader(WebGraphicsContext3D* context, unsigned type, const std::string& shaderSource) 94 unsigned ProgramBindingBase::loadShader(WebGraphicsContext3D* context, unsigned type, const std::string& shaderSource)
94 { 95 {
95 unsigned shader = context->createShader(type); 96 unsigned shader = context->createShader(type);
96 if (!shader) 97 if (!shader)
97 return 0; 98 return 0;
98 GLC(context, context->shaderSource(shader, shaderSource.data())); 99 GLC(context, context->shaderSource(shader, shaderSource.data()));
99 GLC(context, context->compileShader(shader)); 100 GLC(context, context->compileShader(shader));
100 #if CC_DCHECK_ENABLED() 101 #ifndef NDEBUG
101 int compiled = 0; 102 int compiled = 0;
102 GLC(context, context->getShaderiv(shader, GraphicsContext3D::COMPILE_STATUS, &compiled)); 103 GLC(context, context->getShaderiv(shader, GraphicsContext3D::COMPILE_STATUS, &compiled));
103 if (!compiled) { 104 if (!compiled) {
104 GLC(context, context->deleteShader(shader)); 105 GLC(context, context->deleteShader(shader));
105 return 0; 106 return 0;
106 } 107 }
107 #endif 108 #endif
108 return shader; 109 return shader;
109 } 110 }
110 111
111 unsigned ProgramBindingBase::createShaderProgram(WebGraphicsContext3D* context, unsigned vertexShader, unsigned fragmentShader) 112 unsigned ProgramBindingBase::createShaderProgram(WebGraphicsContext3D* context, unsigned vertexShader, unsigned fragmentShader)
112 { 113 {
113 unsigned programObject = context->createProgram(); 114 unsigned programObject = context->createProgram();
114 if (!programObject) { 115 if (!programObject) {
115 if (!contextLost(context)) 116 if (!contextLost(context))
116 LOG(ERROR) << "Failed to create shader program"; 117 LOG_ERROR("Failed to create shader program");
117 return 0; 118 return 0;
118 } 119 }
119 120
120 GLC(context, context->attachShader(programObject, vertexShader)); 121 GLC(context, context->attachShader(programObject, vertexShader));
121 GLC(context, context->attachShader(programObject, fragmentShader)); 122 GLC(context, context->attachShader(programObject, fragmentShader));
122 123
123 // Bind the common attrib locations. 124 // Bind the common attrib locations.
124 GLC(context, context->bindAttribLocation(programObject, GeometryBinding::pos itionAttribLocation(), "a_position")); 125 GLC(context, context->bindAttribLocation(programObject, GeometryBinding::pos itionAttribLocation(), "a_position"));
125 GLC(context, context->bindAttribLocation(programObject, GeometryBinding::tex CoordAttribLocation(), "a_texCoord")); 126 GLC(context, context->bindAttribLocation(programObject, GeometryBinding::tex CoordAttribLocation(), "a_texCoord"));
126 127
127 return programObject; 128 return programObject;
128 } 129 }
129 130
130 void ProgramBindingBase::cleanupShaders(WebGraphicsContext3D* context) 131 void ProgramBindingBase::cleanupShaders(WebGraphicsContext3D* context)
131 { 132 {
132 if (m_vertexShaderId) { 133 if (m_vertexShaderId) {
133 GLC(context, context->deleteShader(m_vertexShaderId)); 134 GLC(context, context->deleteShader(m_vertexShaderId));
134 m_vertexShaderId = 0; 135 m_vertexShaderId = 0;
135 } 136 }
136 if (m_fragmentShaderId) { 137 if (m_fragmentShaderId) {
137 GLC(context, context->deleteShader(m_fragmentShaderId)); 138 GLC(context, context->deleteShader(m_fragmentShaderId));
138 m_fragmentShaderId = 0; 139 m_fragmentShaderId = 0;
139 } 140 }
140 } 141 }
141 142
142 } // namespace cc 143 } // 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