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() { |
33 m_observer = nullptr; | |
34 } | |
25 | 35 |
26 bool CanvasSurfaceLayerBridge::createSurfaceLayer(int canvasWidth, | 36 void CanvasSurfaceLayerBridge::createSolidColorLayer() { |
27 int canvasHeight) { | 37 m_solidColorLayer = cc::SolidColorLayer::Create(); |
28 if (!m_service->GetSurfaceId(&m_surfaceId)) | 38 m_solidColorLayer->SetBackgroundColor(SK_ColorTRANSPARENT); |
29 return false; | 39 m_webLayer = Platform::current()->compositorSupport()->createLayerFromCCLayer( |
40 m_solidColorLayer.get()); | |
41 GraphicsLayer::registerContentsLayer(m_webLayer.get()); | |
42 } | |
30 | 43 |
31 cc::SurfaceLayer::SatisfyCallback satisfyCallback = | 44 void CanvasSurfaceLayerBridge::OnSurfaceCreated(const cc::SurfaceId& surfaceId, |
32 convertToBaseCallback(WTF::bind( | 45 int32_t width, |
33 &CanvasSurfaceLayerBridge::satisfyCallback, WTF::unretained(this))); | 46 int32_t height, |
34 cc::SurfaceLayer::RequireCallback requireCallback = | 47 float deviceScaleFactor) { |
35 convertToBaseCallback(WTF::bind( | 48 if (!m_currentSurfaceId.is_valid() || surfaceId != m_currentSurfaceId) { |
36 &CanvasSurfaceLayerBridge::requireCallback, WTF::unretained(this))); | 49 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 | 50 |
42 m_webLayer = Platform::current()->compositorSupport()->createLayerFromCCLayer( | 51 cc::SurfaceLayer::SatisfyCallback satisfyCallback = |
43 m_surfaceLayer.get()); | 52 convertToBaseCallback(WTF::bind( |
44 GraphicsLayer::registerContentsLayer(m_webLayer.get()); | 53 &CanvasSurfaceLayerBridge::satisfyCallback, WTF::unretained(this))); |
45 return true; | 54 cc::SurfaceLayer::RequireCallback requireCallback = |
55 convertToBaseCallback(WTF::bind( | |
56 &CanvasSurfaceLayerBridge::requireCallback, WTF::unretained(this))); | |
57 m_surfaceLayer = cc::SurfaceLayer::Create(std::move(satisfyCallback), | |
58 std::move(requireCallback)); | |
59 m_surfaceLayer->SetSurfaceId(m_currentSurfaceId, deviceScaleFactor, | |
60 gfx::Size(width, height)); | |
61 | |
62 GraphicsLayer::unregisterContentsLayer(m_webLayer.get()); | |
63 m_webLayer->removeFromParent(); | |
64 | |
65 m_webLayer = | |
Fady Samuel
2016/12/15 19:54:52
You don't need to create a new layer every time th
xlai (Olivia)
2016/12/15 22:20:12
Done. But I'm wondering, when SurfaceId, and possi
Fady Samuel
2016/12/15 22:26:01
Yes, you just call SetSurfaceId
| |
66 Platform::current()->compositorSupport()->createLayerFromCCLayer( | |
67 m_surfaceLayer.get()); | |
68 GraphicsLayer::registerContentsLayer(m_webLayer.get()); | |
69 | |
70 m_observer->OnWebLayerReplaced(); | |
71 } | |
46 } | 72 } |
47 | 73 |
48 void CanvasSurfaceLayerBridge::satisfyCallback( | 74 void CanvasSurfaceLayerBridge::satisfyCallback( |
49 const cc::SurfaceSequence& sequence) { | 75 const cc::SurfaceSequence& sequence) { |
50 m_service->Satisfy(sequence); | 76 m_service->Satisfy(sequence); |
51 } | 77 } |
52 | 78 |
53 void CanvasSurfaceLayerBridge::requireCallback( | 79 void CanvasSurfaceLayerBridge::requireCallback( |
54 const cc::SurfaceId& surfaceId, | 80 const cc::SurfaceId& surfaceId, |
55 const cc::SurfaceSequence& sequence) { | 81 const cc::SurfaceSequence& sequence) { |
56 m_service->Require(surfaceId, sequence); | 82 m_service->Require(surfaceId, sequence); |
57 } | 83 } |
58 | 84 |
59 } // namespace blink | 85 } // namespace blink |
OLD | NEW |