Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(59)

Side by Side Diff: chrome/browser/media/desktop_media_list.cc

Issue 1503563004: Desktop chrome tab capture-chooseDesktopMedia() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review round 4 Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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;
qiangchen 2015/12/16 21:08:36 Consider using scoped_ptr to avoid an explicit del
GeorgeZ 2015/12/16 22:38:40 Done.
44
45 // Create a skia image.
46 return gfx::ImageSkia::CreateFrom1xBitmap(result);
47 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698