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

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

Issue 1550593002: Switch to standard integer types in chrome/browser/, part 2 of 4. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 12 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
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 #include "chrome/browser/media/native_desktop_media_list.h" 5 #include "chrome/browser/media/native_desktop_media_list.h"
6 6
7 #include <stddef.h>
8 #include <stdint.h>
9
7 #include <map> 10 #include <map>
8 #include <set> 11 #include <set>
9 #include <sstream> 12 #include <sstream>
10 13
11 #include "base/hash.h" 14 #include "base/hash.h"
12 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/macros.h"
13 #include "base/strings/utf_string_conversions.h" 17 #include "base/strings/utf_string_conversions.h"
14 #include "base/threading/sequenced_worker_pool.h" 18 #include "base/threading/sequenced_worker_pool.h"
15 #include "chrome/browser/media/desktop_media_list_observer.h" 19 #include "chrome/browser/media/desktop_media_list_observer.h"
16 #include "chrome/grit/generated_resources.h" 20 #include "chrome/grit/generated_resources.h"
17 #include "content/public/browser/browser_thread.h" 21 #include "content/public/browser/browser_thread.h"
18 #include "media/base/video_util.h" 22 #include "media/base/video_util.h"
19 #include "third_party/libyuv/include/libyuv/scale_argb.h" 23 #include "third_party/libyuv/include/libyuv/scale_argb.h"
20 #include "third_party/skia/include/core/SkBitmap.h" 24 #include "third_party/skia/include/core/SkBitmap.h"
21 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" 25 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h"
22 #include "third_party/webrtc/modules/desktop_capture/screen_capturer.h" 26 #include "third_party/webrtc/modules/desktop_capture/screen_capturer.h"
23 #include "third_party/webrtc/modules/desktop_capture/window_capturer.h" 27 #include "third_party/webrtc/modules/desktop_capture/window_capturer.h"
24 #include "ui/base/l10n/l10n_util.h" 28 #include "ui/base/l10n/l10n_util.h"
25 #include "ui/gfx/skia_util.h" 29 #include "ui/gfx/skia_util.h"
26 30
27 using content::BrowserThread; 31 using content::BrowserThread;
28 using content::DesktopMediaID; 32 using content::DesktopMediaID;
29 33
30 namespace { 34 namespace {
31 35
32 // Update the list every second. 36 // Update the list every second.
33 const int kDefaultUpdatePeriod = 1000; 37 const int kDefaultUpdatePeriod = 1000;
34 38
35 // Returns a hash of a DesktopFrame content to detect when image for a desktop 39 // Returns a hash of a DesktopFrame content to detect when image for a desktop
36 // media source has changed. 40 // media source has changed.
37 uint32 GetFrameHash(webrtc::DesktopFrame* frame) { 41 uint32_t GetFrameHash(webrtc::DesktopFrame* frame) {
38 int data_size = frame->stride() * frame->size().height(); 42 int data_size = frame->stride() * frame->size().height();
39 return base::SuperFastHash(reinterpret_cast<char*>(frame->data()), data_size); 43 return base::SuperFastHash(reinterpret_cast<char*>(frame->data()), data_size);
40 } 44 }
41 45
42 gfx::ImageSkia ScaleDesktopFrame(scoped_ptr<webrtc::DesktopFrame> frame, 46 gfx::ImageSkia ScaleDesktopFrame(scoped_ptr<webrtc::DesktopFrame> frame,
43 gfx::Size size) { 47 gfx::Size size) {
44 gfx::Rect scaled_rect = media::ComputeLetterboxRegion( 48 gfx::Rect scaled_rect = media::ComputeLetterboxRegion(
45 gfx::Rect(0, 0, size.width(), size.height()), 49 gfx::Rect(0, 0, size.width(), size.height()),
46 gfx::Size(frame->size().width(), frame->size().height())); 50 gfx::Size(frame->size().width(), frame->size().height()));
47 51
48 SkBitmap result; 52 SkBitmap result;
49 result.allocN32Pixels(scaled_rect.width(), scaled_rect.height(), true); 53 result.allocN32Pixels(scaled_rect.width(), scaled_rect.height(), true);
50 result.lockPixels(); 54 result.lockPixels();
51 55
52 uint8* pixels_data = reinterpret_cast<uint8*>(result.getPixels()); 56 uint8_t* pixels_data = reinterpret_cast<uint8_t*>(result.getPixels());
53 libyuv::ARGBScale(frame->data(), frame->stride(), 57 libyuv::ARGBScale(frame->data(), frame->stride(),
54 frame->size().width(), frame->size().height(), 58 frame->size().width(), frame->size().height(),
55 pixels_data, result.rowBytes(), 59 pixels_data, result.rowBytes(),
56 scaled_rect.width(), scaled_rect.height(), 60 scaled_rect.width(), scaled_rect.height(),
57 libyuv::kFilterBilinear); 61 libyuv::kFilterBilinear);
58 62
59 // Set alpha channel values to 255 for all pixels. 63 // Set alpha channel values to 255 for all pixels.
60 // TODO(sergeyu): Fix screen/window capturers to capture alpha channel and 64 // TODO(sergeyu): Fix screen/window capturers to capture alpha channel and
61 // remove this code. Currently screen/window capturers (at least some 65 // remove this code. Currently screen/window capturers (at least some
62 // implementations) only capture R, G and B channels and set Alpha to 0. 66 // implementations) only capture R, G and B channels and set Alpha to 0.
(...skipping 24 matching lines...) Expand all
87 public: 91 public:
88 Worker(base::WeakPtr<NativeDesktopMediaList> media_list, 92 Worker(base::WeakPtr<NativeDesktopMediaList> media_list,
89 scoped_ptr<webrtc::ScreenCapturer> screen_capturer, 93 scoped_ptr<webrtc::ScreenCapturer> screen_capturer,
90 scoped_ptr<webrtc::WindowCapturer> window_capturer); 94 scoped_ptr<webrtc::WindowCapturer> window_capturer);
91 ~Worker() override; 95 ~Worker() override;
92 96
93 void Refresh(const gfx::Size& thumbnail_size, 97 void Refresh(const gfx::Size& thumbnail_size,
94 content::DesktopMediaID::Id view_dialog_id); 98 content::DesktopMediaID::Id view_dialog_id);
95 99
96 private: 100 private:
97 typedef std::map<DesktopMediaID, uint32> ImageHashesMap; 101 typedef std::map<DesktopMediaID, uint32_t> ImageHashesMap;
98 102
99 // webrtc::DesktopCapturer::Callback interface. 103 // webrtc::DesktopCapturer::Callback interface.
100 webrtc::SharedMemory* CreateSharedMemory(size_t size) override; 104 webrtc::SharedMemory* CreateSharedMemory(size_t size) override;
101 void OnCaptureCompleted(webrtc::DesktopFrame* frame) override; 105 void OnCaptureCompleted(webrtc::DesktopFrame* frame) override;
102 106
103 base::WeakPtr<NativeDesktopMediaList> media_list_; 107 base::WeakPtr<NativeDesktopMediaList> media_list_;
104 108
105 scoped_ptr<webrtc::ScreenCapturer> screen_capturer_; 109 scoped_ptr<webrtc::ScreenCapturer> screen_capturer_;
106 scoped_ptr<webrtc::WindowCapturer> window_capturer_; 110 scoped_ptr<webrtc::WindowCapturer> window_capturer_;
107 111
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 break; 195 break;
192 196
193 default: 197 default:
194 NOTREACHED(); 198 NOTREACHED();
195 } 199 }
196 200
197 // Expect that DesktopCapturer to always captures frames synchronously. 201 // Expect that DesktopCapturer to always captures frames synchronously.
198 // |current_frame_| may be NULL if capture failed (e.g. because window has 202 // |current_frame_| may be NULL if capture failed (e.g. because window has
199 // been closed). 203 // been closed).
200 if (current_frame_) { 204 if (current_frame_) {
201 uint32 frame_hash = GetFrameHash(current_frame_.get()); 205 uint32_t frame_hash = GetFrameHash(current_frame_.get());
202 new_image_hashes[source.id] = frame_hash; 206 new_image_hashes[source.id] = frame_hash;
203 207
204 // Scale the image only if it has changed. 208 // Scale the image only if it has changed.
205 ImageHashesMap::iterator it = image_hashes_.find(source.id); 209 ImageHashesMap::iterator it = image_hashes_.find(source.id);
206 if (it == image_hashes_.end() || it->second != frame_hash) { 210 if (it == image_hashes_.end() || it->second != frame_hash) {
207 gfx::ImageSkia thumbnail = 211 gfx::ImageSkia thumbnail =
208 ScaleDesktopFrame(current_frame_.Pass(), thumbnail_size); 212 ScaleDesktopFrame(current_frame_.Pass(), thumbnail_size);
209 BrowserThread::PostTask( 213 BrowserThread::PostTask(
210 BrowserThread::UI, FROM_HERE, 214 BrowserThread::UI, FROM_HERE,
211 base::Bind(&NativeDesktopMediaList::OnSourceThumbnail, 215 base::Bind(&NativeDesktopMediaList::OnSourceThumbnail,
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 observer_->OnSourceThumbnailChanged(index); 365 observer_->OnSourceThumbnailChanged(index);
362 } 366 }
363 367
364 void NativeDesktopMediaList::OnRefreshFinished() { 368 void NativeDesktopMediaList::OnRefreshFinished() {
365 BrowserThread::PostDelayedTask( 369 BrowserThread::PostDelayedTask(
366 BrowserThread::UI, FROM_HERE, 370 BrowserThread::UI, FROM_HERE,
367 base::Bind(&NativeDesktopMediaList::Refresh, 371 base::Bind(&NativeDesktopMediaList::Refresh,
368 weak_factory_.GetWeakPtr()), 372 weak_factory_.GetWeakPtr()),
369 update_period_); 373 update_period_);
370 } 374 }
OLDNEW
« no previous file with comments | « chrome/browser/media/native_desktop_media_list.h ('k') | chrome/browser/media/native_desktop_media_list_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698