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/layers/surface_layer.h" |
8 #include "cc/surfaces/surface_id.h" | 9 #include "cc/surfaces/surface_id.h" |
9 #include "cc/surfaces/surface_sequence.h" | 10 #include "cc/surfaces/surface_sequence.h" |
10 #include "platform/graphics/GraphicsLayer.h" | 11 #include "platform/graphics/GraphicsLayer.h" |
11 #include "platform/mojo/MojoHelper.h" | 12 #include "platform/mojo/MojoHelper.h" |
12 #include "public/platform/Platform.h" | 13 #include "public/platform/Platform.h" |
13 #include "public/platform/WebCompositorSupport.h" | 14 #include "public/platform/WebCompositorSupport.h" |
14 #include "public/platform/WebLayer.h" | 15 #include "public/platform/WebLayer.h" |
15 #include "ui/gfx/geometry/size.h" | 16 #include "ui/gfx/geometry/size.h" |
16 #include "wtf/Functional.h" | 17 #include "wtf/Functional.h" |
17 | 18 |
18 namespace blink { | 19 namespace blink { |
19 | 20 |
20 CanvasSurfaceLayerBridge::CanvasSurfaceLayerBridge( | 21 CanvasSurfaceLayerBridge::CanvasSurfaceLayerBridge( |
21 mojom::blink::OffscreenCanvasSurfacePtr service) | 22 mojom::blink::OffscreenCanvasSurfacePtr service, |
22 : m_service(std::move(service)) {} | 23 CanvasSurfaceLayerBridgeObserver* observer) |
| 24 : m_observer(observer), |
| 25 m_service(std::move(service)), |
| 26 m_binding(this), |
| 27 m_frameSinkId(Platform::current()->generateFrameSinkId()) { |
| 28 // This FrameSinkId will be used throughout the lifecycle of this canvas. |
| 29 m_service->SetClient(m_binding.CreateInterfacePtrAndBind(), m_frameSinkId); |
| 30 } |
23 | 31 |
24 CanvasSurfaceLayerBridge::~CanvasSurfaceLayerBridge() {} | 32 CanvasSurfaceLayerBridge::~CanvasSurfaceLayerBridge() {} |
25 | 33 |
26 bool CanvasSurfaceLayerBridge::createSurfaceLayer(int canvasWidth, | 34 void CanvasSurfaceLayerBridge::createSolidColorLayer() { |
27 int canvasHeight) { | 35 m_solidColorLayer = cc::SolidColorLayer::Create(); |
28 if (!m_service->GetSurfaceId(&m_surfaceId)) | 36 m_solidColorLayer->SetBackgroundColor(SK_ColorBLUE); |
29 return false; | 37 m_webLayer = Platform::current()->compositorSupport()->createLayerFromCCLayer( |
| 38 m_solidColorLayer.get()); |
| 39 GraphicsLayer::registerContentsLayer(m_webLayer.get()); |
| 40 } |
30 | 41 |
31 cc::SurfaceLayer::SatisfyCallback satisfyCallback = | 42 void CanvasSurfaceLayerBridge::OnSurfaceCreated(const cc::SurfaceId& surfaceId, |
32 convertToBaseCallback(WTF::bind( | 43 int32_t width, |
33 &CanvasSurfaceLayerBridge::satisfyCallback, WTF::unretained(this))); | 44 int32_t height, |
34 cc::SurfaceLayer::RequireCallback requireCallback = | 45 float deviceScaleFactor) { |
35 convertToBaseCallback(WTF::bind( | 46 if (!m_currentSurfaceId.is_valid() || surfaceId != m_currentSurfaceId) { |
36 &CanvasSurfaceLayerBridge::requireCallback, WTF::unretained(this))); | 47 m_currentSurfaceId = surfaceId; |
37 m_surfaceLayer = cc::SurfaceLayer::Create(std::move(satisfyCallback), | |
38 std::move(requireCallback)); | |
39 m_surfaceLayer->SetSurfaceId(m_surfaceId, 1.f, | |
40 gfx::Size(canvasWidth, canvasHeight)); | |
41 | 48 |
42 m_webLayer = Platform::current()->compositorSupport()->createLayerFromCCLayer( | 49 cc::SurfaceLayer::SatisfyCallback satisfyCallback = |
43 m_surfaceLayer.get()); | 50 convertToBaseCallback(WTF::bind( |
44 GraphicsLayer::registerContentsLayer(m_webLayer.get()); | 51 &CanvasSurfaceLayerBridge::satisfyCallback, WTF::unretained(this))); |
45 return true; | 52 cc::SurfaceLayer::RequireCallback requireCallback = |
| 53 convertToBaseCallback(WTF::bind( |
| 54 &CanvasSurfaceLayerBridge::requireCallback, WTF::unretained(this))); |
| 55 m_surfaceLayer = cc::SurfaceLayer::Create(std::move(satisfyCallback), |
| 56 std::move(requireCallback)); |
| 57 m_surfaceLayer->SetSurfaceId(m_currentSurfaceId, device_scale_factor, |
| 58 gfx::Size(width, height)); |
| 59 |
| 60 GraphicsLayer::unregisterContentsLayer(m_webLayer.get()); |
| 61 m_webLayer->removeFromParent(); |
| 62 |
| 63 m_webLayer = |
| 64 Platform::current()->compositorSupport()->createLayerFromCCLayer( |
| 65 m_surfaceLayer.get()); |
| 66 GraphicsLayer::registerContentsLayer(m_webLayer.get()); |
| 67 |
| 68 m_observer->OnWebLayerReplaced(); |
| 69 } |
46 } | 70 } |
47 | 71 |
48 void CanvasSurfaceLayerBridge::satisfyCallback( | 72 void CanvasSurfaceLayerBridge::satisfyCallback( |
49 const cc::SurfaceSequence& sequence) { | 73 const cc::SurfaceSequence& sequence) { |
50 m_service->Satisfy(sequence); | 74 m_service->Satisfy(sequence); |
51 } | 75 } |
52 | 76 |
53 void CanvasSurfaceLayerBridge::requireCallback( | 77 void CanvasSurfaceLayerBridge::requireCallback( |
54 const cc::SurfaceId& surfaceId, | 78 const cc::SurfaceId& surfaceId, |
55 const cc::SurfaceSequence& sequence) { | 79 const cc::SurfaceSequence& sequence) { |
56 m_service->Require(surfaceId, sequence); | 80 m_service->Require(surfaceId, sequence); |
57 } | 81 } |
58 | 82 |
59 } // namespace blink | 83 } // namespace blink |
OLD | NEW |