heads_up_display_layer_impl.h revision eb525c5499e34cc9c4b825d6d9e75bb07cc06ace
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 17class SkCanvas; 18class SkPaint; 19class SkTypeface; 20struct SkRect; 21 22namespace cc { 23 24class DebugRectHistory; 25class FrameRateCounter; 26class PaintTimeCounter; 27 28class 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(ResourceProvider* resource_provider); 44 45 virtual void DidLoseOutputSurface() OVERRIDE; 46 47 virtual bool LayerIsAlwaysDamaged() const OVERRIDE; 48 49 private: 50 class Graph { 51 public: 52 Graph(double indicator_value, double start_upper_bound); 53 54 // Eases the upper bound, which limits what is currently visible in the 55 // graph, so that the graph always scales to either it's max or 56 // default_upper_bound. 57 double UpdateUpperBound(); 58 59 double value; 60 double min; 61 double max; 62 63 double current_upper_bound; 64 const double default_upper_bound; 65 const double indicator; 66 }; 67 68 HeadsUpDisplayLayerImpl(LayerTreeImpl* tree_impl, int id); 69 70 virtual const char* LayerTypeAsString() const OVERRIDE; 71 72 void UpdateHudContents(); 73 void DrawHudContents(SkCanvas* canvas) const; 74 75 void DrawText(SkCanvas* canvas, 76 SkPaint* paint, 77 const std::string& text, 78 SkPaint::Align align, 79 int size, 80 int x, 81 int y) const; 82 void DrawText(SkCanvas* canvas, 83 SkPaint* paint, 84 const std::string& text, 85 SkPaint::Align align, 86 int size, 87 const SkPoint& pos) const; 88 void DrawGraphBackground(SkCanvas* canvas, 89 SkPaint* paint, 90 const SkRect& bounds) const; 91 void DrawGraphLines(SkCanvas* canvas, 92 SkPaint* paint, 93 const SkRect& bounds, 94 const Graph& graph) const; 95 96 SkRect DrawFPSDisplay(SkCanvas* canvas, 97 const FrameRateCounter* fps_counter, 98 int right, 99 int top) const; 100 SkRect DrawMemoryDisplay(SkCanvas* canvas, 101 int top, 102 int right, 103 int width) const; 104 SkRect DrawPaintTimeDisplay(SkCanvas* canvas, 105 const PaintTimeCounter* paint_time_counter, 106 int top, 107 int right) const; 108 void DrawDebugRects(SkCanvas* canvas, 109 DebugRectHistory* debug_rect_history) const; 110 111 scoped_ptr<ScopedResource> hud_resource_; 112 scoped_ptr<SkCanvas> hud_canvas_; 113 114 skia::RefPtr<SkTypeface> typeface_; 115 116 Graph fps_graph_; 117 Graph paint_time_graph_; 118 MemoryHistory::Entry memory_entry_; 119 120 base::TimeTicks time_of_last_graph_update_; 121 122 DISALLOW_COPY_AND_ASSIGN(HeadsUpDisplayLayerImpl); 123}; 124 125} // namespace cc 126 127#endif // CC_LAYERS_HEADS_UP_DISPLAY_LAYER_IMPL_H_ 128