| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #ifndef GPU_COMMAND_BUFFER_SERVICE_SHADER_MANAGER_H_ | 5 #ifndef GPU_COMMAND_BUFFER_SERVICE_SHADER_MANAGER_H_ |
| 6 #define GPU_COMMAND_BUFFER_SERVICE_SHADER_MANAGER_H_ | 6 #define GPU_COMMAND_BUFFER_SERVICE_SHADER_MANAGER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 class ShaderManager { | 21 class ShaderManager { |
| 22 public: | 22 public: |
| 23 // This is used to keep the source code for a shader. This is because in order | 23 // This is used to keep the source code for a shader. This is because in order |
| 24 // to emluate GLES2 the shaders will have to be re-written before passed to | 24 // to emluate GLES2 the shaders will have to be re-written before passed to |
| 25 // the underlying OpenGL. But, when the user calls glGetShaderSource they | 25 // the underlying OpenGL. But, when the user calls glGetShaderSource they |
| 26 // should get the source they passed in, not the re-written source. | 26 // should get the source they passed in, not the re-written source. |
| 27 class ShaderInfo : public base::RefCounted<ShaderInfo> { | 27 class ShaderInfo : public base::RefCounted<ShaderInfo> { |
| 28 public: | 28 public: |
| 29 typedef scoped_refptr<ShaderInfo> Ref; | 29 typedef scoped_refptr<ShaderInfo> Ref; |
| 30 | 30 |
| 31 explicit ShaderInfo(GLuint service_id) | 31 explicit ShaderInfo(GLuint service_id, GLenum shader_type) |
| 32 : service_id_(service_id) { | 32 : service_id_(service_id), |
| 33 shader_type_(shader_type) { |
| 33 } | 34 } |
| 34 | 35 |
| 35 void Update(const std::string& source) { | 36 void Update(const std::string& source) { |
| 36 source_ = source; | 37 source_ = source; |
| 37 } | 38 } |
| 38 | 39 |
| 39 GLuint service_id() const { | 40 GLuint service_id() const { |
| 40 return service_id_; | 41 return service_id_; |
| 41 } | 42 } |
| 42 | 43 |
| 43 const std::string& source() { | 44 GLenum shader_type() const { |
| 45 return shader_type_; |
| 46 } |
| 47 |
| 48 const std::string& source() const { |
| 44 return source_; | 49 return source_; |
| 45 } | 50 } |
| 46 | 51 |
| 47 bool IsDeleted() { | 52 bool IsDeleted() const { |
| 48 return service_id_ == 0; | 53 return service_id_ == 0; |
| 49 } | 54 } |
| 50 | 55 |
| 51 private: | 56 private: |
| 52 friend class base::RefCounted<ShaderInfo>; | 57 friend class base::RefCounted<ShaderInfo>; |
| 53 friend class ShaderManager; | 58 friend class ShaderManager; |
| 54 ~ShaderInfo() { } | 59 ~ShaderInfo() { } |
| 55 | 60 |
| 56 void MarkAsDeleted() { | 61 void MarkAsDeleted() { |
| 57 service_id_ = 0; | 62 service_id_ = 0; |
| 58 } | 63 } |
| 59 | 64 |
| 60 // The shader this ShaderInfo is tracking. | 65 // The shader this ShaderInfo is tracking. |
| 61 GLuint service_id_; | 66 GLuint service_id_; |
| 67 // Type of shader - GL_VERTEX_SHADER or GL_FRAGMENT_SHADER. |
| 68 GLenum shader_type_; |
| 62 | 69 |
| 63 // The shader source as passed to glShaderSource. | 70 // The shader source as passed to glShaderSource. |
| 64 std::string source_; | 71 std::string source_; |
| 65 }; | 72 }; |
| 66 | 73 |
| 67 ShaderManager() { | 74 ShaderManager() { |
| 68 } | 75 } |
| 69 | 76 |
| 70 // Creates a shader info for the given shader ID. | 77 // Creates a shader info for the given shader ID. |
| 71 void CreateShaderInfo(GLuint client_id, GLuint service_id); | 78 void CreateShaderInfo(GLuint client_id, |
| 79 GLuint service_id, |
| 80 GLenum shader_type); |
| 72 | 81 |
| 73 // Gets an existing shader info for the given shader ID. Returns NULL if none | 82 // Gets an existing shader info for the given shader ID. Returns NULL if none |
| 74 // exists. | 83 // exists. |
| 75 ShaderInfo* GetShaderInfo(GLuint client_id); | 84 ShaderInfo* GetShaderInfo(GLuint client_id); |
| 76 | 85 |
| 77 // Deletes the shader info for the given shader. | 86 // Deletes the shader info for the given shader. |
| 78 void RemoveShaderInfo(GLuint client_id); | 87 void RemoveShaderInfo(GLuint client_id); |
| 79 | 88 |
| 80 // Gets a client id for a given service id. | 89 // Gets a client id for a given service id. |
| 81 bool GetClientId(GLuint service_id, GLuint* client_id) const; | 90 bool GetClientId(GLuint service_id, GLuint* client_id) const; |
| 82 | 91 |
| 83 private: | 92 private: |
| 84 // Info for each shader by service side shader Id. | 93 // Info for each shader by service side shader Id. |
| 85 typedef std::map<GLuint, ShaderInfo::Ref> ShaderInfoMap; | 94 typedef std::map<GLuint, ShaderInfo::Ref> ShaderInfoMap; |
| 86 ShaderInfoMap shader_infos_; | 95 ShaderInfoMap shader_infos_; |
| 87 | 96 |
| 88 DISALLOW_COPY_AND_ASSIGN(ShaderManager); | 97 DISALLOW_COPY_AND_ASSIGN(ShaderManager); |
| 89 }; | 98 }; |
| 90 | 99 |
| 91 } // namespace gles2 | 100 } // namespace gles2 |
| 92 } // namespace gpu | 101 } // namespace gpu |
| 93 | 102 |
| 94 #endif // GPU_COMMAND_BUFFER_SERVICE_SHADER_MANAGER_H_ | 103 #endif // GPU_COMMAND_BUFFER_SERVICE_SHADER_MANAGER_H_ |
| 95 | 104 |
| OLD | NEW |