Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // 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.
| |
| 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); | |
|
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.
| |
| 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. | |
|
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
| |
| 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 scoped_ptr<SkImage> temp_image( | |
| 42 SkImage::NewFromBitmap(favicon.AsBitmap())); | |
| 43 canvas.drawImageRect(temp_image.get(), dest_rect, nullptr); | |
| 44 | |
| 45 // Create a skia image. | |
| 46 return gfx::ImageSkia::CreateFrom1xBitmap(result); | |
| 47 } | |
| OLD | NEW |