| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "cc/quads/list_container.h" | 5 #include "cc/quads/list_container.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "cc/base/scoped_ptr_vector.h" | 10 #include "cc/base/scoped_ptr_vector.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 | 61 |
| 62 void* AddElement() { | 62 void* AddElement() { |
| 63 DCHECK_LT(size, capacity); | 63 DCHECK_LT(size, capacity); |
| 64 ++size; | 64 ++size; |
| 65 return LastElement(); | 65 return LastElement(); |
| 66 } | 66 } |
| 67 | 67 |
| 68 char* Begin() const { return data.get(); } | 68 char* Begin() const { return data.get(); } |
| 69 char* End() const { return data.get() + size * step; } | 69 char* End() const { return data.get() + size * step; } |
| 70 char* LastElement() const { return data.get() + (size - 1) * step; } | 70 char* LastElement() const { return data.get() + (size - 1) * step; } |
| 71 char* ElementAt(size_t index) const { return data.get() + index * step; } |
| 71 | 72 |
| 72 private: | 73 private: |
| 73 DISALLOW_COPY_AND_ASSIGN(InnerList); | 74 DISALLOW_COPY_AND_ASSIGN(InnerList); |
| 74 }; | 75 }; |
| 75 | 76 |
| 76 explicit ListContainerCharAllocator(size_t element_size) | 77 explicit ListContainerCharAllocator(size_t element_size) |
| 77 : element_size_(element_size), | 78 : element_size_(element_size), |
| 78 size_(0), | 79 size_(0), |
| 79 list_count_(0), | 80 list_count_(0), |
| 80 last_list_(NULL) { | 81 last_list_(NULL) { |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 return &*iter; | 367 return &*iter; |
| 367 } | 368 } |
| 368 | 369 |
| 369 template <typename BaseElementType> | 370 template <typename BaseElementType> |
| 370 const BaseElementType* ListContainer<BaseElementType>::back() const { | 371 const BaseElementType* ListContainer<BaseElementType>::back() const { |
| 371 ConstReverseIterator iter = rbegin(); | 372 ConstReverseIterator iter = rbegin(); |
| 372 return &*iter; | 373 return &*iter; |
| 373 } | 374 } |
| 374 | 375 |
| 375 template <typename BaseElementType> | 376 template <typename BaseElementType> |
| 377 const BaseElementType* ListContainer<BaseElementType>::at(size_t index) const { |
| 378 DCHECK_LT(index, size()); |
| 379 size_t list_index; |
| 380 for (list_index = 0; list_index < data_->list_count(); ++list_index) { |
| 381 size_t current_size = data_->InnerListById(list_index)->size; |
| 382 if (index < current_size) |
| 383 break; |
| 384 index -= current_size; |
| 385 } |
| 386 return &*ConstIterator(data_.get(), |
| 387 list_index, |
| 388 data_->InnerListById(list_index)->ElementAt(index)); |
| 389 } |
| 390 |
| 391 template <typename BaseElementType> |
| 392 BaseElementType* ListContainer<BaseElementType>::at(size_t index) { |
| 393 DCHECK_LT(index, size()); |
| 394 size_t list_index; |
| 395 for (list_index = 0; list_index < data_->list_count(); ++list_index) { |
| 396 size_t current_size = data_->InnerListById(list_index)->size; |
| 397 if (index < current_size) |
| 398 break; |
| 399 index -= current_size; |
| 400 } |
| 401 return &*Iterator(data_.get(), |
| 402 list_index, |
| 403 data_->InnerListById(list_index)->ElementAt(index)); |
| 404 } |
| 405 |
| 406 template <typename BaseElementType> |
| 376 BaseElementType* ListContainer<BaseElementType>::Allocate( | 407 BaseElementType* ListContainer<BaseElementType>::Allocate( |
| 377 size_t size_of_actual_element_in_bytes) { | 408 size_t size_of_actual_element_in_bytes) { |
| 378 DCHECK_LE(size_of_actual_element_in_bytes, data_->element_size()); | 409 DCHECK_LE(size_of_actual_element_in_bytes, data_->element_size()); |
| 379 void* result = data_->Allocate(); | 410 void* result = data_->Allocate(); |
| 380 return static_cast<BaseElementType*>(result); | 411 return static_cast<BaseElementType*>(result); |
| 381 } | 412 } |
| 382 | 413 |
| 383 template <typename BaseElementType> | 414 template <typename BaseElementType> |
| 384 size_t ListContainer<BaseElementType>::size() const { | 415 size_t ListContainer<BaseElementType>::size() const { |
| 385 return data_->size(); | 416 return data_->size(); |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 583 ListContainer<BaseElementType>::ConstReverseIterator:: | 614 ListContainer<BaseElementType>::ConstReverseIterator:: |
| 584 operator++() { | 615 operator++() { |
| 585 this->ReverseIncrement(); | 616 this->ReverseIncrement(); |
| 586 return *this; | 617 return *this; |
| 587 } | 618 } |
| 588 | 619 |
| 589 template class ListContainer<SharedQuadState>; | 620 template class ListContainer<SharedQuadState>; |
| 590 template class ListContainer<DrawQuad>; | 621 template class ListContainer<DrawQuad>; |
| 591 | 622 |
| 592 } // namespace cc | 623 } // namespace cc |
| OLD | NEW |