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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_MEDIA_DESKTOP_MEDIA_LIST_H_ 5 #ifndef CHROME_BROWSER_MEDIA_DESKTOP_MEDIA_LIST_H_
6 #define CHROME_BROWSER_MEDIA_DESKTOP_MEDIA_LIST_H_ 6 #define CHROME_BROWSER_MEDIA_DESKTOP_MEDIA_LIST_H_
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/strings/string16.h" 9 #include "base/strings/string16.h"
10 #include "base/time/time.h" 10 #include "base/time/time.h"
11 #include "content/public/browser/desktop_media_id.h" 11 #include "content/public/browser/desktop_media_id.h"
12 #include "ui/gfx/image/image.h"
12 #include "ui/gfx/image/image_skia.h" 13 #include "ui/gfx/image/image_skia.h"
13 14
14 class DesktopMediaListObserver; 15 class DesktopMediaListObserver;
15 16
16 // DesktopMediaList provides the list of desktop media source (screens, windows, 17 // DesktopMediaList provides the list of desktop media source (screens, windows,
17 // tabs), and their thumbnails, to the desktop media picker dialog. It 18 // tabs), and their thumbnails, to the desktop media picker dialog. It
18 // transparently updates the list in the background, and notifies the desktop 19 // transparently updates the list in the background, and notifies the desktop
19 // media picker when something changes. 20 // media picker when something changes.
20 class DesktopMediaList { 21 class DesktopMediaList {
21 public: 22 public:
23 enum SourceTypes { SCREENS = 1, WINDOWS = 2, TABS = 4 };
22 // Struct used to represent each entry in the list. 24 // Struct used to represent each entry in the list.
23 struct Source { 25 struct Source {
24 // Id of the source. 26 // Id of the source.
25 content::DesktopMediaID id; 27 content::DesktopMediaID id;
26 28
27 // Name of the source that should be shown to the user. 29 // Name of the source that should be shown to the user.
28 base::string16 name; 30 base::string16 name;
29 31
30 // The thumbnail for the source. 32 // The thumbnail for the source.
31 gfx::ImageSkia thumbnail; 33 gfx::ImageSkia thumbnail;
(...skipping 17 matching lines...) Expand all
49 51
50 // Starts updating the model. The model is initially empty, so OnSourceAdded() 52 // Starts updating the model. The model is initially empty, so OnSourceAdded()
51 // notifications will be generated for each existing source as it is 53 // notifications will be generated for each existing source as it is
52 // enumerated. After the initial enumeration the model will be refreshed based 54 // enumerated. After the initial enumeration the model will be refreshed based
53 // on the update period, and notifications generated only for changes in the 55 // on the update period, and notifications generated only for changes in the
54 // model. 56 // model.
55 virtual void StartUpdating(DesktopMediaListObserver* observer) = 0; 57 virtual void StartUpdating(DesktopMediaListObserver* observer) = 0;
56 58
57 virtual int GetSourceCount() const = 0; 59 virtual int GetSourceCount() const = 0;
58 virtual const Source& GetSource(int index) const = 0; 60 virtual const Source& GetSource(int index) const = 0;
61
62 protected:
63 // Create a image with an enlarged favicon on its center and black boundary.
64 // If fails, an empty image will return.
65 // The function is used to create a thumbnail for chrome tab preview.
66 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.
67 gfx::Image& favicon) {
68 // Enlarge scale for favicon.
69 int scale = 3;
qiangchen 2015/12/07 22:45:56 const?
GeorgeZ 2015/12/09 19:36:37 Done.
70 // Thickness of image boundary.
71 int thick = 5;
qiangchen 2015/12/07 22:45:56 const?
GeorgeZ 2015/12/09 19:36:37 Done.
72
73 // Sanity check. If failed, return a empty image.
74 if (size.width() < favicon.Width() * scale ||
75 size.height() < favicon.Height() * scale)
76 return gfx::ImageSkia();
77
78 // Create a SkBitmap for faviocn.
79 SkBitmap icon = favicon.AsBitmap();
80
81 // Create a bitmap.
82 SkBitmap result;
83 result.allocN32Pixels(size.width(), size.height(), true);
84
85 // Two SkBitmaps' color type need match to merge.
86 if (icon.colorType() != result.colorType())
87 return gfx::ImageSkia();
88
89 result.lockPixels();
90 uint8* pixels_data = reinterpret_cast<uint8*>(result.getPixels());
91
92 // Set background.
93 int span = result.rowBytes();
94 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
95 for (int y = 0; y < result.height(); ++y) {
96 for (int x = 0; x < result.width(); ++x) {
97 if (y < thick || y >= result.height() - thick || x < thick ||
98 x >= result.width() - thick) {
99 pixels_data[span * y + x * bpp] = 0;
100 pixels_data[span * y + x * bpp + 1] = 0;
101 pixels_data[span * y + x * bpp + 2] = 0;
102 } else {
103 pixels_data[span * y + x * bpp] = 0xff;
104 pixels_data[span * y + x * bpp + 1] = 0xff;
105 pixels_data[span * y + x * bpp + 2] = 0xff;
106 }
107 pixels_data[span * y + x * bpp + 3] = 0xff;
108 }
109 }
110
111 // Copy enlarged favicon into center of result image.
112 icon.lockPixels();
113 uint8* icon_data = reinterpret_cast<uint8*>(icon.getPixels());
114
115 int icon_span = icon.rowBytes();
116 int icon_bpp = icon.bytesPerPixel();
117 int offsety = (result.height() - icon.height() * scale) / 2;
118 int offsetx = (result.width() - icon.width() * scale) / 2;
119 for (int y = 0; y < icon.height() * scale; ++y) {
120 for (int x = 0; x < icon.width() * scale; ++x) {
121 pixels_data[span * (y + offsety) + (x + offsetx) * bpp] =
122 icon_data[icon_span * (y / scale) + (x / scale) * icon_bpp];
123 pixels_data[span * (y + offsety) + (x + offsetx) * bpp + 1] =
124 icon_data[icon_span * (y / scale) + (x / scale) * icon_bpp + 1];
125 pixels_data[span * (y + offsety) + (x + offsetx) * bpp + 2] =
126 icon_data[icon_span * (y / scale) + (x / scale) * icon_bpp + 2];
127 }
128 }
129 icon.unlockPixels();
130 result.unlockPixels();
131
132 // Create a skia image.
133 return gfx::ImageSkia::CreateFrom1xBitmap(result);
134 }
59 }; 135 };
60 136
61 #endif // CHROME_BROWSER_MEDIA_DESKTOP_MEDIA_LIST_H_ 137 #endif // CHROME_BROWSER_MEDIA_DESKTOP_MEDIA_LIST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698