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

Unified 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 round2 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 side-by-side diff with in-line comments
Download patch
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..958b9d3301fcc0c487c694830c36165c1b9d574f
--- /dev/null
+++ b/chrome/browser/media/desktop_media_list.cc
@@ -0,0 +1,46 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// 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);
+ 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.
+ 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 SkImage* temp_image = SkImage::NewFromBitmap(favicon.AsBitmap());
miu 2015/12/14 20:21:08 Make sure you delete the SkImage to avoid memory l
GeorgeZ 2015/12/14 21:50:27 good catch.
+ canvas.drawImageRect(temp_image, dest_rect, nullptr);
+
+ // Create a skia image.
+ return gfx::ImageSkia::CreateFrom1xBitmap(result);
+}

Powered by Google App Engine
This is Rietveld 408576698