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" |
12 | 18 |
13 namespace blink { | 19 namespace blink { |
14 | 20 |
15 CanvasSurfaceLayerBridge::CanvasSurfaceLayerBridge() | 21 CanvasSurfaceLayerBridge::CanvasSurfaceLayerBridge() |
16 { | 22 { |
17 m_solidColorLayer = cc::SolidColorLayer::Create(); | 23 DCHECK(!m_service.is_bound()); |
18 m_solidColorLayer->SetBackgroundColor(SK_ColorBLUE); | 24 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 } | 25 } |
22 | 26 |
23 CanvasSurfaceLayerBridge::~CanvasSurfaceLayerBridge() | 27 CanvasSurfaceLayerBridge::~CanvasSurfaceLayerBridge() |
24 { | 28 { |
25 } | 29 } |
26 | 30 |
| 31 bool CanvasSurfaceLayerBridge::createSurfaceLayer(int canvasWidth, int canvasHei
ght) |
| 32 { |
| 33 // Get SurfaceId from browser. |
| 34 bool success = this->syncGetServiceId(); |
| 35 if (!success) |
| 36 return false; |
| 37 |
| 38 // Immediately send an Async message to browser to request Surface creation. |
| 39 this->asyncRequestSurfaceCreation(); |
| 40 |
| 41 // Create SurfaceLayer. |
| 42 const cc::SurfaceLayer::SatisfyCallback& satisfyCallback = createBaseCallbac
k(bind<cc::SurfaceSequence>(&CanvasSurfaceLayerBridge::satisfyCallback, this)); |
| 43 const cc::SurfaceLayer::RequireCallback& requireCallback = createBaseCallbac
k(bind<cc::SurfaceId, cc::SurfaceSequence>(&CanvasSurfaceLayerBridge::requireCal
lback, this)); |
| 44 m_surfaceLayer = cc::SurfaceLayer::Create(satisfyCallback, requireCallback); |
| 45 m_surfaceLayer->SetSurfaceId(m_surfaceId, 1.f, gfx::Size(canvasWidth, canvas
Height)); |
| 46 |
| 47 // Convert SurfaceLayer to WebLayer and register it. |
| 48 m_webLayer = adoptPtr(Platform::current()->compositorSupport()->createLayerF
romCCLayer(m_surfaceLayer.get())); |
| 49 GraphicsLayer::registerContentsLayer(m_webLayer.get()); |
| 50 return true; |
27 } | 51 } |
| 52 |
| 53 void CanvasSurfaceLayerBridge::satisfyCallback(cc::SurfaceSequence sequence) |
| 54 { |
| 55 m_service->Satisfy(sequence); |
| 56 } |
| 57 |
| 58 void CanvasSurfaceLayerBridge::requireCallback(cc::SurfaceId surfaceId, cc::Surf
aceSequence sequence) |
| 59 { |
| 60 m_service->Require(surfaceId, sequence); |
| 61 } |
| 62 |
| 63 bool CanvasSurfaceLayerBridge::syncGetServiceId() |
| 64 { |
| 65 return m_service->GetSurfaceId(&m_surfaceId); |
| 66 } |
| 67 |
| 68 void CanvasSurfaceLayerBridge::asyncRequestSurfaceCreation() |
| 69 { |
| 70 m_service->RequestSurfaceCreation(m_surfaceId); |
| 71 } |
| 72 |
| 73 } // namespace blink |
OLD | NEW |