Index: blimp/client/core/contents/blimp_contents_view_impl.cc |
diff --git a/blimp/client/core/contents/blimp_contents_view_impl.cc b/blimp/client/core/contents/blimp_contents_view_impl.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..a5a7aa8ca495d9dcdf51ad25b083e4bc87648e15 |
--- /dev/null |
+++ b/blimp/client/core/contents/blimp_contents_view_impl.cc |
@@ -0,0 +1,77 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "blimp/client/core/contents/blimp_contents_view_impl.h" |
+ |
+#include "base/bind.h" |
+#include "base/callback_helpers.h" |
+#include "base/threading/thread_task_runner_handle.h" |
+#include "blimp/client/core/contents/blimp_contents_impl.h" |
+#include "cc/output/copy_output_request.h" |
+#include "cc/output/copy_output_result.h" |
+#include "ui/gfx/geometry/size.h" |
+ |
+namespace blimp { |
+namespace client { |
+ |
+BlimpContentsViewImpl::BlimpContentsViewImpl( |
+ BlimpContentsImpl* blimp_contents, |
+ scoped_refptr<cc::Layer> contents_layer) |
+ : blimp_contents_(blimp_contents), |
+ contents_layer_(contents_layer), |
Khushal
2016/09/13 23:47:10
nit: std::move is nicer.
David Trainor- moved to gerrit
2016/09/14 00:31:09
Done.
|
+ weak_ptr_factory_(this) {} |
Khushal
2016/09/13 23:47:10
DCHECK content_layer_ and blimp_contents?
David Trainor- moved to gerrit
2016/09/14 00:31:09
Done.
|
+ |
+BlimpContentsViewImpl::~BlimpContentsViewImpl() = default; |
+ |
+scoped_refptr<cc::Layer> BlimpContentsViewImpl::GetLayer() { |
+ return contents_layer_; |
+} |
+ |
+void BlimpContentsViewImpl::SetSizeAndScale(const gfx::Size& size, |
+ float device_scale_factor) { |
+ blimp_contents_->SetSizeAndScale(size, device_scale_factor); |
+} |
+ |
+bool BlimpContentsViewImpl::OnTouchEvent(const ui::MotionEvent& motion_event) { |
+ return blimp_contents_->compositor_manager()->OnTouchEvent(motion_event); |
+} |
+ |
+void BlimpContentsViewImpl::CopyFromCompositingSurface( |
+ const ReadbackRequestCallback& callback, |
+ bool flush_pending_commits) { |
+ // If we currently have a readback or we don't have a content layer drop the |
+ // readback request. |
+ if (!readback_callback_.is_null() || !contents_layer_) { |
Khushal
2016/09/13 23:47:10
We should always have a content_layer_ here. This
David Trainor- moved to gerrit
2016/09/14 00:31:09
Done.
|
+ base::ThreadTaskRunnerHandle::Get()->PostTask( |
+ FROM_HERE, base::Bind(callback, nullptr)); |
+ return; |
+ } |
+ |
+ readback_callback_ = callback; |
+ |
+ if (flush_pending_commits) { |
+ blimp_contents_->compositor_manager()->NotifyWhenDonePendingCommits( |
+ base::Bind(&BlimpContentsViewImpl::StartReadbackRequest, |
+ weak_ptr_factory_.GetWeakPtr())); |
+ } else { |
+ StartReadbackRequest(); |
+ } |
+} |
+ |
+void BlimpContentsViewImpl::StartReadbackRequest() { |
+ std::unique_ptr<cc::CopyOutputRequest> request = |
+ cc::CopyOutputRequest::CreateBitmapRequest( |
+ base::Bind(&BlimpContentsViewImpl::OnReadbackComplete, |
+ weak_ptr_factory_.GetWeakPtr())); |
+ contents_layer_->RequestCopyOfOutput(std::move(request)); |
+} |
+ |
+void BlimpContentsViewImpl::OnReadbackComplete( |
+ std::unique_ptr<cc::CopyOutputResult> result) { |
+ DCHECK(!readback_callback_.is_null()); |
+ base::ResetAndReturn(&readback_callback_).Run(result->TakeBitmap()); |
+} |
+ |
+} // namespace client |
+} // namespace blimp |