Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(206)

Unified Diff: content/browser/renderer_host/offscreen_canvas_surface_service_impl.cc

Issue 2036663003: Establish mojo service between Canvas (blink) and SurfaceManager (browser) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/renderer_host/offscreen_canvas_surface_service_impl.cc
diff --git a/content/browser/renderer_host/offscreen_canvas_surface_service_impl.cc b/content/browser/renderer_host/offscreen_canvas_surface_service_impl.cc
new file mode 100644
index 0000000000000000000000000000000000000000..2af3f9566ef0243a7cb490ceaabf6d71c3312764
--- /dev/null
+++ b/content/browser/renderer_host/offscreen_canvas_surface_service_impl.cc
@@ -0,0 +1,146 @@
+// 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 "content/browser/renderer_host/offscreen_canvas_surface_service_impl.h"
+
+#include "base/bind_helpers.h"
+#include "cc/surfaces/surface.h"
+#include "cc/surfaces/surface_manager.h"
+#include "content/browser/compositor/surface_utils.h"
+#include "content/public/browser/browser_thread.h"
+
+namespace mojo {
+
+template <>
+struct TypeConverter<cc::SurfaceId, blink::mojom::SurfaceIdPtr> {
+ static cc::SurfaceId Convert(const blink::mojom::SurfaceIdPtr& input) {
Fady Samuel 2016/06/02 22:32:23 Please avoid using type converters.
+ return input ?
+ cc::SurfaceId(input->id_namespace, input->local_id, input->nonce) :
+ cc::SurfaceId();
+ }
+};
+
+template <>
+struct TypeConverter<blink::mojom::SurfaceIdPtr, cc::SurfaceId> {
+ static blink::mojom::SurfaceIdPtr Convert(const cc::SurfaceId& input) {
+ blink::mojom::SurfaceIdPtr result = blink::mojom::SurfaceId::New();
+ result->id_namespace = input.id_namespace();
+ result->local_id = input.local_id();
+ result->nonce = input.nonce();
+ return result;
+ }
+};
+
+template <>
+struct TypeConverter<cc::SurfaceSequence, blink::mojom::SurfaceSequencePtr> {
+ static cc::SurfaceSequence Convert(
+ const blink::mojom::SurfaceSequencePtr& input) {
+ return input ? cc::SurfaceSequence(input->id_namespace, input->sequence)
+ : cc::SurfaceSequence();
+ }
+};
+
+template <>
+struct TypeConverter<blink::mojom::SurfaceSequencePtr, cc::SurfaceSequence> {
+ static blink::mojom::SurfaceSequencePtr Convert(
+ const cc::SurfaceSequence& input) {
+ blink::mojom::SurfaceSequencePtr result =
+ blink::mojom::SurfaceSequence::New();
+ result->id_namespace = input.id_namespace;
+ result->sequence = input.sequence;
+ return result;
+ }
+};
+
+} // namespace mojo
+
+namespace content {
+
+// static
+void OffscreenCanvasSurfaceServiceImpl::Create(
+ mojo::InterfaceRequest<blink::mojom::OffscreenCanvasSurfaceService> request)
+{
+ // |binding_| will take ownership of OffscreenCanvasSurfaceServiceImpl
+ new OffscreenCanvasSurfaceServiceImpl(std::move(request));
+}
+
+OffscreenCanvasSurfaceServiceImpl::OffscreenCanvasSurfaceServiceImpl(
+ mojo::InterfaceRequest<blink::mojom::OffscreenCanvasSurfaceService> request)
+ : binding_(this, std::move(request))
+{
+ id_allocator_ = CreateSurfaceIdAllocator();
+}
+
+OffscreenCanvasSurfaceServiceImpl::~OffscreenCanvasSurfaceServiceImpl()
+{
+ if (surface_factory_) {
+ surface_factory_->DestroyAll();
+ }
+}
+
+void OffscreenCanvasSurfaceServiceImpl::GetSurfaceId(
+ const GetSurfaceIdCallback& callback) {
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
+
+ cc::SurfaceId surface_id = id_allocator_->GenerateId();
+
+ blink::mojom::SurfaceIdPtr surface_id_ptr =
+ mojo::ConvertTo<blink::mojom::SurfaceIdPtr>(surface_id);
+ callback.Run(std::move(surface_id_ptr));
Fady Samuel 2016/06/02 22:32:23 This shouldn't need to be sync.
+}
+
+void OffscreenCanvasSurfaceServiceImpl::RequestSurfaceCreation(
+ const blink::mojom::SurfaceIdPtr surface_id)
+{
+ cc::SurfaceManager* manager = GetSurfaceManager();
+ if (!surface_factory_) {
+ surface_factory_ = base::WrapUnique(
+ new cc::SurfaceFactory(manager, this));
+ }
+ surface_factory_->Create(mojo::ConvertTo<cc::SurfaceId>(surface_id));
+}
+
+void OffscreenCanvasSurfaceServiceImpl::Require(
+ blink::mojom::SurfaceIdPtr surface_id,
+ blink::mojom::SurfaceSequencePtr sequence)
+{
+ cc::SurfaceManager* manager = GetSurfaceManager();
+ cc::Surface* surface = manager->GetSurfaceForId(
+ mojo::ConvertTo<cc::SurfaceId>(surface_id));
+ if (!surface) {
+ LOG(ERROR) << "Attempting to require callback on nonexistent surface";
+ return;
+ }
+ surface->AddDestructionDependency(
+ mojo::ConvertTo<cc::SurfaceSequence>(sequence));
+}
+
+void OffscreenCanvasSurfaceServiceImpl::Satisfy(
+ blink::mojom::SurfaceSequencePtr sequence)
+{
+ cc::SurfaceSequence ccSequence =
+ mojo::ConvertTo<cc::SurfaceSequence>(sequence);
+ std::vector<uint32_t> sequences;
+ sequences.push_back(ccSequence.sequence);
+ cc::SurfaceManager* manager = GetSurfaceManager();
+ manager->DidSatisfySequences(ccSequence.id_namespace, &sequences);
+}
+
+// TODO: Implement cc::SurfaceFactoryClient functions for resources return.
+void OffscreenCanvasSurfaceServiceImpl::ReturnResources(
+ const cc::ReturnedResourceArray& resources)
+{
+}
+
+void OffscreenCanvasSurfaceServiceImpl::WillDrawSurface(
+ cc::SurfaceId id, const gfx::Rect& damage_rect)
+{
+}
+
+void OffscreenCanvasSurfaceServiceImpl::SetBeginFrameSource(
+ cc::BeginFrameSource* begin_frame_source)
+{
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698