| 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 "content/browser/media/capture/aura_window_capture_machine.h" | 5 #include "content/browser/media/capture/aura_window_capture_machine.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
| 12 #include "base/timer/timer.h" | |
| 13 #include "cc/output/copy_output_request.h" | 12 #include "cc/output/copy_output_request.h" |
| 14 #include "cc/output/copy_output_result.h" | 13 #include "cc/output/copy_output_result.h" |
| 15 #include "content/browser/compositor/gl_helper.h" | 14 #include "content/browser/compositor/gl_helper.h" |
| 16 #include "content/browser/compositor/image_transport_factory.h" | 15 #include "content/browser/compositor/image_transport_factory.h" |
| 17 #include "content/browser/media/capture/desktop_capture_device_uma_types.h" | 16 #include "content/browser/media/capture/desktop_capture_device_uma_types.h" |
| 18 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
| 19 #include "content/public/browser/power_save_blocker.h" | 18 #include "content/public/browser/power_save_blocker.h" |
| 20 #include "media/base/video_capture_types.h" | 19 #include "media/base/video_capture_types.h" |
| 21 #include "media/base/video_util.h" | 20 #include "media/base/video_util.h" |
| 22 #include "media/capture/content/thread_safe_capture_oracle.h" | 21 #include "media/capture/content/thread_safe_capture_oracle.h" |
| 23 #include "media/capture/content/video_capture_oracle.h" | 22 #include "media/capture/content/video_capture_oracle.h" |
| 24 #include "skia/ext/image_operations.h" | 23 #include "skia/ext/image_operations.h" |
| 25 #include "third_party/skia/include/core/SkBitmap.h" | 24 #include "third_party/skia/include/core/SkBitmap.h" |
| 26 #include "ui/aura/client/screen_position_client.h" | 25 #include "ui/aura/client/screen_position_client.h" |
| 27 #include "ui/aura/env.h" | 26 #include "ui/aura/env.h" |
| 28 #include "ui/aura/window.h" | 27 #include "ui/aura/window.h" |
| 29 #include "ui/aura/window_observer.h" | 28 #include "ui/aura/window_observer.h" |
| 30 #include "ui/aura/window_tree_host.h" | 29 #include "ui/aura/window_tree_host.h" |
| 31 #include "ui/base/cursor/cursors_aura.h" | 30 #include "ui/base/cursor/cursors_aura.h" |
| 32 #include "ui/compositor/compositor.h" | 31 #include "ui/compositor/compositor.h" |
| 33 #include "ui/compositor/dip_util.h" | 32 #include "ui/compositor/dip_util.h" |
| 34 #include "ui/compositor/layer.h" | 33 #include "ui/compositor/layer.h" |
| 35 #include "ui/gfx/screen.h" | 34 #include "ui/gfx/screen.h" |
| 36 #include "ui/wm/public/activation_client.h" | 35 #include "ui/wm/public/activation_client.h" |
| 37 | 36 |
| 38 namespace content { | 37 namespace content { |
| 39 | 38 |
| 40 AuraWindowCaptureMachine::AuraWindowCaptureMachine() | 39 AuraWindowCaptureMachine::AuraWindowCaptureMachine() |
| 41 : desktop_window_(NULL), | 40 : desktop_window_(NULL), |
| 42 timer_(true, true), | |
| 43 screen_capture_(false), | 41 screen_capture_(false), |
| 44 weak_factory_(this) {} | 42 weak_factory_(this) {} |
| 45 | 43 |
| 46 AuraWindowCaptureMachine::~AuraWindowCaptureMachine() {} | 44 AuraWindowCaptureMachine::~AuraWindowCaptureMachine() {} |
| 47 | 45 |
| 48 void AuraWindowCaptureMachine::Start( | 46 void AuraWindowCaptureMachine::Start( |
| 49 const scoped_refptr<media::ThreadSafeCaptureOracle>& oracle_proxy, | 47 const scoped_refptr<media::ThreadSafeCaptureOracle>& oracle_proxy, |
| 50 const media::VideoCaptureParams& params, | 48 const media::VideoCaptureParams& params, |
| 51 const base::Callback<void(bool)> callback) { | 49 const base::Callback<void(bool)> callback) { |
| 52 // Starts the capture machine asynchronously. | 50 // Starts the capture machine asynchronously. |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 // Start observing compositor updates. | 82 // Start observing compositor updates. |
| 85 if (desktop_window_->GetHost()) | 83 if (desktop_window_->GetHost()) |
| 86 desktop_window_->GetHost()->compositor()->AddObserver(this); | 84 desktop_window_->GetHost()->compositor()->AddObserver(this); |
| 87 | 85 |
| 88 power_save_blocker_.reset( | 86 power_save_blocker_.reset( |
| 89 PowerSaveBlocker::Create( | 87 PowerSaveBlocker::Create( |
| 90 PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep, | 88 PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep, |
| 91 PowerSaveBlocker::kReasonOther, | 89 PowerSaveBlocker::kReasonOther, |
| 92 "DesktopCaptureDevice is running").release()); | 90 "DesktopCaptureDevice is running").release()); |
| 93 | 91 |
| 94 // Starts timer. | |
| 95 timer_.Start(FROM_HERE, | |
| 96 std::max(oracle_proxy_->min_capture_period(), | |
| 97 base::TimeDelta::FromMilliseconds(media:: | |
| 98 VideoCaptureOracle::kMinTimerPollPeriodMillis)), | |
| 99 base::Bind(&AuraWindowCaptureMachine::Capture, | |
| 100 base::Unretained(this), false)); | |
| 101 | |
| 102 return true; | 92 return true; |
| 103 } | 93 } |
| 104 | 94 |
| 105 void AuraWindowCaptureMachine::Stop(const base::Closure& callback) { | 95 void AuraWindowCaptureMachine::Stop(const base::Closure& callback) { |
| 106 // Stops the capture machine asynchronously. | 96 // Stops the capture machine asynchronously. |
| 107 BrowserThread::PostTask( | 97 BrowserThread::PostTask( |
| 108 BrowserThread::UI, FROM_HERE, base::Bind( | 98 BrowserThread::UI, FROM_HERE, base::Bind( |
| 109 &AuraWindowCaptureMachine::InternalStop, | 99 &AuraWindowCaptureMachine::InternalStop, |
| 110 base::Unretained(this), | 100 base::Unretained(this), |
| 111 callback)); | 101 callback)); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 123 if (desktop_window_) { | 113 if (desktop_window_) { |
| 124 aura::WindowTreeHost* window_host = desktop_window_->GetHost(); | 114 aura::WindowTreeHost* window_host = desktop_window_->GetHost(); |
| 125 // In the host destructor the compositor is destroyed before the window. | 115 // In the host destructor the compositor is destroyed before the window. |
| 126 if (window_host && window_host->compositor()) | 116 if (window_host && window_host->compositor()) |
| 127 window_host->compositor()->RemoveObserver(this); | 117 window_host->compositor()->RemoveObserver(this); |
| 128 desktop_window_->RemoveObserver(this); | 118 desktop_window_->RemoveObserver(this); |
| 129 desktop_window_ = NULL; | 119 desktop_window_ = NULL; |
| 130 cursor_renderer_.reset(); | 120 cursor_renderer_.reset(); |
| 131 } | 121 } |
| 132 | 122 |
| 133 // Stop timer. | 123 callback.Run(); |
| 134 timer_.Stop(); | 124 } |
| 135 | 125 |
| 136 callback.Run(); | 126 void AuraWindowCaptureMachine::MaybeCaptureForRefresh() { |
| 127 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 128 Capture(false); |
| 137 } | 129 } |
| 138 | 130 |
| 139 void AuraWindowCaptureMachine::SetWindow(aura::Window* window) { | 131 void AuraWindowCaptureMachine::SetWindow(aura::Window* window) { |
| 140 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 132 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 141 | 133 |
| 142 DCHECK(!desktop_window_); | 134 DCHECK(!desktop_window_); |
| 143 desktop_window_ = window; | 135 desktop_window_ = window; |
| 144 cursor_renderer_.reset(new CursorRendererAura(window, kCursorAlwaysEnabled)); | 136 cursor_renderer_.reset(new CursorRendererAura(window, kCursorAlwaysEnabled)); |
| 145 | 137 |
| 146 // Start observing window events. | 138 // Start observing window events. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 172 | 164 |
| 173 scoped_refptr<media::VideoFrame> frame; | 165 scoped_refptr<media::VideoFrame> frame; |
| 174 media::ThreadSafeCaptureOracle::CaptureFrameCallback capture_frame_cb; | 166 media::ThreadSafeCaptureOracle::CaptureFrameCallback capture_frame_cb; |
| 175 | 167 |
| 176 // TODO(miu): Need to fix this so the compositor is providing the presentation | 168 // TODO(miu): Need to fix this so the compositor is providing the presentation |
| 177 // timestamps and damage regions, to leverage the frame timestamp rewriting | 169 // timestamps and damage regions, to leverage the frame timestamp rewriting |
| 178 // logic. http://crbug.com/492839 | 170 // logic. http://crbug.com/492839 |
| 179 const base::TimeTicks start_time = base::TimeTicks::Now(); | 171 const base::TimeTicks start_time = base::TimeTicks::Now(); |
| 180 const media::VideoCaptureOracle::Event event = | 172 const media::VideoCaptureOracle::Event event = |
| 181 dirty ? media::VideoCaptureOracle::kCompositorUpdate | 173 dirty ? media::VideoCaptureOracle::kCompositorUpdate |
| 182 : media::VideoCaptureOracle::kTimerPoll; | 174 : media::VideoCaptureOracle::kActiveRefreshRequest; |
| 183 if (oracle_proxy_->ObserveEventAndDecideCapture( | 175 if (oracle_proxy_->ObserveEventAndDecideCapture( |
| 184 event, gfx::Rect(), start_time, &frame, &capture_frame_cb)) { | 176 event, gfx::Rect(), start_time, &frame, &capture_frame_cb)) { |
| 185 scoped_ptr<cc::CopyOutputRequest> request = | 177 scoped_ptr<cc::CopyOutputRequest> request = |
| 186 cc::CopyOutputRequest::CreateRequest( | 178 cc::CopyOutputRequest::CreateRequest( |
| 187 base::Bind(&AuraWindowCaptureMachine::DidCopyOutput, | 179 base::Bind(&AuraWindowCaptureMachine::DidCopyOutput, |
| 188 weak_factory_.GetWeakPtr(), | 180 weak_factory_.GetWeakPtr(), |
| 189 frame, start_time, capture_frame_cb)); | 181 frame, start_time, capture_frame_cb)); |
| 190 gfx::Rect window_rect = gfx::Rect(desktop_window_->bounds().width(), | 182 gfx::Rect window_rect = gfx::Rect(desktop_window_->bounds().width(), |
| 191 desktop_window_->bounds().height()); | 183 desktop_window_->bounds().height()); |
| 192 request->set_area(window_rect); | 184 request->set_area(window_rect); |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 // TODO(miu): The CopyOutputRequest should be made earlier, at WillCommit(). | 352 // TODO(miu): The CopyOutputRequest should be made earlier, at WillCommit(). |
| 361 // http://crbug.com/492839 | 353 // http://crbug.com/492839 |
| 362 BrowserThread::PostTask( | 354 BrowserThread::PostTask( |
| 363 BrowserThread::UI, | 355 BrowserThread::UI, |
| 364 FROM_HERE, | 356 FROM_HERE, |
| 365 base::Bind(&AuraWindowCaptureMachine::Capture, weak_factory_.GetWeakPtr(), | 357 base::Bind(&AuraWindowCaptureMachine::Capture, weak_factory_.GetWeakPtr(), |
| 366 true)); | 358 true)); |
| 367 } | 359 } |
| 368 | 360 |
| 369 } // namespace content | 361 } // namespace content |
| OLD | NEW |