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/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 61 | 61 |
| 62 double HeadsUpDisplayLayerImpl::Graph::UpdateUpperBound() { | 62 double HeadsUpDisplayLayerImpl::Graph::UpdateUpperBound() { |
| 63 double target_upper_bound = std::max(max, default_upper_bound); | 63 double target_upper_bound = std::max(max, default_upper_bound); |
| 64 current_upper_bound += (target_upper_bound - current_upper_bound) * 0.5; | 64 current_upper_bound += (target_upper_bound - current_upper_bound) * 0.5; |
| 65 return current_upper_bound; | 65 return current_upper_bound; |
| 66 } | 66 } |
| 67 | 67 |
| 68 HeadsUpDisplayLayerImpl::HeadsUpDisplayLayerImpl(LayerTreeImpl* tree_impl, | 68 HeadsUpDisplayLayerImpl::HeadsUpDisplayLayerImpl(LayerTreeImpl* tree_impl, |
| 69 int id) | 69 int id) |
| 70 : LayerImpl(tree_impl, id), | 70 : LayerImpl(tree_impl, id), |
| 71 hud_resource_(NULL), | |
| 71 typeface_(skia::AdoptRef( | 72 typeface_(skia::AdoptRef( |
| 72 SkTypeface::CreateFromName("monospace", SkTypeface::kBold))), | 73 SkTypeface::CreateFromName("monospace", SkTypeface::kBold))), |
| 73 fps_graph_(60.0, 80.0), | 74 fps_graph_(60.0, 80.0), |
| 74 paint_time_graph_(16.0, 48.0), | 75 paint_time_graph_(16.0, 48.0), |
| 75 fade_step_(0) {} | 76 fade_step_(0) { |
| 77 } | |
| 76 | 78 |
| 77 HeadsUpDisplayLayerImpl::~HeadsUpDisplayLayerImpl() {} | 79 HeadsUpDisplayLayerImpl::~HeadsUpDisplayLayerImpl() {} |
| 78 | 80 |
| 79 scoped_ptr<LayerImpl> HeadsUpDisplayLayerImpl::CreateLayerImpl( | 81 scoped_ptr<LayerImpl> HeadsUpDisplayLayerImpl::CreateLayerImpl( |
| 80 LayerTreeImpl* tree_impl) { | 82 LayerTreeImpl* tree_impl) { |
| 81 return HeadsUpDisplayLayerImpl::Create(tree_impl, id()).PassAs<LayerImpl>(); | 83 return HeadsUpDisplayLayerImpl::Create(tree_impl, id()).PassAs<LayerImpl>(); |
| 82 } | 84 } |
| 83 | 85 |
| 86 ScopedResource* HeadsUpDisplayLayerImpl::AcquireResource( | |
| 87 ResourceProvider* resource_provider) { | |
| 88 HUDResourceList::iterator iter; | |
| 89 for (iter = resources_.begin(); iter != resources_.end(); ++iter) { | |
| 90 if (!resource_provider->InUseByConsumer((*iter)->id())) | |
|
danakj
2014/08/25 14:51:21
how come this doesn't check content_bounds?
JungJik
2014/08/26 11:16:35
I was trying to remove all resources which have di
| |
| 91 return *iter; | |
| 92 } | |
| 93 | |
| 94 scoped_ptr<ScopedResource> resource = | |
| 95 ScopedResource::Create(resource_provider); | |
| 96 resource->Allocate( | |
| 97 content_bounds(), ResourceProvider::TextureHintImmutable, RGBA_8888); | |
| 98 resources_.push_back(resource.release()); | |
| 99 return resources_.back(); | |
| 100 } | |
| 101 | |
| 102 void HeadsUpDisplayLayerImpl::ReleaseUnusedResources( | |
| 103 ResourceProvider* resource_provider) { | |
| 104 bool found_unused_resource = false; | |
| 105 | |
| 106 HUDResourceList::iterator iter; | |
| 107 for (iter = resources_.begin(); iter != resources_.end(); ++iter) { | |
| 108 if ((*iter)->size() != content_bounds()) { | |
| 109 ReleaseResource(iter); | |
|
danakj
2014/08/25 14:51:21
calling erase during iteration, this invalidates t
| |
| 110 continue; | |
| 111 } | |
| 112 | |
| 113 if (!resource_provider->InUseByConsumer((*iter)->id())) { | |
| 114 if (found_unused_resource) | |
|
danakj
2014/08/25 14:51:21
if you make Acquire move the resource it chooses t
| |
| 115 ReleaseResource(iter); | |
| 116 found_unused_resource = true; | |
| 117 } | |
| 118 } | |
| 119 } | |
| 120 | |
| 121 void HeadsUpDisplayLayerImpl::ReleaseResource(HUDResourceList::iterator iter) { | |
| 122 ScopedResource* resource = *iter; | |
| 123 if (resource->id()) | |
|
danakj
2014/08/25 14:51:21
why would we have a resource without an id in the
| |
| 124 resource->Free(); | |
|
danakj
2014/08/25 14:51:21
the destructor already calls Free, you just need t
| |
| 125 resources_.erase(iter); | |
| 126 delete resource; | |
|
danakj
2014/08/25 14:51:21
manual memory management :(
what if you put the S
JungJik
2014/08/26 11:16:35
thanks for comments. ScopedPtrVector, this is what
| |
| 127 } | |
| 128 | |
| 84 bool HeadsUpDisplayLayerImpl::WillDraw(DrawMode draw_mode, | 129 bool HeadsUpDisplayLayerImpl::WillDraw(DrawMode draw_mode, |
| 85 ResourceProvider* resource_provider) { | 130 ResourceProvider* resource_provider) { |
| 86 if (draw_mode == DRAW_MODE_RESOURCELESS_SOFTWARE) | 131 if (draw_mode == DRAW_MODE_RESOURCELESS_SOFTWARE) |
| 87 return false; | 132 return false; |
| 88 | 133 |
| 89 if (!hud_resource_) | 134 ReleaseUnusedResources(resource_provider); |
| 90 hud_resource_ = ScopedResource::Create(resource_provider); | |
| 91 | 135 |
| 92 // TODO(danakj): The HUD could swap between two textures instead of creating a | 136 hud_resource_ = AcquireResource(resource_provider); |
|
danakj
2014/08/25 14:51:21
how about just using the resources_.back() and mov
JungJik
2014/08/26 11:16:35
okay, I will apply it in next patch. thank you.
| |
| 93 // texture every frame in ubercompositor. | |
| 94 if (hud_resource_->size() != content_bounds() || | |
| 95 (hud_resource_->id() && | |
| 96 resource_provider->InUseByConsumer(hud_resource_->id()))) { | |
| 97 hud_resource_->Free(); | |
| 98 } | |
| 99 | |
| 100 if (!hud_resource_->id()) { | |
| 101 hud_resource_->Allocate( | |
| 102 content_bounds(), ResourceProvider::TextureHintImmutable, RGBA_8888); | |
| 103 } | |
| 104 | 137 |
| 105 return LayerImpl::WillDraw(draw_mode, resource_provider); | 138 return LayerImpl::WillDraw(draw_mode, resource_provider); |
| 106 } | 139 } |
| 107 | 140 |
| 108 void HeadsUpDisplayLayerImpl::AppendQuads( | 141 void HeadsUpDisplayLayerImpl::AppendQuads( |
| 109 RenderPass* render_pass, | 142 RenderPass* render_pass, |
| 110 const OcclusionTracker<LayerImpl>& occlusion_tracker, | 143 const OcclusionTracker<LayerImpl>& occlusion_tracker, |
| 111 AppendQuadsData* append_quads_data) { | 144 AppendQuadsData* append_quads_data) { |
| 112 if (!hud_resource_->id()) | 145 if (!hud_resource_->id()) |
| 113 return; | 146 return; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 179 DCHECK(pixels); | 212 DCHECK(pixels); |
| 180 gfx::Rect content_rect(content_bounds()); | 213 gfx::Rect content_rect(content_bounds()); |
| 181 DCHECK(info.colorType() == kN32_SkColorType); | 214 DCHECK(info.colorType() == kN32_SkColorType); |
| 182 resource_provider->SetPixels(hud_resource_->id(), | 215 resource_provider->SetPixels(hud_resource_->id(), |
| 183 static_cast<const uint8_t*>(pixels), | 216 static_cast<const uint8_t*>(pixels), |
| 184 content_rect, | 217 content_rect, |
| 185 content_rect, | 218 content_rect, |
| 186 gfx::Vector2d()); | 219 gfx::Vector2d()); |
| 187 } | 220 } |
| 188 | 221 |
| 189 void HeadsUpDisplayLayerImpl::ReleaseResources() { hud_resource_.reset(); } | 222 void HeadsUpDisplayLayerImpl::ReleaseResources() { |
| 223 HUDResourceList::iterator iter; | |
| 224 for (iter = resources_.begin(); iter != resources_.end(); ++iter) | |
| 225 ReleaseResource(iter); | |
|
danakj
2014/08/25 14:51:21
If you erase while iterating the same list, you're
JungJik
2014/08/26 11:16:35
I will remember it.
| |
| 226 hud_resource_ = NULL; | |
| 227 } | |
| 190 | 228 |
| 191 void HeadsUpDisplayLayerImpl::UpdateHudContents() { | 229 void HeadsUpDisplayLayerImpl::UpdateHudContents() { |
| 192 const LayerTreeDebugState& debug_state = layer_tree_impl()->debug_state(); | 230 const LayerTreeDebugState& debug_state = layer_tree_impl()->debug_state(); |
| 193 | 231 |
| 194 // Don't update numbers every frame so text is readable. | 232 // Don't update numbers every frame so text is readable. |
| 195 base::TimeTicks now = layer_tree_impl()->CurrentBeginFrameArgs().frame_time; | 233 base::TimeTicks now = layer_tree_impl()->CurrentBeginFrameArgs().frame_time; |
| 196 if (base::TimeDelta(now - time_of_last_graph_update_).InSecondsF() > 0.25f) { | 234 if (base::TimeDelta(now - time_of_last_graph_update_).InSecondsF() > 0.25f) { |
| 197 time_of_last_graph_update_ = now; | 235 time_of_last_graph_update_ = now; |
| 198 | 236 |
| 199 if (debug_state.show_fps_counter) { | 237 if (debug_state.show_fps_counter) { |
| (...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 762 return "cc::HeadsUpDisplayLayerImpl"; | 800 return "cc::HeadsUpDisplayLayerImpl"; |
| 763 } | 801 } |
| 764 | 802 |
| 765 void HeadsUpDisplayLayerImpl::AsValueInto( | 803 void HeadsUpDisplayLayerImpl::AsValueInto( |
| 766 base::debug::TracedValue* dict) const { | 804 base::debug::TracedValue* dict) const { |
| 767 LayerImpl::AsValueInto(dict); | 805 LayerImpl::AsValueInto(dict); |
| 768 dict->SetString("layer_name", "Heads Up Display Layer"); | 806 dict->SetString("layer_name", "Heads Up Display Layer"); |
| 769 } | 807 } |
| 770 | 808 |
| 771 } // namespace cc | 809 } // namespace cc |
| OLD | NEW |