| 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/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 default_upper_bound(start_upper_bound), | 60 default_upper_bound(start_upper_bound), |
| 61 indicator(indicator_value) {} | 61 indicator(indicator_value) {} |
| 62 | 62 |
| 63 double HeadsUpDisplayLayerImpl::Graph::UpdateUpperBound() { | 63 double HeadsUpDisplayLayerImpl::Graph::UpdateUpperBound() { |
| 64 double target_upper_bound = std::max(max, default_upper_bound); | 64 double target_upper_bound = std::max(max, default_upper_bound); |
| 65 current_upper_bound += (target_upper_bound - current_upper_bound) * 0.5; | 65 current_upper_bound += (target_upper_bound - current_upper_bound) * 0.5; |
| 66 return current_upper_bound; | 66 return current_upper_bound; |
| 67 } | 67 } |
| 68 | 68 |
| 69 HeadsUpDisplayLayerImpl::HeadsUpDisplayLayerImpl(LayerTreeImpl* tree_impl, | 69 HeadsUpDisplayLayerImpl::HeadsUpDisplayLayerImpl(LayerTreeImpl* tree_impl, |
| 70 int id) | 70 int id, |
| 71 SkTypeface* typeface) |
| 71 : LayerImpl(tree_impl, id), | 72 : LayerImpl(tree_impl, id), |
| 72 typeface_(skia::AdoptRef( | 73 hud_canvas_(nullptr), |
| 73 SkTypeface::CreateFromName("monospace", SkTypeface::kBold))), | 74 typeface_(typeface), |
| 74 fps_graph_(60.0, 80.0), | 75 fps_graph_(60.0, 80.0), |
| 75 paint_time_graph_(16.0, 48.0), | 76 paint_time_graph_(16.0, 48.0), |
| 76 fade_step_(0) {} | 77 fade_step_(0) { |
| 78 } |
| 77 | 79 |
| 78 HeadsUpDisplayLayerImpl::~HeadsUpDisplayLayerImpl() {} | 80 HeadsUpDisplayLayerImpl::~HeadsUpDisplayLayerImpl() {} |
| 79 | 81 |
| 80 scoped_ptr<LayerImpl> HeadsUpDisplayLayerImpl::CreateLayerImpl( | 82 scoped_ptr<LayerImpl> HeadsUpDisplayLayerImpl::CreateLayerImpl( |
| 81 LayerTreeImpl* tree_impl) { | 83 LayerTreeImpl* tree_impl) { |
| 82 return HeadsUpDisplayLayerImpl::Create(tree_impl, id()); | 84 return HeadsUpDisplayLayerImpl::Create(tree_impl, id(), typeface_); |
| 83 } | 85 } |
| 84 | 86 |
| 85 void HeadsUpDisplayLayerImpl::AcquireResource( | 87 void HeadsUpDisplayLayerImpl::AcquireResource( |
| 86 ResourceProvider* resource_provider) { | 88 ResourceProvider* resource_provider) { |
| 87 for (ScopedPtrVector<ScopedResource>::iterator it = resources_.begin(); | 89 for (ScopedPtrVector<ScopedResource>::iterator it = resources_.begin(); |
| 88 it != resources_.end(); | 90 it != resources_.end(); |
| 89 ++it) { | 91 ++it) { |
| 90 if (!resource_provider->InUseByConsumer((*it)->id())) { | 92 if (!resource_provider->InUseByConsumer((*it)->id())) { |
| 91 resources_.swap(it, resources_.end() - 1); | 93 resources_.swap(it, resources_.end() - 1); |
| 92 return; | 94 return; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 | 176 |
| 175 SkISize canvas_size; | 177 SkISize canvas_size; |
| 176 if (hud_canvas_) | 178 if (hud_canvas_) |
| 177 canvas_size = hud_canvas_->getDeviceSize(); | 179 canvas_size = hud_canvas_->getDeviceSize(); |
| 178 else | 180 else |
| 179 canvas_size.set(0, 0); | 181 canvas_size.set(0, 0); |
| 180 | 182 |
| 181 if (canvas_size.width() != content_bounds().width() || | 183 if (canvas_size.width() != content_bounds().width() || |
| 182 canvas_size.height() != content_bounds().height() || !hud_canvas_) { | 184 canvas_size.height() != content_bounds().height() || !hud_canvas_) { |
| 183 TRACE_EVENT0("cc", "ResizeHudCanvas"); | 185 TRACE_EVENT0("cc", "ResizeHudCanvas"); |
| 184 bool opaque = false; | 186 |
| 185 hud_canvas_ = make_scoped_ptr(skia::CreateBitmapCanvas( | 187 hud_surface_ = skia::AdoptRef(SkSurface::NewRasterN32Premul( |
| 186 content_bounds().width(), content_bounds().height(), opaque)); | 188 content_bounds().width(), content_bounds().height())); |
| 189 hud_canvas_ = hud_surface_->getCanvas(); |
| 187 } | 190 } |
| 188 | 191 |
| 189 UpdateHudContents(); | 192 UpdateHudContents(); |
| 190 | 193 |
| 191 { | 194 { |
| 192 TRACE_EVENT0("cc", "DrawHudContents"); | 195 TRACE_EVENT0("cc", "DrawHudContents"); |
| 193 hud_canvas_->clear(SkColorSetARGB(0, 0, 0, 0)); | 196 hud_canvas_->clear(SkColorSetARGB(0, 0, 0, 0)); |
| 194 hud_canvas_->save(); | 197 hud_canvas_->save(); |
| 195 hud_canvas_->scale(contents_scale_x(), contents_scale_y()); | 198 hud_canvas_->scale(contents_scale_x(), contents_scale_y()); |
| 196 | 199 |
| 197 DrawHudContents(hud_canvas_.get()); | 200 DrawHudContents(hud_canvas_); |
| 198 | 201 |
| 199 hud_canvas_->restore(); | 202 hud_canvas_->restore(); |
| 200 } | 203 } |
| 201 | 204 |
| 202 TRACE_EVENT0("cc", "UploadHudTexture"); | 205 TRACE_EVENT0("cc", "UploadHudTexture"); |
| 203 SkImageInfo info; | 206 SkImageInfo info; |
| 204 size_t row_bytes = 0; | 207 size_t row_bytes = 0; |
| 205 const void* pixels = hud_canvas_->peekPixels(&info, &row_bytes); | 208 const void* pixels = hud_canvas_->peekPixels(&info, &row_bytes); |
| 206 DCHECK(pixels); | 209 DCHECK(pixels); |
| 207 gfx::Rect content_rect(content_bounds()); | 210 gfx::Rect content_rect(content_bounds()); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 const std::string& text, | 296 const std::string& text, |
| 294 SkPaint::Align align, | 297 SkPaint::Align align, |
| 295 int size, | 298 int size, |
| 296 int x, | 299 int x, |
| 297 int y) const { | 300 int y) const { |
| 298 const bool anti_alias = paint->isAntiAlias(); | 301 const bool anti_alias = paint->isAntiAlias(); |
| 299 paint->setAntiAlias(true); | 302 paint->setAntiAlias(true); |
| 300 | 303 |
| 301 paint->setTextSize(size); | 304 paint->setTextSize(size); |
| 302 paint->setTextAlign(align); | 305 paint->setTextAlign(align); |
| 303 paint->setTypeface(typeface_.get()); | 306 paint->setTypeface(typeface_); |
| 304 canvas->drawText(text.c_str(), text.length(), x, y, *paint); | 307 canvas->drawText(text.c_str(), text.length(), x, y, *paint); |
| 305 | 308 |
| 306 paint->setAntiAlias(anti_alias); | 309 paint->setAntiAlias(anti_alias); |
| 307 } | 310 } |
| 308 | 311 |
| 309 void HeadsUpDisplayLayerImpl::DrawText(SkCanvas* canvas, | 312 void HeadsUpDisplayLayerImpl::DrawText(SkCanvas* canvas, |
| 310 SkPaint* paint, | 313 SkPaint* paint, |
| 311 const std::string& text, | 314 const std::string& text, |
| 312 SkPaint::Align align, | 315 SkPaint::Align align, |
| 313 int size, | 316 int size, |
| (...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 699 gfx::Rect clip_rect = debug_layer_rect; | 702 gfx::Rect clip_rect = debug_layer_rect; |
| 700 clip_rect.Intersect(gfx::Rect(content_bounds())); | 703 clip_rect.Intersect(gfx::Rect(content_bounds())); |
| 701 SkRect sk_clip_rect = RectToSkRect(clip_rect); | 704 SkRect sk_clip_rect = RectToSkRect(clip_rect); |
| 702 | 705 |
| 703 canvas->save(); | 706 canvas->save(); |
| 704 canvas->clipRect(sk_clip_rect); | 707 canvas->clipRect(sk_clip_rect); |
| 705 canvas->translate(sk_clip_rect.x(), sk_clip_rect.y()); | 708 canvas->translate(sk_clip_rect.x(), sk_clip_rect.y()); |
| 706 | 709 |
| 707 SkPaint label_paint = CreatePaint(); | 710 SkPaint label_paint = CreatePaint(); |
| 708 label_paint.setTextSize(kFontHeight); | 711 label_paint.setTextSize(kFontHeight); |
| 709 label_paint.setTypeface(typeface_.get()); | 712 label_paint.setTypeface(typeface_); |
| 710 label_paint.setColor(stroke_color); | 713 label_paint.setColor(stroke_color); |
| 711 | 714 |
| 712 const SkScalar label_text_width = | 715 const SkScalar label_text_width = |
| 713 label_paint.measureText(label_text.c_str(), label_text.length()); | 716 label_paint.measureText(label_text.c_str(), label_text.length()); |
| 714 canvas->drawRect(SkRect::MakeWH(label_text_width + 2 * kPadding, | 717 canvas->drawRect(SkRect::MakeWH(label_text_width + 2 * kPadding, |
| 715 kFontHeight + 2 * kPadding), | 718 kFontHeight + 2 * kPadding), |
| 716 label_paint); | 719 label_paint); |
| 717 | 720 |
| 718 label_paint.setAntiAlias(true); | 721 label_paint.setAntiAlias(true); |
| 719 label_paint.setColor(SkColorSetARGB(255, 50, 50, 50)); | 722 label_paint.setColor(SkColorSetARGB(255, 50, 50, 50)); |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 838 return "cc::HeadsUpDisplayLayerImpl"; | 841 return "cc::HeadsUpDisplayLayerImpl"; |
| 839 } | 842 } |
| 840 | 843 |
| 841 void HeadsUpDisplayLayerImpl::AsValueInto( | 844 void HeadsUpDisplayLayerImpl::AsValueInto( |
| 842 base::debug::TracedValue* dict) const { | 845 base::debug::TracedValue* dict) const { |
| 843 LayerImpl::AsValueInto(dict); | 846 LayerImpl::AsValueInto(dict); |
| 844 dict->SetString("layer_name", "Heads Up Display Layer"); | 847 dict->SetString("layer_name", "Heads Up Display Layer"); |
| 845 } | 848 } |
| 846 | 849 |
| 847 } // namespace cc | 850 } // namespace cc |
| OLD | NEW |