OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/speech/speech_recognition_bubble.h" | 5 #include "chrome/browser/speech/speech_recognition_bubble.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "content/public/browser/web_contents.h" | 10 #include "content/public/browser/web_contents.h" |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 src_rect.x() < spinner_image->width(); | 88 src_rect.x() < spinner_image->width(); |
89 src_rect.Offset(frame_size, 0)) { | 89 src_rect.Offset(frame_size, 0)) { |
90 gfx::ImageSkia frame = gfx::ImageSkiaOperations::ExtractSubset( | 90 gfx::ImageSkia frame = gfx::ImageSkiaOperations::ExtractSubset( |
91 *spinner_image, src_rect); | 91 *spinner_image, src_rect); |
92 | 92 |
93 // The image created by ExtractSubset just points to the same pixels as | 93 // The image created by ExtractSubset just points to the same pixels as |
94 // the original and adjusts rowBytes accordingly. However that doesn't | 94 // the original and adjusts rowBytes accordingly. However that doesn't |
95 // render properly and gets vertically squished in Linux due to a bug in | 95 // render properly and gets vertically squished in Linux due to a bug in |
96 // Skia. Until that gets fixed we work around by taking a real copy of it | 96 // Skia. Until that gets fixed we work around by taking a real copy of it |
97 // below as the copied image has the correct rowBytes and renders fine. | 97 // below as the copied image has the correct rowBytes and renders fine. |
98 frame.EnsureRepsForSupportedScaleFactors(); | 98 frame.EnsureRepsForSupportedScales(); |
99 std::vector<gfx::ImageSkiaRep> image_reps = frame.image_reps(); | 99 std::vector<gfx::ImageSkiaRep> image_reps = frame.image_reps(); |
100 gfx::ImageSkia frame_copy; | 100 gfx::ImageSkia frame_copy; |
101 for (size_t i = 0; i < image_reps.size(); ++i) { | 101 for (size_t i = 0; i < image_reps.size(); ++i) { |
102 const SkBitmap& copy_src = image_reps[i].sk_bitmap(); | 102 const SkBitmap& copy_src = image_reps[i].sk_bitmap(); |
103 SkBitmap copy_dst; | 103 SkBitmap copy_dst; |
104 copy_src.copyTo(©_dst, SkBitmap::kARGB_8888_Config); | 104 copy_src.copyTo(©_dst, SkBitmap::kARGB_8888_Config); |
105 frame_copy.AddRepresentation(gfx::ImageSkiaRep( | 105 frame_copy.AddRepresentation(gfx::ImageSkiaRep( |
106 copy_dst, image_reps[i].scale_factor())); | 106 copy_dst, image_reps[i].scale())); |
107 } | 107 } |
108 spinner_.push_back(frame_copy); | 108 spinner_.push_back(frame_copy); |
109 | 109 |
110 // The warm up spinner animation is a gray scale version of the real one. | 110 // The warm up spinner animation is a gray scale version of the real one. |
111 warm_up_.push_back(gfx::ImageSkiaOperations::CreateHSLShiftedImage( | 111 warm_up_.push_back(gfx::ImageSkiaOperations::CreateHSLShiftedImage( |
112 frame_copy, kGrayscaleShift)); | 112 frame_copy, kGrayscaleShift)); |
113 } | 113 } |
114 } | 114 } |
115 | 115 |
116 base::LazyInstance<SpeechRecognitionBubbleImages> g_images = | 116 base::LazyInstance<SpeechRecognitionBubbleImages> g_images = |
(...skipping 16 matching lines...) Expand all Loading... |
133 | 133 |
134 return CreateNativeBubble(web_contents, delegate, element_rect); | 134 return CreateNativeBubble(web_contents, delegate, element_rect); |
135 } | 135 } |
136 | 136 |
137 SpeechRecognitionBubbleBase::SpeechRecognitionBubbleBase( | 137 SpeechRecognitionBubbleBase::SpeechRecognitionBubbleBase( |
138 WebContents* web_contents) | 138 WebContents* web_contents) |
139 : weak_factory_(this), | 139 : weak_factory_(this), |
140 animation_step_(0), | 140 animation_step_(0), |
141 display_mode_(DISPLAY_MODE_RECORDING), | 141 display_mode_(DISPLAY_MODE_RECORDING), |
142 web_contents_(web_contents), | 142 web_contents_(web_contents), |
143 scale_factor_(ui::SCALE_FACTOR_NONE) { | 143 scale_(1.0f) { |
144 gfx::NativeView view = | 144 gfx::NativeView view = |
145 web_contents_ ? web_contents_->GetView()->GetNativeView() : NULL; | 145 web_contents_ ? web_contents_->GetView()->GetNativeView() : NULL; |
146 gfx::Screen* screen = gfx::Screen::GetScreenFor(view); | 146 gfx::Screen* screen = gfx::Screen::GetScreenFor(view); |
147 gfx::Display display = screen->GetDisplayNearestWindow(view); | 147 gfx::Display display = screen->GetDisplayNearestWindow(view); |
148 scale_factor_ = ui::GetScaleFactorFromScale( | 148 scale_ = display.device_scale_factor(); |
149 display.device_scale_factor()); | |
150 | 149 |
151 const gfx::ImageSkiaRep& rep = | 150 const gfx::ImageSkiaRep& rep = |
152 g_images.Get().mic_empty()->GetRepresentation(scale_factor_); | 151 g_images.Get().mic_empty()->GetRepresentation(scale_); |
153 mic_image_.reset(new SkBitmap()); | 152 mic_image_.reset(new SkBitmap()); |
154 mic_image_->setConfig(SkBitmap::kARGB_8888_Config, | 153 mic_image_->setConfig(SkBitmap::kARGB_8888_Config, |
155 rep.pixel_width(), rep.pixel_height()); | 154 rep.pixel_width(), rep.pixel_height()); |
156 mic_image_->allocPixels(); | 155 mic_image_->allocPixels(); |
157 | 156 |
158 buffer_image_.reset(new SkBitmap()); | 157 buffer_image_.reset(new SkBitmap()); |
159 buffer_image_->setConfig(SkBitmap::kARGB_8888_Config, | 158 buffer_image_->setConfig(SkBitmap::kARGB_8888_Config, |
160 rep.pixel_width(), rep.pixel_height()); | 159 rep.pixel_width(), rep.pixel_height()); |
161 buffer_image_->allocPixels(); | 160 buffer_image_->allocPixels(); |
162 } | 161 } |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 int width = mic_image_->width(); | 227 int width = mic_image_->width(); |
229 int height = mic_image_->height(); | 228 int height = mic_image_->height(); |
230 SkCanvas buffer_canvas(*buffer_image_); | 229 SkCanvas buffer_canvas(*buffer_image_); |
231 | 230 |
232 buffer_canvas.save(); | 231 buffer_canvas.save(); |
233 const int kVolumeSteps = 12; | 232 const int kVolumeSteps = 12; |
234 SkScalar clip_right = | 233 SkScalar clip_right = |
235 (((1.0f - volume) * (width * (kVolumeSteps + 1))) - width) / kVolumeSteps; | 234 (((1.0f - volume) * (width * (kVolumeSteps + 1))) - width) / kVolumeSteps; |
236 buffer_canvas.clipRect(SkRect::MakeLTRB(0, 0, | 235 buffer_canvas.clipRect(SkRect::MakeLTRB(0, 0, |
237 SkIntToScalar(width) - clip_right, SkIntToScalar(height))); | 236 SkIntToScalar(width) - clip_right, SkIntToScalar(height))); |
238 buffer_canvas.drawBitmap( | 237 buffer_canvas.drawBitmap(image.GetRepresentation(scale_).sk_bitmap(), 0, 0); |
239 image.GetRepresentation(scale_factor_).sk_bitmap(), 0, 0); | |
240 buffer_canvas.restore(); | 238 buffer_canvas.restore(); |
241 SkPaint multiply_paint; | 239 SkPaint multiply_paint; |
242 multiply_paint.setXfermodeMode(SkXfermode::kModulate_Mode); | 240 multiply_paint.setXfermodeMode(SkXfermode::kModulate_Mode); |
243 buffer_canvas.drawBitmap( | 241 buffer_canvas.drawBitmap( |
244 g_images.Get().mic_mask()->GetRepresentation(scale_factor_).sk_bitmap(), | 242 g_images.Get().mic_mask()->GetRepresentation(scale_).sk_bitmap(), |
245 -clip_right, 0, &multiply_paint); | 243 -clip_right, 0, &multiply_paint); |
246 | 244 |
247 canvas->drawBitmap(*buffer_image_.get(), 0, 0); | 245 canvas->drawBitmap(*buffer_image_.get(), 0, 0); |
248 } | 246 } |
249 | 247 |
250 void SpeechRecognitionBubbleBase::SetInputVolume(float volume, | 248 void SpeechRecognitionBubbleBase::SetInputVolume(float volume, |
251 float noise_volume) { | 249 float noise_volume) { |
252 mic_image_->eraseARGB(0, 0, 0, 0); | 250 mic_image_->eraseARGB(0, 0, 0, 0); |
253 SkCanvas canvas(*mic_image_); | 251 SkCanvas canvas(*mic_image_); |
254 | 252 |
255 // Draw the empty volume image first and the current volume image on top, | 253 // Draw the empty volume image first and the current volume image on top, |
256 // and then the noise volume image on top of both. | 254 // and then the noise volume image on top of both. |
257 canvas.drawBitmap( | 255 canvas.drawBitmap( |
258 g_images.Get().mic_empty()->GetRepresentation(scale_factor_).sk_bitmap(), | 256 g_images.Get().mic_empty()->GetRepresentation(scale_).sk_bitmap(), |
259 0, 0); | 257 0, 0); |
260 DrawVolumeOverlay(&canvas, *g_images.Get().mic_full(), volume); | 258 DrawVolumeOverlay(&canvas, *g_images.Get().mic_full(), volume); |
261 DrawVolumeOverlay(&canvas, *g_images.Get().mic_noise(), noise_volume); | 259 DrawVolumeOverlay(&canvas, *g_images.Get().mic_noise(), noise_volume); |
262 | 260 |
263 gfx::ImageSkia image(gfx::ImageSkiaRep(*mic_image_.get(), scale_factor_)); | 261 gfx::ImageSkia image(gfx::ImageSkiaRep(*mic_image_.get(), scale_)); |
264 SetImage(image); | 262 SetImage(image); |
265 } | 263 } |
266 | 264 |
267 WebContents* SpeechRecognitionBubbleBase::GetWebContents() { | 265 WebContents* SpeechRecognitionBubbleBase::GetWebContents() { |
268 return web_contents_; | 266 return web_contents_; |
269 } | 267 } |
270 | 268 |
271 void SpeechRecognitionBubbleBase::SetImage(const gfx::ImageSkia& image) { | 269 void SpeechRecognitionBubbleBase::SetImage(const gfx::ImageSkia& image) { |
272 icon_image_ = image; | 270 icon_image_ = image; |
273 UpdateImage(); | 271 UpdateImage(); |
274 } | 272 } |
275 | 273 |
276 gfx::ImageSkia SpeechRecognitionBubbleBase::icon_image() { | 274 gfx::ImageSkia SpeechRecognitionBubbleBase::icon_image() { |
277 return icon_image_; | 275 return icon_image_; |
278 } | 276 } |
OLD | NEW |