| 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 <stack> | 5 #include <stack> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "gpu/command_buffer/client/share_group.h" | 8 #include "gpu/command_buffer/client/share_group.h" |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 | 24 |
| 25 // The standard id handler. | 25 // The standard id handler. |
| 26 class IdHandler : public IdHandlerInterface { | 26 class IdHandler : public IdHandlerInterface { |
| 27 public: | 27 public: |
| 28 IdHandler() { } | 28 IdHandler() { } |
| 29 virtual ~IdHandler() { } | 29 virtual ~IdHandler() { } |
| 30 | 30 |
| 31 // Overridden from IdHandlerInterface. | 31 // Overridden from IdHandlerInterface. |
| 32 virtual void MakeIds( | 32 virtual void MakeIds( |
| 33 GLES2Implementation* /* gl_impl */, | 33 GLES2Implementation* /* gl_impl */, |
| 34 GLuint id_offset, GLsizei n, GLuint* ids) OVERRIDE { | 34 GLuint id_offset, GLsizei n, GLuint* ids) override { |
| 35 base::AutoLock auto_lock(lock_); | 35 base::AutoLock auto_lock(lock_); |
| 36 if (id_offset == 0) { | 36 if (id_offset == 0) { |
| 37 for (GLsizei ii = 0; ii < n; ++ii) { | 37 for (GLsizei ii = 0; ii < n; ++ii) { |
| 38 ids[ii] = id_allocator_.AllocateID(); | 38 ids[ii] = id_allocator_.AllocateID(); |
| 39 } | 39 } |
| 40 } else { | 40 } else { |
| 41 for (GLsizei ii = 0; ii < n; ++ii) { | 41 for (GLsizei ii = 0; ii < n; ++ii) { |
| 42 ids[ii] = id_allocator_.AllocateIDAtOrAbove(id_offset); | 42 ids[ii] = id_allocator_.AllocateIDAtOrAbove(id_offset); |
| 43 id_offset = ids[ii] + 1; | 43 id_offset = ids[ii] + 1; |
| 44 } | 44 } |
| 45 } | 45 } |
| 46 } | 46 } |
| 47 | 47 |
| 48 // Overridden from IdHandlerInterface. | 48 // Overridden from IdHandlerInterface. |
| 49 virtual bool FreeIds( | 49 virtual bool FreeIds( |
| 50 GLES2Implementation* gl_impl, | 50 GLES2Implementation* gl_impl, |
| 51 GLsizei n, const GLuint* ids, DeleteFn delete_fn) OVERRIDE { | 51 GLsizei n, const GLuint* ids, DeleteFn delete_fn) override { |
| 52 base::AutoLock auto_lock(lock_); | 52 base::AutoLock auto_lock(lock_); |
| 53 | 53 |
| 54 for (GLsizei ii = 0; ii < n; ++ii) { | 54 for (GLsizei ii = 0; ii < n; ++ii) { |
| 55 id_allocator_.FreeID(ids[ii]); | 55 id_allocator_.FreeID(ids[ii]); |
| 56 } | 56 } |
| 57 | 57 |
| 58 (gl_impl->*delete_fn)(n, ids); | 58 (gl_impl->*delete_fn)(n, ids); |
| 59 // We need to ensure that the delete call is evaluated on the service side | 59 // We need to ensure that the delete call is evaluated on the service side |
| 60 // before any other contexts issue commands using these client ids. | 60 // before any other contexts issue commands using these client ids. |
| 61 // TODO(vmiura): Can remove this by virtualizing internal ids, however | 61 // TODO(vmiura): Can remove this by virtualizing internal ids, however |
| 62 // this code only affects PPAPI for now. | 62 // this code only affects PPAPI for now. |
| 63 gl_impl->helper()->CommandBufferHelper::Flush(); | 63 gl_impl->helper()->CommandBufferHelper::Flush(); |
| 64 return true; | 64 return true; |
| 65 } | 65 } |
| 66 | 66 |
| 67 // Overridden from IdHandlerInterface. | 67 // Overridden from IdHandlerInterface. |
| 68 virtual bool MarkAsUsedForBind(GLuint id) OVERRIDE { | 68 virtual bool MarkAsUsedForBind(GLuint id) override { |
| 69 if (id == 0) | 69 if (id == 0) |
| 70 return true; | 70 return true; |
| 71 base::AutoLock auto_lock(lock_); | 71 base::AutoLock auto_lock(lock_); |
| 72 return id_allocator_.MarkAsUsed(id); | 72 return id_allocator_.MarkAsUsed(id); |
| 73 } | 73 } |
| 74 | 74 |
| 75 virtual void FreeContext(GLES2Implementation* gl_impl) OVERRIDE {} | 75 virtual void FreeContext(GLES2Implementation* gl_impl) override {} |
| 76 | 76 |
| 77 private: | 77 private: |
| 78 base::Lock lock_; | 78 base::Lock lock_; |
| 79 IdAllocator id_allocator_; | 79 IdAllocator id_allocator_; |
| 80 }; | 80 }; |
| 81 | 81 |
| 82 // An id handler that requires Gen before Bind. | 82 // An id handler that requires Gen before Bind. |
| 83 class StrictIdHandler : public IdHandlerInterface { | 83 class StrictIdHandler : public IdHandlerInterface { |
| 84 public: | 84 public: |
| 85 explicit StrictIdHandler(int id_namespace) : id_namespace_(id_namespace) {} | 85 explicit StrictIdHandler(int id_namespace) : id_namespace_(id_namespace) {} |
| 86 virtual ~StrictIdHandler() {} | 86 virtual ~StrictIdHandler() {} |
| 87 | 87 |
| 88 // Overridden from IdHandler. | 88 // Overridden from IdHandler. |
| 89 virtual void MakeIds(GLES2Implementation* gl_impl, | 89 virtual void MakeIds(GLES2Implementation* gl_impl, |
| 90 GLuint /* id_offset */, | 90 GLuint /* id_offset */, |
| 91 GLsizei n, | 91 GLsizei n, |
| 92 GLuint* ids) OVERRIDE { | 92 GLuint* ids) override { |
| 93 base::AutoLock auto_lock(lock_); | 93 base::AutoLock auto_lock(lock_); |
| 94 | 94 |
| 95 // Collect pending FreeIds from other flush_generation. | 95 // Collect pending FreeIds from other flush_generation. |
| 96 CollectPendingFreeIds(gl_impl); | 96 CollectPendingFreeIds(gl_impl); |
| 97 | 97 |
| 98 for (GLsizei ii = 0; ii < n; ++ii) { | 98 for (GLsizei ii = 0; ii < n; ++ii) { |
| 99 if (!free_ids_.empty()) { | 99 if (!free_ids_.empty()) { |
| 100 // Allocate a previously freed Id. | 100 // Allocate a previously freed Id. |
| 101 ids[ii] = free_ids_.top(); | 101 ids[ii] = free_ids_.top(); |
| 102 free_ids_.pop(); | 102 free_ids_.pop(); |
| 103 | 103 |
| 104 // Record kIdInUse state. | 104 // Record kIdInUse state. |
| 105 DCHECK(id_states_[ids[ii] - 1] == kIdFree); | 105 DCHECK(id_states_[ids[ii] - 1] == kIdFree); |
| 106 id_states_[ids[ii] - 1] = kIdInUse; | 106 id_states_[ids[ii] - 1] = kIdInUse; |
| 107 } else { | 107 } else { |
| 108 // Allocate a new Id. | 108 // Allocate a new Id. |
| 109 id_states_.push_back(kIdInUse); | 109 id_states_.push_back(kIdInUse); |
| 110 ids[ii] = id_states_.size(); | 110 ids[ii] = id_states_.size(); |
| 111 } | 111 } |
| 112 } | 112 } |
| 113 } | 113 } |
| 114 | 114 |
| 115 // Overridden from IdHandler. | 115 // Overridden from IdHandler. |
| 116 virtual bool FreeIds(GLES2Implementation* gl_impl, | 116 virtual bool FreeIds(GLES2Implementation* gl_impl, |
| 117 GLsizei n, | 117 GLsizei n, |
| 118 const GLuint* ids, | 118 const GLuint* ids, |
| 119 DeleteFn delete_fn) OVERRIDE { | 119 DeleteFn delete_fn) override { |
| 120 | 120 |
| 121 // Delete stub must run before CollectPendingFreeIds. | 121 // Delete stub must run before CollectPendingFreeIds. |
| 122 (gl_impl->*delete_fn)(n, ids); | 122 (gl_impl->*delete_fn)(n, ids); |
| 123 | 123 |
| 124 { | 124 { |
| 125 base::AutoLock auto_lock(lock_); | 125 base::AutoLock auto_lock(lock_); |
| 126 | 126 |
| 127 // Collect pending FreeIds from other flush_generation. | 127 // Collect pending FreeIds from other flush_generation. |
| 128 CollectPendingFreeIds(gl_impl); | 128 CollectPendingFreeIds(gl_impl); |
| 129 | 129 |
| 130 // Save Ids to free in a later flush_generation. | 130 // Save Ids to free in a later flush_generation. |
| 131 ShareGroupContextData::IdHandlerData* ctxt_data = | 131 ShareGroupContextData::IdHandlerData* ctxt_data = |
| 132 gl_impl->share_group_context_data()->id_handler_data(id_namespace_); | 132 gl_impl->share_group_context_data()->id_handler_data(id_namespace_); |
| 133 | 133 |
| 134 for (GLsizei ii = 0; ii < n; ++ii) { | 134 for (GLsizei ii = 0; ii < n; ++ii) { |
| 135 GLuint id = ids[ii]; | 135 GLuint id = ids[ii]; |
| 136 if (id != 0) { | 136 if (id != 0) { |
| 137 // Save freed Id for later. | 137 // Save freed Id for later. |
| 138 DCHECK(id_states_[id - 1] == kIdInUse); | 138 DCHECK(id_states_[id - 1] == kIdInUse); |
| 139 id_states_[id - 1] = kIdPendingFree; | 139 id_states_[id - 1] = kIdPendingFree; |
| 140 ctxt_data->freed_ids_.push_back(id); | 140 ctxt_data->freed_ids_.push_back(id); |
| 141 } | 141 } |
| 142 } | 142 } |
| 143 } | 143 } |
| 144 | 144 |
| 145 return true; | 145 return true; |
| 146 } | 146 } |
| 147 | 147 |
| 148 // Overridden from IdHandler. | 148 // Overridden from IdHandler. |
| 149 virtual bool MarkAsUsedForBind(GLuint id) OVERRIDE { | 149 virtual bool MarkAsUsedForBind(GLuint id) override { |
| 150 #ifndef NDEBUG | 150 #ifndef NDEBUG |
| 151 if (id != 0) { | 151 if (id != 0) { |
| 152 base::AutoLock auto_lock(lock_); | 152 base::AutoLock auto_lock(lock_); |
| 153 DCHECK(id_states_[id - 1] == kIdInUse); | 153 DCHECK(id_states_[id - 1] == kIdInUse); |
| 154 } | 154 } |
| 155 #endif | 155 #endif |
| 156 return true; | 156 return true; |
| 157 } | 157 } |
| 158 | 158 |
| 159 // Overridden from IdHandlerInterface. | 159 // Overridden from IdHandlerInterface. |
| 160 virtual void FreeContext(GLES2Implementation* gl_impl) OVERRIDE { | 160 virtual void FreeContext(GLES2Implementation* gl_impl) override { |
| 161 base::AutoLock auto_lock(lock_); | 161 base::AutoLock auto_lock(lock_); |
| 162 CollectPendingFreeIds(gl_impl); | 162 CollectPendingFreeIds(gl_impl); |
| 163 } | 163 } |
| 164 | 164 |
| 165 private: | 165 private: |
| 166 enum IdState { kIdFree, kIdPendingFree, kIdInUse }; | 166 enum IdState { kIdFree, kIdPendingFree, kIdInUse }; |
| 167 | 167 |
| 168 void CollectPendingFreeIds(GLES2Implementation* gl_impl) { | 168 void CollectPendingFreeIds(GLES2Implementation* gl_impl) { |
| 169 uint32 flush_generation = gl_impl->helper()->flush_generation(); | 169 uint32 flush_generation = gl_impl->helper()->flush_generation(); |
| 170 ShareGroupContextData::IdHandlerData* ctxt_data = | 170 ShareGroupContextData::IdHandlerData* ctxt_data = |
| (...skipping 20 matching lines...) Expand all Loading... |
| 191 | 191 |
| 192 // An id handler for ids that are never reused. | 192 // An id handler for ids that are never reused. |
| 193 class NonReusedIdHandler : public IdHandlerInterface { | 193 class NonReusedIdHandler : public IdHandlerInterface { |
| 194 public: | 194 public: |
| 195 NonReusedIdHandler() : last_id_(0) {} | 195 NonReusedIdHandler() : last_id_(0) {} |
| 196 virtual ~NonReusedIdHandler() {} | 196 virtual ~NonReusedIdHandler() {} |
| 197 | 197 |
| 198 // Overridden from IdHandlerInterface. | 198 // Overridden from IdHandlerInterface. |
| 199 virtual void MakeIds( | 199 virtual void MakeIds( |
| 200 GLES2Implementation* /* gl_impl */, | 200 GLES2Implementation* /* gl_impl */, |
| 201 GLuint id_offset, GLsizei n, GLuint* ids) OVERRIDE { | 201 GLuint id_offset, GLsizei n, GLuint* ids) override { |
| 202 base::AutoLock auto_lock(lock_); | 202 base::AutoLock auto_lock(lock_); |
| 203 for (GLsizei ii = 0; ii < n; ++ii) { | 203 for (GLsizei ii = 0; ii < n; ++ii) { |
| 204 ids[ii] = ++last_id_ + id_offset; | 204 ids[ii] = ++last_id_ + id_offset; |
| 205 } | 205 } |
| 206 } | 206 } |
| 207 | 207 |
| 208 // Overridden from IdHandlerInterface. | 208 // Overridden from IdHandlerInterface. |
| 209 virtual bool FreeIds( | 209 virtual bool FreeIds( |
| 210 GLES2Implementation* gl_impl, | 210 GLES2Implementation* gl_impl, |
| 211 GLsizei n, const GLuint* ids, DeleteFn delete_fn) OVERRIDE { | 211 GLsizei n, const GLuint* ids, DeleteFn delete_fn) override { |
| 212 // Ids are never freed. | 212 // Ids are never freed. |
| 213 (gl_impl->*delete_fn)(n, ids); | 213 (gl_impl->*delete_fn)(n, ids); |
| 214 return true; | 214 return true; |
| 215 } | 215 } |
| 216 | 216 |
| 217 // Overridden from IdHandlerInterface. | 217 // Overridden from IdHandlerInterface. |
| 218 virtual bool MarkAsUsedForBind(GLuint /* id */) OVERRIDE { | 218 virtual bool MarkAsUsedForBind(GLuint /* id */) override { |
| 219 // This is only used for Shaders and Programs which have no bind. | 219 // This is only used for Shaders and Programs which have no bind. |
| 220 return false; | 220 return false; |
| 221 } | 221 } |
| 222 | 222 |
| 223 virtual void FreeContext(GLES2Implementation* gl_impl) OVERRIDE {} | 223 virtual void FreeContext(GLES2Implementation* gl_impl) override {} |
| 224 | 224 |
| 225 private: | 225 private: |
| 226 base::Lock lock_; | 226 base::Lock lock_; |
| 227 GLuint last_id_; | 227 GLuint last_id_; |
| 228 }; | 228 }; |
| 229 | 229 |
| 230 ShareGroup::ShareGroup(bool bind_generates_resource) | 230 ShareGroup::ShareGroup(bool bind_generates_resource) |
| 231 : bind_generates_resource_(bind_generates_resource) { | 231 : bind_generates_resource_(bind_generates_resource) { |
| 232 if (bind_generates_resource) { | 232 if (bind_generates_resource) { |
| 233 for (int i = 0; i < id_namespaces::kNumIdNamespaces; ++i) { | 233 for (int i = 0; i < id_namespaces::kNumIdNamespaces; ++i) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 250 } | 250 } |
| 251 | 251 |
| 252 void ShareGroup::set_program_info_manager(ProgramInfoManager* manager) { | 252 void ShareGroup::set_program_info_manager(ProgramInfoManager* manager) { |
| 253 program_info_manager_.reset(manager); | 253 program_info_manager_.reset(manager); |
| 254 } | 254 } |
| 255 | 255 |
| 256 ShareGroup::~ShareGroup() {} | 256 ShareGroup::~ShareGroup() {} |
| 257 | 257 |
| 258 } // namespace gles2 | 258 } // namespace gles2 |
| 259 } // namespace gpu | 259 } // namespace gpu |
| OLD | NEW |