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/surface_embedding.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 |
| 21 namespace { | |
| 22 | |
| 23 class SurfaceEmbedding : public cc::SurfaceEmbeddingUsingSequence { | |
| 24 public: | |
| 25 SurfaceEmbedding(const mojom::blink::OffscreenCanvasSurfacePtr& m_service) | |
| 26 : m_service(m_service) {} | |
| 27 void RequireSequence(const cc::SurfaceId& id, | |
| 28 const cc::SurfaceSequence& seq) const override { | |
| 29 m_service->Require(id, seq); | |
| 30 } | |
| 31 void SatisfySequence(const cc::SurfaceSequence& seq) const override { | |
| 32 m_service->Satisfy(seq); | |
| 33 } | |
| 34 | |
| 35 protected: | |
| 36 ~SurfaceEmbedding() override = default; | |
| 37 | |
| 38 private: | |
| 39 const mojom::blink::OffscreenCanvasSurfacePtr& m_service; | |
|
Fady Samuel
2016/12/12 16:25:07
This is likely going to have lifetime issues.
| |
| 40 }; | |
| 41 | |
| 42 } // namespace | |
| 43 | |
| 20 CanvasSurfaceLayerBridge::CanvasSurfaceLayerBridge( | 44 CanvasSurfaceLayerBridge::CanvasSurfaceLayerBridge( |
| 21 mojom::blink::OffscreenCanvasSurfacePtr service) | 45 mojom::blink::OffscreenCanvasSurfacePtr service) |
| 22 : m_service(std::move(service)) {} | 46 : m_service(std::move(service)) {} |
| 23 | 47 |
| 24 CanvasSurfaceLayerBridge::~CanvasSurfaceLayerBridge() {} | 48 CanvasSurfaceLayerBridge::~CanvasSurfaceLayerBridge() {} |
| 25 | 49 |
| 26 bool CanvasSurfaceLayerBridge::createSurfaceLayer(int canvasWidth, | 50 bool CanvasSurfaceLayerBridge::createSurfaceLayer(int canvasWidth, |
| 27 int canvasHeight) { | 51 int canvasHeight) { |
| 28 if (!m_service->GetSurfaceId(&m_surfaceId)) | 52 if (!m_service->GetSurfaceId(&m_surfaceId)) |
| 29 return false; | 53 return false; |
| 30 | 54 |
| 31 cc::SurfaceLayer::SatisfyCallback satisfyCallback = | 55 cc::SurfaceEmbeddingPtr ref(new SurfaceEmbedding(m_service)); |
| 32 convertToBaseCallback(WTF::bind( | 56 m_surfaceLayer = cc::SurfaceLayer::Create(std::move(ref)); |
| 33 &CanvasSurfaceLayerBridge::satisfyCallback, WTF::unretained(this))); | 57 cc::SurfaceInfo info(m_surfaceId, 1.f, gfx::Size(canvasWidth, canvasHeight)); |
| 34 cc::SurfaceLayer::RequireCallback requireCallback = | 58 m_surfaceLayer->SetSurfaceInfo(info); |
| 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 | 59 |
| 42 m_webLayer = Platform::current()->compositorSupport()->createLayerFromCCLayer( | 60 m_webLayer = Platform::current()->compositorSupport()->createLayerFromCCLayer( |
| 43 m_surfaceLayer.get()); | 61 m_surfaceLayer.get()); |
| 44 GraphicsLayer::registerContentsLayer(m_webLayer.get()); | 62 GraphicsLayer::registerContentsLayer(m_webLayer.get()); |
| 45 return true; | 63 return true; |
| 46 } | 64 } |
| 47 | 65 |
| 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 | 66 } // namespace blink |
| OLD | NEW |