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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 43 swizzle_matrix.fMat[2 + 5 * 0] = 1; | 43 swizzle_matrix.fMat[2 + 5 * 0] = 1; |
| 44 swizzle_matrix.fMat[3 + 5 * 3] = 1; | 44 swizzle_matrix.fMat[3 + 5 * 3] = 1; |
| 45 | 45 |
| 46 skia::RefPtr<SkColorMatrixFilter> filter = | 46 skia::RefPtr<SkColorMatrixFilter> filter = |
| 47 skia::AdoptRef(SkColorMatrixFilter::Create(swizzle_matrix)); | 47 skia::AdoptRef(SkColorMatrixFilter::Create(swizzle_matrix)); |
| 48 paint.setColorFilter(filter.get()); | 48 paint.setColorFilter(filter.get()); |
| 49 #endif | 49 #endif |
| 50 return paint; | 50 return paint; |
| 51 } | 51 } |
| 52 | 52 |
| 53 class CompareResourceSize { | |
|
danakj
2014/08/29 16:42:46
move this down above the function that uses it
| |
| 54 public: | |
| 55 explicit CompareResourceSize(gfx::Size size_) : compare_size_(size_) {} | |
|
danakj
2014/08/29 16:42:47
const gfx::Size&
| |
| 56 | |
| 57 bool operator()(const ScopedResource* resource) { | |
| 58 return (resource->size() == compare_size_); | |
|
danakj
2014/08/29 16:42:47
drop the extra ()s
| |
| 59 } | |
| 60 | |
| 61 private: | |
| 62 const gfx::Size compare_size_; | |
| 63 }; | |
| 64 | |
| 53 HeadsUpDisplayLayerImpl::Graph::Graph(double indicator_value, | 65 HeadsUpDisplayLayerImpl::Graph::Graph(double indicator_value, |
| 54 double start_upper_bound) | 66 double start_upper_bound) |
| 55 : value(0.0), | 67 : value(0.0), |
| 56 min(0.0), | 68 min(0.0), |
| 57 max(0.0), | 69 max(0.0), |
| 58 current_upper_bound(start_upper_bound), | 70 current_upper_bound(start_upper_bound), |
| 59 default_upper_bound(start_upper_bound), | 71 default_upper_bound(start_upper_bound), |
| 60 indicator(indicator_value) {} | 72 indicator(indicator_value) {} |
| 61 | 73 |
| 62 double HeadsUpDisplayLayerImpl::Graph::UpdateUpperBound() { | 74 double HeadsUpDisplayLayerImpl::Graph::UpdateUpperBound() { |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 74 paint_time_graph_(16.0, 48.0), | 86 paint_time_graph_(16.0, 48.0), |
| 75 fade_step_(0) {} | 87 fade_step_(0) {} |
| 76 | 88 |
| 77 HeadsUpDisplayLayerImpl::~HeadsUpDisplayLayerImpl() {} | 89 HeadsUpDisplayLayerImpl::~HeadsUpDisplayLayerImpl() {} |
| 78 | 90 |
| 79 scoped_ptr<LayerImpl> HeadsUpDisplayLayerImpl::CreateLayerImpl( | 91 scoped_ptr<LayerImpl> HeadsUpDisplayLayerImpl::CreateLayerImpl( |
| 80 LayerTreeImpl* tree_impl) { | 92 LayerTreeImpl* tree_impl) { |
| 81 return HeadsUpDisplayLayerImpl::Create(tree_impl, id()).PassAs<LayerImpl>(); | 93 return HeadsUpDisplayLayerImpl::Create(tree_impl, id()).PassAs<LayerImpl>(); |
| 82 } | 94 } |
| 83 | 95 |
| 96 void HeadsUpDisplayLayerImpl::AcquireResource( | |
| 97 ResourceProvider* resource_provider) { | |
| 98 for (ScopedPtrVector<ScopedResource>::iterator it = resources_.begin(); | |
| 99 it != resources_.end(); | |
| 100 ++it) { | |
| 101 if (!resource_provider->InUseByConsumer((*it)->id())) { | |
| 102 resources_.swap(it, resources_.end() - 1); | |
| 103 return; | |
| 104 } | |
| 105 } | |
| 106 | |
| 107 scoped_ptr<ScopedResource> resource = | |
| 108 ScopedResource::Create(resource_provider); | |
| 109 resource->Allocate( | |
| 110 content_bounds(), ResourceProvider::TextureHintImmutable, RGBA_8888); | |
| 111 resources_.push_back(resource.Pass()); | |
| 112 } | |
| 113 | |
| 114 void HeadsUpDisplayLayerImpl::ReleaseUnmatchedSizeResources( | |
| 115 ResourceProvider* resource_provider) { | |
| 116 ScopedPtrVector<ScopedResource>::iterator it_erase = resources_.end(); | |
| 117 for (ScopedPtrVector<ScopedResource>::iterator it = resources_.begin(); | |
| 118 it != resources_.end(); | |
| 119 ++it) { | |
| 120 if ((*it)->size() != content_bounds()) { | |
| 121 it_erase = resources_.partition(CompareResourceSize(content_bounds())); | |
|
danakj
2014/08/29 16:42:47
if you wanna use partition, why do the for loop ar
| |
| 122 break; | |
| 123 } | |
| 124 } | |
| 125 if (it_erase != resources_.end()) | |
|
danakj
2014/08/29 16:42:46
drop the if, just erase.
| |
| 126 resources_.erase(it_erase, resources_.end()); | |
| 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 ReleaseUnmatchedSizeResources(resource_provider); |
| 90 hud_resource_ = ScopedResource::Create(resource_provider); | 135 AcquireResource(resource_provider); |
| 91 | |
| 92 // TODO(danakj): The HUD could swap between two textures instead of creating a | |
| 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 | |
| 105 return LayerImpl::WillDraw(draw_mode, resource_provider); | 136 return LayerImpl::WillDraw(draw_mode, resource_provider); |
| 106 } | 137 } |
| 107 | 138 |
| 108 void HeadsUpDisplayLayerImpl::AppendQuads( | 139 void HeadsUpDisplayLayerImpl::AppendQuads( |
| 109 RenderPass* render_pass, | 140 RenderPass* render_pass, |
| 110 const OcclusionTracker<LayerImpl>& occlusion_tracker, | 141 const OcclusionTracker<LayerImpl>& occlusion_tracker, |
| 111 AppendQuadsData* append_quads_data) { | 142 AppendQuadsData* append_quads_data) { |
| 112 if (!hud_resource_->id()) | 143 if (!resources_.back()->id()) |
| 113 return; | 144 return; |
| 114 | 145 |
| 115 SharedQuadState* shared_quad_state = | 146 SharedQuadState* shared_quad_state = |
| 116 render_pass->CreateAndAppendSharedQuadState(); | 147 render_pass->CreateAndAppendSharedQuadState(); |
| 117 PopulateSharedQuadState(shared_quad_state); | 148 PopulateSharedQuadState(shared_quad_state); |
| 118 | 149 |
| 119 gfx::Rect quad_rect(content_bounds()); | 150 gfx::Rect quad_rect(content_bounds()); |
| 120 gfx::Rect opaque_rect(contents_opaque() ? quad_rect : gfx::Rect()); | 151 gfx::Rect opaque_rect(contents_opaque() ? quad_rect : gfx::Rect()); |
| 121 gfx::Rect visible_quad_rect(quad_rect); | 152 gfx::Rect visible_quad_rect(quad_rect); |
| 122 bool premultiplied_alpha = true; | 153 bool premultiplied_alpha = true; |
| 123 gfx::PointF uv_top_left(0.f, 0.f); | 154 gfx::PointF uv_top_left(0.f, 0.f); |
| 124 gfx::PointF uv_bottom_right(1.f, 1.f); | 155 gfx::PointF uv_bottom_right(1.f, 1.f); |
| 125 const float vertex_opacity[] = { 1.f, 1.f, 1.f, 1.f }; | 156 const float vertex_opacity[] = { 1.f, 1.f, 1.f, 1.f }; |
| 126 bool flipped = false; | 157 bool flipped = false; |
| 127 TextureDrawQuad* quad = | 158 TextureDrawQuad* quad = |
| 128 render_pass->CreateAndAppendDrawQuad<TextureDrawQuad>(); | 159 render_pass->CreateAndAppendDrawQuad<TextureDrawQuad>(); |
| 129 quad->SetNew(shared_quad_state, | 160 quad->SetNew(shared_quad_state, |
| 130 quad_rect, | 161 quad_rect, |
| 131 opaque_rect, | 162 opaque_rect, |
| 132 visible_quad_rect, | 163 visible_quad_rect, |
| 133 hud_resource_->id(), | 164 resources_.back()->id(), |
| 134 premultiplied_alpha, | 165 premultiplied_alpha, |
| 135 uv_top_left, | 166 uv_top_left, |
| 136 uv_bottom_right, | 167 uv_bottom_right, |
| 137 SK_ColorTRANSPARENT, | 168 SK_ColorTRANSPARENT, |
| 138 vertex_opacity, | 169 vertex_opacity, |
| 139 flipped); | 170 flipped); |
| 140 } | 171 } |
| 141 | 172 |
| 142 void HeadsUpDisplayLayerImpl::UpdateHudTexture( | 173 void HeadsUpDisplayLayerImpl::UpdateHudTexture( |
| 143 DrawMode draw_mode, | 174 DrawMode draw_mode, |
| 144 ResourceProvider* resource_provider) { | 175 ResourceProvider* resource_provider) { |
| 145 if (draw_mode == DRAW_MODE_RESOURCELESS_SOFTWARE || !hud_resource_->id()) | 176 if (draw_mode == DRAW_MODE_RESOURCELESS_SOFTWARE || !resources_.back()->id()) |
| 146 return; | 177 return; |
| 147 | 178 |
| 148 SkISize canvas_size; | 179 SkISize canvas_size; |
| 149 if (hud_canvas_) | 180 if (hud_canvas_) |
| 150 canvas_size = hud_canvas_->getDeviceSize(); | 181 canvas_size = hud_canvas_->getDeviceSize(); |
| 151 else | 182 else |
| 152 canvas_size.set(0, 0); | 183 canvas_size.set(0, 0); |
| 153 | 184 |
| 154 if (canvas_size.width() != content_bounds().width() || | 185 if (canvas_size.width() != content_bounds().width() || |
| 155 canvas_size.height() != content_bounds().height() || !hud_canvas_) { | 186 canvas_size.height() != content_bounds().height() || !hud_canvas_) { |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 172 hud_canvas_->restore(); | 203 hud_canvas_->restore(); |
| 173 } | 204 } |
| 174 | 205 |
| 175 TRACE_EVENT0("cc", "UploadHudTexture"); | 206 TRACE_EVENT0("cc", "UploadHudTexture"); |
| 176 SkImageInfo info; | 207 SkImageInfo info; |
| 177 size_t row_bytes = 0; | 208 size_t row_bytes = 0; |
| 178 const void* pixels = hud_canvas_->peekPixels(&info, &row_bytes); | 209 const void* pixels = hud_canvas_->peekPixels(&info, &row_bytes); |
| 179 DCHECK(pixels); | 210 DCHECK(pixels); |
| 180 gfx::Rect content_rect(content_bounds()); | 211 gfx::Rect content_rect(content_bounds()); |
| 181 DCHECK(info.colorType() == kN32_SkColorType); | 212 DCHECK(info.colorType() == kN32_SkColorType); |
| 182 resource_provider->SetPixels(hud_resource_->id(), | 213 resource_provider->SetPixels(resources_.back()->id(), |
| 183 static_cast<const uint8_t*>(pixels), | 214 static_cast<const uint8_t*>(pixels), |
| 184 content_rect, | 215 content_rect, |
| 185 content_rect, | 216 content_rect, |
| 186 gfx::Vector2d()); | 217 gfx::Vector2d()); |
| 187 } | 218 } |
| 188 | 219 |
| 189 void HeadsUpDisplayLayerImpl::ReleaseResources() { hud_resource_.reset(); } | 220 void HeadsUpDisplayLayerImpl::ReleaseResources() { |
| 221 resources_.clear(); | |
| 222 } | |
| 190 | 223 |
| 191 void HeadsUpDisplayLayerImpl::UpdateHudContents() { | 224 void HeadsUpDisplayLayerImpl::UpdateHudContents() { |
| 192 const LayerTreeDebugState& debug_state = layer_tree_impl()->debug_state(); | 225 const LayerTreeDebugState& debug_state = layer_tree_impl()->debug_state(); |
| 193 | 226 |
| 194 // Don't update numbers every frame so text is readable. | 227 // Don't update numbers every frame so text is readable. |
| 195 base::TimeTicks now = layer_tree_impl()->CurrentBeginFrameArgs().frame_time; | 228 base::TimeTicks now = layer_tree_impl()->CurrentBeginFrameArgs().frame_time; |
| 196 if (base::TimeDelta(now - time_of_last_graph_update_).InSecondsF() > 0.25f) { | 229 if (base::TimeDelta(now - time_of_last_graph_update_).InSecondsF() > 0.25f) { |
| 197 time_of_last_graph_update_ = now; | 230 time_of_last_graph_update_ = now; |
| 198 | 231 |
| 199 if (debug_state.show_fps_counter) { | 232 if (debug_state.show_fps_counter) { |
| (...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 762 return "cc::HeadsUpDisplayLayerImpl"; | 795 return "cc::HeadsUpDisplayLayerImpl"; |
| 763 } | 796 } |
| 764 | 797 |
| 765 void HeadsUpDisplayLayerImpl::AsValueInto( | 798 void HeadsUpDisplayLayerImpl::AsValueInto( |
| 766 base::debug::TracedValue* dict) const { | 799 base::debug::TracedValue* dict) const { |
| 767 LayerImpl::AsValueInto(dict); | 800 LayerImpl::AsValueInto(dict); |
| 768 dict->SetString("layer_name", "Heads Up Display Layer"); | 801 dict->SetString("layer_name", "Heads Up Display Layer"); |
| 769 } | 802 } |
| 770 | 803 |
| 771 } // namespace cc | 804 } // namespace cc |
| OLD | NEW |