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/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 base::WeakPtr<CanvasSurfaceLayerBridge> bridge) | |
| 29 : m_bridge(bridge) {} | |
| 30 | |
| 31 private: | |
| 32 ~OffscreenCanvasSurfaceReferenceFactory() override = default; | |
| 33 | |
| 34 // cc::SequenceSurfaceReferenceFactory implementation: | |
| 35 void RequireSequence(const cc::SurfaceId& id, | |
| 36 const cc::SurfaceSequence& sequence) const override { | |
| 37 DCHECK(m_bridge); | |
| 38 m_bridge->requireCallback(id, sequence); | |
| 39 } | |
| 40 | |
| 41 void SatisfySequence(const cc::SurfaceSequence& sequence) const override { | |
| 42 DCHECK(m_bridge); | |
| 43 m_bridge->satisfyCallback(sequence); | |
| 44 } | |
| 45 | |
| 46 base::WeakPtr<CanvasSurfaceLayerBridge> m_bridge; | |
|
jbauman
2016/12/15 20:55:49
We really need to fix the satisfy swap promise soo
| |
| 47 | |
| 48 DISALLOW_COPY_AND_ASSIGN(OffscreenCanvasSurfaceReferenceFactory); | |
| 49 }; | |
| 50 | |
| 51 } // namespace | |
| 52 | |
| 20 CanvasSurfaceLayerBridge::CanvasSurfaceLayerBridge( | 53 CanvasSurfaceLayerBridge::CanvasSurfaceLayerBridge( |
| 21 mojom::blink::OffscreenCanvasSurfacePtr service) | 54 mojom::blink::OffscreenCanvasSurfacePtr service) |
| 22 : m_service(std::move(service)) {} | 55 : m_service(std::move(service)), m_weakFactory(this) { |
| 56 m_refFactory = | |
| 57 new OffscreenCanvasSurfaceReferenceFactory(m_weakFactory.GetWeakPtr()); | |
| 58 } | |
| 23 | 59 |
| 24 CanvasSurfaceLayerBridge::~CanvasSurfaceLayerBridge() {} | 60 CanvasSurfaceLayerBridge::~CanvasSurfaceLayerBridge() {} |
| 25 | 61 |
| 26 bool CanvasSurfaceLayerBridge::createSurfaceLayer(int canvasWidth, | 62 bool CanvasSurfaceLayerBridge::createSurfaceLayer(int canvasWidth, |
| 27 int canvasHeight) { | 63 int canvasHeight) { |
| 28 if (!m_service->GetSurfaceId(&m_surfaceId)) | 64 if (!m_service->GetSurfaceId(&m_surfaceId)) |
| 29 return false; | 65 return false; |
| 30 | 66 |
| 31 cc::SurfaceLayer::SatisfyCallback satisfyCallback = | 67 m_surfaceLayer = cc::SurfaceLayer::Create(m_refFactory); |
| 32 convertToBaseCallback(WTF::bind( | 68 cc::SurfaceInfo info(m_surfaceId, 1.f, gfx::Size(canvasWidth, canvasHeight)); |
| 33 &CanvasSurfaceLayerBridge::satisfyCallback, WTF::unretained(this))); | 69 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 | 70 |
| 42 m_webLayer = Platform::current()->compositorSupport()->createLayerFromCCLayer( | 71 m_webLayer = Platform::current()->compositorSupport()->createLayerFromCCLayer( |
| 43 m_surfaceLayer.get()); | 72 m_surfaceLayer.get()); |
| 44 GraphicsLayer::registerContentsLayer(m_webLayer.get()); | 73 GraphicsLayer::registerContentsLayer(m_webLayer.get()); |
| 45 return true; | 74 return true; |
| 46 } | 75 } |
| 47 | 76 |
| 48 void CanvasSurfaceLayerBridge::satisfyCallback( | 77 void CanvasSurfaceLayerBridge::satisfyCallback( |
| 49 const cc::SurfaceSequence& sequence) { | 78 const cc::SurfaceSequence& sequence) { |
| 50 m_service->Satisfy(sequence); | 79 m_service->Satisfy(sequence); |
| 51 } | 80 } |
| 52 | 81 |
| 53 void CanvasSurfaceLayerBridge::requireCallback( | 82 void CanvasSurfaceLayerBridge::requireCallback( |
| 54 const cc::SurfaceId& surfaceId, | 83 const cc::SurfaceId& surfaceId, |
| 55 const cc::SurfaceSequence& sequence) { | 84 const cc::SurfaceSequence& sequence) { |
| 56 m_service->Require(surfaceId, sequence); | 85 m_service->Require(surfaceId, sequence); |
| 57 } | 86 } |
| 58 | 87 |
| 59 } // namespace blink | 88 } // namespace blink |
| OLD | NEW |