Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(98)

Unified Diff: ui/gfx/image/image_skia_sources.cc

Issue 10699065: chromeos: Fix pixelated icons in app list and launcher (part 1) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: for comments in #2 Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/gfx/image/image_skia_sources.cc
diff --git a/ui/gfx/image/image_skia_sources.cc b/ui/gfx/image/image_skia_sources.cc
new file mode 100644
index 0000000000000000000000000000000000000000..196f33e481c9a41457f9be6928085cd7f6009f53
--- /dev/null
+++ b/ui/gfx/image/image_skia_sources.cc
@@ -0,0 +1,98 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ui/gfx/image/image_skia_sources.h"
pkotwicz 2012/07/10 22:59:56 Move this file here: https://chromiumcodereview.ap
xiyuan 2012/07/11 17:39:13 Done.
+
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+#include "skia/ext/image_operations.h"
+#include "ui/gfx/image/image_skia.h"
+#include "ui/gfx/image/image_skia_rep.h"
+#include "ui/gfx/image/image_skia_source.h"
+#include "ui/gfx/size.h"
+#include "ui/gfx/skbitmap_operations.h"
+
+namespace gfx {
+namespace image_skia_sources {
+
+namespace {
+
+class ResizeSource : public ImageSkiaSource {
+ public:
+ ResizeSource(const ImageSkia& source,
+ const Size& target_dip_size)
+ : source_(source),
+ target_dip_size_(target_dip_size) {
+ }
+ virtual ~ResizeSource() {}
+
+ private:
+ // gfx::ImageSkiaSource overrides:
+ virtual ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) OVERRIDE {
+ const ImageSkiaRep& image_rep = source_.GetRepresentation(scale_factor);
+ if (image_rep.GetWidth() == target_dip_size_.width() &&
+ image_rep.GetHeight() == target_dip_size_.height())
+ return image_rep;
+
+ const float scale = image_rep.GetScale();;
+ const Size target_pixel_size(target_dip_size_.Scale(scale));
+ const SkBitmap resized = skia::ImageOperations::Resize(
+ image_rep.sk_bitmap(),
+ skia::ImageOperations::RESIZE_BEST,
+ target_pixel_size.width(),
+ target_pixel_size.height());
+ return ImageSkiaRep(resized, image_rep.scale_factor());
+ }
+
+ const ImageSkia source_;
+ const Size target_dip_size_;
+
+ DISALLOW_COPY_AND_ASSIGN(ResizeSource);
+};
+
+class DropShadowSource : public ImageSkiaSource {
+ public:
+ DropShadowSource(const ImageSkia& source,
+ const ShadowValues& dip_shadows)
+ : source_(source),
+ dip_shadows_(dip_shadows) {
+ }
+ virtual ~DropShadowSource() {}
+
+ private:
+ // gfx::ImageSkiaSource overrides:
+ virtual ImageSkiaRep GetImageForScale(ui::ScaleFactor scale_factor) OVERRIDE {
+ const ImageSkiaRep& image_rep = source_.GetRepresentation(scale_factor);
+
+ const float scale = image_rep.GetScale();
+ ShadowValues pixel_shadows;
pkotwicz 2012/07/10 22:59:56 rename to shadows_in_pixel to be consistent with o
xiyuan 2012/07/11 17:39:13 Done.
+ for (size_t i = 0; i < dip_shadows_.size(); ++i)
+ pixel_shadows.push_back(dip_shadows_[i].Scale(scale));
+
+ const SkBitmap shadow_image = SkBitmapOperations::CreateDropShadow(
+ image_rep.sk_bitmap(),
+ pixel_shadows);
+ return ImageSkiaRep(shadow_image, image_rep.scale_factor());
+ }
+
+ const ImageSkia source_;
+ const ShadowValues dip_shadows_;
+
+ DISALLOW_COPY_AND_ASSIGN(DropShadowSource);
+};
+
+} // namespace
+
+ImageSkiaSource* CreateResizeSource(const ImageSkia& source,
+ const Size& target_dip_size) {
+ return new ResizeSource(source, target_dip_size);
+}
+
+ImageSkiaSource* CreateDropShadowSource(const ImageSkia& source,
+ const ShadowValues& shadows) {
+ return new DropShadowSource(source, shadows);
+}
+
+} // namespace image_skia_sources
+} // namesoace gfx

Powered by Google App Engine
This is Rietveld 408576698