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

Unified Diff: third_party/WebKit/Source/platform/graphics/CanvasSurfaceLayerBridge.cpp

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: third_party/WebKit/Source/platform/graphics/CanvasSurfaceLayerBridge.cpp
diff --git a/third_party/WebKit/Source/platform/graphics/CanvasSurfaceLayerBridge.cpp b/third_party/WebKit/Source/platform/graphics/CanvasSurfaceLayerBridge.cpp
index b13d9ad7c36c2260ff386af7f2fdae63c4b4564e..a0d3c26d5423a863948ebfeb6812e9d31273f999 100644
--- a/third_party/WebKit/Source/platform/graphics/CanvasSurfaceLayerBridge.cpp
+++ b/third_party/WebKit/Source/platform/graphics/CanvasSurfaceLayerBridge.cpp
@@ -4,24 +4,126 @@
#include "platform/graphics/CanvasSurfaceLayerBridge.h"
-#include "cc/layers/solid_color_layer.h"
+#include "cc/layers/surface_layer.h"
+#include "cc/surfaces/surface_id.h"
+#include "cc/surfaces/surface_sequence.h"
#include "platform/graphics/GraphicsLayer.h"
+#include "platform/mojo/MojoHelper.h"
#include "public/platform/Platform.h"
+#include "public/platform/ServiceRegistry.h"
#include "public/platform/WebCompositorSupport.h"
#include "public/platform/WebLayer.h"
+#include "ui/gfx/geometry/size.h"
+#include "wtf/Functional.h"
+
+namespace mojo {
+
+template <>
+struct TypeConverter<cc::SurfaceId, blink::mojom::blink::SurfaceIdPtr> {
Fady Samuel 2016/06/02 22:32:23 Please avoid using type converters and use the cc:
+ static cc::SurfaceId Convert(const blink::mojom::blink::SurfaceIdPtr& input)
+ {
+ return input ? cc::SurfaceId(input->id_namespace, input->local_id, input->nonce) : cc::SurfaceId();
+ }
+};
+
+template <>
+struct TypeConverter<blink::mojom::blink::SurfaceIdPtr, cc::SurfaceId> {
+ static blink::mojom::blink::SurfaceIdPtr Convert(const cc::SurfaceId& input)
+ {
+ blink::mojom::blink::SurfaceIdPtr result = blink::mojom::blink::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::blink::SurfaceSequencePtr> {
Fady Samuel 2016/06/02 22:32:23 This needs a StructTraits in cc/ipc. Pleasae avoid
+ static cc::SurfaceSequence Convert(const blink::mojom::blink::SurfaceSequencePtr& input)
+ {
+ return input ? cc::SurfaceSequence(input->id_namespace, input->sequence) : cc::SurfaceSequence();
+ }
+};
+
+template <>
+struct TypeConverter<blink::mojom::blink::SurfaceSequencePtr, cc::SurfaceSequence> {
+ static blink::mojom::blink::SurfaceSequencePtr Convert(const cc::SurfaceSequence& input)
+ {
+ blink::mojom::blink::SurfaceSequencePtr result = blink::mojom::blink::SurfaceSequence::New();
+ result->id_namespace = input.id_namespace;
+ result->sequence = input.sequence;
+ return result;
+ }
+};
+
+} // namespace mojo
+
namespace blink {
CanvasSurfaceLayerBridge::CanvasSurfaceLayerBridge()
{
- m_solidColorLayer = cc::SolidColorLayer::Create();
- m_solidColorLayer->SetBackgroundColor(SK_ColorBLUE);
- m_webLayer = adoptPtr(Platform::current()->compositorSupport()->createLayerFromCCLayer(m_solidColorLayer.get()));
- GraphicsLayer::registerContentsLayer(m_webLayer.get());
+ DCHECK(!m_service.is_bound());
+ Platform::current()->serviceRegistry()->connectToRemoteService(mojo::GetProxy(&m_service));
}
CanvasSurfaceLayerBridge::~CanvasSurfaceLayerBridge()
{
}
+bool CanvasSurfaceLayerBridge::createSurfaceLayer(int canvasWidth, int canvasHeight)
+{
+ // Get SurfaceId from browser.
+ bool success = this->syncGetServiceId();
+ if (!success)
+ return false;
+ DCHECK(this->m_surfaceIdPtr);
+ m_surfaceId = mojo::ConvertTo<cc::SurfaceId>(m_surfaceIdPtr);
+
+ // Immediately send an Async message to browser to request Surface creation.
+ this->asyncRequestSurfaceCreation();
+
+ // Create SurfaceLayer.
+ const cc::SurfaceLayer::SatisfyCallback& satisfyCallback = createBaseCallback(bind<cc::SurfaceSequence>(&CanvasSurfaceLayerBridge::satisfyCallback, this));
+ const cc::SurfaceLayer::RequireCallback& requireCallback = createBaseCallback(bind<cc::SurfaceId, cc::SurfaceSequence>(&CanvasSurfaceLayerBridge::requireCallback, this));
+ m_surfaceLayer = cc::SurfaceLayer::Create(satisfyCallback, requireCallback);
+ m_surfaceLayer->SetSurfaceId(m_surfaceId, 1.f, gfx::Size(canvasWidth, canvasHeight));
+
+ // Convert SurfaceLayer to WebLayer and register it.
+ m_webLayer = adoptPtr(Platform::current()->compositorSupport()->createLayerFromCCLayer(m_surfaceLayer.get()));
+ GraphicsLayer::registerContentsLayer(m_webLayer.get());
+ return true;
+}
+
+void CanvasSurfaceLayerBridge::satisfyCallback(cc::SurfaceSequence sequence)
+{
+ this->asyncSatisfy(sequence);
+}
+
+void CanvasSurfaceLayerBridge::requireCallback(cc::SurfaceId surfaceId, cc::SurfaceSequence sequence)
+{
+ this->asyncRequire(surfaceId, sequence);
+}
+
+bool CanvasSurfaceLayerBridge::syncGetServiceId()
+{
+ return m_service->GetSurfaceId(&m_surfaceIdPtr);
+}
+
+void CanvasSurfaceLayerBridge::asyncRequestSurfaceCreation()
+{
+ m_service->RequestSurfaceCreation(m_surfaceIdPtr.Clone());
+}
+
+void CanvasSurfaceLayerBridge::asyncSatisfy(const cc::SurfaceSequence& sequence)
+{
+ m_service->Satisfy(mojo::ConvertTo<blink::mojom::blink::SurfaceSequencePtr>(sequence));
}
+
+void CanvasSurfaceLayerBridge::asyncRequire(const cc::SurfaceId& surfaceId, const cc::SurfaceSequence& sequence)
+{
+ m_service->Require(mojo::ConvertTo<blink::mojom::blink::SurfaceIdPtr>(surfaceId), mojo::ConvertTo<blink::mojom::blink::SurfaceSequencePtr>(sequence));
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698