| 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.EnsureRepsForSupportedScales(); | 98 frame.EnsureRepsForSupportedScaleFactors(); |
| 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())); | 106 copy_dst, image_reps[i].scale_factor())); |
| 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_(1.0f) { | 143 scale_factor_(ui::SCALE_FACTOR_NONE) { |
| 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_ = display.device_scale_factor(); | 148 scale_factor_ = ui::GetScaleFactorFromScale( |
| 149 display.device_scale_factor()); |
| 149 | 150 |
| 150 const gfx::ImageSkiaRep& rep = | 151 const gfx::ImageSkiaRep& rep = |
| 151 g_images.Get().mic_empty()->GetRepresentation(scale_); | 152 g_images.Get().mic_empty()->GetRepresentation(scale_factor_); |
| 152 mic_image_.reset(new SkBitmap()); | 153 mic_image_.reset(new SkBitmap()); |
| 153 mic_image_->setConfig(SkBitmap::kARGB_8888_Config, | 154 mic_image_->setConfig(SkBitmap::kARGB_8888_Config, |
| 154 rep.pixel_width(), rep.pixel_height()); | 155 rep.pixel_width(), rep.pixel_height()); |
| 155 mic_image_->allocPixels(); | 156 mic_image_->allocPixels(); |
| 156 | 157 |
| 157 buffer_image_.reset(new SkBitmap()); | 158 buffer_image_.reset(new SkBitmap()); |
| 158 buffer_image_->setConfig(SkBitmap::kARGB_8888_Config, | 159 buffer_image_->setConfig(SkBitmap::kARGB_8888_Config, |
| 159 rep.pixel_width(), rep.pixel_height()); | 160 rep.pixel_width(), rep.pixel_height()); |
| 160 buffer_image_->allocPixels(); | 161 buffer_image_->allocPixels(); |
| 161 } | 162 } |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 int width = mic_image_->width(); | 228 int width = mic_image_->width(); |
| 228 int height = mic_image_->height(); | 229 int height = mic_image_->height(); |
| 229 SkCanvas buffer_canvas(*buffer_image_); | 230 SkCanvas buffer_canvas(*buffer_image_); |
| 230 | 231 |
| 231 buffer_canvas.save(); | 232 buffer_canvas.save(); |
| 232 const int kVolumeSteps = 12; | 233 const int kVolumeSteps = 12; |
| 233 SkScalar clip_right = | 234 SkScalar clip_right = |
| 234 (((1.0f - volume) * (width * (kVolumeSteps + 1))) - width) / kVolumeSteps; | 235 (((1.0f - volume) * (width * (kVolumeSteps + 1))) - width) / kVolumeSteps; |
| 235 buffer_canvas.clipRect(SkRect::MakeLTRB(0, 0, | 236 buffer_canvas.clipRect(SkRect::MakeLTRB(0, 0, |
| 236 SkIntToScalar(width) - clip_right, SkIntToScalar(height))); | 237 SkIntToScalar(width) - clip_right, SkIntToScalar(height))); |
| 237 buffer_canvas.drawBitmap(image.GetRepresentation(scale_).sk_bitmap(), 0, 0); | 238 buffer_canvas.drawBitmap( |
| 239 image.GetRepresentation(scale_factor_).sk_bitmap(), 0, 0); |
| 238 buffer_canvas.restore(); | 240 buffer_canvas.restore(); |
| 239 SkPaint multiply_paint; | 241 SkPaint multiply_paint; |
| 240 multiply_paint.setXfermodeMode(SkXfermode::kModulate_Mode); | 242 multiply_paint.setXfermodeMode(SkXfermode::kModulate_Mode); |
| 241 buffer_canvas.drawBitmap( | 243 buffer_canvas.drawBitmap( |
| 242 g_images.Get().mic_mask()->GetRepresentation(scale_).sk_bitmap(), | 244 g_images.Get().mic_mask()->GetRepresentation(scale_factor_).sk_bitmap(), |
| 243 -clip_right, 0, &multiply_paint); | 245 -clip_right, 0, &multiply_paint); |
| 244 | 246 |
| 245 canvas->drawBitmap(*buffer_image_.get(), 0, 0); | 247 canvas->drawBitmap(*buffer_image_.get(), 0, 0); |
| 246 } | 248 } |
| 247 | 249 |
| 248 void SpeechRecognitionBubbleBase::SetInputVolume(float volume, | 250 void SpeechRecognitionBubbleBase::SetInputVolume(float volume, |
| 249 float noise_volume) { | 251 float noise_volume) { |
| 250 mic_image_->eraseARGB(0, 0, 0, 0); | 252 mic_image_->eraseARGB(0, 0, 0, 0); |
| 251 SkCanvas canvas(*mic_image_); | 253 SkCanvas canvas(*mic_image_); |
| 252 | 254 |
| 253 // Draw the empty volume image first and the current volume image on top, | 255 // Draw the empty volume image first and the current volume image on top, |
| 254 // and then the noise volume image on top of both. | 256 // and then the noise volume image on top of both. |
| 255 canvas.drawBitmap( | 257 canvas.drawBitmap( |
| 256 g_images.Get().mic_empty()->GetRepresentation(scale_).sk_bitmap(), | 258 g_images.Get().mic_empty()->GetRepresentation(scale_factor_).sk_bitmap(), |
| 257 0, 0); | 259 0, 0); |
| 258 DrawVolumeOverlay(&canvas, *g_images.Get().mic_full(), volume); | 260 DrawVolumeOverlay(&canvas, *g_images.Get().mic_full(), volume); |
| 259 DrawVolumeOverlay(&canvas, *g_images.Get().mic_noise(), noise_volume); | 261 DrawVolumeOverlay(&canvas, *g_images.Get().mic_noise(), noise_volume); |
| 260 | 262 |
| 261 gfx::ImageSkia image(gfx::ImageSkiaRep(*mic_image_.get(), scale_)); | 263 gfx::ImageSkia image(gfx::ImageSkiaRep(*mic_image_.get(), scale_factor_)); |
| 262 SetImage(image); | 264 SetImage(image); |
| 263 } | 265 } |
| 264 | 266 |
| 265 WebContents* SpeechRecognitionBubbleBase::GetWebContents() { | 267 WebContents* SpeechRecognitionBubbleBase::GetWebContents() { |
| 266 return web_contents_; | 268 return web_contents_; |
| 267 } | 269 } |
| 268 | 270 |
| 269 void SpeechRecognitionBubbleBase::SetImage(const gfx::ImageSkia& image) { | 271 void SpeechRecognitionBubbleBase::SetImage(const gfx::ImageSkia& image) { |
| 270 icon_image_ = image; | 272 icon_image_ = image; |
| 271 UpdateImage(); | 273 UpdateImage(); |
| 272 } | 274 } |
| 273 | 275 |
| 274 gfx::ImageSkia SpeechRecognitionBubbleBase::icon_image() { | 276 gfx::ImageSkia SpeechRecognitionBubbleBase::icon_image() { |
| 275 return icon_image_; | 277 return icon_image_; |
| 276 } | 278 } |
| OLD | NEW |