OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/devtools/protocol/page_handler.h" | 5 #include "content/browser/devtools/protocol/page_handler.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/base64.h" | 9 #include "base/base64.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
138 | 138 |
139 void PageHandler::SetClient(std::unique_ptr<Client> client) { | 139 void PageHandler::SetClient(std::unique_ptr<Client> client) { |
140 client_.swap(client); | 140 client_.swap(client); |
141 } | 141 } |
142 | 142 |
143 void PageHandler::Detached() { | 143 void PageHandler::Detached() { |
144 Disable(); | 144 Disable(); |
145 } | 145 } |
146 | 146 |
147 void PageHandler::OnSwapCompositorFrame( | 147 void PageHandler::OnSwapCompositorFrame( |
148 const cc::CompositorFrameMetadata& frame_metadata) { | 148 cc::CompositorFrameMetadata frame_metadata) { |
149 last_compositor_frame_metadata_ = frame_metadata; | 149 last_compositor_frame_metadata_ = std::move(frame_metadata); |
150 has_compositor_frame_metadata_ = true; | 150 has_compositor_frame_metadata_ = true; |
151 | 151 |
152 if (screencast_enabled_) | 152 if (screencast_enabled_) |
153 InnerSwapCompositorFrame(); | 153 InnerSwapCompositorFrame(); |
154 color_picker_->OnSwapCompositorFrame(); | 154 color_picker_->OnSwapCompositorFrame(); |
155 } | 155 } |
156 | 156 |
157 void PageHandler::OnSynchronousSwapCompositorFrame( | 157 void PageHandler::OnSynchronousSwapCompositorFrame( |
158 const cc::CompositorFrameMetadata& frame_metadata) { | 158 cc::CompositorFrameMetadata frame_metadata) { |
159 last_compositor_frame_metadata_ = has_compositor_frame_metadata_ ? | 159 if (has_compositor_frame_metadata_) { |
160 next_compositor_frame_metadata_ : frame_metadata; | 160 last_compositor_frame_metadata_ = |
161 next_compositor_frame_metadata_ = frame_metadata; | 161 std::move(next_compositor_frame_metadata_); |
162 next_compositor_frame_metadata_ = std::move(frame_metadata); | |
163 } else { | |
164 last_compositor_frame_metadata_ = std::move(frame_metadata); | |
danakj
2016/06/24 21:45:18
nit: you could keep the next_cfm part outside the
Fady Samuel
2016/06/24 22:24:37
Done.
| |
165 next_compositor_frame_metadata_ = last_compositor_frame_metadata_.Clone(); | |
166 } | |
167 | |
162 has_compositor_frame_metadata_ = true; | 168 has_compositor_frame_metadata_ = true; |
163 | 169 |
164 if (screencast_enabled_) | 170 if (screencast_enabled_) |
165 InnerSwapCompositorFrame(); | 171 InnerSwapCompositorFrame(); |
166 color_picker_->OnSwapCompositorFrame(); | 172 color_picker_->OnSwapCompositorFrame(); |
167 } | 173 } |
168 | 174 |
169 void PageHandler::Observe(int type, | 175 void PageHandler::Observe(int type, |
170 const NotificationSource& source, | 176 const NotificationSource& source, |
171 const NotificationDetails& details) { | 177 const NotificationDetails& details) { |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
418 | 424 |
419 if (scale <= 0) | 425 if (scale <= 0) |
420 scale = 0.1; | 426 scale = 0.1; |
421 | 427 |
422 gfx::Size snapshot_size_dip(gfx::ToRoundedSize( | 428 gfx::Size snapshot_size_dip(gfx::ToRoundedSize( |
423 gfx::ScaleSize(viewport_size_dip, scale))); | 429 gfx::ScaleSize(viewport_size_dip, scale))); |
424 | 430 |
425 if (snapshot_size_dip.width() > 0 && snapshot_size_dip.height() > 0) { | 431 if (snapshot_size_dip.width() > 0 && snapshot_size_dip.height() > 0) { |
426 gfx::Rect viewport_bounds_dip(gfx::ToRoundedSize(viewport_size_dip)); | 432 gfx::Rect viewport_bounds_dip(gfx::ToRoundedSize(viewport_size_dip)); |
427 view->CopyFromCompositingSurface( | 433 view->CopyFromCompositingSurface( |
428 viewport_bounds_dip, | 434 viewport_bounds_dip, snapshot_size_dip, |
429 snapshot_size_dip, | |
430 base::Bind(&PageHandler::ScreencastFrameCaptured, | 435 base::Bind(&PageHandler::ScreencastFrameCaptured, |
431 weak_factory_.GetWeakPtr(), | 436 weak_factory_.GetWeakPtr(), |
432 last_compositor_frame_metadata_), | 437 last_compositor_frame_metadata_.Clone()), |
danakj
2016/06/24 21:45:18
use base::Passed( of Clone()) here
Fady Samuel
2016/06/24 22:24:37
Done.
| |
433 kN32_SkColorType); | 438 kN32_SkColorType); |
434 frames_in_flight_++; | 439 frames_in_flight_++; |
435 } | 440 } |
436 } | 441 } |
437 | 442 |
438 void PageHandler::ScreencastFrameCaptured( | 443 void PageHandler::ScreencastFrameCaptured( |
439 const cc::CompositorFrameMetadata& metadata, | 444 const cc::CompositorFrameMetadata& metadata, |
danakj
2016/06/24 21:45:18
take this by value
Fady Samuel
2016/06/24 22:24:37
Done.
| |
440 const SkBitmap& bitmap, | 445 const SkBitmap& bitmap, |
441 ReadbackResponse response) { | 446 ReadbackResponse response) { |
442 if (response != READBACK_SUCCESS) { | 447 if (response != READBACK_SUCCESS) { |
443 if (capture_retry_count_) { | 448 if (capture_retry_count_) { |
444 --capture_retry_count_; | 449 --capture_retry_count_; |
445 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 450 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
446 FROM_HERE, base::Bind(&PageHandler::InnerSwapCompositorFrame, | 451 FROM_HERE, base::Bind(&PageHandler::InnerSwapCompositorFrame, |
447 weak_factory_.GetWeakPtr()), | 452 weak_factory_.GetWeakPtr()), |
448 base::TimeDelta::FromMilliseconds(kFrameRetryDelayMs)); | 453 base::TimeDelta::FromMilliseconds(kFrameRetryDelayMs)); |
449 } | 454 } |
450 --frames_in_flight_; | 455 --frames_in_flight_; |
451 return; | 456 return; |
452 } | 457 } |
453 base::PostTaskAndReplyWithResult( | 458 base::PostTaskAndReplyWithResult( |
454 base::WorkerPool::GetTaskRunner(true).get(), | 459 base::WorkerPool::GetTaskRunner(true).get(), FROM_HERE, |
455 FROM_HERE, | 460 base::Bind(&EncodeScreencastFrame, bitmap, screencast_format_, |
456 base::Bind(&EncodeScreencastFrame, | 461 screencast_quality_), |
457 bitmap, screencast_format_, screencast_quality_), | |
458 base::Bind(&PageHandler::ScreencastFrameEncoded, | 462 base::Bind(&PageHandler::ScreencastFrameEncoded, |
459 weak_factory_.GetWeakPtr(), metadata, base::Time::Now())); | 463 weak_factory_.GetWeakPtr(), metadata.Clone(), |
danakj
2016/06/24 21:45:18
use base::Passed(&metadata) here,
then you avoid
Fady Samuel
2016/06/24 22:24:37
Done.
| |
464 base::Time::Now())); | |
460 } | 465 } |
461 | 466 |
462 void PageHandler::ScreencastFrameEncoded( | 467 void PageHandler::ScreencastFrameEncoded( |
463 const cc::CompositorFrameMetadata& metadata, | 468 const cc::CompositorFrameMetadata& metadata, |
danakj
2016/06/24 21:45:18
and take this by value
Fady Samuel
2016/06/24 22:24:37
Done.
| |
464 const base::Time& timestamp, | 469 const base::Time& timestamp, |
465 const std::string& data) { | 470 const std::string& data) { |
466 // Consider metadata empty in case it has no device scale factor. | 471 // Consider metadata empty in case it has no device scale factor. |
467 if (metadata.device_scale_factor == 0 || !host_ || data.empty()) { | 472 if (metadata.device_scale_factor == 0 || !host_ || data.empty()) { |
468 --frames_in_flight_; | 473 --frames_in_flight_; |
469 return; | 474 return; |
470 } | 475 } |
471 | 476 |
472 RenderWidgetHostViewBase* view = static_cast<RenderWidgetHostViewBase*>( | 477 RenderWidgetHostViewBase* view = static_cast<RenderWidgetHostViewBase*>( |
473 host_->GetView()); | 478 host_->GetView()); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
514 | 519 |
515 void PageHandler::OnColorPicked(int r, int g, int b, int a) { | 520 void PageHandler::OnColorPicked(int r, int g, int b, int a) { |
516 scoped_refptr<dom::RGBA> color = | 521 scoped_refptr<dom::RGBA> color = |
517 dom::RGBA::Create()->set_r(r)->set_g(g)->set_b(b)->set_a(a); | 522 dom::RGBA::Create()->set_r(r)->set_g(g)->set_b(b)->set_a(a); |
518 client_->ColorPicked(ColorPickedParams::Create()->set_color(color)); | 523 client_->ColorPicked(ColorPickedParams::Create()->set_color(color)); |
519 } | 524 } |
520 | 525 |
521 } // namespace page | 526 } // namespace page |
522 } // namespace devtools | 527 } // namespace devtools |
523 } // namespace content | 528 } // namespace content |
OLD | NEW |