Chromium Code Reviews| 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..958b9d3301fcc0c487c694830c36165c1b9d574f |
| --- /dev/null |
| +++ b/chrome/browser/media/desktop_media_list.cc |
| @@ -0,0 +1,46 @@ |
| +// 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" |
| +#include "third_party/skia/include/core/SkCanvas.h" |
| +#include "third_party/skia/include/core/SkImage.h" |
| + |
| +gfx::ImageSkia DesktopMediaList::CreateEnlargedFaviconImage( |
| + gfx::Size size, |
| + gfx::Image& favicon) { |
| + // Create a bitmap. |
| + SkBitmap result; |
| + result.allocN32Pixels(size.width(), size.height(), true); |
| + SkCanvas canvas(result); |
| + |
| + // Fill with white. |
| + canvas.drawARGB(255, 255, 255, 255); |
| + |
| + // Draw black border. |
| + const int thickness = result.width() / 30; |
| + SkPaint paint; |
| + paint.setARGB(255, 0, 0, 0); |
| + paint.setStyle(SkPaint::kStroke_Style); |
| + paint.setStrokeWidth(thickness); |
| + canvas.drawRectCoords(thickness, // left |
| + thickness, // top |
| + result.width() - thickness, // right |
| + result.height() - thickness, // bottom |
| + paint); |
| + |
| + // Draw a scaled favicon image into the center of result image to take up to |
| + // 3/4 of result image. |
| + const double scale = fmin(3.0 / 4 * result.width() / favicon.Width(), |
| + 3.0 / 4 * result.height() / favicon.Height()); |
| + SkRect dest_rect; |
| + dest_rect.set(result.width() / 2 - favicon.Width() * scale / 2, // left |
| + result.height() / 2 - favicon.Height() * scale / 2, // top |
| + result.width() / 2 + favicon.Width() * scale / 2, // right |
| + result.height() / 2 + favicon.Height() * scale / 2); // bottom |
| + const SkImage* temp_image = SkImage::NewFromBitmap(favicon.AsBitmap()); |
|
miu
2015/12/14 20:21:08
Make sure you delete the SkImage to avoid memory l
GeorgeZ
2015/12/14 21:50:27
good catch.
|
| + canvas.drawImageRect(temp_image, dest_rect, nullptr); |
| + |
| + // Create a skia image. |
| + return gfx::ImageSkia::CreateFrom1xBitmap(result); |
| +} |