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..729bafc37763f7b5c15bc3d9e759272a2547d88b |
| --- /dev/null |
| +++ b/chrome/browser/media/desktop_media_list.cc |
| @@ -0,0 +1,47 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
|
mark a. foltz
2016/01/04 20:11:40
s/2015/2016/
GeorgeZ
2016/01/06 22:41:39
Done.
|
| +// 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); |
|
mark a. foltz
2016/01/04 20:11:40
What restrictions are there on |size|?
GeorgeZ
2016/01/06 22:41:39
Added a restriction for minimal size.
|
| + 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. |
|
mark a. foltz
2016/01/04 20:11:40
Will there be a black border, inset by a white bor
GeorgeZ
2016/01/06 22:41:38
There are examples in design doc https://goo.gl/uo
|
| + 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 scoped_ptr<SkImage> temp_image( |
| + SkImage::NewFromBitmap(favicon.AsBitmap())); |
| + canvas.drawImageRect(temp_image.get(), dest_rect, nullptr); |
| + |
| + // Create a skia image. |
| + return gfx::ImageSkia::CreateFrom1xBitmap(result); |
| +} |