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