| OLD | NEW |
| 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/webrtc/native_desktop_media_list.h" | 5 #include "chrome/browser/media/webrtc/native_desktop_media_list.h" |
| 6 | 6 |
| 7 #include "base/hash.h" | 7 #include "base/hash.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "base/threading/sequenced_worker_pool.h" | 9 #include "base/threading/sequenced_worker_pool.h" |
| 10 #include "chrome/browser/media/webrtc/desktop_media_list_observer.h" | 10 #include "chrome/browser/media/webrtc/desktop_media_list_observer.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 } | 47 } |
| 48 | 48 |
| 49 gfx::ImageSkia ScaleDesktopFrame(std::unique_ptr<webrtc::DesktopFrame> frame, | 49 gfx::ImageSkia ScaleDesktopFrame(std::unique_ptr<webrtc::DesktopFrame> frame, |
| 50 gfx::Size size) { | 50 gfx::Size size) { |
| 51 gfx::Rect scaled_rect = media::ComputeLetterboxRegion( | 51 gfx::Rect scaled_rect = media::ComputeLetterboxRegion( |
| 52 gfx::Rect(0, 0, size.width(), size.height()), | 52 gfx::Rect(0, 0, size.width(), size.height()), |
| 53 gfx::Size(frame->size().width(), frame->size().height())); | 53 gfx::Size(frame->size().width(), frame->size().height())); |
| 54 | 54 |
| 55 SkBitmap result; | 55 SkBitmap result; |
| 56 result.allocN32Pixels(scaled_rect.width(), scaled_rect.height(), true); | 56 result.allocN32Pixels(scaled_rect.width(), scaled_rect.height(), true); |
| 57 result.lockPixels(); | |
| 58 | 57 |
| 59 uint8_t* pixels_data = reinterpret_cast<uint8_t*>(result.getPixels()); | 58 uint8_t* pixels_data = reinterpret_cast<uint8_t*>(result.getPixels()); |
| 60 libyuv::ARGBScale(frame->data(), frame->stride(), | 59 libyuv::ARGBScale(frame->data(), frame->stride(), |
| 61 frame->size().width(), frame->size().height(), | 60 frame->size().width(), frame->size().height(), |
| 62 pixels_data, result.rowBytes(), | 61 pixels_data, result.rowBytes(), |
| 63 scaled_rect.width(), scaled_rect.height(), | 62 scaled_rect.width(), scaled_rect.height(), |
| 64 libyuv::kFilterBilinear); | 63 libyuv::kFilterBilinear); |
| 65 | 64 |
| 66 // Set alpha channel values to 255 for all pixels. | 65 // Set alpha channel values to 255 for all pixels. |
| 67 // TODO(sergeyu): Fix screen/window capturers to capture alpha channel and | 66 // TODO(sergeyu): Fix screen/window capturers to capture alpha channel and |
| 68 // remove this code. Currently screen/window capturers (at least some | 67 // remove this code. Currently screen/window capturers (at least some |
| 69 // implementations) only capture R, G and B channels and set Alpha to 0. | 68 // implementations) only capture R, G and B channels and set Alpha to 0. |
| 70 // crbug.com/264424 | 69 // crbug.com/264424 |
| 71 for (int y = 0; y < result.height(); ++y) { | 70 for (int y = 0; y < result.height(); ++y) { |
| 72 for (int x = 0; x < result.width(); ++x) { | 71 for (int x = 0; x < result.width(); ++x) { |
| 73 pixels_data[result.rowBytes() * y + x * result.bytesPerPixel() + 3] = | 72 pixels_data[result.rowBytes() * y + x * result.bytesPerPixel() + 3] = |
| 74 0xff; | 73 0xff; |
| 75 } | 74 } |
| 76 } | 75 } |
| 77 | 76 |
| 78 result.unlockPixels(); | |
| 79 | |
| 80 return gfx::ImageSkia::CreateFrom1xBitmap(result); | 77 return gfx::ImageSkia::CreateFrom1xBitmap(result); |
| 81 } | 78 } |
| 82 | 79 |
| 83 } // namespace | 80 } // namespace |
| 84 | 81 |
| 85 class NativeDesktopMediaList::Worker | 82 class NativeDesktopMediaList::Worker |
| 86 : public webrtc::DesktopCapturer::Callback { | 83 : public webrtc::DesktopCapturer::Callback { |
| 87 public: | 84 public: |
| 88 Worker(base::WeakPtr<NativeDesktopMediaList> media_list, | 85 Worker(base::WeakPtr<NativeDesktopMediaList> media_list, |
| 89 std::unique_ptr<webrtc::DesktopCapturer> screen_capturer, | 86 std::unique_ptr<webrtc::DesktopCapturer> screen_capturer, |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 if (pending_aura_capture_requests_ == 0) { | 366 if (pending_aura_capture_requests_ == 0) { |
| 370 previous_aura_thumbnail_hashes_ = std::move(new_aura_thumbnail_hashes_); | 367 previous_aura_thumbnail_hashes_ = std::move(new_aura_thumbnail_hashes_); |
| 371 // Schedule next refresh if aura thumbnail captures finished after native | 368 // Schedule next refresh if aura thumbnail captures finished after native |
| 372 // thumbnail captures. | 369 // thumbnail captures. |
| 373 if (!pending_native_thumbnail_capture_) | 370 if (!pending_native_thumbnail_capture_) |
| 374 ScheduleNextRefresh(); | 371 ScheduleNextRefresh(); |
| 375 } | 372 } |
| 376 } | 373 } |
| 377 | 374 |
| 378 #endif // defined(USE_AURA) | 375 #endif // defined(USE_AURA) |
| OLD | NEW |