diff options
author | sadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-21 16:27:45 +0000 |
---|---|---|
committer | sadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-21 16:27:45 +0000 |
commit | d1a494af361712b4b443856dbf2fd0cce82c1338 (patch) | |
tree | c756c9b5e0173d728dd30f3581554ca2c34a1429 /chrome | |
parent | 81396bf04ac04cf695499d1b76e6ff9c52ed8f26 (diff) | |
download | chromium_src-d1a494af361712b4b443856dbf2fd0cce82c1338.zip chromium_src-d1a494af361712b4b443856dbf2fd0cce82c1338.tar.gz chromium_src-d1a494af361712b4b443856dbf2fd0cce82c1338.tar.bz2 |
Speech bubble: Use the images of the appropriate scale for the speech bubble.
Instead of using ImageSkia to replace the use of SkBitmap altogether, this CL
makes sure that the correct SkBitmap from the ImageSkia is used.
BUG=141146
Review URL: https://chromiumcodereview.appspot.com/10859002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@152568 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/speech/speech_recognition_bubble.cc | 36 | ||||
-rw-r--r-- | chrome/browser/speech/speech_recognition_bubble.h | 8 |
2 files changed, 31 insertions, 13 deletions
diff --git a/chrome/browser/speech/speech_recognition_bubble.cc b/chrome/browser/speech/speech_recognition_bubble.cc index a9aafba..c768e64 100644 --- a/chrome/browser/speech/speech_recognition_bubble.cc +++ b/chrome/browser/speech/speech_recognition_bubble.cc @@ -2,16 +2,19 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "chrome/browser/speech/speech_recognition_bubble.h" + #include "base/bind.h" #include "base/lazy_instance.h" #include "base/message_loop.h" -#include "chrome/browser/speech/speech_recognition_bubble.h" #include "content/public/browser/web_contents.h" #include "grit/generated_resources.h" #include "grit/theme_resources.h" #include "ui/base/resource/resource_bundle.h" #include "ui/gfx/canvas.h" +#include "ui/gfx/display.h" #include "ui/gfx/rect.h" +#include "ui/gfx/screen.h" #include "ui/gfx/skbitmap_operations.h" using content::WebContents; @@ -125,17 +128,23 @@ SpeechRecognitionBubbleBase::SpeechRecognitionBubbleBase( WebContents* web_contents) : ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), display_mode_(DISPLAY_MODE_RECORDING), - web_contents_(web_contents) { + web_contents_(web_contents), + scale_factor_(ui::SCALE_FACTOR_NONE) { + gfx::Display display = gfx::Screen::GetDisplayNearestWindow( + web_contents_ ? web_contents_->GetNativeView() : NULL); + scale_factor_ = ui::GetScaleFactorFromScale( + display.device_scale_factor()); + + const gfx::ImageSkiaRep& rep = + g_images.Get().mic_empty()->GetRepresentation(scale_factor_); mic_image_.reset(new SkBitmap()); mic_image_->setConfig(SkBitmap::kARGB_8888_Config, - g_images.Get().mic_empty()->width(), - g_images.Get().mic_empty()->height()); + rep.pixel_width(), rep.pixel_height()); mic_image_->allocPixels(); buffer_image_.reset(new SkBitmap()); buffer_image_->setConfig(SkBitmap::kARGB_8888_Config, - g_images.Get().mic_empty()->width(), - g_images.Get().mic_empty()->height()); + rep.pixel_width(), rep.pixel_height()); buffer_image_->allocPixels(); } @@ -213,12 +222,14 @@ void SpeechRecognitionBubbleBase::DrawVolumeOverlay(SkCanvas* canvas, (((1.0f - volume) * (width * (kVolumeSteps + 1))) - width) / kVolumeSteps; buffer_canvas.clipRect(SkRect::MakeLTRB(0, 0, SkIntToScalar(width) - clip_right, SkIntToScalar(height))); - buffer_canvas.drawBitmap(image, 0, 0); + buffer_canvas.drawBitmap( + image.GetRepresentation(scale_factor_).sk_bitmap(), 0, 0); buffer_canvas.restore(); SkPaint multiply_paint; multiply_paint.setXfermode(SkXfermode::Create(SkXfermode::kMultiply_Mode)); - buffer_canvas.drawBitmap(*g_images.Get().mic_mask(), -clip_right, 0, - &multiply_paint); + buffer_canvas.drawBitmap( + g_images.Get().mic_mask()->GetRepresentation(scale_factor_).sk_bitmap(), + -clip_right, 0, &multiply_paint); canvas->drawBitmap(*buffer_image_.get(), 0, 0); } @@ -230,11 +241,14 @@ void SpeechRecognitionBubbleBase::SetInputVolume(float volume, // Draw the empty volume image first and the current volume image on top, // and then the noise volume image on top of both. - canvas.drawBitmap(*g_images.Get().mic_empty(), 0, 0); + canvas.drawBitmap( + g_images.Get().mic_empty()->GetRepresentation(scale_factor_).sk_bitmap(), + 0, 0); DrawVolumeOverlay(&canvas, *g_images.Get().mic_full(), volume); DrawVolumeOverlay(&canvas, *g_images.Get().mic_noise(), noise_volume); - SetImage(*mic_image_.get()); + gfx::ImageSkia image(gfx::ImageSkiaRep(*mic_image_.get(), scale_factor_)); + SetImage(image); } WebContents* SpeechRecognitionBubbleBase::GetWebContents() { diff --git a/chrome/browser/speech/speech_recognition_bubble.h b/chrome/browser/speech/speech_recognition_bubble.h index 699b273..c2950b6 100644 --- a/chrome/browser/speech/speech_recognition_bubble.h +++ b/chrome/browser/speech/speech_recognition_bubble.h @@ -10,6 +10,7 @@ #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" #include "base/string16.h" +#include "ui/base/layout.h" class SkBitmap; class SkCanvas; @@ -170,11 +171,10 @@ class SpeechRecognitionBubbleBase : public SpeechRecognitionBubble { // Task factory used for animation timer. base::WeakPtrFactory<SpeechRecognitionBubbleBase> weak_factory_; int animation_step_; // Current index/step of the animation. - std::vector<gfx::ImageSkia> animation_frames_; - std::vector<gfx::ImageSkia> warming_up_frames_; DisplayMode display_mode_; string16 message_text_; // Text displayed in DISPLAY_MODE_MESSAGE + // The current microphone image with volume level indication. scoped_ptr<SkBitmap> mic_image_; // A temporary buffer image used in creating the above mic image. @@ -183,6 +183,10 @@ class SpeechRecognitionBubbleBase : public SpeechRecognitionBubble { content::WebContents* web_contents_; // The current image displayed in the bubble's icon widget. scoped_ptr<gfx::ImageSkia> icon_image_; + // The scale factor used for the web-contents. + ui::ScaleFactor scale_factor_; + + DISALLOW_COPY_AND_ASSIGN(SpeechRecognitionBubbleBase); }; // This typedef is to workaround the issue with certain versions of |