Chromium Code Reviews| 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 "platform/graphics/CanvasSurfaceLayerBridge.h" | 5 #include "platform/graphics/CanvasSurfaceLayerBridge.h" |
| 6 | 6 |
| 7 #include "cc/layers/solid_color_layer.h" | 7 #include "cc/layers/surface_layer.h" |
| 8 #include "cc/surfaces/surface_id.h" | |
| 9 #include "cc/surfaces/surface_sequence.h" | |
| 8 #include "platform/graphics/GraphicsLayer.h" | 10 #include "platform/graphics/GraphicsLayer.h" |
| 11 #include "platform/mojo/MojoHelper.h" | |
| 9 #include "public/platform/Platform.h" | 12 #include "public/platform/Platform.h" |
| 13 #include "public/platform/ServiceRegistry.h" | |
| 10 #include "public/platform/WebCompositorSupport.h" | 14 #include "public/platform/WebCompositorSupport.h" |
| 11 #include "public/platform/WebLayer.h" | 15 #include "public/platform/WebLayer.h" |
| 16 #include "ui/gfx/geometry/size.h" | |
| 17 #include "wtf/Functional.h" | |
| 18 | |
| 19 namespace mojo { | |
| 20 | |
| 21 template <> | |
| 22 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:
| |
| 23 static cc::SurfaceId Convert(const blink::mojom::blink::SurfaceIdPtr& input) | |
| 24 { | |
| 25 return input ? cc::SurfaceId(input->id_namespace, input->local_id, input ->nonce) : cc::SurfaceId(); | |
| 26 } | |
| 27 }; | |
| 28 | |
| 29 template <> | |
| 30 struct TypeConverter<blink::mojom::blink::SurfaceIdPtr, cc::SurfaceId> { | |
| 31 static blink::mojom::blink::SurfaceIdPtr Convert(const cc::SurfaceId& input) | |
| 32 { | |
| 33 blink::mojom::blink::SurfaceIdPtr result = blink::mojom::blink::SurfaceI d::New(); | |
| 34 result->id_namespace = input.id_namespace(); | |
| 35 result->local_id = input.local_id(); | |
| 36 result->nonce = input.nonce(); | |
| 37 return result; | |
| 38 } | |
| 39 }; | |
| 40 | |
| 41 template <> | |
| 42 struct TypeConverter<cc::SurfaceSequence, blink::mojom::blink::SurfaceSequencePt r> { | |
|
Fady Samuel
2016/06/02 22:32:23
This needs a StructTraits in cc/ipc. Pleasae avoid
| |
| 43 static cc::SurfaceSequence Convert(const blink::mojom::blink::SurfaceSequenc ePtr& input) | |
| 44 { | |
| 45 return input ? cc::SurfaceSequence(input->id_namespace, input->sequence) : cc::SurfaceSequence(); | |
| 46 } | |
| 47 }; | |
| 48 | |
| 49 template <> | |
| 50 struct TypeConverter<blink::mojom::blink::SurfaceSequencePtr, cc::SurfaceSequenc e> { | |
| 51 static blink::mojom::blink::SurfaceSequencePtr Convert(const cc::SurfaceSequ ence& input) | |
| 52 { | |
| 53 blink::mojom::blink::SurfaceSequencePtr result = blink::mojom::blink::Su rfaceSequence::New(); | |
| 54 result->id_namespace = input.id_namespace; | |
| 55 result->sequence = input.sequence; | |
| 56 return result; | |
| 57 } | |
| 58 }; | |
| 59 | |
| 60 } // namespace mojo | |
| 61 | |
| 12 | 62 |
| 13 namespace blink { | 63 namespace blink { |
| 14 | 64 |
| 15 CanvasSurfaceLayerBridge::CanvasSurfaceLayerBridge() | 65 CanvasSurfaceLayerBridge::CanvasSurfaceLayerBridge() |
| 16 { | 66 { |
| 17 m_solidColorLayer = cc::SolidColorLayer::Create(); | 67 DCHECK(!m_service.is_bound()); |
| 18 m_solidColorLayer->SetBackgroundColor(SK_ColorBLUE); | 68 Platform::current()->serviceRegistry()->connectToRemoteService(mojo::GetProx y(&m_service)); |
| 19 m_webLayer = adoptPtr(Platform::current()->compositorSupport()->createLayerF romCCLayer(m_solidColorLayer.get())); | |
| 20 GraphicsLayer::registerContentsLayer(m_webLayer.get()); | |
| 21 } | 69 } |
| 22 | 70 |
| 23 CanvasSurfaceLayerBridge::~CanvasSurfaceLayerBridge() | 71 CanvasSurfaceLayerBridge::~CanvasSurfaceLayerBridge() |
| 24 { | 72 { |
| 25 } | 73 } |
| 26 | 74 |
| 75 bool CanvasSurfaceLayerBridge::createSurfaceLayer(int canvasWidth, int canvasHei ght) | |
| 76 { | |
| 77 // Get SurfaceId from browser. | |
| 78 bool success = this->syncGetServiceId(); | |
| 79 if (!success) | |
| 80 return false; | |
| 81 DCHECK(this->m_surfaceIdPtr); | |
| 82 m_surfaceId = mojo::ConvertTo<cc::SurfaceId>(m_surfaceIdPtr); | |
| 83 | |
| 84 // Immediately send an Async message to browser to request Surface creation. | |
| 85 this->asyncRequestSurfaceCreation(); | |
| 86 | |
| 87 // Create SurfaceLayer. | |
| 88 const cc::SurfaceLayer::SatisfyCallback& satisfyCallback = createBaseCallbac k(bind<cc::SurfaceSequence>(&CanvasSurfaceLayerBridge::satisfyCallback, this)); | |
| 89 const cc::SurfaceLayer::RequireCallback& requireCallback = createBaseCallbac k(bind<cc::SurfaceId, cc::SurfaceSequence>(&CanvasSurfaceLayerBridge::requireCal lback, this)); | |
| 90 m_surfaceLayer = cc::SurfaceLayer::Create(satisfyCallback, requireCallback); | |
| 91 m_surfaceLayer->SetSurfaceId(m_surfaceId, 1.f, gfx::Size(canvasWidth, canvas Height)); | |
| 92 | |
| 93 // Convert SurfaceLayer to WebLayer and register it. | |
| 94 m_webLayer = adoptPtr(Platform::current()->compositorSupport()->createLayerF romCCLayer(m_surfaceLayer.get())); | |
| 95 GraphicsLayer::registerContentsLayer(m_webLayer.get()); | |
| 96 return true; | |
| 27 } | 97 } |
| 98 | |
| 99 void CanvasSurfaceLayerBridge::satisfyCallback(cc::SurfaceSequence sequence) | |
| 100 { | |
| 101 this->asyncSatisfy(sequence); | |
| 102 } | |
| 103 | |
| 104 void CanvasSurfaceLayerBridge::requireCallback(cc::SurfaceId surfaceId, cc::Surf aceSequence sequence) | |
| 105 { | |
| 106 this->asyncRequire(surfaceId, sequence); | |
| 107 } | |
| 108 | |
| 109 bool CanvasSurfaceLayerBridge::syncGetServiceId() | |
| 110 { | |
| 111 return m_service->GetSurfaceId(&m_surfaceIdPtr); | |
| 112 } | |
| 113 | |
| 114 void CanvasSurfaceLayerBridge::asyncRequestSurfaceCreation() | |
| 115 { | |
| 116 m_service->RequestSurfaceCreation(m_surfaceIdPtr.Clone()); | |
| 117 } | |
| 118 | |
| 119 void CanvasSurfaceLayerBridge::asyncSatisfy(const cc::SurfaceSequence& sequence) | |
| 120 { | |
| 121 m_service->Satisfy(mojo::ConvertTo<blink::mojom::blink::SurfaceSequencePtr>( sequence)); | |
| 122 } | |
| 123 | |
| 124 void CanvasSurfaceLayerBridge::asyncRequire(const cc::SurfaceId& surfaceId, cons t cc::SurfaceSequence& sequence) | |
| 125 { | |
| 126 m_service->Require(mojo::ConvertTo<blink::mojom::blink::SurfaceIdPtr>(surfac eId), mojo::ConvertTo<blink::mojom::blink::SurfaceSequencePtr>(sequence)); | |
| 127 } | |
| 128 | |
| 129 } // namespace blink | |
| OLD | NEW |