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 shader_id) | 31 explicit ShaderInfo(GLuint service_id) |
32 : shader_id_(shader_id) { | 32 : service_id_(service_id) { |
33 } | 33 } |
34 | 34 |
35 void Update(const std::string& source) { | 35 void Update(const std::string& source) { |
36 source_ = source; | 36 source_ = source; |
37 } | 37 } |
38 | 38 |
| 39 GLuint service_id() const { |
| 40 return service_id_; |
| 41 } |
| 42 |
39 const std::string& source() { | 43 const std::string& source() { |
40 return source_; | 44 return source_; |
41 } | 45 } |
42 | 46 |
43 bool IsDeleted() { | 47 bool IsDeleted() { |
44 return shader_id_ == 0; | 48 return service_id_ == 0; |
45 } | 49 } |
46 | 50 |
47 private: | 51 private: |
48 friend class base::RefCounted<ShaderInfo>; | 52 friend class base::RefCounted<ShaderInfo>; |
49 friend class ShaderManager; | 53 friend class ShaderManager; |
50 ~ShaderInfo() { } | 54 ~ShaderInfo() { } |
51 | 55 |
52 void MarkAsDeleted() { | 56 void MarkAsDeleted() { |
53 shader_id_ = 0; | 57 service_id_ = 0; |
54 } | 58 } |
55 | 59 |
56 // The shader this ShaderInfo is tracking. | 60 // The shader this ShaderInfo is tracking. |
57 GLuint shader_id_; | 61 GLuint service_id_; |
58 | 62 |
59 // The shader source as passed to glShaderSource. | 63 // The shader source as passed to glShaderSource. |
60 std::string source_; | 64 std::string source_; |
61 }; | 65 }; |
62 | 66 |
63 ShaderManager() { | 67 ShaderManager() { |
64 } | 68 } |
65 | 69 |
66 // Creates a shader info for the given shader ID. | 70 // Creates a shader info for the given shader ID. |
67 void CreateShaderInfo(GLuint shader_id); | 71 void CreateShaderInfo(GLuint client_id, GLuint service_id); |
68 | 72 |
69 // Gets an existing shader info for the given shader ID. Returns NULL if none | 73 // Gets an existing shader info for the given shader ID. Returns NULL if none |
70 // exists. | 74 // exists. |
71 ShaderInfo* GetShaderInfo(GLuint shader_id); | 75 ShaderInfo* GetShaderInfo(GLuint client_id); |
72 | 76 |
73 // Deletes the shader info for the given shader. | 77 // Deletes the shader info for the given shader. |
74 void RemoveShaderInfo(GLuint shader_id); | 78 void RemoveShaderInfo(GLuint client_id); |
| 79 |
| 80 // Gets a client id for a given service id. |
| 81 bool GetClientId(GLuint service_id, GLuint* client_id) const; |
75 | 82 |
76 private: | 83 private: |
77 // Info for each shader by service side shader Id. | 84 // Info for each shader by service side shader Id. |
78 typedef std::map<GLuint, ShaderInfo::Ref> ShaderInfoMap; | 85 typedef std::map<GLuint, ShaderInfo::Ref> ShaderInfoMap; |
79 ShaderInfoMap shader_infos_; | 86 ShaderInfoMap shader_infos_; |
80 | 87 |
81 DISALLOW_COPY_AND_ASSIGN(ShaderManager); | 88 DISALLOW_COPY_AND_ASSIGN(ShaderManager); |
82 }; | 89 }; |
83 | 90 |
84 } // namespace gles2 | 91 } // namespace gles2 |
85 } // namespace gpu | 92 } // namespace gpu |
86 | 93 |
87 #endif // GPU_COMMAND_BUFFER_SERVICE_SHADER_MANAGER_H_ | 94 #endif // GPU_COMMAND_BUFFER_SERVICE_SHADER_MANAGER_H_ |
88 | 95 |
OLD | NEW |