Roll src/third_party/WebKit a1ed6cd:9e03af6 (svn 190836:190842)
[chromium-blink-merge.git] / cc / layers / heads_up_display_layer_impl.h
blob54bf153d1e5669e9645543d660267761f3817f9e
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.
5 #ifndef CC_LAYERS_HEADS_UP_DISPLAY_LAYER_IMPL_H_
6 #define CC_LAYERS_HEADS_UP_DISPLAY_LAYER_IMPL_H_
8 #include <string>
9 #include <vector>
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"
19 class SkCanvas;
20 class SkPaint;
21 class SkTypeface;
22 struct SkRect;
24 namespace cc {
26 class FrameRateCounter;
27 class PaintTimeCounter;
29 class CC_EXPORT HeadsUpDisplayLayerImpl : public LayerImpl {
30 public:
31 static scoped_ptr<HeadsUpDisplayLayerImpl> Create(LayerTreeImpl* tree_impl,
32 int id) {
33 return make_scoped_ptr(new HeadsUpDisplayLayerImpl(tree_impl, id));
35 ~HeadsUpDisplayLayerImpl() override;
37 scoped_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl) override;
39 bool WillDraw(DrawMode draw_mode,
40 ResourceProvider* resource_provider) override;
41 void AppendQuads(RenderPass* render_pass,
42 AppendQuadsData* append_quads_data) override;
43 void UpdateHudTexture(DrawMode draw_mode,
44 ResourceProvider* resource_provider);
46 void ReleaseResources() override;
48 bool IsAnimatingHUDContents() const { return fade_step_ > 0; }
50 private:
51 class Graph {
52 public:
53 Graph(double indicator_value, double start_upper_bound);
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();
60 double value;
61 double min;
62 double max;
64 double current_upper_bound;
65 const double default_upper_bound;
66 const double indicator;
69 HeadsUpDisplayLayerImpl(LayerTreeImpl* tree_impl, int id);
71 const char* LayerTypeAsString() const override;
73 void AsValueInto(base::trace_event::TracedValue* dict) const override;
75 void UpdateHudContents();
76 void DrawHudContents(SkCanvas* canvas);
78 void DrawText(SkCanvas* canvas,
79 SkPaint* paint,
80 const std::string& text,
81 SkPaint::Align align,
82 int size,
83 int x,
84 int y) const;
85 void DrawText(SkCanvas* canvas,
86 SkPaint* paint,
87 const std::string& text,
88 SkPaint::Align align,
89 int size,
90 const SkPoint& pos) const;
91 void DrawGraphBackground(SkCanvas* canvas,
92 SkPaint* paint,
93 const SkRect& bounds) const;
94 void DrawGraphLines(SkCanvas* canvas,
95 SkPaint* paint,
96 const SkRect& bounds,
97 const Graph& graph) const;
99 SkRect DrawFPSDisplay(SkCanvas* canvas,
100 const FrameRateCounter* fps_counter,
101 int right,
102 int top) const;
103 SkRect DrawMemoryDisplay(SkCanvas* canvas,
104 int top,
105 int right,
106 int width) const;
107 SkRect DrawGpuRasterizationStatus(SkCanvas* canvas,
108 int right,
109 int top,
110 int width) const;
111 SkRect DrawPaintTimeDisplay(SkCanvas* canvas,
112 const PaintTimeCounter* paint_time_counter,
113 int top,
114 int right) const;
115 void DrawDebugRect(SkCanvas* canvas,
116 SkPaint* paint,
117 const DebugRect& rect,
118 SkColor stroke_color,
119 SkColor fill_color,
120 float stroke_width,
121 const std::string& label_text) const;
122 void DrawDebugRects(SkCanvas* canvas, DebugRectHistory* debug_rect_history);
124 void AcquireResource(ResourceProvider* resource_provider);
125 void ReleaseUnmatchedSizeResources(ResourceProvider* resource_provider);
127 ScopedPtrVector<ScopedResource> resources_;
128 skia::RefPtr<SkSurface> hud_surface_;
130 skia::RefPtr<SkTypeface> typeface_;
132 float internal_contents_scale_;
133 gfx::Size internal_content_bounds_;
135 Graph fps_graph_;
136 Graph paint_time_graph_;
137 MemoryHistory::Entry memory_entry_;
138 int fade_step_;
139 std::vector<DebugRect> paint_rects_;
141 base::TimeTicks time_of_last_graph_update_;
143 DISALLOW_COPY_AND_ASSIGN(HeadsUpDisplayLayerImpl);
146 } // namespace cc
148 #endif // CC_LAYERS_HEADS_UP_DISPLAY_LAYER_IMPL_H_