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 <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 | 210 |
211 void HeadsUpDisplayLayerImpl::ReleaseResources() { | 211 void HeadsUpDisplayLayerImpl::ReleaseResources() { |
212 resources_.clear(); | 212 resources_.clear(); |
213 } | 213 } |
214 | 214 |
215 gfx::Rect HeadsUpDisplayLayerImpl::GetEnclosingRectInTargetSpace() const { | 215 gfx::Rect HeadsUpDisplayLayerImpl::GetEnclosingRectInTargetSpace() const { |
216 DCHECK_GT(internal_contents_scale_, 0.f); | 216 DCHECK_GT(internal_contents_scale_, 0.f); |
217 return GetScaledEnclosingRectInTargetSpace(internal_contents_scale_); | 217 return GetScaledEnclosingRectInTargetSpace(internal_contents_scale_); |
218 } | 218 } |
219 | 219 |
220 void HeadsUpDisplayLayerImpl::SetHUDTypeface( | 220 void HeadsUpDisplayLayerImpl::SetHUDTypeface(sk_sp<SkTypeface> typeface) { |
221 const skia::RefPtr<SkTypeface>& typeface) { | |
222 if (typeface_ == typeface) | 221 if (typeface_ == typeface) |
223 return; | 222 return; |
224 | 223 |
225 DCHECK(typeface_.get() == nullptr); | 224 DCHECK(typeface_.get() == nullptr); |
226 typeface_ = typeface; | 225 typeface_ = std::move(typeface); |
227 NoteLayerPropertyChanged(); | 226 NoteLayerPropertyChanged(); |
228 } | 227 } |
229 | 228 |
230 void HeadsUpDisplayLayerImpl::PushPropertiesTo(LayerImpl* layer) { | 229 void HeadsUpDisplayLayerImpl::PushPropertiesTo(LayerImpl* layer) { |
231 LayerImpl::PushPropertiesTo(layer); | 230 LayerImpl::PushPropertiesTo(layer); |
232 | 231 |
233 HeadsUpDisplayLayerImpl* layer_impl = | 232 HeadsUpDisplayLayerImpl* layer_impl = |
234 static_cast<HeadsUpDisplayLayerImpl*>(layer); | 233 static_cast<HeadsUpDisplayLayerImpl*>(layer); |
235 | 234 |
236 layer_impl->SetHUDTypeface(typeface_); | 235 layer_impl->SetHUDTypeface(typeface_); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 if (debug_state.ShowMemoryStats() && memory_entry_.total_bytes_used) | 283 if (debug_state.ShowMemoryStats() && memory_entry_.total_bytes_used) |
285 DrawMemoryDisplay(canvas, 0, area.bottom(), SkMaxScalar(area.width(), 150)); | 284 DrawMemoryDisplay(canvas, 0, area.bottom(), SkMaxScalar(area.width(), 150)); |
286 } | 285 } |
287 int HeadsUpDisplayLayerImpl::MeasureText(SkPaint* paint, | 286 int HeadsUpDisplayLayerImpl::MeasureText(SkPaint* paint, |
288 const std::string& text, | 287 const std::string& text, |
289 int size) const { | 288 int size) const { |
290 DCHECK(typeface_.get()); | 289 DCHECK(typeface_.get()); |
291 const bool anti_alias = paint->isAntiAlias(); | 290 const bool anti_alias = paint->isAntiAlias(); |
292 paint->setAntiAlias(true); | 291 paint->setAntiAlias(true); |
293 paint->setTextSize(size); | 292 paint->setTextSize(size); |
294 paint->setTypeface(typeface_.get()); | 293 paint->setTypeface(typeface_); |
295 SkScalar text_width = paint->measureText(text.c_str(), text.length()); | 294 SkScalar text_width = paint->measureText(text.c_str(), text.length()); |
296 | 295 |
297 paint->setAntiAlias(anti_alias); | 296 paint->setAntiAlias(anti_alias); |
298 return SkScalarCeilToInt(text_width); | 297 return SkScalarCeilToInt(text_width); |
299 } | 298 } |
300 void HeadsUpDisplayLayerImpl::DrawText(SkCanvas* canvas, | 299 void HeadsUpDisplayLayerImpl::DrawText(SkCanvas* canvas, |
301 SkPaint* paint, | 300 SkPaint* paint, |
302 const std::string& text, | 301 const std::string& text, |
303 SkPaint::Align align, | 302 SkPaint::Align align, |
304 int size, | 303 int size, |
305 int x, | 304 int x, |
306 int y) const { | 305 int y) const { |
307 DCHECK(typeface_.get()); | 306 DCHECK(typeface_.get()); |
308 const bool anti_alias = paint->isAntiAlias(); | 307 const bool anti_alias = paint->isAntiAlias(); |
309 paint->setAntiAlias(true); | 308 paint->setAntiAlias(true); |
310 | 309 |
311 paint->setTextSize(size); | 310 paint->setTextSize(size); |
312 paint->setTextAlign(align); | 311 paint->setTextAlign(align); |
313 paint->setTypeface(typeface_.get()); | 312 paint->setTypeface(typeface_); |
314 canvas->drawText(text.c_str(), text.length(), x, y, *paint); | 313 canvas->drawText(text.c_str(), text.length(), x, y, *paint); |
315 | 314 |
316 paint->setAntiAlias(anti_alias); | 315 paint->setAntiAlias(anti_alias); |
317 } | 316 } |
318 | 317 |
319 void HeadsUpDisplayLayerImpl::DrawText(SkCanvas* canvas, | 318 void HeadsUpDisplayLayerImpl::DrawText(SkCanvas* canvas, |
320 SkPaint* paint, | 319 SkPaint* paint, |
321 const std::string& text, | 320 const std::string& text, |
322 SkPaint::Align align, | 321 SkPaint::Align align, |
323 int size, | 322 int size, |
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
678 gfx::Rect clip_rect = debug_layer_rect; | 677 gfx::Rect clip_rect = debug_layer_rect; |
679 clip_rect.Intersect(gfx::Rect(internal_content_bounds_)); | 678 clip_rect.Intersect(gfx::Rect(internal_content_bounds_)); |
680 SkRect sk_clip_rect = RectToSkRect(clip_rect); | 679 SkRect sk_clip_rect = RectToSkRect(clip_rect); |
681 | 680 |
682 canvas->save(); | 681 canvas->save(); |
683 canvas->clipRect(sk_clip_rect); | 682 canvas->clipRect(sk_clip_rect); |
684 canvas->translate(sk_clip_rect.x(), sk_clip_rect.y()); | 683 canvas->translate(sk_clip_rect.x(), sk_clip_rect.y()); |
685 | 684 |
686 SkPaint label_paint = CreatePaint(); | 685 SkPaint label_paint = CreatePaint(); |
687 label_paint.setTextSize(kFontHeight); | 686 label_paint.setTextSize(kFontHeight); |
688 label_paint.setTypeface(typeface_.get()); | 687 label_paint.setTypeface(typeface_); |
689 label_paint.setColor(stroke_color); | 688 label_paint.setColor(stroke_color); |
690 | 689 |
691 const SkScalar label_text_width = | 690 const SkScalar label_text_width = |
692 label_paint.measureText(label_text.c_str(), label_text.length()); | 691 label_paint.measureText(label_text.c_str(), label_text.length()); |
693 canvas->drawRect(SkRect::MakeWH(label_text_width + 2 * kPadding, | 692 canvas->drawRect(SkRect::MakeWH(label_text_width + 2 * kPadding, |
694 kFontHeight + 2 * kPadding), | 693 kFontHeight + 2 * kPadding), |
695 label_paint); | 694 label_paint); |
696 | 695 |
697 label_paint.setAntiAlias(true); | 696 label_paint.setAntiAlias(true); |
698 label_paint.setColor(SkColorSetARGB(255, 50, 50, 50)); | 697 label_paint.setColor(SkColorSetARGB(255, 50, 50, 50)); |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
807 return "cc::HeadsUpDisplayLayerImpl"; | 806 return "cc::HeadsUpDisplayLayerImpl"; |
808 } | 807 } |
809 | 808 |
810 void HeadsUpDisplayLayerImpl::AsValueInto( | 809 void HeadsUpDisplayLayerImpl::AsValueInto( |
811 base::trace_event::TracedValue* dict) const { | 810 base::trace_event::TracedValue* dict) const { |
812 LayerImpl::AsValueInto(dict); | 811 LayerImpl::AsValueInto(dict); |
813 dict->SetString("layer_name", "Heads Up Display Layer"); | 812 dict->SetString("layer_name", "Heads Up Display Layer"); |
814 } | 813 } |
815 | 814 |
816 } // namespace cc | 815 } // namespace cc |
OLD | NEW |