| 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 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 #include "ui/aura/window_tree_host.h" | 29 #include "ui/aura/window_tree_host.h" |
| 30 #include "ui/base/cursor/cursors_aura.h" | 30 #include "ui/base/cursor/cursors_aura.h" |
| 31 #include "ui/compositor/compositor.h" | 31 #include "ui/compositor/compositor.h" |
| 32 #include "ui/compositor/dip_util.h" | 32 #include "ui/compositor/dip_util.h" |
| 33 #include "ui/compositor/layer.h" | 33 #include "ui/compositor/layer.h" |
| 34 #include "ui/gfx/screen.h" | 34 #include "ui/gfx/screen.h" |
| 35 #include "ui/wm/public/activation_client.h" | 35 #include "ui/wm/public/activation_client.h" |
| 36 | 36 |
| 37 namespace content { | 37 namespace content { |
| 38 | 38 |
| 39 namespace { | |
| 40 | |
| 41 void RunSingleReleaseCallback(scoped_ptr<cc::SingleReleaseCallback> cb, | |
| 42 const gpu::SyncToken& sync_token) { | |
| 43 cb->Run(sync_token, false); | |
| 44 } | |
| 45 | |
| 46 } // namespace | |
| 47 | |
| 48 AuraWindowCaptureMachine::AuraWindowCaptureMachine() | 39 AuraWindowCaptureMachine::AuraWindowCaptureMachine() |
| 49 : desktop_window_(NULL), | 40 : desktop_window_(NULL), |
| 50 timer_(true, true), | 41 timer_(true, true), |
| 51 screen_capture_(false), | 42 screen_capture_(false), |
| 52 weak_factory_(this) {} | 43 weak_factory_(this) {} |
| 53 | 44 |
| 54 AuraWindowCaptureMachine::~AuraWindowCaptureMachine() {} | 45 AuraWindowCaptureMachine::~AuraWindowCaptureMachine() {} |
| 55 | 46 |
| 56 void AuraWindowCaptureMachine::Start( | 47 void AuraWindowCaptureMachine::Start( |
| 57 const scoped_refptr<media::ThreadSafeCaptureOracle>& oracle_proxy, | 48 const scoped_refptr<media::ThreadSafeCaptureOracle>& oracle_proxy, |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 | 230 |
| 240 bool AuraWindowCaptureMachine::ProcessCopyOutputResponse( | 231 bool AuraWindowCaptureMachine::ProcessCopyOutputResponse( |
| 241 scoped_refptr<media::VideoFrame> video_frame, | 232 scoped_refptr<media::VideoFrame> video_frame, |
| 242 base::TimeTicks start_time, | 233 base::TimeTicks start_time, |
| 243 const CaptureFrameCallback& capture_frame_cb, | 234 const CaptureFrameCallback& capture_frame_cb, |
| 244 scoped_ptr<cc::CopyOutputResult> result) { | 235 scoped_ptr<cc::CopyOutputResult> result) { |
| 245 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 236 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 246 | 237 |
| 247 if (result->IsEmpty() || result->size().IsEmpty() || !desktop_window_) | 238 if (result->IsEmpty() || result->size().IsEmpty() || !desktop_window_) |
| 248 return false; | 239 return false; |
| 249 | 240 DCHECK(video_frame.get()); |
| 250 if (capture_params_.requested_format.pixel_storage == | |
| 251 media::PIXEL_STORAGE_TEXTURE) { | |
| 252 DCHECK_EQ(media::PIXEL_FORMAT_ARGB, | |
| 253 capture_params_.requested_format.pixel_format); | |
| 254 DCHECK(!video_frame.get()); | |
| 255 cc::TextureMailbox texture_mailbox; | |
| 256 scoped_ptr<cc::SingleReleaseCallback> release_callback; | |
| 257 result->TakeTexture(&texture_mailbox, &release_callback); | |
| 258 DCHECK(texture_mailbox.IsTexture()); | |
| 259 if (!texture_mailbox.IsTexture()) | |
| 260 return false; | |
| 261 video_frame = media::VideoFrame::WrapNativeTexture( | |
| 262 media::PIXEL_FORMAT_ARGB, | |
| 263 gpu::MailboxHolder(texture_mailbox.mailbox(), | |
| 264 texture_mailbox.sync_token(), | |
| 265 texture_mailbox.target()), | |
| 266 base::Bind(&RunSingleReleaseCallback, base::Passed(&release_callback)), | |
| 267 result->size(), gfx::Rect(result->size()), result->size(), | |
| 268 base::TimeDelta()); | |
| 269 capture_frame_cb.Run(video_frame, start_time, true); | |
| 270 return true; | |
| 271 } else { | |
| 272 DCHECK(video_frame.get()); | |
| 273 } | |
| 274 | 241 |
| 275 // Compute the dest size we want after the letterboxing resize. Make the | 242 // Compute the dest size we want after the letterboxing resize. Make the |
| 276 // coordinates and sizes even because we letterbox in YUV space | 243 // coordinates and sizes even because we letterbox in YUV space |
| 277 // (see CopyRGBToVideoFrame). They need to be even for the UV samples to | 244 // (see CopyRGBToVideoFrame). They need to be even for the UV samples to |
| 278 // line up correctly. | 245 // line up correctly. |
| 279 // The video frame's visible_rect() and the result's size() are both physical | 246 // The video frame's visible_rect() and the result's size() are both physical |
| 280 // pixels. | 247 // pixels. |
| 281 gfx::Rect region_in_frame = media::ComputeLetterboxRegion( | 248 gfx::Rect region_in_frame = media::ComputeLetterboxRegion( |
| 282 video_frame->visible_rect(), result->size()); | 249 video_frame->visible_rect(), result->size()); |
| 283 region_in_frame = gfx::Rect(region_in_frame.x() & ~1, | 250 region_in_frame = gfx::Rect(region_in_frame.x() & ~1, |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 // TODO(miu): The CopyOutputRequest should be made earlier, at WillCommit(). | 359 // TODO(miu): The CopyOutputRequest should be made earlier, at WillCommit(). |
| 393 // http://crbug.com/492839 | 360 // http://crbug.com/492839 |
| 394 BrowserThread::PostTask( | 361 BrowserThread::PostTask( |
| 395 BrowserThread::UI, | 362 BrowserThread::UI, |
| 396 FROM_HERE, | 363 FROM_HERE, |
| 397 base::Bind(&AuraWindowCaptureMachine::Capture, weak_factory_.GetWeakPtr(), | 364 base::Bind(&AuraWindowCaptureMachine::Capture, weak_factory_.GetWeakPtr(), |
| 398 true)); | 365 true)); |
| 399 } | 366 } |
| 400 | 367 |
| 401 } // namespace content | 368 } // namespace content |
| OLD | NEW |