| 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 #ifndef GPU_COMMAND_BUFFER_CLIENT_SHARE_GROUP_H_ | 5 #ifndef GPU_COMMAND_BUFFER_CLIENT_SHARE_GROUP_H_ |
| 6 #define GPU_COMMAND_BUFFER_CLIENT_SHARE_GROUP_H_ | 6 #define GPU_COMMAND_BUFFER_CLIENT_SHARE_GROUP_H_ |
| 7 | 7 |
| 8 #include <GLES2/gl2.h> | 8 #include <GLES2/gl2.h> |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "gles2_impl_export.h" | 10 #include "gles2_impl_export.h" |
| 11 #include "gpu/command_buffer/client/ref_counted.h" | 11 #include "gpu/command_buffer/client/ref_counted.h" |
| 12 #include "gpu/command_buffer/common/gles2_cmd_format.h" | 12 #include "gpu/command_buffer/common/gles2_cmd_format.h" |
| 13 | 13 |
| 14 namespace gpu { | 14 namespace gpu { |
| 15 namespace gles2 { | 15 namespace gles2 { |
| 16 | 16 |
| 17 class GLES2Implementation; | 17 class GLES2Implementation; |
| 18 class GLES2ImplementationTest; | 18 class GLES2ImplementationTest; |
| 19 class ProgramInfoManager; | 19 class ProgramInfoManager; |
| 20 | 20 |
| 21 typedef void (GLES2Implementation::*DeleteFn)(GLsizei n, const GLuint* ids); | 21 typedef void (GLES2Implementation::*DeleteFn)(GLsizei n, const GLuint* ids); |
| 22 typedef void (GLES2Implementation::*DeleteRangeFn)(const GLuint first_id, |
| 23 GLsizei range); |
| 22 | 24 |
| 23 class ShareGroupContextData { | 25 class ShareGroupContextData { |
| 24 public: | 26 public: |
| 25 struct IdHandlerData { | 27 struct IdHandlerData { |
| 26 IdHandlerData(); | 28 IdHandlerData(); |
| 27 ~IdHandlerData(); | 29 ~IdHandlerData(); |
| 28 | 30 |
| 29 std::vector<GLuint> freed_ids_; | 31 std::vector<GLuint> freed_ids_; |
| 30 uint32 flush_generation_; | 32 uint32 flush_generation_; |
| 31 }; | 33 }; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 54 GLES2Implementation* gl_impl, GLsizei n, const GLuint* ids, | 56 GLES2Implementation* gl_impl, GLsizei n, const GLuint* ids, |
| 55 DeleteFn delete_fn) = 0; | 57 DeleteFn delete_fn) = 0; |
| 56 | 58 |
| 57 // Marks an id as used for glBind functions. id = 0 does nothing. | 59 // Marks an id as used for glBind functions. id = 0 does nothing. |
| 58 virtual bool MarkAsUsedForBind(GLuint id) = 0; | 60 virtual bool MarkAsUsedForBind(GLuint id) = 0; |
| 59 | 61 |
| 60 // Called when a context in the share group is destructed. | 62 // Called when a context in the share group is destructed. |
| 61 virtual void FreeContext(GLES2Implementation* gl_impl) = 0; | 63 virtual void FreeContext(GLES2Implementation* gl_impl) = 0; |
| 62 }; | 64 }; |
| 63 | 65 |
| 66 class RangeIdHandlerInterface { |
| 67 public: |
| 68 RangeIdHandlerInterface() {} |
| 69 virtual ~RangeIdHandlerInterface() {} |
| 70 |
| 71 // Makes a continuous range of ids. Stores the first allocated id to |
| 72 // |first_id| or 0 if allocation failed. |
| 73 virtual void MakeIdRange(GLES2Implementation* gl_impl, |
| 74 GLsizei n, |
| 75 GLuint* first_id) = 0; |
| 76 |
| 77 // Frees a continuous |range| of ids beginning at |first_id|. |
| 78 virtual void FreeIdRange(GLES2Implementation* gl_impl, |
| 79 const GLuint first_id, |
| 80 GLsizei range, |
| 81 DeleteRangeFn delete_fn) = 0; |
| 82 |
| 83 // Called when a context in the share group is destructed. |
| 84 virtual void FreeContext(GLES2Implementation* gl_impl) = 0; |
| 85 }; |
| 86 |
| 64 // ShareGroup manages shared resources for contexts that are sharing resources. | 87 // ShareGroup manages shared resources for contexts that are sharing resources. |
| 65 class GLES2_IMPL_EXPORT ShareGroup | 88 class GLES2_IMPL_EXPORT ShareGroup |
| 66 : public gpu::RefCountedThreadSafe<ShareGroup> { | 89 : public gpu::RefCountedThreadSafe<ShareGroup> { |
| 67 public: | 90 public: |
| 68 ShareGroup(bool bind_generates_resource); | 91 ShareGroup(bool bind_generates_resource); |
| 69 | 92 |
| 70 bool bind_generates_resource() const { | 93 bool bind_generates_resource() const { |
| 71 return bind_generates_resource_; | 94 return bind_generates_resource_; |
| 72 } | 95 } |
| 73 | 96 |
| 74 IdHandlerInterface* GetIdHandler(int namespace_id) const { | 97 IdHandlerInterface* GetIdHandler(int namespace_id) const { |
| 75 return id_handlers_[namespace_id].get(); | 98 return id_handlers_[namespace_id].get(); |
| 76 } | 99 } |
| 77 | 100 |
| 101 RangeIdHandlerInterface* GetRangeIdHandler(int range_namespace_id) const { |
| 102 return range_id_handlers_[range_namespace_id].get(); |
| 103 } |
| 104 |
| 78 ProgramInfoManager* program_info_manager() { | 105 ProgramInfoManager* program_info_manager() { |
| 79 return program_info_manager_.get(); | 106 return program_info_manager_.get(); |
| 80 } | 107 } |
| 81 | 108 |
| 82 void FreeContext(GLES2Implementation* gl_impl) { | 109 void FreeContext(GLES2Implementation* gl_impl) { |
| 83 for (int i = 0; i < id_namespaces::kNumIdNamespaces; ++i) { | 110 for (int i = 0; i < id_namespaces::kNumIdNamespaces; ++i) { |
| 84 id_handlers_[i]->FreeContext(gl_impl); | 111 id_handlers_[i]->FreeContext(gl_impl); |
| 85 } | 112 } |
| 113 for (auto& range_id_handler : range_id_handlers_) { |
| 114 range_id_handler->FreeContext(gl_impl); |
| 115 } |
| 86 } | 116 } |
| 87 | 117 |
| 88 private: | 118 private: |
| 89 friend class gpu::RefCountedThreadSafe<ShareGroup>; | 119 friend class gpu::RefCountedThreadSafe<ShareGroup>; |
| 90 friend class gpu::gles2::GLES2ImplementationTest; | 120 friend class gpu::gles2::GLES2ImplementationTest; |
| 91 ~ShareGroup(); | 121 ~ShareGroup(); |
| 92 | 122 |
| 93 // Install a new program info manager. Used for testing only; | 123 // Install a new program info manager. Used for testing only; |
| 94 void set_program_info_manager(ProgramInfoManager* manager); | 124 void set_program_info_manager(ProgramInfoManager* manager); |
| 95 | 125 |
| 96 scoped_ptr<IdHandlerInterface> id_handlers_[id_namespaces::kNumIdNamespaces]; | 126 scoped_ptr<IdHandlerInterface> id_handlers_[id_namespaces::kNumIdNamespaces]; |
| 127 scoped_ptr<RangeIdHandlerInterface> |
| 128 range_id_handlers_[id_namespaces::kNumRangeIdNamespaces]; |
| 97 scoped_ptr<ProgramInfoManager> program_info_manager_; | 129 scoped_ptr<ProgramInfoManager> program_info_manager_; |
| 98 | 130 |
| 99 bool bind_generates_resource_; | 131 bool bind_generates_resource_; |
| 100 | 132 |
| 101 DISALLOW_COPY_AND_ASSIGN(ShareGroup); | 133 DISALLOW_COPY_AND_ASSIGN(ShareGroup); |
| 102 }; | 134 }; |
| 103 | 135 |
| 104 } // namespace gles2 | 136 } // namespace gles2 |
| 105 } // namespace gpu | 137 } // namespace gpu |
| 106 | 138 |
| 107 #endif // GPU_COMMAND_BUFFER_CLIENT_SHARE_GROUP_H_ | 139 #endif // GPU_COMMAND_BUFFER_CLIENT_SHARE_GROUP_H_ |
| OLD | NEW |