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

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: Created 4 years, 11 months 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 2016 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.h"
6
7 #include "third_party/skia/include/core/SkCanvas.h"
8 #include "third_party/skia/include/core/SkImage.h"
9
10 gfx::ImageSkia CreateEnlargedFaviconImage(gfx::Size size, gfx::Image& favicon) {
11 if (size.width() < 30 || size.height() < 30)
12 return gfx::ImageSkia();
13
14 // Create a bitmap.
15 SkBitmap result;
16 result.allocN32Pixels(size.width(), size.height(), true);
17 SkCanvas canvas(result);
18
19 // Fill with white.
20 canvas.drawARGB(255, 255, 255, 255);
21
22 // Draw black border.
23 const int thickness = result.width() / 30;
24 SkPaint paint;
25 paint.setARGB(255, 0, 0, 0);
26 paint.setStyle(SkPaint::kStroke_Style);
27 paint.setStrokeWidth(thickness);
28 canvas.drawRectCoords(thickness, // left
29 thickness, // top
30 result.width() - thickness, // right
31 result.height() - thickness, // bottom
32 paint);
33
34 // Draw a scaled favicon image into the center of result image to take up to
35 // 3/4 of result image.
36 const double scale = fmin(3.0 / 4 * result.width() / favicon.Width(),
37 3.0 / 4 * result.height() / favicon.Height());
38 SkRect dest_rect;
39 dest_rect.set(result.width() / 2 - favicon.Width() * scale / 2, // left
40 result.height() / 2 - favicon.Height() * scale / 2, // top
41 result.width() / 2 + favicon.Width() * scale / 2, // right
42 result.height() / 2 + favicon.Height() * scale / 2); // bottom
43 const scoped_ptr<SkImage> temp_image(
44 SkImage::NewFromBitmap(favicon.AsBitmap()));
45 canvas.drawImageRect(temp_image.get(), dest_rect, nullptr);
46
47 // Create a skia image.
48 return gfx::ImageSkia::CreateFrom1xBitmap(result);
49 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698