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

Side by Side Diff: cc/ProgramBinding.cpp

Issue 11048044: cc: Switch to Chromium DCHECKs and LOGs (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
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
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 #if USE(ACCELERATED_COMPOSITING) 7 #if USE(ACCELERATED_COMPOSITING)
8 8
9 #include "ProgramBinding.h" 9 #include "ProgramBinding.h"
10 10
(...skipping 11 matching lines...) Expand all
22 : m_program(0) 22 : m_program(0)
23 , m_vertexShaderId(0) 23 , m_vertexShaderId(0)
24 , m_fragmentShaderId(0) 24 , m_fragmentShaderId(0)
25 , m_initialized(false) 25 , m_initialized(false)
26 { 26 {
27 } 27 }
28 28
29 ProgramBindingBase::~ProgramBindingBase() 29 ProgramBindingBase::~ProgramBindingBase()
30 { 30 {
31 // If you hit these asserts, you initialized but forgot to call cleanup(). 31 // If you hit these asserts, you initialized but forgot to call cleanup().
32 ASSERT(!m_program); 32 DCHECK(!m_program);
33 ASSERT(!m_vertexShaderId); 33 DCHECK(!m_vertexShaderId);
34 ASSERT(!m_fragmentShaderId); 34 DCHECK(!m_fragmentShaderId);
35 ASSERT(!m_initialized); 35 DCHECK(!m_initialized);
36 } 36 }
37 37
38 static bool contextLost(WebGraphicsContext3D* context) 38 static bool contextLost(WebGraphicsContext3D* context)
39 { 39 {
40 return (context->getGraphicsResetStatusARB() != GraphicsContext3D::NO_ERROR) ; 40 return (context->getGraphicsResetStatusARB() != GraphicsContext3D::NO_ERROR) ;
41 } 41 }
42 42
43 43
44 void ProgramBindingBase::init(WebGraphicsContext3D* context, const std::string& vertexShader, const std::string& fragmentShader) 44 void ProgramBindingBase::init(WebGraphicsContext3D* context, const std::string& vertexShader, const std::string& fragmentShader)
45 { 45 {
46 TRACE_EVENT0("cc", "ProgramBindingBase::init"); 46 TRACE_EVENT0("cc", "ProgramBindingBase::init");
47 m_vertexShaderId = loadShader(context, GraphicsContext3D::VERTEX_SHADER, ver texShader); 47 m_vertexShaderId = loadShader(context, GraphicsContext3D::VERTEX_SHADER, ver texShader);
48 if (!m_vertexShaderId) { 48 if (!m_vertexShaderId) {
49 if (!contextLost(context)) 49 if (!contextLost(context))
50 LOG_ERROR("Failed to create vertex shader"); 50 LOG(ERROR) << "Failed to create vertex shader";
51 return; 51 return;
52 } 52 }
53 53
54 m_fragmentShaderId = loadShader(context, GraphicsContext3D::FRAGMENT_SHADER, fragmentShader); 54 m_fragmentShaderId = loadShader(context, GraphicsContext3D::FRAGMENT_SHADER, fragmentShader);
55 if (!m_fragmentShaderId) { 55 if (!m_fragmentShaderId) {
56 GLC(context, context->deleteShader(m_vertexShaderId)); 56 GLC(context, context->deleteShader(m_vertexShaderId));
57 m_vertexShaderId = 0; 57 m_vertexShaderId = 0;
58 if (!contextLost(context)) 58 if (!contextLost(context))
59 LOG_ERROR("Failed to create fragment shader"); 59 LOG(ERROR) << "Failed to create fragment shader";
60 return; 60 return;
61 } 61 }
62 62
63 m_program = createShaderProgram(context, m_vertexShaderId, m_fragmentShaderI d); 63 m_program = createShaderProgram(context, m_vertexShaderId, m_fragmentShaderI d);
64 ASSERT(m_program || contextLost(context)); 64 DCHECK(m_program || contextLost(context));
65 } 65 }
66 66
67 void ProgramBindingBase::link(WebGraphicsContext3D* context) 67 void ProgramBindingBase::link(WebGraphicsContext3D* context)
68 { 68 {
69 GLC(context, context->linkProgram(m_program)); 69 GLC(context, context->linkProgram(m_program));
70 cleanupShaders(context); 70 cleanupShaders(context);
71 #ifndef NDEBUG 71 if (DCHECK_IS_ON()) {
72 int linked = 0; 72 int linked = 0;
73 GLC(context, context->getProgramiv(m_program, GraphicsContext3D::LINK_STATUS , &linked)); 73 GLC(context, context->getProgramiv(m_program, GraphicsContext3D::LINK_ST ATUS, &linked));
74 if (!linked) { 74 if (!linked) {
75 if (!contextLost(context)) 75 if (!contextLost(context))
76 LOG_ERROR("Failed to link shader program"); 76 LOG(ERROR) << "Failed to link shader program";
77 GLC(context, context->deleteProgram(m_program)); 77 GLC(context, context->deleteProgram(m_program));
78 return; 78 }
79 } 79 }
80 #endif
81 } 80 }
82 81
83 void ProgramBindingBase::cleanup(WebGraphicsContext3D* context) 82 void ProgramBindingBase::cleanup(WebGraphicsContext3D* context)
84 { 83 {
85 m_initialized = false; 84 m_initialized = false;
86 if (!m_program) 85 if (!m_program)
87 return; 86 return;
88 87
89 ASSERT(context); 88 DCHECK(context);
90 GLC(context, context->deleteProgram(m_program)); 89 GLC(context, context->deleteProgram(m_program));
91 m_program = 0; 90 m_program = 0;
92 91
93 cleanupShaders(context); 92 cleanupShaders(context);
94 } 93 }
95 94
96 unsigned ProgramBindingBase::loadShader(WebGraphicsContext3D* context, unsigned type, const std::string& shaderSource) 95 unsigned ProgramBindingBase::loadShader(WebGraphicsContext3D* context, unsigned type, const std::string& shaderSource)
97 { 96 {
98 unsigned shader = context->createShader(type); 97 unsigned shader = context->createShader(type);
99 if (!shader) 98 if (!shader)
100 return 0; 99 return 0;
101 GLC(context, context->shaderSource(shader, shaderSource.data())); 100 GLC(context, context->shaderSource(shader, shaderSource.data()));
102 GLC(context, context->compileShader(shader)); 101 GLC(context, context->compileShader(shader));
103 #ifndef NDEBUG 102 if (DCHECK_IS_ON()) {
104 int compiled = 0; 103 int compiled = 0;
105 GLC(context, context->getShaderiv(shader, GraphicsContext3D::COMPILE_STATUS, &compiled)); 104 GLC(context, context->getShaderiv(shader, GraphicsContext3D::COMPILE_STA TUS, &compiled));
106 if (!compiled) { 105 if (!compiled) {
107 GLC(context, context->deleteShader(shader)); 106 GLC(context, context->deleteShader(shader));
108 return 0; 107 return 0;
108 }
109 } 109 }
110 #endif
111 return shader; 110 return shader;
112 } 111 }
113 112
114 unsigned ProgramBindingBase::createShaderProgram(WebGraphicsContext3D* context, unsigned vertexShader, unsigned fragmentShader) 113 unsigned ProgramBindingBase::createShaderProgram(WebGraphicsContext3D* context, unsigned vertexShader, unsigned fragmentShader)
115 { 114 {
116 unsigned programObject = context->createProgram(); 115 unsigned programObject = context->createProgram();
117 if (!programObject) { 116 if (!programObject) {
118 if (!contextLost(context)) 117 if (!contextLost(context))
119 LOG_ERROR("Failed to create shader program"); 118 LOG(ERROR) << "Failed to create shader program";
120 return 0; 119 return 0;
121 } 120 }
122 121
123 GLC(context, context->attachShader(programObject, vertexShader)); 122 GLC(context, context->attachShader(programObject, vertexShader));
124 GLC(context, context->attachShader(programObject, fragmentShader)); 123 GLC(context, context->attachShader(programObject, fragmentShader));
125 124
126 // Bind the common attrib locations. 125 // Bind the common attrib locations.
127 GLC(context, context->bindAttribLocation(programObject, GeometryBinding::pos itionAttribLocation(), "a_position")); 126 GLC(context, context->bindAttribLocation(programObject, GeometryBinding::pos itionAttribLocation(), "a_position"));
128 GLC(context, context->bindAttribLocation(programObject, GeometryBinding::tex CoordAttribLocation(), "a_texCoord")); 127 GLC(context, context->bindAttribLocation(programObject, GeometryBinding::tex CoordAttribLocation(), "a_texCoord"));
129 128
130 return programObject; 129 return programObject;
131 } 130 }
132 131
133 void ProgramBindingBase::cleanupShaders(WebGraphicsContext3D* context) 132 void ProgramBindingBase::cleanupShaders(WebGraphicsContext3D* context)
134 { 133 {
135 if (m_vertexShaderId) { 134 if (m_vertexShaderId) {
136 GLC(context, context->deleteShader(m_vertexShaderId)); 135 GLC(context, context->deleteShader(m_vertexShaderId));
137 m_vertexShaderId = 0; 136 m_vertexShaderId = 0;
138 } 137 }
139 if (m_fragmentShaderId) { 138 if (m_fragmentShaderId) {
140 GLC(context, context->deleteShader(m_fragmentShaderId)); 139 GLC(context, context->deleteShader(m_fragmentShaderId));
141 m_fragmentShaderId = 0; 140 m_fragmentShaderId = 0;
142 } 141 }
143 } 142 }
144 143
145 } // namespace cc 144 } // namespace cc
146 145
147 #endif // USE(ACCELERATED_COMPOSITING) 146 #endif // USE(ACCELERATED_COMPOSITING)
OLDNEW
« cc/CCCompletionEvent.h ('K') | « cc/ProgramBinding.h ('k') | cc/RateLimiter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698