| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "blimp/client/core/contents/blimp_contents_view_impl.h" | 5 #include "blimp/client/core/contents/blimp_contents_view_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
| 9 #include "base/threading/thread_task_runner_handle.h" | 9 #include "base/threading/thread_task_runner_handle.h" |
| 10 #include "blimp/client/core/contents/blimp_contents_impl.h" | 10 #include "blimp/client/core/contents/blimp_contents_impl.h" |
| 11 #include "cc/output/copy_output_request.h" | 11 #include "cc/output/copy_output_request.h" |
| 12 #include "cc/output/copy_output_result.h" | 12 #include "cc/output/copy_output_result.h" |
| 13 #include "ui/gfx/geometry/size.h" | 13 #include "ui/gfx/geometry/size.h" |
| 14 | 14 |
| 15 namespace blimp { | 15 namespace blimp { |
| 16 namespace client { | 16 namespace client { |
| 17 | 17 |
| 18 namespace { |
| 19 |
| 20 void SendReadbackResult( |
| 21 const BlimpContentsView::ReadbackRequestCallback& callback, |
| 22 std::unique_ptr<cc::CopyOutputResult> result) { |
| 23 callback.Run(result->TakeBitmap()); |
| 24 } |
| 25 |
| 26 } // namespace |
| 27 |
| 18 BlimpContentsViewImpl::BlimpContentsViewImpl( | 28 BlimpContentsViewImpl::BlimpContentsViewImpl( |
| 19 BlimpContentsImpl* blimp_contents, | 29 BlimpContentsImpl* blimp_contents, |
| 20 scoped_refptr<cc::Layer> contents_layer) | 30 scoped_refptr<cc::Layer> contents_layer) |
| 21 : blimp_contents_(blimp_contents), | 31 : blimp_contents_(blimp_contents), |
| 22 contents_layer_(std::move(contents_layer)), | 32 contents_layer_(std::move(contents_layer)), |
| 23 weak_ptr_factory_(this) { | 33 weak_ptr_factory_(this) { |
| 24 DCHECK(blimp_contents_); | 34 DCHECK(blimp_contents_); |
| 25 DCHECK(contents_layer_); | 35 DCHECK(contents_layer_); |
| 26 } | 36 } |
| 27 | 37 |
| 28 BlimpContentsViewImpl::~BlimpContentsViewImpl() = default; | 38 BlimpContentsViewImpl::~BlimpContentsViewImpl() = default; |
| 29 | 39 |
| 30 scoped_refptr<cc::Layer> BlimpContentsViewImpl::GetLayer() { | 40 scoped_refptr<cc::Layer> BlimpContentsViewImpl::GetLayer() { |
| 31 return contents_layer_; | 41 return contents_layer_; |
| 32 } | 42 } |
| 33 | 43 |
| 34 void BlimpContentsViewImpl::SetSizeAndScale(const gfx::Size& size, | 44 void BlimpContentsViewImpl::SetSizeAndScale(const gfx::Size& size, |
| 35 float device_scale_factor) { | 45 float device_scale_factor) { |
| 36 blimp_contents_->SetSizeAndScale(size, device_scale_factor); | 46 blimp_contents_->SetSizeAndScale(size, device_scale_factor); |
| 37 } | 47 } |
| 38 | 48 |
| 39 bool BlimpContentsViewImpl::OnTouchEvent(const ui::MotionEvent& motion_event) { | 49 bool BlimpContentsViewImpl::OnTouchEvent(const ui::MotionEvent& motion_event) { |
| 40 return blimp_contents_->document_manager()->OnTouchEvent(motion_event); | 50 return blimp_contents_->document_manager()->OnTouchEvent(motion_event); |
| 41 } | 51 } |
| 42 | 52 |
| 43 void BlimpContentsViewImpl::CopyFromCompositingSurface( | 53 void BlimpContentsViewImpl::CopyFromCompositingSurface( |
| 44 const ReadbackRequestCallback& callback) { | 54 const ReadbackRequestCallback& callback) { |
| 45 blimp_contents_->document_manager()->NotifyWhenDonePendingCommits( | 55 blimp_contents_->document_manager()->RequestCopyOfCompositorOutput( |
| 46 base::Bind(&BlimpContentsViewImpl::StartReadbackRequest, | |
| 47 weak_ptr_factory_.GetWeakPtr(), callback)); | |
| 48 } | |
| 49 | |
| 50 void BlimpContentsViewImpl::StartReadbackRequest( | |
| 51 const ReadbackRequestCallback& callback) { | |
| 52 std::unique_ptr<cc::CopyOutputRequest> request = | |
| 53 cc::CopyOutputRequest::CreateBitmapRequest( | 56 cc::CopyOutputRequest::CreateBitmapRequest( |
| 54 base::Bind(&BlimpContentsViewImpl::OnReadbackComplete, | 57 base::Bind(&SendReadbackResult, callback)), |
| 55 weak_ptr_factory_.GetWeakPtr(), callback)); | 58 true); |
| 56 contents_layer_->RequestCopyOfOutput(std::move(request)); | |
| 57 } | |
| 58 | |
| 59 void BlimpContentsViewImpl::OnReadbackComplete( | |
| 60 const ReadbackRequestCallback& callback, | |
| 61 std::unique_ptr<cc::CopyOutputResult> result) { | |
| 62 callback.Run(result->TakeBitmap()); | |
| 63 } | 59 } |
| 64 | 60 |
| 65 } // namespace client | 61 } // namespace client |
| 66 } // namespace blimp | 62 } // namespace blimp |
| OLD | NEW |