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 3 // found in the LICENSE file. 4 5 #ifndef CC_LAYERS_HEADS_UP_DISPLAY_LAYER_IMPL_H_ 6 #define CC_LAYERS_HEADS_UP_DISPLAY_LAYER_IMPL_H_ 7 8 #include <string> 9 10 #include "base/memory/scoped_ptr.h" 11 #include "base/time/time.h" 12 #include "cc/base/cc_export.h" 13 #include "cc/layers/layer_impl.h" 14 #include "cc/resources/memory_history.h" 15 #include "cc/resources/scoped_resource.h" 16 17 class SkCanvas; 18 class SkPaint; 19 class SkTypeface; 20 struct SkRect; 21 22 namespace cc { 23 24 class DebugRectHistory; 25 class FrameRateCounter; 26 class PaintTimeCounter; 27 28 class CC_EXPORT HeadsUpDisplayLayerImpl : public LayerImpl { 29 public: 30 static scoped_ptr<HeadsUpDisplayLayerImpl> Create(LayerTreeImpl* tree_impl, 31 int id) { 32 return make_scoped_ptr(new HeadsUpDisplayLayerImpl(tree_impl, id)); 33 } 34 virtual ~HeadsUpDisplayLayerImpl(); 35 36 virtual scoped_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl) 37 OVERRIDE; 38 39 virtual bool WillDraw(DrawMode draw_mode, 40 ResourceProvider* resource_provider) OVERRIDE; 41 virtual void AppendQuads(QuadSink* quad_sink, 42 AppendQuadsData* append_quads_data) OVERRIDE; 43 void UpdateHudTexture(DrawMode draw_mode, 44 ResourceProvider* resource_provider); 45 46 virtual void DidLoseOutputSurface() OVERRIDE; 47 48 virtual bool LayerIsAlwaysDamaged() const OVERRIDE; 49 50 private: 51 class Graph { 52 public: 53 Graph(double indicator_value, double start_upper_bound); 54 55 // Eases the upper bound, which limits what is currently visible in the 56 // graph, so that the graph always scales to either it's max or 57 // default_upper_bound. 58 double UpdateUpperBound(); 59 60 double value; 61 double min; 62 double max; 63 64 double current_upper_bound; 65 const double default_upper_bound; 66 const double indicator; 67 }; 68 69 HeadsUpDisplayLayerImpl(LayerTreeImpl* tree_impl, int id); 70 71 virtual const char* LayerTypeAsString() const OVERRIDE; 72 73 void UpdateHudContents(); 74 void DrawHudContents(SkCanvas* canvas) const; 75 76 void DrawText(SkCanvas* canvas, 77 SkPaint* paint, 78 const std::string& text, 79 SkPaint::Align align, 80 int size, 81 int x, 82 int y) const; 83 void DrawText(SkCanvas* canvas, 84 SkPaint* paint, 85 const std::string& text, 86 SkPaint::Align align, 87 int size, 88 const SkPoint& pos) const; 89 void DrawGraphBackground(SkCanvas* canvas, 90 SkPaint* paint, 91 const SkRect& bounds) const; 92 void DrawGraphLines(SkCanvas* canvas, 93 SkPaint* paint, 94 const SkRect& bounds, 95 const Graph& graph) const; 96 97 SkRect DrawFPSDisplay(SkCanvas* canvas, 98 const FrameRateCounter* fps_counter, 99 int right, 100 int top) const; 101 SkRect DrawMemoryDisplay(SkCanvas* canvas, 102 int top, 103 int right, 104 int width) const; 105 SkRect DrawPaintTimeDisplay(SkCanvas* canvas, 106 const PaintTimeCounter* paint_time_counter, 107 int top, 108 int right) const; 109 void DrawDebugRects(SkCanvas* canvas, 110 DebugRectHistory* debug_rect_history) const; 111 112 scoped_ptr<ScopedResource> hud_resource_; 113 scoped_ptr<SkCanvas> hud_canvas_; 114 115 skia::RefPtr<SkTypeface> typeface_; 116 117 Graph fps_graph_; 118 Graph paint_time_graph_; 119 MemoryHistory::Entry memory_entry_; 120 121 base::TimeTicks time_of_last_graph_update_; 122 123 DISALLOW_COPY_AND_ASSIGN(HeadsUpDisplayLayerImpl); 124 }; 125 126 } // namespace cc 127 128 #endif // CC_LAYERS_HEADS_UP_DISPLAY_LAYER_IMPL_H_ 129