Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "cc/layers/heads_up_display_layer_impl.h" | 5 #include "cc/layers/heads_up_display_layer_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/numerics/safe_conversions.h" | 10 #include "base/numerics/safe_conversions.h" |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 84 | 84 |
| 85 HeadsUpDisplayLayerImpl::~HeadsUpDisplayLayerImpl() {} | 85 HeadsUpDisplayLayerImpl::~HeadsUpDisplayLayerImpl() {} |
| 86 | 86 |
| 87 scoped_ptr<LayerImpl> HeadsUpDisplayLayerImpl::CreateLayerImpl( | 87 scoped_ptr<LayerImpl> HeadsUpDisplayLayerImpl::CreateLayerImpl( |
| 88 LayerTreeImpl* tree_impl) { | 88 LayerTreeImpl* tree_impl) { |
| 89 return HeadsUpDisplayLayerImpl::Create(tree_impl, id()); | 89 return HeadsUpDisplayLayerImpl::Create(tree_impl, id()); |
| 90 } | 90 } |
| 91 | 91 |
| 92 void HeadsUpDisplayLayerImpl::AcquireResource( | 92 void HeadsUpDisplayLayerImpl::AcquireResource( |
| 93 ResourceProvider* resource_provider) { | 93 ResourceProvider* resource_provider) { |
| 94 for (ScopedPtrVector<ScopedResource>::iterator it = resources_.begin(); | 94 for (std::vector<scoped_ptr<ScopedResource>>::iterator it = |
|
danakj
2015/11/17 01:12:17
auto and ranged-based?
vmpstr
2015/11/17 23:26:23
Done.
| |
| 95 it != resources_.end(); | 95 resources_.begin(); |
| 96 ++it) { | 96 it != resources_.end(); ++it) { |
| 97 if (!resource_provider->InUseByConsumer((*it)->id())) { | 97 if (!resource_provider->InUseByConsumer((*it)->id())) { |
| 98 resources_.swap(it, resources_.end() - 1); | 98 it->swap(resources_.back()); |
| 99 return; | 99 return; |
| 100 } | 100 } |
| 101 } | 101 } |
| 102 | 102 |
| 103 scoped_ptr<ScopedResource> resource = | 103 scoped_ptr<ScopedResource> resource = |
| 104 ScopedResource::Create(resource_provider); | 104 ScopedResource::Create(resource_provider); |
| 105 resource->Allocate(internal_content_bounds_, | 105 resource->Allocate(internal_content_bounds_, |
| 106 ResourceProvider::TEXTURE_HINT_IMMUTABLE, | 106 ResourceProvider::TEXTURE_HINT_IMMUTABLE, |
| 107 resource_provider->best_texture_format()); | 107 resource_provider->best_texture_format()); |
| 108 resources_.push_back(resource.Pass()); | 108 resources_.push_back(resource.Pass()); |
| 109 } | 109 } |
| 110 | 110 |
| 111 class ResourceSizeIsEqualTo { | |
| 112 public: | |
| 113 explicit ResourceSizeIsEqualTo(const gfx::Size& size_) | |
| 114 : compare_size_(size_) {} | |
| 115 | |
| 116 bool operator()(const ScopedResource* resource) { | |
| 117 return resource->size() == compare_size_; | |
| 118 } | |
| 119 | |
| 120 private: | |
| 121 const gfx::Size compare_size_; | |
| 122 }; | |
| 123 | |
| 124 void HeadsUpDisplayLayerImpl::ReleaseUnmatchedSizeResources( | 111 void HeadsUpDisplayLayerImpl::ReleaseUnmatchedSizeResources( |
| 125 ResourceProvider* resource_provider) { | 112 ResourceProvider* resource_provider) { |
| 126 ScopedPtrVector<ScopedResource>::iterator it_erase = | 113 std::vector<scoped_ptr<ScopedResource>>::iterator it_erase = |
| 127 resources_.partition(ResourceSizeIsEqualTo(internal_content_bounds_)); | 114 std::remove_if(resources_.begin(), resources_.end(), |
| 115 [this](const scoped_ptr<ScopedResource>& resource) { | |
|
danakj
2015/11/17 01:12:17
wwooooaa you can do that? and then use member vars
vmpstr
2015/11/17 23:26:23
hehe, yep! :)
| |
| 116 return internal_content_bounds_ != resource->size(); | |
| 117 }); | |
| 128 resources_.erase(it_erase, resources_.end()); | 118 resources_.erase(it_erase, resources_.end()); |
| 129 } | 119 } |
| 130 | 120 |
| 131 bool HeadsUpDisplayLayerImpl::WillDraw(DrawMode draw_mode, | 121 bool HeadsUpDisplayLayerImpl::WillDraw(DrawMode draw_mode, |
| 132 ResourceProvider* resource_provider) { | 122 ResourceProvider* resource_provider) { |
| 133 if (draw_mode == DRAW_MODE_RESOURCELESS_SOFTWARE) | 123 if (draw_mode == DRAW_MODE_RESOURCELESS_SOFTWARE) |
| 134 return false; | 124 return false; |
| 135 | 125 |
| 136 internal_contents_scale_ = GetIdealContentsScale(); | 126 internal_contents_scale_ = GetIdealContentsScale(); |
| 137 internal_content_bounds_ = | 127 internal_content_bounds_ = |
| (...skipping 665 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 803 return "cc::HeadsUpDisplayLayerImpl"; | 793 return "cc::HeadsUpDisplayLayerImpl"; |
| 804 } | 794 } |
| 805 | 795 |
| 806 void HeadsUpDisplayLayerImpl::AsValueInto( | 796 void HeadsUpDisplayLayerImpl::AsValueInto( |
| 807 base::trace_event::TracedValue* dict) const { | 797 base::trace_event::TracedValue* dict) const { |
| 808 LayerImpl::AsValueInto(dict); | 798 LayerImpl::AsValueInto(dict); |
| 809 dict->SetString("layer_name", "Heads Up Display Layer"); | 799 dict->SetString("layer_name", "Heads Up Display Layer"); |
| 810 } | 800 } |
| 811 | 801 |
| 812 } // namespace cc | 802 } // namespace cc |
| OLD | NEW |