Chromium Code Reviews| 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 "../client/atomicops.h" | 5 #include "../client/atomicops.h" |
|
tfarina
2012/09/08 02:41:46
ouch, this should use full/absolute path, no??
| |
| 6 #include "../client/share_group.h" | 6 #include "../client/share_group.h" |
| 7 #include "../client/gles2_implementation.h" | 7 #include "../client/gles2_implementation.h" |
| 8 #include "../client/program_info_manager.h" | 8 #include "../client/program_info_manager.h" |
| 9 #include "../common/id_allocator.h" | 9 #include "../common/id_allocator.h" |
| 10 #include "../common/logging.h" | 10 #include "../common/logging.h" |
| 11 | 11 |
| 12 namespace gpu { | 12 namespace gpu { |
| 13 namespace gles2 { | 13 namespace gles2 { |
| 14 | 14 |
| 15 COMPILE_ASSERT(gpu::kInvalidResource == 0, | 15 COMPILE_ASSERT(gpu::kInvalidResource == 0, |
| 16 INVALID_RESOURCE_NOT_0_AS_GL_EXPECTS); | 16 INVALID_RESOURCE_NOT_0_AS_GL_EXPECTS); |
| 17 | 17 |
| 18 // The standard id handler. | 18 // The standard id handler. |
| 19 class IdHandler : public IdHandlerInterface { | 19 class IdHandler : public IdHandlerInterface { |
| 20 public: | 20 public: |
| 21 IdHandler() { } | 21 IdHandler() { } |
| 22 virtual ~IdHandler() { } | 22 virtual ~IdHandler() { } |
| 23 | 23 |
| 24 // Overridden from IdHandlerInterface. | 24 // Overridden from IdHandlerInterface. |
| 25 virtual void Destroy(GLES2Implementation* /* gl_impl */) { | 25 virtual void Destroy(GLES2Implementation* /* gl_impl */) OVERRIDE { |
| 26 } | 26 } |
| 27 | 27 |
| 28 // Overridden from IdHandlerInterface. | 28 // Overridden from IdHandlerInterface. |
| 29 virtual void MakeIds( | 29 virtual void MakeIds( |
| 30 GLES2Implementation* /* gl_impl */, | 30 GLES2Implementation* /* gl_impl */, |
| 31 GLuint id_offset, GLsizei n, GLuint* ids) { | 31 GLuint id_offset, GLsizei n, GLuint* ids) OVERRIDE { |
| 32 if (id_offset == 0) { | 32 if (id_offset == 0) { |
| 33 for (GLsizei ii = 0; ii < n; ++ii) { | 33 for (GLsizei ii = 0; ii < n; ++ii) { |
| 34 ids[ii] = id_allocator_.AllocateID(); | 34 ids[ii] = id_allocator_.AllocateID(); |
| 35 } | 35 } |
| 36 } else { | 36 } else { |
| 37 for (GLsizei ii = 0; ii < n; ++ii) { | 37 for (GLsizei ii = 0; ii < n; ++ii) { |
| 38 ids[ii] = id_allocator_.AllocateIDAtOrAbove(id_offset); | 38 ids[ii] = id_allocator_.AllocateIDAtOrAbove(id_offset); |
| 39 id_offset = ids[ii] + 1; | 39 id_offset = ids[ii] + 1; |
| 40 } | 40 } |
| 41 } | 41 } |
| 42 } | 42 } |
| 43 | 43 |
| 44 // Overridden from IdHandlerInterface. | 44 // Overridden from IdHandlerInterface. |
| 45 virtual bool FreeIds( | 45 virtual bool FreeIds( |
| 46 GLES2Implementation* gl_impl, | 46 GLES2Implementation* gl_impl, |
| 47 GLsizei n, const GLuint* ids, DeleteFn delete_fn) { | 47 GLsizei n, const GLuint* ids, DeleteFn delete_fn) OVERRIDE { |
| 48 for (GLsizei ii = 0; ii < n; ++ii) { | 48 for (GLsizei ii = 0; ii < n; ++ii) { |
| 49 id_allocator_.FreeID(ids[ii]); | 49 id_allocator_.FreeID(ids[ii]); |
| 50 } | 50 } |
| 51 (gl_impl->*delete_fn)(n, ids); | 51 (gl_impl->*delete_fn)(n, ids); |
| 52 // We need to ensure that the delete call is evaluated on the service side | 52 // We need to ensure that the delete call is evaluated on the service side |
| 53 // before any other contexts issue commands using these client ids. | 53 // before any other contexts issue commands using these client ids. |
| 54 gl_impl->helper()->CommandBufferHelper::Flush(); | 54 gl_impl->helper()->CommandBufferHelper::Flush(); |
| 55 return true; | 55 return true; |
| 56 } | 56 } |
| 57 | 57 |
| 58 // Overridden from IdHandlerInterface. | 58 // Overridden from IdHandlerInterface. |
| 59 virtual bool MarkAsUsedForBind(GLuint id) { | 59 virtual bool MarkAsUsedForBind(GLuint id) OVERRIDE { |
| 60 return id == 0 ? true : id_allocator_.MarkAsUsed(id); | 60 return id == 0 ? true : id_allocator_.MarkAsUsed(id); |
| 61 } | 61 } |
| 62 protected: | 62 protected: |
| 63 IdAllocator id_allocator_; | 63 IdAllocator id_allocator_; |
| 64 }; | 64 }; |
| 65 | 65 |
| 66 // An id handler that require Gen before Bind. | 66 // An id handler that require Gen before Bind. |
| 67 class StrictIdHandler : public IdHandler { | 67 class StrictIdHandler : public IdHandler { |
| 68 public: | 68 public: |
| 69 StrictIdHandler() { } | 69 StrictIdHandler() { } |
| 70 virtual ~StrictIdHandler() { } | 70 virtual ~StrictIdHandler() { } |
| 71 | 71 |
| 72 // Overridden from IdHandler. | 72 // Overridden from IdHandler. |
| 73 virtual bool MarkAsUsedForBind(GLuint id) { | 73 virtual bool MarkAsUsedForBind(GLuint id) { |
| 74 GPU_DCHECK(id == 0 || id_allocator_.InUse(id)); | 74 GPU_DCHECK(id == 0 || id_allocator_.InUse(id)); |
| 75 return IdHandler::MarkAsUsedForBind(id); | 75 return IdHandler::MarkAsUsedForBind(id); |
| 76 } | 76 } |
| 77 }; | 77 }; |
| 78 | 78 |
| 79 // An id handler for ids that are never reused. | 79 // An id handler for ids that are never reused. |
| 80 class NonReusedIdHandler : public IdHandlerInterface { | 80 class NonReusedIdHandler : public IdHandlerInterface { |
| 81 public: | 81 public: |
| 82 NonReusedIdHandler() : last_id_(0) { } | 82 NonReusedIdHandler() : last_id_(0) {} |
| 83 virtual ~NonReusedIdHandler() { } | 83 virtual ~NonReusedIdHandler() {} |
| 84 | 84 |
| 85 // Overridden from IdHandlerInterface. | 85 // Overridden from IdHandlerInterface. |
| 86 virtual void Destroy(GLES2Implementation* /* gl_impl */) { | 86 virtual void Destroy(GLES2Implementation* /* gl_impl */) OVERRIDE { |
| 87 } | 87 } |
| 88 | 88 |
| 89 // Overridden from IdHandlerInterface. | 89 // Overridden from IdHandlerInterface. |
| 90 virtual void MakeIds( | 90 virtual void MakeIds( |
| 91 GLES2Implementation* /* gl_impl */, | 91 GLES2Implementation* /* gl_impl */, |
| 92 GLuint id_offset, GLsizei n, GLuint* ids) { | 92 GLuint id_offset, GLsizei n, GLuint* ids) OVERRIDE { |
| 93 for (GLsizei ii = 0; ii < n; ++ii) { | 93 for (GLsizei ii = 0; ii < n; ++ii) { |
| 94 ids[ii] = ++last_id_ + id_offset; | 94 ids[ii] = ++last_id_ + id_offset; |
| 95 } | 95 } |
| 96 } | 96 } |
| 97 | 97 |
| 98 // Overridden from IdHandlerInterface. | 98 // Overridden from IdHandlerInterface. |
| 99 virtual bool FreeIds( | 99 virtual bool FreeIds( |
| 100 GLES2Implementation* gl_impl, | 100 GLES2Implementation* gl_impl, |
| 101 GLsizei n, const GLuint* ids, DeleteFn delete_fn) { | 101 GLsizei n, const GLuint* ids, DeleteFn delete_fn) OVERRIDE { |
| 102 // Ids are never freed. | 102 // Ids are never freed. |
| 103 (gl_impl->*delete_fn)(n, ids); | 103 (gl_impl->*delete_fn)(n, ids); |
| 104 return true; | 104 return true; |
| 105 } | 105 } |
| 106 | 106 |
| 107 // Overridden from IdHandlerInterface. | 107 // Overridden from IdHandlerInterface. |
| 108 virtual bool MarkAsUsedForBind(GLuint /* id */) { | 108 virtual bool MarkAsUsedForBind(GLuint /* id */) OVERRIDE { |
| 109 // This is only used for Shaders and Programs which have no bind. | 109 // This is only used for Shaders and Programs which have no bind. |
| 110 return false; | 110 return false; |
| 111 } | 111 } |
| 112 | 112 |
| 113 private: | 113 private: |
| 114 GLuint last_id_; | 114 GLuint last_id_; |
| 115 }; | 115 }; |
| 116 | 116 |
| 117 // An id handler for shared ids. | 117 // An id handler for shared ids. |
| 118 class SharedIdHandler : public IdHandlerInterface { | 118 class SharedIdHandler : public IdHandlerInterface { |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 232 | 232 |
| 233 ShareGroup::~ShareGroup() { | 233 ShareGroup::~ShareGroup() { |
| 234 for (int i = 0; i < id_namespaces::kNumIdNamespaces; ++i) { | 234 for (int i = 0; i < id_namespaces::kNumIdNamespaces; ++i) { |
| 235 id_handlers_[i]->Destroy(gles2_); | 235 id_handlers_[i]->Destroy(gles2_); |
| 236 id_handlers_[i].reset(); | 236 id_handlers_[i].reset(); |
| 237 } | 237 } |
| 238 } | 238 } |
| 239 | 239 |
| 240 } // namespace gles2 | 240 } // namespace gles2 |
| 241 } // namespace gpu | 241 } // namespace gpu |
| OLD | NEW |