OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/tabs/tab_audio_indicator.h" | 5 #include "chrome/browser/ui/tabs/tab_audio_indicator.h" |
6 | 6 |
7 #include "grit/theme_resources.h" | 7 #include "grit/theme_resources.h" |
8 #include "ui/base/animation/animation_container.h" | 8 #include "ui/base/animation/animation_container.h" |
9 #include "ui/base/animation/linear_animation.h" | 9 #include "ui/base/animation/linear_animation.h" |
10 #include "ui/base/resource/resource_bundle.h" | 10 #include "ui/base/resource/resource_bundle.h" |
11 #include "ui/gfx/canvas.h" | 11 #include "ui/gfx/canvas.h" |
12 #include "ui/gfx/rect.h" | 12 #include "ui/gfx/rect.h" |
13 #include "ui/gfx/skia_util.h" | 13 #include "ui/gfx/skia_util.h" |
14 | 14 |
15 namespace { | 15 namespace { |
16 | 16 |
17 // The number of columns to draw for the equalizer graphic. | 17 // The number of columns to draw for the equalizer graphic. |
18 const size_t kEqualizerColumnCount = 3; | 18 const size_t kEqualizerColumnCount = 3; |
19 | 19 |
20 // The equalizer cycles between these frames. An equalizer frame is 2 columns | 20 // The equalizer cycles between these frames. An equalizer frame is 2 columns |
21 // where each column ranges from 0 to 4. | 21 // where each column ranges from 0 to 4. |
22 const size_t kEqualizerFrames[][kEqualizerColumnCount] = { | 22 const size_t kEqualizerFrames[][kEqualizerColumnCount] = { |
23 { 0, 1, 2 }, | 23 { 1, 1, 1 }, |
24 { 1, 2, 3 }, | 24 { 1, 2, 2 }, |
25 { 2, 3, 2 }, | 25 { 2, 2, 3 }, |
26 { 3, 2, 1 }, | 26 { 3, 3, 2 }, |
27 { 2, 1, 0 }, | 27 { 3, 2, 1 }, |
28 { 1, 0, 1 }, | 28 { 2, 1, 2 }, |
29 { 0, 1, 2 }, | 29 { 1, 2, 3 }, |
30 { 0, 0, 2 }, | 30 { 2, 1, 2 }, |
31 { 0, 0, 1 }, | 31 { 3, 2, 1 }, |
32 { 1, 0, 0 }, | 32 { 3, 2, 1 }, |
33 { 2, 1, 0 }, | 33 { 2, 3, 2 }, |
34 { 1, 0, 1 }, | 34 { 1, 2, 3 }, |
| 35 { 2, 1, 2 }, |
35 }; | 36 }; |
36 | 37 |
37 // The space between equalizer levels. | 38 // The space between equalizer levels. |
38 const int kEqualizerColumnPadding = 1; | 39 const int kEqualizerColumnPadding = 1; |
39 | 40 |
40 // The duration of each equalizer frame. | 41 // The duration of each equalizer frame. |
41 const size_t kAnimationCycleDurationMs = 300; | 42 const size_t kAnimationCycleDurationMs = 250; |
42 | 43 |
43 // The duration of the "ending" animation once audio stops playing. | 44 // The duration of the "ending" animation once audio stops playing. |
44 const size_t kAnimationEndingDurationMs = 1000; | 45 const size_t kAnimationEndingDurationMs = 1000; |
45 | 46 |
46 // Target frames per second. In reality fewer frames are drawn because the | 47 // Target frames per second. In reality fewer frames are drawn because the |
47 // equalizer levels change slowly. | 48 // equalizer levels change slowly. |
48 const int kFPS = 15; | 49 const int kFPS = 15; |
49 | 50 |
50 } // namespace | 51 } // namespace |
51 | 52 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 | 90 |
90 // Draw 3 equalizer columns. |IDR_AUDIO_EQUALIZER_COLUMN| is a column of the | 91 // Draw 3 equalizer columns. |IDR_AUDIO_EQUALIZER_COLUMN| is a column of the |
91 // equalizer with 4 levels. The current level is between 0 and 4 so the | 92 // equalizer with 4 levels. The current level is between 0 and 4 so the |
92 // image is shifted down and then drawn. | 93 // image is shifted down and then drawn. |
93 if (state_ != STATE_NOT_ANIMATING) { | 94 if (state_ != STATE_NOT_ANIMATING) { |
94 ui::ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 95 ui::ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
95 gfx::ImageSkia* image(rb.GetImageSkiaNamed(IDR_AUDIO_EQUALIZER_COLUMN)); | 96 gfx::ImageSkia* image(rb.GetImageSkiaNamed(IDR_AUDIO_EQUALIZER_COLUMN)); |
96 int x = rect.right(); | 97 int x = rect.right(); |
97 std::vector<int> levels = GetCurrentEqualizerLevels(); | 98 std::vector<int> levels = GetCurrentEqualizerLevels(); |
98 for (int i = levels.size() - 1; i >= 0; --i) { | 99 for (int i = levels.size() - 1; i >= 0; --i) { |
| 100 x -= image->width(); |
99 if (levels[i] == 0) | 101 if (levels[i] == 0) |
100 continue; | 102 continue; |
101 | 103 |
102 // Shift the image down by the level. | 104 // Shift the image down by the level. |
103 int y = rect.bottom() - levels[i] * 2; | 105 int y = rect.bottom() - levels[i] * 2; |
104 x -= image->width(); | |
105 canvas->DrawImageInt(*image, x, y); | 106 canvas->DrawImageInt(*image, x, y); |
106 | 107 |
107 // Clip the equalizer column so the favicon doesn't obscure it. | 108 // Clip the equalizer column so the favicon doesn't obscure it. |
108 gfx::Rect equalizer_rect(x, y, image->width(), image->height()); | 109 gfx::Rect equalizer_rect(x, y, image->width(), image->height()); |
109 canvas->sk_canvas()->clipRect( | 110 canvas->sk_canvas()->clipRect( |
110 gfx::RectToSkRect(equalizer_rect), SkRegion::kDifference_Op); | 111 gfx::RectToSkRect(equalizer_rect), SkRegion::kDifference_Op); |
111 | 112 |
112 // Padding is baked into both sides of the icons so overlap the images. | 113 // Padding is baked into both sides of the icons so overlap the images. |
113 x += kEqualizerColumnPadding; | 114 x += kEqualizerColumnPadding; |
114 } | 115 } |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 // level and the target equalizer level. | 156 // level and the target equalizer level. |
156 for (size_t i = 0; i < kEqualizerColumnCount; ++i) { | 157 for (size_t i = 0; i < kEqualizerColumnCount; ++i) { |
157 int start = kEqualizerFrames[frame_index_][i]; | 158 int start = kEqualizerFrames[frame_index_][i]; |
158 int end = state_ == STATE_ANIMATION_ENDING | 159 int end = state_ == STATE_ANIMATION_ENDING |
159 ? 0 | 160 ? 0 |
160 : kEqualizerFrames[next_frame_index][i]; | 161 : kEqualizerFrames[next_frame_index][i]; |
161 levels.push_back(animation_->CurrentValueBetween(start, end)); | 162 levels.push_back(animation_->CurrentValueBetween(start, end)); |
162 } | 163 } |
163 return levels; | 164 return levels; |
164 } | 165 } |
OLD | NEW |