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 (auto& resource : resources_) { |
95 it != resources_.end(); | 95 if (!resource_provider->InUseByConsumer(resource->id())) { |
96 ++it) { | 96 resource.swap(resources_.back()); |
97 if (!resource_provider->InUseByConsumer((*it)->id())) { | |
98 resources_.swap(it, resources_.end() - 1); | |
99 return; | 97 return; |
100 } | 98 } |
101 } | 99 } |
102 | 100 |
103 scoped_ptr<ScopedResource> resource = | 101 scoped_ptr<ScopedResource> resource = |
104 ScopedResource::Create(resource_provider); | 102 ScopedResource::Create(resource_provider); |
105 resource->Allocate(internal_content_bounds_, | 103 resource->Allocate(internal_content_bounds_, |
106 ResourceProvider::TEXTURE_HINT_IMMUTABLE, | 104 ResourceProvider::TEXTURE_HINT_IMMUTABLE, |
107 resource_provider->best_texture_format()); | 105 resource_provider->best_texture_format()); |
108 resources_.push_back(resource.Pass()); | 106 resources_.push_back(resource.Pass()); |
109 } | 107 } |
110 | 108 |
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( | 109 void HeadsUpDisplayLayerImpl::ReleaseUnmatchedSizeResources( |
125 ResourceProvider* resource_provider) { | 110 ResourceProvider* resource_provider) { |
126 ScopedPtrVector<ScopedResource>::iterator it_erase = | 111 auto it_erase = |
127 resources_.partition(ResourceSizeIsEqualTo(internal_content_bounds_)); | 112 std::remove_if(resources_.begin(), resources_.end(), |
| 113 [this](const scoped_ptr<ScopedResource>& resource) { |
| 114 return internal_content_bounds_ != resource->size(); |
| 115 }); |
128 resources_.erase(it_erase, resources_.end()); | 116 resources_.erase(it_erase, resources_.end()); |
129 } | 117 } |
130 | 118 |
131 bool HeadsUpDisplayLayerImpl::WillDraw(DrawMode draw_mode, | 119 bool HeadsUpDisplayLayerImpl::WillDraw(DrawMode draw_mode, |
132 ResourceProvider* resource_provider) { | 120 ResourceProvider* resource_provider) { |
133 if (draw_mode == DRAW_MODE_RESOURCELESS_SOFTWARE) | 121 if (draw_mode == DRAW_MODE_RESOURCELESS_SOFTWARE) |
134 return false; | 122 return false; |
135 | 123 |
136 internal_contents_scale_ = GetIdealContentsScale(); | 124 internal_contents_scale_ = GetIdealContentsScale(); |
137 internal_content_bounds_ = | 125 internal_content_bounds_ = |
(...skipping 665 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
803 return "cc::HeadsUpDisplayLayerImpl"; | 791 return "cc::HeadsUpDisplayLayerImpl"; |
804 } | 792 } |
805 | 793 |
806 void HeadsUpDisplayLayerImpl::AsValueInto( | 794 void HeadsUpDisplayLayerImpl::AsValueInto( |
807 base::trace_event::TracedValue* dict) const { | 795 base::trace_event::TracedValue* dict) const { |
808 LayerImpl::AsValueInto(dict); | 796 LayerImpl::AsValueInto(dict); |
809 dict->SetString("layer_name", "Heads Up Display Layer"); | 797 dict->SetString("layer_name", "Heads Up Display Layer"); |
810 } | 798 } |
811 | 799 |
812 } // namespace cc | 800 } // namespace cc |
OLD | NEW |