Index: chrome/browser/media/desktop_media_list.cc |
diff --git a/chrome/browser/media/desktop_media_list.cc b/chrome/browser/media/desktop_media_list.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..0d8c661afba4d53818733fd9d251b615965c662e |
--- /dev/null |
+++ b/chrome/browser/media/desktop_media_list.cc |
@@ -0,0 +1,76 @@ |
+// Copyright 2015 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 "chrome/browser/media/desktop_media_list_ash.h" |
+ |
+gfx::ImageSkia DesktopMediaList::CreateImageEncloseFavicon( |
+ gfx::Size size, |
+ gfx::Image& favicon) { |
+ // Enlarge scale for favicon. |
+ const int scale = 3; |
miu
2015/12/12 00:00:33
style nit: kScale
GeorgeZ
2015/12/14 18:33:07
variable is removed
|
+ // Thickness of image boundary. |
+ const int thick = 5; |
miu
2015/12/12 00:00:33
style nit: kBoundaryThickness
GeorgeZ
2015/12/14 18:33:07
variable is removed
|
+ |
+ // Sanity check. If failed, return a empty image. |
miu
2015/12/12 00:00:33
The entire rest of this function is re-inventing c
GeorgeZ
2015/12/14 18:33:07
Done.
|
+ if (size.width() < favicon.Width() * scale || |
+ size.height() < favicon.Height() * scale) |
+ return gfx::ImageSkia(); |
+ |
+ // Create a SkBitmap for faviocn. |
+ SkBitmap icon = favicon.AsBitmap(); |
+ |
+ // Create a bitmap. |
+ SkBitmap result; |
+ result.allocN32Pixels(size.width(), size.height(), true); |
+ |
+ // Two SkBitmaps' color type need match to merge. |
+ if (icon.colorType() != result.colorType()) |
+ return gfx::ImageSkia(); |
+ |
+ result.lockPixels(); |
+ uint8* pixels_data = reinterpret_cast<uint8*>(result.getPixels()); |
+ |
+ // Set background. |
+ int span = result.rowBytes(); |
+ int bpp = result.bytesPerPixel(); |
+ for (int y = 0; y < result.height(); ++y) { |
+ for (int x = 0; x < result.width(); ++x) { |
+ if (y < thick || y >= result.height() - thick || x < thick || |
+ x >= result.width() - thick) { |
+ pixels_data[span * y + x * bpp] = 0; |
+ pixels_data[span * y + x * bpp + 1] = 0; |
+ pixels_data[span * y + x * bpp + 2] = 0; |
+ } else { |
+ pixels_data[span * y + x * bpp] = 0xff; |
+ pixels_data[span * y + x * bpp + 1] = 0xff; |
+ pixels_data[span * y + x * bpp + 2] = 0xff; |
+ } |
+ pixels_data[span * y + x * bpp + 3] = 0xff; |
+ } |
+ } |
+ |
+ // Copy enlarged favicon into center of result image. |
+ icon.lockPixels(); |
+ uint8* icon_data = reinterpret_cast<uint8*>(icon.getPixels()); |
+ |
+ int icon_span = icon.rowBytes(); |
+ int icon_bpp = icon.bytesPerPixel(); |
+ int offsety = (result.height() - icon.height() * scale) / 2; |
+ int offsetx = (result.width() - icon.width() * scale) / 2; |
+ for (int y = 0; y < icon.height() * scale; ++y) { |
+ for (int x = 0; x < icon.width() * scale; ++x) { |
+ pixels_data[span * (y + offsety) + (x + offsetx) * bpp] = |
+ icon_data[icon_span * (y / scale) + (x / scale) * icon_bpp]; |
+ pixels_data[span * (y + offsety) + (x + offsetx) * bpp + 1] = |
+ icon_data[icon_span * (y / scale) + (x / scale) * icon_bpp + 1]; |
+ pixels_data[span * (y + offsety) + (x + offsetx) * bpp + 2] = |
+ icon_data[icon_span * (y / scale) + (x / scale) * icon_bpp + 2]; |
+ } |
+ } |
+ icon.unlockPixels(); |
+ result.unlockPixels(); |
+ |
+ // Create a skia image. |
+ return gfx::ImageSkia::CreateFrom1xBitmap(result); |
+} |