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/command_buffer/service/shader_manager.h" | 5 #include "gpu/command_buffer/service/shader_manager.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 source_for_driver = translated_source_.c_str(); | 54 source_for_driver = translated_source_.c_str(); |
55 } | 55 } |
56 | 56 |
57 glShaderSource(service_id_, 1, &source_for_driver, NULL); | 57 glShaderSource(service_id_, 1, &source_for_driver, NULL); |
58 glCompileShader(service_id_); | 58 glCompileShader(service_id_); |
59 if (type == kANGLE) { | 59 if (type == kANGLE) { |
60 GLint max_len = 0; | 60 GLint max_len = 0; |
61 glGetShaderiv(service_id_, | 61 glGetShaderiv(service_id_, |
62 GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE, | 62 GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE, |
63 &max_len); | 63 &max_len); |
64 scoped_ptr<char[]> buffer(new char[max_len]); | 64 translated_source_.resize(max_len); |
65 GLint len = 0; | 65 GLint len = 0; |
66 glGetTranslatedShaderSourceANGLE( | 66 glGetTranslatedShaderSourceANGLE( |
67 service_id_, max_len, &len, buffer.get()); | 67 service_id_, translated_source_.size(), |
| 68 &len, &translated_source_.at(0)); |
68 DCHECK(max_len == 0 || len < max_len); | 69 DCHECK(max_len == 0 || len < max_len); |
69 DCHECK(len == 0 || buffer[len] == '\0'); | 70 DCHECK(len == 0 || translated_source_[len] == '\0'); |
70 translated_source_ = std::string(buffer.get(), len); | 71 translated_source_.resize(len); |
71 } | 72 } |
72 | 73 |
73 GLint status = GL_FALSE; | 74 GLint status = GL_FALSE; |
74 glGetShaderiv(service_id_, GL_COMPILE_STATUS, &status); | 75 glGetShaderiv(service_id_, GL_COMPILE_STATUS, &status); |
75 if (status != GL_TRUE) { | 76 if (status != GL_TRUE) { |
76 // We cannot reach here if we are using the shader translator. | 77 // We cannot reach here if we are using the shader translator. |
77 // All invalid shaders must be rejected by the translator. | 78 // All invalid shaders must be rejected by the translator. |
78 // All translated shaders must compile. | 79 // All translated shaders must compile. |
79 GLint max_len = 0; | 80 GLint max_len = 0; |
80 glGetShaderiv(service_id_, GL_INFO_LOG_LENGTH, &max_len); | 81 glGetShaderiv(service_id_, GL_INFO_LOG_LENGTH, &max_len); |
81 scoped_ptr<char[]> buffer(new char[max_len]); | 82 log_info_.resize(max_len); |
82 GLint len = 0; | 83 GLint len = 0; |
83 glGetShaderInfoLog(service_id_, max_len, &len, buffer.get()); | 84 glGetShaderInfoLog(service_id_, log_info_.size(), &len, &log_info_.at(0)); |
84 DCHECK(max_len == 0 || len < max_len); | 85 DCHECK(max_len == 0 || len < max_len); |
85 DCHECK(len == 0 || buffer[len] == '\0'); | 86 DCHECK(len == 0 || log_info_[len] == '\0'); |
86 valid_ = false; | 87 valid_ = false; |
87 log_info_ = std::string(buffer.get(), len); | 88 log_info_.resize(len); |
88 LOG_IF(ERROR, translator) | 89 LOG_IF(ERROR, translator) |
89 << "Shader translator allowed/produced an invalid shader " | 90 << "Shader translator allowed/produced an invalid shader " |
90 << "unless the driver is buggy:" | 91 << "unless the driver is buggy:" |
91 << "\n--original-shader--\n" << source_ | 92 << "\n--original-shader--\n" << source_ |
92 << "\n--translated-shader--\n" << source_for_driver | 93 << "\n--translated-shader--\n" << source_for_driver |
93 << "\n--info-log--\n" << log_info_; | 94 << "\n--info-log--\n" << log_info_; |
94 } | 95 } |
95 } | 96 } |
96 | 97 |
97 void Shader::IncUseCount() { | 98 void Shader::IncUseCount() { |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 DCHECK(shader); | 235 DCHECK(shader); |
235 DCHECK(IsOwned(shader)); | 236 DCHECK(IsOwned(shader)); |
236 shader->DecUseCount(); | 237 shader->DecUseCount(); |
237 RemoveShader(shader); | 238 RemoveShader(shader); |
238 } | 239 } |
239 | 240 |
240 } // namespace gles2 | 241 } // namespace gles2 |
241 } // namespace gpu | 242 } // namespace gpu |
242 | 243 |
243 | 244 |
OLD | NEW |