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/surface_layer.h" | 7 #include "cc/layers/surface_layer.h" |
8 #include "cc/surfaces/sequence_surface_reference_factory.h" | |
8 #include "cc/surfaces/surface_id.h" | 9 #include "cc/surfaces/surface_id.h" |
10 #include "cc/surfaces/surface_info.h" | |
9 #include "cc/surfaces/surface_sequence.h" | 11 #include "cc/surfaces/surface_sequence.h" |
10 #include "platform/graphics/GraphicsLayer.h" | 12 #include "platform/graphics/GraphicsLayer.h" |
11 #include "platform/mojo/MojoHelper.h" | 13 #include "platform/mojo/MojoHelper.h" |
12 #include "public/platform/Platform.h" | 14 #include "public/platform/Platform.h" |
13 #include "public/platform/WebCompositorSupport.h" | 15 #include "public/platform/WebCompositorSupport.h" |
14 #include "public/platform/WebLayer.h" | 16 #include "public/platform/WebLayer.h" |
15 #include "ui/gfx/geometry/size.h" | 17 #include "ui/gfx/geometry/size.h" |
16 #include "wtf/Functional.h" | 18 #include "wtf/Functional.h" |
17 | 19 |
18 namespace blink { | 20 namespace blink { |
19 | 21 |
22 namespace { | |
23 | |
24 class OffscreenCanvasSurfaceReferenceFactory | |
25 : public cc::SequenceSurfaceReferenceFactory { | |
26 public: | |
27 OffscreenCanvasSurfaceReferenceFactory( | |
28 const mojom::blink::OffscreenCanvasSurfacePtr& m_service) | |
29 : m_service(m_service) {} | |
Fady Samuel
2016/12/13 22:55:06
nit: new line.
Saman Sami
2016/12/14 17:50:02
Done.
| |
30 void RequireSequence(const cc::SurfaceId& id, | |
31 const cc::SurfaceSequence& sequence) const override { | |
32 m_service->Require(id, sequence); | |
33 } | |
Fady Samuel
2016/12/13 22:55:06
nit: new line
Saman Sami
2016/12/14 17:50:02
Done.
| |
34 void SatisfySequence(const cc::SurfaceSequence& sequence) const override { | |
35 m_service->Satisfy(sequence); | |
36 } | |
37 | |
38 protected: | |
39 ~OffscreenCanvasSurfaceReferenceFactory() override = default; | |
40 | |
41 private: | |
42 const mojom::blink::OffscreenCanvasSurfacePtr& m_service; | |
Fady Samuel
2016/12/13 22:55:06
This isn't safe because OffscreenCanvasSurfaceRefe
Saman Sami
2016/12/14 17:50:02
Will do in a future patch.
| |
43 | |
44 DISALLOW_COPY_AND_ASSIGN(OffscreenCanvasSurfaceReferenceFactory); | |
45 }; | |
46 | |
47 } // namespace | |
48 | |
20 CanvasSurfaceLayerBridge::CanvasSurfaceLayerBridge( | 49 CanvasSurfaceLayerBridge::CanvasSurfaceLayerBridge( |
21 mojom::blink::OffscreenCanvasSurfacePtr service) | 50 mojom::blink::OffscreenCanvasSurfacePtr service) |
22 : m_service(std::move(service)) {} | 51 : m_service(std::move(service)), |
52 m_refFactory(new OffscreenCanvasSurfaceReferenceFactory(m_service)) {} | |
23 | 53 |
24 CanvasSurfaceLayerBridge::~CanvasSurfaceLayerBridge() {} | 54 CanvasSurfaceLayerBridge::~CanvasSurfaceLayerBridge() {} |
25 | 55 |
26 bool CanvasSurfaceLayerBridge::createSurfaceLayer(int canvasWidth, | 56 bool CanvasSurfaceLayerBridge::createSurfaceLayer(int canvasWidth, |
27 int canvasHeight) { | 57 int canvasHeight) { |
28 if (!m_service->GetSurfaceId(&m_surfaceId)) | 58 if (!m_service->GetSurfaceId(&m_surfaceId)) |
29 return false; | 59 return false; |
30 | 60 |
31 cc::SurfaceLayer::SatisfyCallback satisfyCallback = | 61 m_surfaceLayer = cc::SurfaceLayer::Create(m_refFactory); |
32 convertToBaseCallback(WTF::bind( | 62 cc::SurfaceInfo info(m_surfaceId, 1.f, gfx::Size(canvasWidth, canvasHeight)); |
33 &CanvasSurfaceLayerBridge::satisfyCallback, WTF::unretained(this))); | 63 m_surfaceLayer->SetSurfaceInfo(info); |
34 cc::SurfaceLayer::RequireCallback requireCallback = | |
35 convertToBaseCallback(WTF::bind( | |
36 &CanvasSurfaceLayerBridge::requireCallback, WTF::unretained(this))); | |
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 | 64 |
42 m_webLayer = Platform::current()->compositorSupport()->createLayerFromCCLayer( | 65 m_webLayer = Platform::current()->compositorSupport()->createLayerFromCCLayer( |
43 m_surfaceLayer.get()); | 66 m_surfaceLayer.get()); |
44 GraphicsLayer::registerContentsLayer(m_webLayer.get()); | 67 GraphicsLayer::registerContentsLayer(m_webLayer.get()); |
45 return true; | 68 return true; |
46 } | 69 } |
47 | 70 |
48 void CanvasSurfaceLayerBridge::satisfyCallback( | |
49 const cc::SurfaceSequence& sequence) { | |
50 m_service->Satisfy(sequence); | |
51 } | |
52 | |
53 void CanvasSurfaceLayerBridge::requireCallback( | |
54 const cc::SurfaceId& surfaceId, | |
55 const cc::SurfaceSequence& sequence) { | |
56 m_service->Require(surfaceId, sequence); | |
57 } | |
58 | |
59 } // namespace blink | 71 } // namespace blink |
OLD | NEW |