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

Unified Diff: chrome/browser/media/desktop_media_list.h

Issue 1503563004: Desktop chrome tab capture-chooseDesktopMedia() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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.h
diff --git a/chrome/browser/media/desktop_media_list.h b/chrome/browser/media/desktop_media_list.h
index d8b2e237f343cd13b8b39c5bfa21605329315296..58e564804993128c4d3d44f6b5daec7d321349ea 100644
--- a/chrome/browser/media/desktop_media_list.h
+++ b/chrome/browser/media/desktop_media_list.h
@@ -9,6 +9,7 @@
#include "base/strings/string16.h"
#include "base/time/time.h"
#include "content/public/browser/desktop_media_id.h"
+#include "ui/gfx/image/image.h"
#include "ui/gfx/image/image_skia.h"
class DesktopMediaListObserver;
@@ -19,6 +20,7 @@ class DesktopMediaListObserver;
// media picker when something changes.
class DesktopMediaList {
public:
+ enum SourceTypes { SCREENS = 1, WINDOWS = 2, TABS = 4 };
// Struct used to represent each entry in the list.
struct Source {
// Id of the source.
@@ -56,6 +58,80 @@ class DesktopMediaList {
virtual int GetSourceCount() const = 0;
virtual const Source& GetSource(int index) const = 0;
+
+ protected:
+ // Create a image with an enlarged favicon on its center and black boundary.
+ // If fails, an empty image will return.
+ // The function is used to create a thumbnail for chrome tab preview.
+ static gfx::ImageSkia CreateImageEncloseFavicon(gfx::Size size,
qiangchen 2015/12/07 22:45:56 Better to separate the definition from declaration
GeorgeZ 2015/12/09 19:36:37 Done.
+ gfx::Image& favicon) {
+ // Enlarge scale for favicon.
+ int scale = 3;
qiangchen 2015/12/07 22:45:56 const?
GeorgeZ 2015/12/09 19:36:37 Done.
+ // Thickness of image boundary.
+ int thick = 5;
qiangchen 2015/12/07 22:45:56 const?
GeorgeZ 2015/12/09 19:36:37 Done.
+
+ // Sanity check. If failed, return a empty image.
+ if (size.width() < favicon.Width() * scale ||
+ size.height() < favicon.Height() * scale)
+ return gfx::ImageSkia();
+
+ // Create a SkBitmap for faviocn.
+ SkBitmap icon = favicon.AsBitmap();
+
+ // Create a bitmap.
+ SkBitmap result;
+ result.allocN32Pixels(size.width(), size.height(), true);
+
+ // Two SkBitmaps' color type need match to merge.
+ if (icon.colorType() != result.colorType())
+ return gfx::ImageSkia();
+
+ result.lockPixels();
+ uint8* pixels_data = reinterpret_cast<uint8*>(result.getPixels());
+
+ // Set background.
+ int span = result.rowBytes();
+ int bpp = result.bytesPerPixel();
qiangchen 2015/12/07 22:45:56 Again my question, the follow code seems to assume
GeorgeZ 2015/12/09 19:36:37 result.allocN32Pixels() guarantees result image's
+ for (int y = 0; y < result.height(); ++y) {
+ for (int x = 0; x < result.width(); ++x) {
+ if (y < thick || y >= result.height() - thick || x < thick ||
+ x >= result.width() - thick) {
+ pixels_data[span * y + x * bpp] = 0;
+ pixels_data[span * y + x * bpp + 1] = 0;
+ pixels_data[span * y + x * bpp + 2] = 0;
+ } else {
+ pixels_data[span * y + x * bpp] = 0xff;
+ pixels_data[span * y + x * bpp + 1] = 0xff;
+ pixels_data[span * y + x * bpp + 2] = 0xff;
+ }
+ pixels_data[span * y + x * bpp + 3] = 0xff;
+ }
+ }
+
+ // Copy enlarged favicon into center of result image.
+ icon.lockPixels();
+ uint8* icon_data = reinterpret_cast<uint8*>(icon.getPixels());
+
+ int icon_span = icon.rowBytes();
+ int icon_bpp = icon.bytesPerPixel();
+ int offsety = (result.height() - icon.height() * scale) / 2;
+ int offsetx = (result.width() - icon.width() * scale) / 2;
+ for (int y = 0; y < icon.height() * scale; ++y) {
+ for (int x = 0; x < icon.width() * scale; ++x) {
+ pixels_data[span * (y + offsety) + (x + offsetx) * bpp] =
+ icon_data[icon_span * (y / scale) + (x / scale) * icon_bpp];
+ pixels_data[span * (y + offsety) + (x + offsetx) * bpp + 1] =
+ icon_data[icon_span * (y / scale) + (x / scale) * icon_bpp + 1];
+ pixels_data[span * (y + offsety) + (x + offsetx) * bpp + 2] =
+ icon_data[icon_span * (y / scale) + (x / scale) * icon_bpp + 2];
+ }
+ }
+ icon.unlockPixels();
+ result.unlockPixels();
+
+ // Create a skia image.
+ return gfx::ImageSkia::CreateFrom1xBitmap(result);
+ }
};
#endif // CHROME_BROWSER_MEDIA_DESKTOP_MEDIA_LIST_H_

Powered by Google App Engine
This is Rietveld 408576698