OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/media/desktop_media_list_ash.h" |
| 6 #include "third_party/skia/include/core/SkCanvas.h" |
| 7 #include "third_party/skia/include/core/SkImage.h" |
| 8 |
| 9 gfx::ImageSkia DesktopMediaList::CreateEnlargedFaviconImage( |
| 10 gfx::Size size, |
| 11 gfx::Image& favicon) { |
| 12 // Create a bitmap. |
| 13 SkBitmap result; |
| 14 result.allocN32Pixels(size.width(), size.height(), true); |
| 15 SkCanvas canvas(result); |
| 16 |
| 17 // Fill with white. |
| 18 canvas.drawARGB(255, 255, 255, 255); |
| 19 |
| 20 // Draw black border. |
| 21 const int thickness = result.width() / 30; |
| 22 SkPaint paint; |
| 23 paint.setARGB(255, 0, 0, 0); |
| 24 paint.setStyle(SkPaint::kStroke_Style); |
| 25 paint.setStrokeWidth(thickness); |
| 26 canvas.drawRectCoords(thickness, // left |
| 27 thickness, // top |
| 28 result.width() - thickness, // right |
| 29 result.height() - thickness, // bottom |
| 30 paint); |
| 31 |
| 32 // Draw a scaled favicon image into the center of result image to take up to |
| 33 // 3/4 of result image. |
| 34 const double scale = fmin(3.0 / 4 * result.width() / favicon.Width(), |
| 35 3.0 / 4 * result.height() / favicon.Height()); |
| 36 SkRect dest_rect; |
| 37 dest_rect.set(result.width() / 2 - favicon.Width() * scale / 2, // left |
| 38 result.height() / 2 - favicon.Height() * scale / 2, // top |
| 39 result.width() / 2 + favicon.Width() * scale / 2, // right |
| 40 result.height() / 2 + favicon.Height() * scale / 2); // bottom |
| 41 const SkImage* temp_image = SkImage::NewFromBitmap(favicon.AsBitmap()); |
| 42 canvas.drawImageRect(temp_image, dest_rect, nullptr); |
| 43 delete temp_image; |
| 44 |
| 45 // Create a skia image. |
| 46 return gfx::ImageSkia::CreateFrom1xBitmap(result); |
| 47 } |
OLD | NEW |