| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/desktop_capture_device_aura.h" | 5 #include "content/browser/media/capture/aura_window_capture_machine.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "base/timer/timer.h" | 9 #include "base/timer/timer.h" |
| 10 #include "cc/output/copy_output_request.h" | 10 #include "cc/output/copy_output_request.h" |
| 11 #include "cc/output/copy_output_result.h" | 11 #include "cc/output/copy_output_result.h" |
| 12 #include "content/browser/compositor/image_transport_factory.h" | 12 #include "content/browser/compositor/image_transport_factory.h" |
| 13 #include "content/browser/media/capture/content_video_capture_device_core.h" | 13 #include "content/browser/media/capture/content_video_capture_device_core.h" |
| 14 #include "content/browser/media/capture/desktop_capture_device_uma_types.h" | 14 #include "content/browser/media/capture/desktop_capture_device_uma_types.h" |
| 15 #include "content/common/gpu/client/gl_helper.h" | 15 #include "content/common/gpu/client/gl_helper.h" |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 int color_v = clip_byte(((color_r * 112 + color_g * -94 + | 82 int color_v = clip_byte(((color_r * 112 + color_g * -94 + |
| 83 color_b * -18 + 128) >> 8) + 128); | 83 color_b * -18 + 128) >> 8) + 128); |
| 84 uplane[x / 2] = alpha_blend(alpha, color_u, uplane[x / 2]); | 84 uplane[x / 2] = alpha_blend(alpha, color_u, uplane[x / 2]); |
| 85 vplane[x / 2] = alpha_blend(alpha, color_v, vplane[x / 2]); | 85 vplane[x / 2] = alpha_blend(alpha, color_v, vplane[x / 2]); |
| 86 } | 86 } |
| 87 } | 87 } |
| 88 } | 88 } |
| 89 cursor_bitmap.unlockPixels(); | 89 cursor_bitmap.unlockPixels(); |
| 90 } | 90 } |
| 91 | 91 |
| 92 class DesktopVideoCaptureMachine | 92 void CopyOutputFinishedForVideo( |
| 93 : public VideoCaptureMachine, | 93 base::TimeTicks start_time, |
| 94 public aura::WindowObserver, | 94 const ThreadSafeCaptureOracle::CaptureFrameCallback& capture_frame_cb, |
| 95 public ui::CompositorObserver, | 95 const scoped_refptr<media::VideoFrame>& target, |
| 96 public base::SupportsWeakPtr<DesktopVideoCaptureMachine> { | 96 const SkBitmap& cursor_bitmap, |
| 97 public: | 97 const gfx::Point& cursor_position, |
| 98 DesktopVideoCaptureMachine(const DesktopMediaID& source); | 98 scoped_ptr<cc::SingleReleaseCallback> release_callback, |
| 99 ~DesktopVideoCaptureMachine() override; | 99 bool result) { |
| 100 if (!cursor_bitmap.isNull()) |
| 101 RenderCursorOnVideoFrame(target, cursor_bitmap, cursor_position); |
| 102 release_callback->Run(0, false); |
| 103 capture_frame_cb.Run(target, start_time, result); |
| 104 } |
| 100 | 105 |
| 101 // VideoCaptureFrameSource overrides. | 106 void RunSingleReleaseCallback(scoped_ptr<cc::SingleReleaseCallback> cb, |
| 102 bool Start(const scoped_refptr<ThreadSafeCaptureOracle>& oracle_proxy, | 107 uint32 sync_point) { |
| 103 const media::VideoCaptureParams& params) override; | 108 cb->Run(sync_point, false); |
| 104 void Stop(const base::Closure& callback) override; | 109 } |
| 105 | 110 |
| 106 // Implements aura::WindowObserver. | 111 } // namespace |
| 107 void OnWindowBoundsChanged(aura::Window* window, | |
| 108 const gfx::Rect& old_bounds, | |
| 109 const gfx::Rect& new_bounds) override; | |
| 110 void OnWindowDestroyed(aura::Window* window) override; | |
| 111 void OnWindowAddedToRootWindow(aura::Window* window) override; | |
| 112 void OnWindowRemovingFromRootWindow(aura::Window* window, | |
| 113 aura::Window* new_root) override; | |
| 114 | 112 |
| 115 // Implements ui::CompositorObserver. | 113 AuraWindowCaptureMachine::AuraWindowCaptureMachine() |
| 116 void OnCompositingDidCommit(ui::Compositor* compositor) override {} | |
| 117 void OnCompositingStarted(ui::Compositor* compositor, | |
| 118 base::TimeTicks start_time) override {} | |
| 119 void OnCompositingEnded(ui::Compositor* compositor) override; | |
| 120 void OnCompositingAborted(ui::Compositor* compositor) override {} | |
| 121 void OnCompositingLockStateChanged(ui::Compositor* compositor) override {} | |
| 122 void OnCompositingShuttingDown(ui::Compositor* compositor) override {} | |
| 123 | |
| 124 private: | |
| 125 // Captures a frame. | |
| 126 // |dirty| is false for timer polls and true for compositor updates. | |
| 127 void Capture(bool dirty); | |
| 128 | |
| 129 // Update capture size. Must be called on the UI thread. | |
| 130 void UpdateCaptureSize(); | |
| 131 | |
| 132 // Response callback for cc::Layer::RequestCopyOfOutput(). | |
| 133 void DidCopyOutput( | |
| 134 scoped_refptr<media::VideoFrame> video_frame, | |
| 135 base::TimeTicks start_time, | |
| 136 const ThreadSafeCaptureOracle::CaptureFrameCallback& capture_frame_cb, | |
| 137 scoped_ptr<cc::CopyOutputResult> result); | |
| 138 | |
| 139 // A helper which does the real work for DidCopyOutput. Returns true if | |
| 140 // succeeded. | |
| 141 bool ProcessCopyOutputResponse( | |
| 142 scoped_refptr<media::VideoFrame> video_frame, | |
| 143 base::TimeTicks start_time, | |
| 144 const ThreadSafeCaptureOracle::CaptureFrameCallback& capture_frame_cb, | |
| 145 scoped_ptr<cc::CopyOutputResult> result); | |
| 146 | |
| 147 // Helper function to update cursor state. | |
| 148 // |region_in_frame| defines the desktop bound in the captured frame. | |
| 149 // Returns the current cursor position in captured frame. | |
| 150 gfx::Point UpdateCursorState(const gfx::Rect& region_in_frame); | |
| 151 | |
| 152 // Clears cursor state. | |
| 153 void ClearCursorState(); | |
| 154 | |
| 155 // The window associated with the desktop. | |
| 156 aura::Window* desktop_window_; | |
| 157 | |
| 158 // The timer that kicks off period captures. | |
| 159 base::Timer timer_; | |
| 160 | |
| 161 // The id of the window being captured. | |
| 162 DesktopMediaID window_id_; | |
| 163 | |
| 164 // Makes all the decisions about which frames to copy, and how. | |
| 165 scoped_refptr<ThreadSafeCaptureOracle> oracle_proxy_; | |
| 166 | |
| 167 // The capture parameters for this capture. | |
| 168 media::VideoCaptureParams capture_params_; | |
| 169 | |
| 170 // YUV readback pipeline. | |
| 171 scoped_ptr<content::ReadbackYUVInterface> yuv_readback_pipeline_; | |
| 172 | |
| 173 // Cursor state. | |
| 174 ui::Cursor last_cursor_; | |
| 175 gfx::Point cursor_hot_point_; | |
| 176 SkBitmap scaled_cursor_bitmap_; | |
| 177 | |
| 178 // TODO(jiayl): Remove power_save_blocker_ when there is an API to keep the | |
| 179 // screen from sleeping for the drive-by web. | |
| 180 scoped_ptr<PowerSaveBlocker> power_save_blocker_; | |
| 181 | |
| 182 DISALLOW_COPY_AND_ASSIGN(DesktopVideoCaptureMachine); | |
| 183 }; | |
| 184 | |
| 185 DesktopVideoCaptureMachine::DesktopVideoCaptureMachine( | |
| 186 const DesktopMediaID& source) | |
| 187 : desktop_window_(NULL), | 114 : desktop_window_(NULL), |
| 188 timer_(true, true), | 115 timer_(true, true), |
| 189 window_id_(source) {} | 116 screen_capture_(false) {} |
| 190 | 117 |
| 191 DesktopVideoCaptureMachine::~DesktopVideoCaptureMachine() {} | 118 AuraWindowCaptureMachine::~AuraWindowCaptureMachine() {} |
| 192 | 119 |
| 193 bool DesktopVideoCaptureMachine::Start( | 120 bool AuraWindowCaptureMachine::Start( |
| 194 const scoped_refptr<ThreadSafeCaptureOracle>& oracle_proxy, | 121 const scoped_refptr<ThreadSafeCaptureOracle>& oracle_proxy, |
| 195 const media::VideoCaptureParams& params) { | 122 const media::VideoCaptureParams& params) { |
| 196 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 123 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 197 | 124 DCHECK(desktop_window_); |
| 198 desktop_window_ = content::DesktopMediaID::GetAuraWindowById(window_id_); | |
| 199 if (!desktop_window_) | |
| 200 return false; | |
| 201 | 125 |
| 202 // If the associated layer is already destroyed then return failure. | 126 // If the associated layer is already destroyed then return failure. |
| 203 ui::Layer* layer = desktop_window_->layer(); | 127 ui::Layer* layer = desktop_window_->layer(); |
| 204 if (!layer) | 128 if (!layer) |
| 205 return false; | 129 return false; |
| 206 | 130 |
| 207 DCHECK(oracle_proxy.get()); | 131 DCHECK(oracle_proxy.get()); |
| 208 oracle_proxy_ = oracle_proxy; | 132 oracle_proxy_ = oracle_proxy; |
| 209 capture_params_ = params; | 133 capture_params_ = params; |
| 210 | 134 |
| 211 // Update capture size. | 135 // Update capture size. |
| 212 UpdateCaptureSize(); | 136 UpdateCaptureSize(); |
| 213 | 137 |
| 214 // Start observing window events. | |
| 215 desktop_window_->AddObserver(this); | |
| 216 | |
| 217 // Start observing compositor updates. | |
| 218 if (desktop_window_->GetHost()) | |
| 219 desktop_window_->GetHost()->compositor()->AddObserver(this); | |
| 220 | |
| 221 power_save_blocker_.reset( | 138 power_save_blocker_.reset( |
| 222 PowerSaveBlocker::Create( | 139 PowerSaveBlocker::Create( |
| 223 PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep, | 140 PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep, |
| 224 PowerSaveBlocker::kReasonOther, | 141 PowerSaveBlocker::kReasonOther, |
| 225 "DesktopCaptureDevice is running").release()); | 142 "DesktopCaptureDevice is running").release()); |
| 226 | 143 |
| 227 // Starts timer. | 144 // Starts timer. |
| 228 timer_.Start(FROM_HERE, oracle_proxy_->min_capture_period(), | 145 timer_.Start(FROM_HERE, oracle_proxy_->min_capture_period(), |
| 229 base::Bind(&DesktopVideoCaptureMachine::Capture, AsWeakPtr(), | 146 base::Bind(&AuraWindowCaptureMachine::Capture, AsWeakPtr(), |
| 230 false)); | 147 false)); |
| 231 | 148 |
| 232 return true; | 149 return true; |
| 233 } | 150 } |
| 234 | 151 |
| 235 void DesktopVideoCaptureMachine::Stop(const base::Closure& callback) { | 152 void AuraWindowCaptureMachine::Stop(const base::Closure& callback) { |
| 236 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 153 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 237 power_save_blocker_.reset(); | 154 power_save_blocker_.reset(); |
| 238 | 155 |
| 239 // Stop observing compositor and window events. | 156 // Stop observing compositor and window events. |
| 240 if (desktop_window_) { | 157 if (desktop_window_) { |
| 241 aura::WindowTreeHost* window_host = desktop_window_->GetHost(); | 158 aura::WindowTreeHost* window_host = desktop_window_->GetHost(); |
| 242 // In the host destructor the compositor is destroyed before the window. | 159 // In the host destructor the compositor is destroyed before the window. |
| 243 if (window_host && window_host->compositor()) | 160 if (window_host && window_host->compositor()) |
| 244 window_host->compositor()->RemoveObserver(this); | 161 window_host->compositor()->RemoveObserver(this); |
| 245 desktop_window_->RemoveObserver(this); | 162 desktop_window_->RemoveObserver(this); |
| 246 desktop_window_ = NULL; | 163 desktop_window_ = NULL; |
| 247 } | 164 } |
| 248 | 165 |
| 249 // Stop timer. | 166 // Stop timer. |
| 250 timer_.Stop(); | 167 timer_.Stop(); |
| 251 | 168 |
| 252 callback.Run(); | 169 callback.Run(); |
| 253 } | 170 } |
| 254 | 171 |
| 255 void DesktopVideoCaptureMachine::UpdateCaptureSize() { | 172 void AuraWindowCaptureMachine::SetWindow(aura::Window* window) { |
| 173 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 174 |
| 175 DCHECK(!desktop_window_); |
| 176 desktop_window_ = window; |
| 177 |
| 178 // Start observing window events. |
| 179 desktop_window_->AddObserver(this); |
| 180 |
| 181 // Start observing compositor updates. |
| 182 if (desktop_window_->GetHost()) |
| 183 desktop_window_->GetHost()->compositor()->AddObserver(this); |
| 184 |
| 185 // We must store this for the UMA reporting in DidCopyOutput() as |
| 186 // desktop_window_ might be destroyed at that point. |
| 187 screen_capture_ = window->IsRootWindow(); |
| 188 IncrementDesktopCaptureCounter(screen_capture_ ? SCREEN_CAPTURER_CREATED |
| 189 : WINDOW_CAPTURER_CREATED); |
| 190 } |
| 191 |
| 192 void AuraWindowCaptureMachine::UpdateCaptureSize() { |
| 256 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 193 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 257 if (oracle_proxy_.get() && desktop_window_) { | 194 if (oracle_proxy_.get() && desktop_window_) { |
| 258 ui::Layer* layer = desktop_window_->layer(); | 195 ui::Layer* layer = desktop_window_->layer(); |
| 259 oracle_proxy_->UpdateCaptureSize(ui::ConvertSizeToPixel( | 196 oracle_proxy_->UpdateCaptureSize(ui::ConvertSizeToPixel( |
| 260 layer, layer->bounds().size())); | 197 layer, layer->bounds().size())); |
| 261 } | 198 } |
| 262 ClearCursorState(); | 199 ClearCursorState(); |
| 263 } | 200 } |
| 264 | 201 |
| 265 void DesktopVideoCaptureMachine::Capture(bool dirty) { | 202 void AuraWindowCaptureMachine::Capture(bool dirty) { |
| 266 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 203 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 267 | 204 |
| 268 // Do not capture if the desktop window is already destroyed. | 205 // Do not capture if the desktop window is already destroyed. |
| 269 if (!desktop_window_) | 206 if (!desktop_window_) |
| 270 return; | 207 return; |
| 271 | 208 |
| 272 scoped_refptr<media::VideoFrame> frame; | 209 scoped_refptr<media::VideoFrame> frame; |
| 273 ThreadSafeCaptureOracle::CaptureFrameCallback capture_frame_cb; | 210 ThreadSafeCaptureOracle::CaptureFrameCallback capture_frame_cb; |
| 274 | 211 |
| 275 const base::TimeTicks start_time = base::TimeTicks::Now(); | 212 const base::TimeTicks start_time = base::TimeTicks::Now(); |
| 276 const VideoCaptureOracle::Event event = | 213 const VideoCaptureOracle::Event event = |
| 277 dirty ? VideoCaptureOracle::kCompositorUpdate | 214 dirty ? VideoCaptureOracle::kCompositorUpdate |
| 278 : VideoCaptureOracle::kTimerPoll; | 215 : VideoCaptureOracle::kTimerPoll; |
| 279 if (oracle_proxy_->ObserveEventAndDecideCapture( | 216 if (oracle_proxy_->ObserveEventAndDecideCapture( |
| 280 event, gfx::Rect(), start_time, &frame, &capture_frame_cb)) { | 217 event, gfx::Rect(), start_time, &frame, &capture_frame_cb)) { |
| 281 scoped_ptr<cc::CopyOutputRequest> request = | 218 scoped_ptr<cc::CopyOutputRequest> request = |
| 282 cc::CopyOutputRequest::CreateRequest( | 219 cc::CopyOutputRequest::CreateRequest( |
| 283 base::Bind(&DesktopVideoCaptureMachine::DidCopyOutput, | 220 base::Bind(&AuraWindowCaptureMachine::DidCopyOutput, |
| 284 AsWeakPtr(), frame, start_time, capture_frame_cb)); | 221 AsWeakPtr(), frame, start_time, capture_frame_cb)); |
| 285 gfx::Rect window_rect = gfx::Rect(desktop_window_->bounds().width(), | 222 gfx::Rect window_rect = gfx::Rect(desktop_window_->bounds().width(), |
| 286 desktop_window_->bounds().height()); | 223 desktop_window_->bounds().height()); |
| 287 request->set_area(window_rect); | 224 request->set_area(window_rect); |
| 288 desktop_window_->layer()->RequestCopyOfOutput(request.Pass()); | 225 desktop_window_->layer()->RequestCopyOfOutput(request.Pass()); |
| 289 } | 226 } |
| 290 } | 227 } |
| 291 | 228 |
| 292 void CopyOutputFinishedForVideo( | 229 void AuraWindowCaptureMachine::DidCopyOutput( |
| 293 base::TimeTicks start_time, | |
| 294 const ThreadSafeCaptureOracle::CaptureFrameCallback& capture_frame_cb, | |
| 295 const scoped_refptr<media::VideoFrame>& target, | |
| 296 const SkBitmap& cursor_bitmap, | |
| 297 const gfx::Point& cursor_position, | |
| 298 scoped_ptr<cc::SingleReleaseCallback> release_callback, | |
| 299 bool result) { | |
| 300 if (!cursor_bitmap.isNull()) | |
| 301 RenderCursorOnVideoFrame(target, cursor_bitmap, cursor_position); | |
| 302 release_callback->Run(0, false); | |
| 303 capture_frame_cb.Run(target, start_time, result); | |
| 304 } | |
| 305 | |
| 306 void RunSingleReleaseCallback(scoped_ptr<cc::SingleReleaseCallback> cb, | |
| 307 uint32 sync_point) { | |
| 308 cb->Run(sync_point, false); | |
| 309 } | |
| 310 | |
| 311 void DesktopVideoCaptureMachine::DidCopyOutput( | |
| 312 scoped_refptr<media::VideoFrame> video_frame, | 230 scoped_refptr<media::VideoFrame> video_frame, |
| 313 base::TimeTicks start_time, | 231 base::TimeTicks start_time, |
| 314 const ThreadSafeCaptureOracle::CaptureFrameCallback& capture_frame_cb, | 232 const ThreadSafeCaptureOracle::CaptureFrameCallback& capture_frame_cb, |
| 315 scoped_ptr<cc::CopyOutputResult> result) { | 233 scoped_ptr<cc::CopyOutputResult> result) { |
| 316 static bool first_call = true; | 234 static bool first_call = true; |
| 317 | 235 |
| 318 bool succeeded = ProcessCopyOutputResponse( | 236 bool succeeded = ProcessCopyOutputResponse( |
| 319 video_frame, start_time, capture_frame_cb, result.Pass()); | 237 video_frame, start_time, capture_frame_cb, result.Pass()); |
| 320 | 238 |
| 321 base::TimeDelta capture_time = base::TimeTicks::Now() - start_time; | 239 base::TimeDelta capture_time = base::TimeTicks::Now() - start_time; |
| 322 | 240 |
| 323 // The two UMA_ blocks must be put in its own scope since it creates a static | 241 // The two UMA_ blocks must be put in its own scope since it creates a static |
| 324 // variable which expected constant histogram name. | 242 // variable which expected constant histogram name. |
| 325 if (window_id_.type == DesktopMediaID::TYPE_SCREEN) { | 243 if (screen_capture_) { |
| 326 UMA_HISTOGRAM_TIMES(kUmaScreenCaptureTime, capture_time); | 244 UMA_HISTOGRAM_TIMES(kUmaScreenCaptureTime, capture_time); |
| 327 } else { | 245 } else { |
| 328 UMA_HISTOGRAM_TIMES(kUmaWindowCaptureTime, capture_time); | 246 UMA_HISTOGRAM_TIMES(kUmaWindowCaptureTime, capture_time); |
| 329 } | 247 } |
| 330 | 248 |
| 331 if (first_call) { | 249 if (first_call) { |
| 332 first_call = false; | 250 first_call = false; |
| 333 if (window_id_.type == DesktopMediaID::TYPE_SCREEN) { | 251 if (screen_capture_) { |
| 334 IncrementDesktopCaptureCounter(succeeded ? FIRST_SCREEN_CAPTURE_SUCCEEDED | 252 IncrementDesktopCaptureCounter(succeeded ? FIRST_SCREEN_CAPTURE_SUCCEEDED |
| 335 : FIRST_SCREEN_CAPTURE_FAILED); | 253 : FIRST_SCREEN_CAPTURE_FAILED); |
| 336 } else { | 254 } else { |
| 337 IncrementDesktopCaptureCounter(succeeded | 255 IncrementDesktopCaptureCounter(succeeded |
| 338 ? FIRST_WINDOW_CAPTURE_SUCCEEDED | 256 ? FIRST_WINDOW_CAPTURE_SUCCEEDED |
| 339 : FIRST_WINDOW_CAPTURE_FAILED); | 257 : FIRST_WINDOW_CAPTURE_FAILED); |
| 340 } | 258 } |
| 341 } | 259 } |
| 342 } | 260 } |
| 343 | 261 |
| 344 bool DesktopVideoCaptureMachine::ProcessCopyOutputResponse( | 262 bool AuraWindowCaptureMachine::ProcessCopyOutputResponse( |
| 345 scoped_refptr<media::VideoFrame> video_frame, | 263 scoped_refptr<media::VideoFrame> video_frame, |
| 346 base::TimeTicks start_time, | 264 base::TimeTicks start_time, |
| 347 const ThreadSafeCaptureOracle::CaptureFrameCallback& capture_frame_cb, | 265 const ThreadSafeCaptureOracle::CaptureFrameCallback& capture_frame_cb, |
| 348 scoped_ptr<cc::CopyOutputResult> result) { | 266 scoped_ptr<cc::CopyOutputResult> result) { |
| 349 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 267 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 350 if (result->IsEmpty() || result->size().IsEmpty() || !desktop_window_) | 268 if (result->IsEmpty() || result->size().IsEmpty() || !desktop_window_) |
| 351 return false; | 269 return false; |
| 352 | 270 |
| 353 if (capture_params_.requested_format.pixel_format == | 271 if (capture_params_.requested_format.pixel_format == |
| 354 media::PIXEL_FORMAT_TEXTURE) { | 272 media::PIXEL_FORMAT_TEXTURE) { |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 base::Bind(&CopyOutputFinishedForVideo, | 338 base::Bind(&CopyOutputFinishedForVideo, |
| 421 start_time, | 339 start_time, |
| 422 capture_frame_cb, | 340 capture_frame_cb, |
| 423 video_frame, | 341 video_frame, |
| 424 scaled_cursor_bitmap_, | 342 scaled_cursor_bitmap_, |
| 425 cursor_position_in_frame, | 343 cursor_position_in_frame, |
| 426 base::Passed(&release_callback))); | 344 base::Passed(&release_callback))); |
| 427 return true; | 345 return true; |
| 428 } | 346 } |
| 429 | 347 |
| 430 gfx::Point DesktopVideoCaptureMachine::UpdateCursorState( | 348 gfx::Point AuraWindowCaptureMachine::UpdateCursorState( |
| 431 const gfx::Rect& region_in_frame) { | 349 const gfx::Rect& region_in_frame) { |
| 432 const gfx::Rect desktop_bounds = desktop_window_->layer()->bounds(); | 350 const gfx::Rect desktop_bounds = desktop_window_->layer()->bounds(); |
| 433 gfx::NativeCursor cursor = | 351 gfx::NativeCursor cursor = |
| 434 desktop_window_->GetHost()->last_cursor(); | 352 desktop_window_->GetHost()->last_cursor(); |
| 435 if (last_cursor_ != cursor) { | 353 if (last_cursor_ != cursor) { |
| 436 SkBitmap cursor_bitmap; | 354 SkBitmap cursor_bitmap; |
| 437 if (ui::GetCursorBitmap(cursor, &cursor_bitmap, &cursor_hot_point_)) { | 355 if (ui::GetCursorBitmap(cursor, &cursor_bitmap, &cursor_hot_point_)) { |
| 438 scaled_cursor_bitmap_ = skia::ImageOperations::Resize( | 356 scaled_cursor_bitmap_ = skia::ImageOperations::Resize( |
| 439 cursor_bitmap, | 357 cursor_bitmap, |
| 440 skia::ImageOperations::RESIZE_BEST, | 358 skia::ImageOperations::RESIZE_BEST, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 457 desktop_window_->layer(), cursor_hot_point_); | 375 desktop_window_->layer(), cursor_hot_point_); |
| 458 cursor_position.Offset(-desktop_bounds.x() - hot_point_in_dip.x(), | 376 cursor_position.Offset(-desktop_bounds.x() - hot_point_in_dip.x(), |
| 459 -desktop_bounds.y() - hot_point_in_dip.y()); | 377 -desktop_bounds.y() - hot_point_in_dip.y()); |
| 460 return gfx::Point( | 378 return gfx::Point( |
| 461 region_in_frame.x() + cursor_position.x() * region_in_frame.width() / | 379 region_in_frame.x() + cursor_position.x() * region_in_frame.width() / |
| 462 desktop_bounds.width(), | 380 desktop_bounds.width(), |
| 463 region_in_frame.y() + cursor_position.y() * region_in_frame.height() / | 381 region_in_frame.y() + cursor_position.y() * region_in_frame.height() / |
| 464 desktop_bounds.height()); | 382 desktop_bounds.height()); |
| 465 } | 383 } |
| 466 | 384 |
| 467 void DesktopVideoCaptureMachine::ClearCursorState() { | 385 void AuraWindowCaptureMachine::ClearCursorState() { |
| 468 last_cursor_ = ui::Cursor(); | 386 last_cursor_ = ui::Cursor(); |
| 469 cursor_hot_point_ = gfx::Point(); | 387 cursor_hot_point_ = gfx::Point(); |
| 470 scaled_cursor_bitmap_.reset(); | 388 scaled_cursor_bitmap_.reset(); |
| 471 } | 389 } |
| 472 | 390 |
| 473 void DesktopVideoCaptureMachine::OnWindowBoundsChanged( | 391 void AuraWindowCaptureMachine::OnWindowBoundsChanged( |
| 474 aura::Window* window, | 392 aura::Window* window, |
| 475 const gfx::Rect& old_bounds, | 393 const gfx::Rect& old_bounds, |
| 476 const gfx::Rect& new_bounds) { | 394 const gfx::Rect& new_bounds) { |
| 477 DCHECK(desktop_window_ && window == desktop_window_); | 395 DCHECK(desktop_window_ && window == desktop_window_); |
| 478 | 396 |
| 479 // Post task to update capture size on UI thread. | 397 // Post task to update capture size on UI thread. |
| 480 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( | 398 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( |
| 481 &DesktopVideoCaptureMachine::UpdateCaptureSize, AsWeakPtr())); | 399 &AuraWindowCaptureMachine::UpdateCaptureSize, AsWeakPtr())); |
| 482 } | 400 } |
| 483 | 401 |
| 484 void DesktopVideoCaptureMachine::OnWindowDestroyed(aura::Window* window) { | 402 void AuraWindowCaptureMachine::OnWindowDestroyed(aura::Window* window) { |
| 485 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 403 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 486 | 404 |
| 487 Stop(base::Bind(&base::DoNothing)); | 405 Stop(base::Bind(&base::DoNothing)); |
| 488 | 406 |
| 489 oracle_proxy_->ReportError("OnWindowDestroyed()"); | 407 oracle_proxy_->ReportError("OnWindowDestroyed()"); |
| 490 } | 408 } |
| 491 | 409 |
| 492 void DesktopVideoCaptureMachine::OnWindowAddedToRootWindow( | 410 void AuraWindowCaptureMachine::OnWindowAddedToRootWindow( |
| 493 aura::Window* window) { | 411 aura::Window* window) { |
| 494 DCHECK(window == desktop_window_); | 412 DCHECK(window == desktop_window_); |
| 495 window->GetHost()->compositor()->AddObserver(this); | 413 window->GetHost()->compositor()->AddObserver(this); |
| 496 } | 414 } |
| 497 | 415 |
| 498 void DesktopVideoCaptureMachine::OnWindowRemovingFromRootWindow( | 416 void AuraWindowCaptureMachine::OnWindowRemovingFromRootWindow( |
| 499 aura::Window* window, | 417 aura::Window* window, |
| 500 aura::Window* new_root) { | 418 aura::Window* new_root) { |
| 501 DCHECK(window == desktop_window_); | 419 DCHECK(window == desktop_window_); |
| 502 window->GetHost()->compositor()->RemoveObserver(this); | 420 window->GetHost()->compositor()->RemoveObserver(this); |
| 503 } | 421 } |
| 504 | 422 |
| 505 void DesktopVideoCaptureMachine::OnCompositingEnded( | 423 void AuraWindowCaptureMachine::OnCompositingEnded( |
| 506 ui::Compositor* compositor) { | 424 ui::Compositor* compositor) { |
| 507 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( | 425 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( |
| 508 &DesktopVideoCaptureMachine::Capture, AsWeakPtr(), true)); | 426 &AuraWindowCaptureMachine::Capture, AsWeakPtr(), true)); |
| 509 } | |
| 510 | |
| 511 } // namespace | |
| 512 | |
| 513 DesktopCaptureDeviceAura::DesktopCaptureDeviceAura( | |
| 514 const DesktopMediaID& source) | |
| 515 : core_(new ContentVideoCaptureDeviceCore(scoped_ptr<VideoCaptureMachine>( | |
| 516 new DesktopVideoCaptureMachine(source)))) {} | |
| 517 | |
| 518 DesktopCaptureDeviceAura::~DesktopCaptureDeviceAura() { | |
| 519 DVLOG(2) << "DesktopCaptureDeviceAura@" << this << " destroying."; | |
| 520 } | |
| 521 | |
| 522 // static | |
| 523 media::VideoCaptureDevice* DesktopCaptureDeviceAura::Create( | |
| 524 const DesktopMediaID& source) { | |
| 525 IncrementDesktopCaptureCounter(source.type == DesktopMediaID::TYPE_SCREEN | |
| 526 ? SCREEN_CAPTURER_CREATED | |
| 527 : WINDOW_CAPTURER_CREATED); | |
| 528 return new DesktopCaptureDeviceAura(source); | |
| 529 } | |
| 530 | |
| 531 void DesktopCaptureDeviceAura::AllocateAndStart( | |
| 532 const media::VideoCaptureParams& params, | |
| 533 scoped_ptr<Client> client) { | |
| 534 DVLOG(1) << "Allocating " << params.requested_format.frame_size.ToString(); | |
| 535 core_->AllocateAndStart(params, client.Pass()); | |
| 536 } | |
| 537 | |
| 538 void DesktopCaptureDeviceAura::StopAndDeAllocate() { | |
| 539 core_->StopAndDeAllocate(); | |
| 540 } | 427 } |
| 541 | 428 |
| 542 } // namespace content | 429 } // namespace content |
| OLD | NEW |