| 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 | 63 |
| 64 double HeadsUpDisplayLayerImpl::Graph::UpdateUpperBound() { | 64 double HeadsUpDisplayLayerImpl::Graph::UpdateUpperBound() { |
| 65 double target_upper_bound = std::max(max, default_upper_bound); | 65 double target_upper_bound = std::max(max, default_upper_bound); |
| 66 current_upper_bound += (target_upper_bound - current_upper_bound) * 0.5; | 66 current_upper_bound += (target_upper_bound - current_upper_bound) * 0.5; |
| 67 return current_upper_bound; | 67 return current_upper_bound; |
| 68 } | 68 } |
| 69 | 69 |
| 70 HeadsUpDisplayLayerImpl::HeadsUpDisplayLayerImpl(LayerTreeImpl* tree_impl, | 70 HeadsUpDisplayLayerImpl::HeadsUpDisplayLayerImpl(LayerTreeImpl* tree_impl, |
| 71 int id) | 71 int id) |
| 72 : LayerImpl(tree_impl, id), | 72 : LayerImpl(tree_impl, id), |
| 73 typeface_(skia::AdoptRef( |
| 74 SkTypeface::CreateFromName("monospace", SkTypeface::kBold))), |
| 73 internal_contents_scale_(1.f), | 75 internal_contents_scale_(1.f), |
| 74 fps_graph_(60.0, 80.0), | 76 fps_graph_(60.0, 80.0), |
| 75 paint_time_graph_(16.0, 48.0), | 77 paint_time_graph_(16.0, 48.0), |
| 76 fade_step_(0) { | 78 fade_step_(0) { |
| 77 } | 79 } |
| 78 | 80 |
| 79 HeadsUpDisplayLayerImpl::~HeadsUpDisplayLayerImpl() {} | 81 HeadsUpDisplayLayerImpl::~HeadsUpDisplayLayerImpl() {} |
| 80 | 82 |
| 81 scoped_ptr<LayerImpl> HeadsUpDisplayLayerImpl::CreateLayerImpl( | 83 scoped_ptr<LayerImpl> HeadsUpDisplayLayerImpl::CreateLayerImpl( |
| 82 LayerTreeImpl* tree_impl) { | 84 LayerTreeImpl* tree_impl) { |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 nearest_neighbor); | 172 nearest_neighbor); |
| 171 } | 173 } |
| 172 | 174 |
| 173 void HeadsUpDisplayLayerImpl::UpdateHudTexture( | 175 void HeadsUpDisplayLayerImpl::UpdateHudTexture( |
| 174 DrawMode draw_mode, | 176 DrawMode draw_mode, |
| 175 ResourceProvider* resource_provider) { | 177 ResourceProvider* resource_provider) { |
| 176 if (draw_mode == DRAW_MODE_RESOURCELESS_SOFTWARE || !resources_.back()->id()) | 178 if (draw_mode == DRAW_MODE_RESOURCELESS_SOFTWARE || !resources_.back()->id()) |
| 177 return; | 179 return; |
| 178 | 180 |
| 179 SkISize canvas_size; | 181 SkISize canvas_size; |
| 180 if (hud_surface_) | 182 if (hud_canvas_) |
| 181 canvas_size = hud_surface_->getCanvas()->getDeviceSize(); | 183 canvas_size = hud_canvas_->getDeviceSize(); |
| 182 else | 184 else |
| 183 canvas_size.set(0, 0); | 185 canvas_size.set(0, 0); |
| 184 | 186 |
| 185 if (canvas_size.width() != internal_content_bounds_.width() || | 187 if (canvas_size.width() != internal_content_bounds_.width() || |
| 186 canvas_size.height() != internal_content_bounds_.height() || | 188 canvas_size.height() != internal_content_bounds_.height() || |
| 187 !hud_surface_) { | 189 !hud_canvas_) { |
| 188 TRACE_EVENT0("cc", "ResizeHudCanvas"); | 190 TRACE_EVENT0("cc", "ResizeHudCanvas"); |
| 189 | 191 |
| 190 hud_surface_ = skia::AdoptRef(SkSurface::NewRasterN32Premul( | 192 bool opaque = false; |
| 191 internal_content_bounds_.width(), internal_content_bounds_.height())); | 193 hud_canvas_ = make_scoped_ptr( |
| 194 skia::CreateBitmapCanvas(internal_content_bounds_.width(), |
| 195 internal_content_bounds_.height(), opaque)); |
| 192 } | 196 } |
| 193 | 197 |
| 194 UpdateHudContents(); | 198 UpdateHudContents(); |
| 195 | 199 |
| 196 { | 200 { |
| 197 TRACE_EVENT0("cc", "DrawHudContents"); | 201 TRACE_EVENT0("cc", "DrawHudContents"); |
| 198 hud_surface_->getCanvas()->clear(SkColorSetARGB(0, 0, 0, 0)); | 202 hud_canvas_->clear(SkColorSetARGB(0, 0, 0, 0)); |
| 199 hud_surface_->getCanvas()->save(); | 203 hud_canvas_->save(); |
| 200 hud_surface_->getCanvas()->scale(internal_contents_scale_, | 204 hud_canvas_->scale(internal_contents_scale_, internal_contents_scale_); |
| 201 internal_contents_scale_); | |
| 202 | 205 |
| 203 DrawHudContents(hud_surface_->getCanvas()); | 206 DrawHudContents(hud_canvas_.get()); |
| 204 | 207 |
| 205 hud_surface_->getCanvas()->restore(); | 208 hud_canvas_->restore(); |
| 206 } | 209 } |
| 207 | 210 |
| 208 TRACE_EVENT0("cc", "UploadHudTexture"); | 211 TRACE_EVENT0("cc", "UploadHudTexture"); |
| 209 SkImageInfo info; | 212 SkImageInfo info; |
| 210 size_t row_bytes = 0; | 213 size_t row_bytes = 0; |
| 211 const void* pixels = hud_surface_->getCanvas()->peekPixels(&info, &row_bytes); | 214 const void* pixels = hud_canvas_->peekPixels(&info, &row_bytes); |
| 212 DCHECK(pixels); | 215 DCHECK(pixels); |
| 213 DCHECK(info.colorType() == kN32_SkColorType); | 216 DCHECK(info.colorType() == kN32_SkColorType); |
| 214 resource_provider->CopyToResource(resources_.back()->id(), | 217 resource_provider->CopyToResource(resources_.back()->id(), |
| 215 static_cast<const uint8_t*>(pixels), | 218 static_cast<const uint8_t*>(pixels), |
| 216 internal_content_bounds_); | 219 internal_content_bounds_); |
| 217 } | 220 } |
| 218 | 221 |
| 219 void HeadsUpDisplayLayerImpl::ReleaseResources() { | 222 void HeadsUpDisplayLayerImpl::ReleaseResources() { |
| 220 resources_.clear(); | 223 resources_.clear(); |
| 221 } | 224 } |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 const std::string& text, | 299 const std::string& text, |
| 297 SkPaint::Align align, | 300 SkPaint::Align align, |
| 298 int size, | 301 int size, |
| 299 int x, | 302 int x, |
| 300 int y) const { | 303 int y) const { |
| 301 const bool anti_alias = paint->isAntiAlias(); | 304 const bool anti_alias = paint->isAntiAlias(); |
| 302 paint->setAntiAlias(true); | 305 paint->setAntiAlias(true); |
| 303 | 306 |
| 304 paint->setTextSize(size); | 307 paint->setTextSize(size); |
| 305 paint->setTextAlign(align); | 308 paint->setTextAlign(align); |
| 306 paint->setTypeface(layer_tree_impl()->settings().hud_typeface.get()); | 309 paint->setTypeface(typeface_.get()); |
| 307 canvas->drawText(text.c_str(), text.length(), x, y, *paint); | 310 canvas->drawText(text.c_str(), text.length(), x, y, *paint); |
| 308 | 311 |
| 309 paint->setAntiAlias(anti_alias); | 312 paint->setAntiAlias(anti_alias); |
| 310 } | 313 } |
| 311 | 314 |
| 312 void HeadsUpDisplayLayerImpl::DrawText(SkCanvas* canvas, | 315 void HeadsUpDisplayLayerImpl::DrawText(SkCanvas* canvas, |
| 313 SkPaint* paint, | 316 SkPaint* paint, |
| 314 const std::string& text, | 317 const std::string& text, |
| 315 SkPaint::Align align, | 318 SkPaint::Align align, |
| 316 int size, | 319 int size, |
| (...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 703 gfx::Rect clip_rect = debug_layer_rect; | 706 gfx::Rect clip_rect = debug_layer_rect; |
| 704 clip_rect.Intersect(gfx::Rect(internal_content_bounds_)); | 707 clip_rect.Intersect(gfx::Rect(internal_content_bounds_)); |
| 705 SkRect sk_clip_rect = RectToSkRect(clip_rect); | 708 SkRect sk_clip_rect = RectToSkRect(clip_rect); |
| 706 | 709 |
| 707 canvas->save(); | 710 canvas->save(); |
| 708 canvas->clipRect(sk_clip_rect); | 711 canvas->clipRect(sk_clip_rect); |
| 709 canvas->translate(sk_clip_rect.x(), sk_clip_rect.y()); | 712 canvas->translate(sk_clip_rect.x(), sk_clip_rect.y()); |
| 710 | 713 |
| 711 SkPaint label_paint = CreatePaint(); | 714 SkPaint label_paint = CreatePaint(); |
| 712 label_paint.setTextSize(kFontHeight); | 715 label_paint.setTextSize(kFontHeight); |
| 713 label_paint.setTypeface(layer_tree_impl()->settings().hud_typeface.get()); | 716 label_paint.setTypeface(typeface_.get()); |
| 714 label_paint.setColor(stroke_color); | 717 label_paint.setColor(stroke_color); |
| 715 | 718 |
| 716 const SkScalar label_text_width = | 719 const SkScalar label_text_width = |
| 717 label_paint.measureText(label_text.c_str(), label_text.length()); | 720 label_paint.measureText(label_text.c_str(), label_text.length()); |
| 718 canvas->drawRect(SkRect::MakeWH(label_text_width + 2 * kPadding, | 721 canvas->drawRect(SkRect::MakeWH(label_text_width + 2 * kPadding, |
| 719 kFontHeight + 2 * kPadding), | 722 kFontHeight + 2 * kPadding), |
| 720 label_paint); | 723 label_paint); |
| 721 | 724 |
| 722 label_paint.setAntiAlias(true); | 725 label_paint.setAntiAlias(true); |
| 723 label_paint.setColor(SkColorSetARGB(255, 50, 50, 50)); | 726 label_paint.setColor(SkColorSetARGB(255, 50, 50, 50)); |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 832 return "cc::HeadsUpDisplayLayerImpl"; | 835 return "cc::HeadsUpDisplayLayerImpl"; |
| 833 } | 836 } |
| 834 | 837 |
| 835 void HeadsUpDisplayLayerImpl::AsValueInto( | 838 void HeadsUpDisplayLayerImpl::AsValueInto( |
| 836 base::trace_event::TracedValue* dict) const { | 839 base::trace_event::TracedValue* dict) const { |
| 837 LayerImpl::AsValueInto(dict); | 840 LayerImpl::AsValueInto(dict); |
| 838 dict->SetString("layer_name", "Heads Up Display Layer"); | 841 dict->SetString("layer_name", "Heads Up Display Layer"); |
| 839 } | 842 } |
| 840 | 843 |
| 841 } // namespace cc | 844 } // namespace cc |
| OLD | NEW |