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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 74 paint_time_graph_(16.0, 48.0), | 74 paint_time_graph_(16.0, 48.0), |
| 75 fade_step_(0) {} | 75 fade_step_(0) {} |
| 76 | 76 |
| 77 HeadsUpDisplayLayerImpl::~HeadsUpDisplayLayerImpl() {} | 77 HeadsUpDisplayLayerImpl::~HeadsUpDisplayLayerImpl() {} |
| 78 | 78 |
| 79 scoped_ptr<LayerImpl> HeadsUpDisplayLayerImpl::CreateLayerImpl( | 79 scoped_ptr<LayerImpl> HeadsUpDisplayLayerImpl::CreateLayerImpl( |
| 80 LayerTreeImpl* tree_impl) { | 80 LayerTreeImpl* tree_impl) { |
| 81 return HeadsUpDisplayLayerImpl::Create(tree_impl, id()).PassAs<LayerImpl>(); | 81 return HeadsUpDisplayLayerImpl::Create(tree_impl, id()).PassAs<LayerImpl>(); |
| 82 } | 82 } |
| 83 | 83 |
| 84 void HeadsUpDisplayLayerImpl::AcquireResource( | |
| 85 ResourceProvider* resource_provider) { | |
| 86 for (ScopedPtrVector<ScopedResource>::iterator it = resources_.begin(); | |
| 87 it != resources_.end(); | |
| 88 ++it) { | |
| 89 if (!resource_provider->InUseByConsumer((*it)->id())) { | |
| 90 resources_.swap(it, resources_.end() - 1); | |
| 91 return; | |
| 92 } | |
| 93 } | |
| 94 | |
| 95 scoped_ptr<ScopedResource> resource = | |
| 96 ScopedResource::Create(resource_provider); | |
| 97 resource->Allocate( | |
| 98 content_bounds(), ResourceProvider::TextureHintImmutable, RGBA_8888); | |
| 99 resources_.push_back(resource.Pass()); | |
| 100 } | |
| 101 | |
| 102 void HeadsUpDisplayLayerImpl::ReleaseUnmatchedSizeResources( | |
| 103 ResourceProvider* resource_provider) { | |
| 104 ScopedPtrVector<ScopedResource> to_be_kept; | |
| 105 for (ScopedPtrVector<ScopedResource>::iterator it = resources_.begin(); | |
| 106 it != resources_.end(); | |
| 107 ++it) { | |
| 108 if ((*it)->size() == content_bounds()) | |
| 109 to_be_kept.push_back(resources_.take(it)); | |
|
danakj
2014/08/27 13:25:01
i feel like the common case will be that we keep a
JungJik
2014/08/28 15:55:38
thanks for the kind explanation.
however for two r
| |
| 110 } | |
| 111 resources_.clear(); | |
| 112 | |
| 113 resources_.insert_and_take(resources_.begin(), to_be_kept); | |
| 114 } | |
| 115 | |
| 84 bool HeadsUpDisplayLayerImpl::WillDraw(DrawMode draw_mode, | 116 bool HeadsUpDisplayLayerImpl::WillDraw(DrawMode draw_mode, |
| 85 ResourceProvider* resource_provider) { | 117 ResourceProvider* resource_provider) { |
| 86 if (draw_mode == DRAW_MODE_RESOURCELESS_SOFTWARE) | 118 if (draw_mode == DRAW_MODE_RESOURCELESS_SOFTWARE) |
| 87 return false; | 119 return false; |
| 88 | 120 |
| 89 if (!hud_resource_) | 121 ReleaseUnmatchedSizeResources(resource_provider); |
| 90 hud_resource_ = ScopedResource::Create(resource_provider); | |
| 91 | 122 |
|
danakj
2014/08/27 13:25:01
nit: drop whitespace
| |
| 92 // TODO(danakj): The HUD could swap between two textures instead of creating a | 123 AcquireResource(resource_provider); |
| 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 | 124 |
|
danakj
2014/08/27 13:25:01
nit: drop whitespace
| |
| 105 return LayerImpl::WillDraw(draw_mode, resource_provider); | 125 return LayerImpl::WillDraw(draw_mode, resource_provider); |
| 106 } | 126 } |
| 107 | 127 |
| 108 void HeadsUpDisplayLayerImpl::AppendQuads( | 128 void HeadsUpDisplayLayerImpl::AppendQuads( |
| 109 RenderPass* render_pass, | 129 RenderPass* render_pass, |
| 110 const OcclusionTracker<LayerImpl>& occlusion_tracker, | 130 const OcclusionTracker<LayerImpl>& occlusion_tracker, |
| 111 AppendQuadsData* append_quads_data) { | 131 AppendQuadsData* append_quads_data) { |
| 112 if (!hud_resource_->id()) | 132 if (!resources_.back()->id()) |
| 113 return; | 133 return; |
| 114 | 134 |
| 115 SharedQuadState* shared_quad_state = | 135 SharedQuadState* shared_quad_state = |
| 116 render_pass->CreateAndAppendSharedQuadState(); | 136 render_pass->CreateAndAppendSharedQuadState(); |
| 117 PopulateSharedQuadState(shared_quad_state); | 137 PopulateSharedQuadState(shared_quad_state); |
| 118 | 138 |
| 119 gfx::Rect quad_rect(content_bounds()); | 139 gfx::Rect quad_rect(content_bounds()); |
| 120 gfx::Rect opaque_rect(contents_opaque() ? quad_rect : gfx::Rect()); | 140 gfx::Rect opaque_rect(contents_opaque() ? quad_rect : gfx::Rect()); |
| 121 gfx::Rect visible_quad_rect(quad_rect); | 141 gfx::Rect visible_quad_rect(quad_rect); |
| 122 bool premultiplied_alpha = true; | 142 bool premultiplied_alpha = true; |
| 123 gfx::PointF uv_top_left(0.f, 0.f); | 143 gfx::PointF uv_top_left(0.f, 0.f); |
| 124 gfx::PointF uv_bottom_right(1.f, 1.f); | 144 gfx::PointF uv_bottom_right(1.f, 1.f); |
| 125 const float vertex_opacity[] = { 1.f, 1.f, 1.f, 1.f }; | 145 const float vertex_opacity[] = { 1.f, 1.f, 1.f, 1.f }; |
| 126 bool flipped = false; | 146 bool flipped = false; |
| 127 TextureDrawQuad* quad = | 147 TextureDrawQuad* quad = |
| 128 render_pass->CreateAndAppendDrawQuad<TextureDrawQuad>(); | 148 render_pass->CreateAndAppendDrawQuad<TextureDrawQuad>(); |
| 129 quad->SetNew(shared_quad_state, | 149 quad->SetNew(shared_quad_state, |
| 130 quad_rect, | 150 quad_rect, |
| 131 opaque_rect, | 151 opaque_rect, |
| 132 visible_quad_rect, | 152 visible_quad_rect, |
| 133 hud_resource_->id(), | 153 resources_.back()->id(), |
| 134 premultiplied_alpha, | 154 premultiplied_alpha, |
| 135 uv_top_left, | 155 uv_top_left, |
| 136 uv_bottom_right, | 156 uv_bottom_right, |
| 137 SK_ColorTRANSPARENT, | 157 SK_ColorTRANSPARENT, |
| 138 vertex_opacity, | 158 vertex_opacity, |
| 139 flipped); | 159 flipped); |
| 140 } | 160 } |
| 141 | 161 |
| 142 void HeadsUpDisplayLayerImpl::UpdateHudTexture( | 162 void HeadsUpDisplayLayerImpl::UpdateHudTexture( |
| 143 DrawMode draw_mode, | 163 DrawMode draw_mode, |
| 144 ResourceProvider* resource_provider) { | 164 ResourceProvider* resource_provider) { |
| 145 if (draw_mode == DRAW_MODE_RESOURCELESS_SOFTWARE || !hud_resource_->id()) | 165 if (draw_mode == DRAW_MODE_RESOURCELESS_SOFTWARE || !resources_.back()->id()) |
| 146 return; | 166 return; |
| 147 | 167 |
| 148 SkISize canvas_size; | 168 SkISize canvas_size; |
| 149 if (hud_canvas_) | 169 if (hud_canvas_) |
| 150 canvas_size = hud_canvas_->getDeviceSize(); | 170 canvas_size = hud_canvas_->getDeviceSize(); |
| 151 else | 171 else |
| 152 canvas_size.set(0, 0); | 172 canvas_size.set(0, 0); |
| 153 | 173 |
| 154 if (canvas_size.width() != content_bounds().width() || | 174 if (canvas_size.width() != content_bounds().width() || |
| 155 canvas_size.height() != content_bounds().height() || !hud_canvas_) { | 175 canvas_size.height() != content_bounds().height() || !hud_canvas_) { |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 172 hud_canvas_->restore(); | 192 hud_canvas_->restore(); |
| 173 } | 193 } |
| 174 | 194 |
| 175 TRACE_EVENT0("cc", "UploadHudTexture"); | 195 TRACE_EVENT0("cc", "UploadHudTexture"); |
| 176 SkImageInfo info; | 196 SkImageInfo info; |
| 177 size_t row_bytes = 0; | 197 size_t row_bytes = 0; |
| 178 const void* pixels = hud_canvas_->peekPixels(&info, &row_bytes); | 198 const void* pixels = hud_canvas_->peekPixels(&info, &row_bytes); |
| 179 DCHECK(pixels); | 199 DCHECK(pixels); |
| 180 gfx::Rect content_rect(content_bounds()); | 200 gfx::Rect content_rect(content_bounds()); |
| 181 DCHECK(info.colorType() == kN32_SkColorType); | 201 DCHECK(info.colorType() == kN32_SkColorType); |
| 182 resource_provider->SetPixels(hud_resource_->id(), | 202 resource_provider->SetPixels(resources_.back()->id(), |
| 183 static_cast<const uint8_t*>(pixels), | 203 static_cast<const uint8_t*>(pixels), |
| 184 content_rect, | 204 content_rect, |
| 185 content_rect, | 205 content_rect, |
| 186 gfx::Vector2d()); | 206 gfx::Vector2d()); |
| 187 } | 207 } |
| 188 | 208 |
| 189 void HeadsUpDisplayLayerImpl::ReleaseResources() { hud_resource_.reset(); } | 209 void HeadsUpDisplayLayerImpl::ReleaseResources() { |
| 210 resources_.clear(); | |
| 211 } | |
| 190 | 212 |
| 191 void HeadsUpDisplayLayerImpl::UpdateHudContents() { | 213 void HeadsUpDisplayLayerImpl::UpdateHudContents() { |
| 192 const LayerTreeDebugState& debug_state = layer_tree_impl()->debug_state(); | 214 const LayerTreeDebugState& debug_state = layer_tree_impl()->debug_state(); |
| 193 | 215 |
| 194 // Don't update numbers every frame so text is readable. | 216 // Don't update numbers every frame so text is readable. |
| 195 base::TimeTicks now = layer_tree_impl()->CurrentBeginFrameArgs().frame_time; | 217 base::TimeTicks now = layer_tree_impl()->CurrentBeginFrameArgs().frame_time; |
| 196 if (base::TimeDelta(now - time_of_last_graph_update_).InSecondsF() > 0.25f) { | 218 if (base::TimeDelta(now - time_of_last_graph_update_).InSecondsF() > 0.25f) { |
| 197 time_of_last_graph_update_ = now; | 219 time_of_last_graph_update_ = now; |
| 198 | 220 |
| 199 if (debug_state.show_fps_counter) { | 221 if (debug_state.show_fps_counter) { |
| (...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 762 return "cc::HeadsUpDisplayLayerImpl"; | 784 return "cc::HeadsUpDisplayLayerImpl"; |
| 763 } | 785 } |
| 764 | 786 |
| 765 void HeadsUpDisplayLayerImpl::AsValueInto( | 787 void HeadsUpDisplayLayerImpl::AsValueInto( |
| 766 base::debug::TracedValue* dict) const { | 788 base::debug::TracedValue* dict) const { |
| 767 LayerImpl::AsValueInto(dict); | 789 LayerImpl::AsValueInto(dict); |
| 768 dict->SetString("layer_name", "Heads Up Display Layer"); | 790 dict->SetString("layer_name", "Heads Up Display Layer"); |
| 769 } | 791 } |
| 770 | 792 |
| 771 } // namespace cc | 793 } // namespace cc |
| OLD | NEW |