OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "gpu/blink/webgraphicscontext3d_impl.h" | 5 #include "gpu/blink/webgraphicscontext3d_impl.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include "base/atomicops.h" | 9 #include "base/atomicops.h" |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 : initialized_(false), | 66 : initialized_(false), |
67 initialize_failed_(false), | 67 initialize_failed_(false), |
68 context_lost_callback_(0), | 68 context_lost_callback_(0), |
69 error_message_callback_(0), | 69 error_message_callback_(0), |
70 gl_(NULL) {} | 70 gl_(NULL) {} |
71 | 71 |
72 WebGraphicsContext3DImpl::~WebGraphicsContext3DImpl() { | 72 WebGraphicsContext3DImpl::~WebGraphicsContext3DImpl() { |
73 | 73 |
74 } | 74 } |
75 | 75 |
76 bool WebGraphicsContext3DImpl::getActiveAttrib( | |
77 WebGLId program, WGC3Duint index, ActiveInfo& info) { | |
78 GLint max_name_length = -1; | |
79 gl_->GetProgramiv( | |
80 program, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &max_name_length); | |
81 // The caller already checked that there is some active attribute. | |
82 DCHECK_GT(max_name_length, 0); | |
83 scoped_ptr<GLchar[]> name(new GLchar[max_name_length]); | |
84 GLsizei length = 0; | |
85 GLint size = -1; | |
86 GLenum type = 0; | |
87 gl_->GetActiveAttrib( | |
88 program, index, max_name_length, &length, &size, &type, name.get()); | |
89 if (size < 0) { | |
90 return false; | |
91 } | |
92 info.name = blink::WebString::fromUTF8(name.get(), length); | |
93 info.type = type; | |
94 info.size = size; | |
95 return true; | |
96 } | |
97 | |
98 bool WebGraphicsContext3DImpl::getActiveUniform( | |
99 WebGLId program, WGC3Duint index, ActiveInfo& info) { | |
100 GLint max_name_length = -1; | |
101 gl_->GetProgramiv( | |
102 program, GL_ACTIVE_UNIFORM_MAX_LENGTH, &max_name_length); | |
103 // The caller already checked that there is some active uniform. | |
104 DCHECK_GT(max_name_length, 0); | |
105 scoped_ptr<GLchar[]> name(new GLchar[max_name_length]); | |
106 GLsizei length = 0; | |
107 GLint size = -1; | |
108 GLenum type = 0; | |
109 gl_->GetActiveUniform( | |
110 program, index, max_name_length, &length, &size, &type, name.get()); | |
111 if (size < 0) { | |
112 return false; | |
113 } | |
114 info.name = blink::WebString::fromUTF8(name.get(), length); | |
115 info.type = type; | |
116 info.size = size; | |
117 return true; | |
118 } | |
119 | |
120 blink::WebString WebGraphicsContext3DImpl::getProgramInfoLog( | |
121 WebGLId program) { | |
122 GLint logLength = 0; | |
123 gl_->GetProgramiv(program, GL_INFO_LOG_LENGTH, &logLength); | |
124 if (!logLength) | |
125 return blink::WebString(); | |
126 scoped_ptr<GLchar[]> log(new GLchar[logLength]); | |
127 if (!log) | |
128 return blink::WebString(); | |
129 GLsizei returnedLogLength = 0; | |
130 gl_->GetProgramInfoLog( | |
131 program, logLength, &returnedLogLength, log.get()); | |
132 DCHECK_EQ(logLength, returnedLogLength + 1); | |
133 blink::WebString res = | |
134 blink::WebString::fromUTF8(log.get(), returnedLogLength); | |
135 return res; | |
136 } | |
137 | |
138 blink::WebString WebGraphicsContext3DImpl::getShaderInfoLog( | |
139 WebGLId shader) { | |
140 GLint logLength = 0; | |
141 gl_->GetShaderiv(shader, GL_INFO_LOG_LENGTH, &logLength); | |
142 if (!logLength) | |
143 return blink::WebString(); | |
144 scoped_ptr<GLchar[]> log(new GLchar[logLength]); | |
145 if (!log) | |
146 return blink::WebString(); | |
147 GLsizei returnedLogLength = 0; | |
148 gl_->GetShaderInfoLog( | |
149 shader, logLength, &returnedLogLength, log.get()); | |
150 DCHECK_EQ(logLength, returnedLogLength + 1); | |
151 blink::WebString res = | |
152 blink::WebString::fromUTF8(log.get(), returnedLogLength); | |
153 return res; | |
154 } | |
155 | |
156 blink::WebString WebGraphicsContext3DImpl::getShaderSource( | |
157 WebGLId shader) { | |
158 GLint logLength = 0; | |
159 gl_->GetShaderiv(shader, GL_SHADER_SOURCE_LENGTH, &logLength); | |
160 if (!logLength) | |
161 return blink::WebString(); | |
162 scoped_ptr<GLchar[]> log(new GLchar[logLength]); | |
163 if (!log) | |
164 return blink::WebString(); | |
165 GLsizei returnedLogLength = 0; | |
166 gl_->GetShaderSource( | |
167 shader, logLength, &returnedLogLength, log.get()); | |
168 if (!returnedLogLength) | |
169 return blink::WebString(); | |
170 DCHECK_EQ(logLength, returnedLogLength + 1); | |
171 blink::WebString res = | |
172 blink::WebString::fromUTF8(log.get(), returnedLogLength); | |
173 return res; | |
174 } | |
175 | |
176 blink::WebString WebGraphicsContext3DImpl:: | |
177 getTranslatedShaderSourceANGLE(WebGLId shader) { | |
178 GLint logLength = 0; | |
179 gl_->GetShaderiv( | |
180 shader, GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE, &logLength); | |
181 if (!logLength) | |
182 return blink::WebString(); | |
183 scoped_ptr<GLchar[]> log(new GLchar[logLength]); | |
184 if (!log) | |
185 return blink::WebString(); | |
186 GLsizei returnedLogLength = 0; | |
187 gl_->GetTranslatedShaderSourceANGLE( | |
188 shader, logLength, &returnedLogLength, log.get()); | |
189 if (!returnedLogLength) | |
190 return blink::WebString(); | |
191 DCHECK_EQ(logLength, returnedLogLength + 1); | |
192 blink::WebString res = | |
193 blink::WebString::fromUTF8(log.get(), returnedLogLength); | |
194 return res; | |
195 } | |
196 | |
197 void WebGraphicsContext3DImpl::setErrorMessageCallback( | 76 void WebGraphicsContext3DImpl::setErrorMessageCallback( |
198 WebGraphicsContext3D::WebGraphicsErrorMessageCallback* cb) { | 77 WebGraphicsContext3D::WebGraphicsErrorMessageCallback* cb) { |
199 error_message_callback_ = cb; | 78 error_message_callback_ = cb; |
200 } | 79 } |
201 | 80 |
202 void WebGraphicsContext3DImpl::setContextLostCallback( | 81 void WebGraphicsContext3DImpl::setContextLostCallback( |
203 WebGraphicsContext3D::WebGraphicsContextLostCallback* cb) { | 82 WebGraphicsContext3D::WebGraphicsContextLostCallback* cb) { |
204 context_lost_callback_ = cb; | 83 context_lost_callback_ = cb; |
205 } | 84 } |
206 | 85 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 output_attribs->context_type = ::gpu::gles2::CONTEXT_TYPE_WEBGL2; | 141 output_attribs->context_type = ::gpu::gles2::CONTEXT_TYPE_WEBGL2; |
263 break; | 142 break; |
264 default: | 143 default: |
265 NOTREACHED(); | 144 NOTREACHED(); |
266 output_attribs->context_type = ::gpu::gles2::CONTEXT_TYPE_OPENGLES2; | 145 output_attribs->context_type = ::gpu::gles2::CONTEXT_TYPE_OPENGLES2; |
267 break; | 146 break; |
268 } | 147 } |
269 } | 148 } |
270 | 149 |
271 } // namespace gpu_blink | 150 } // namespace gpu_blink |
OLD | NEW |