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>::ElementAt( |
| 378 size_t index) const { |
| 379 DCHECK_LT(index, size()); |
| 380 size_t list_index; |
| 381 for (list_index = 0; list_index < data_->list_count(); ++list_index) { |
| 382 size_t current_size = data_->InnerListById(list_index)->size; |
| 383 if (index < current_size) |
| 384 break; |
| 385 index -= current_size; |
| 386 } |
| 387 return &*ConstIterator(data_.get(), |
| 388 list_index, |
| 389 data_->InnerListById(list_index)->ElementAt(index)); |
| 390 } |
| 391 |
| 392 template <typename BaseElementType> |
| 393 BaseElementType* ListContainer<BaseElementType>::ElementAt(size_t index) { |
| 394 DCHECK_LT(index, size()); |
| 395 size_t list_index; |
| 396 for (list_index = 0; list_index < data_->list_count(); ++list_index) { |
| 397 size_t current_size = data_->InnerListById(list_index)->size; |
| 398 if (index < current_size) |
| 399 break; |
| 400 index -= current_size; |
| 401 } |
| 402 return &*Iterator(data_.get(), |
| 403 list_index, |
| 404 data_->InnerListById(list_index)->ElementAt(index)); |
| 405 } |
| 406 |
| 407 template <typename BaseElementType> |
376 BaseElementType* ListContainer<BaseElementType>::Allocate( | 408 BaseElementType* ListContainer<BaseElementType>::Allocate( |
377 size_t size_of_actual_element_in_bytes) { | 409 size_t size_of_actual_element_in_bytes) { |
378 DCHECK_LE(size_of_actual_element_in_bytes, data_->element_size()); | 410 DCHECK_LE(size_of_actual_element_in_bytes, data_->element_size()); |
379 void* result = data_->Allocate(); | 411 void* result = data_->Allocate(); |
380 return static_cast<BaseElementType*>(result); | 412 return static_cast<BaseElementType*>(result); |
381 } | 413 } |
382 | 414 |
383 template <typename BaseElementType> | 415 template <typename BaseElementType> |
384 size_t ListContainer<BaseElementType>::size() const { | 416 size_t ListContainer<BaseElementType>::size() const { |
385 return data_->size(); | 417 return data_->size(); |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
583 ListContainer<BaseElementType>::ConstReverseIterator:: | 615 ListContainer<BaseElementType>::ConstReverseIterator:: |
584 operator++() { | 616 operator++() { |
585 this->ReverseIncrement(); | 617 this->ReverseIncrement(); |
586 return *this; | 618 return *this; |
587 } | 619 } |
588 | 620 |
589 template class ListContainer<SharedQuadState>; | 621 template class ListContainer<SharedQuadState>; |
590 template class ListContainer<DrawQuad>; | 622 template class ListContainer<DrawQuad>; |
591 | 623 |
592 } // namespace cc | 624 } // namespace cc |
OLD | NEW |