heads_up_display_layer_impl.h revision c2e0dbddbe15c98d52c4786dac06cb8952a8ae6d
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 virtual void DidDraw(ResourceProvider* resource_provider) OVERRIDE; 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 void DrawPlatformLayerTree(SkCanvas* canvas) const; 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