heads_up_display_layer_impl.h revision a93a17c8d99d686bd4a1511e5504e5e6cc9fcadf
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.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 void WillDraw(ResourceProvider* resource_provider) OVERRIDE; 40 virtual void AppendQuads(QuadSink* quad_sink, 41 AppendQuadsData* append_quads_data) OVERRIDE; 42 void UpdateHudTexture(ResourceProvider* resource_provider); 43 44 virtual void DidLoseOutputSurface() OVERRIDE; 45 46 virtual bool LayerIsAlwaysDamaged() const OVERRIDE; 47 48 private: 49 class Graph { 50 public: 51 Graph(double indicator_value, double start_upper_bound); 52 53 // Eases the upper bound, which limits what is currently visible in the 54 // graph, so that the graph always scales to either it's max or 55 // default_upper_bound. 56 double UpdateUpperBound(); 57 58 double value; 59 double min; 60 double max; 61 62 double current_upper_bound; 63 const double default_upper_bound; 64 const double indicator; 65 }; 66 67 HeadsUpDisplayLayerImpl(LayerTreeImpl* tree_impl, int id); 68 69 virtual const char* LayerTypeAsString() const OVERRIDE; 70 71 void UpdateHudContents(); 72 void DrawHudContents(SkCanvas* canvas) const; 73 74 void DrawText(SkCanvas* canvas, 75 SkPaint* paint, 76 const std::string& text, 77 SkPaint::Align align, 78 int size, 79 int x, 80 int y) const; 81 void DrawText(SkCanvas* canvas, 82 SkPaint* paint, 83 const std::string& text, 84 SkPaint::Align align, 85 int size, 86 const SkPoint& pos) const; 87 void DrawGraphBackground(SkCanvas* canvas, 88 SkPaint* paint, 89 const SkRect& bounds) const; 90 void DrawGraphLines(SkCanvas* canvas, 91 SkPaint* paint, 92 const SkRect& bounds, 93 const Graph& graph) const; 94 95 void DrawPlatformLayerTree(SkCanvas* canvas) const; 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