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/layer.h" | |
| 8 #include "cc/layers/solid_color_layer.h" | |
| 7 #include "cc/layers/surface_layer.h" | 9 #include "cc/layers/surface_layer.h" |
| 8 #include "cc/surfaces/surface_id.h" | 10 #include "cc/surfaces/surface_id.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" |
| 14 #include "public/platform/InterfaceProvider.h" | |
| 12 #include "public/platform/Platform.h" | 15 #include "public/platform/Platform.h" |
| 13 #include "public/platform/WebCompositorSupport.h" | 16 #include "public/platform/WebCompositorSupport.h" |
| 14 #include "public/platform/WebLayer.h" | 17 #include "public/platform/WebLayer.h" |
| 18 #include "public/platform/modules/offscreencanvas/offscreen_canvas_surface.mojom -blink.h" | |
| 15 #include "ui/gfx/geometry/size.h" | 19 #include "ui/gfx/geometry/size.h" |
| 16 #include "wtf/Functional.h" | 20 #include "wtf/Functional.h" |
| 17 | 21 |
| 18 namespace blink { | 22 namespace blink { |
| 19 | 23 |
| 20 CanvasSurfaceLayerBridge::CanvasSurfaceLayerBridge( | 24 CanvasSurfaceLayerBridge::CanvasSurfaceLayerBridge( |
| 21 mojom::blink::OffscreenCanvasSurfacePtr service) | 25 CanvasSurfaceLayerBridgeObserver* observer) |
| 22 : m_service(std::move(service)) {} | 26 : m_observer(observer), |
| 27 m_binding(this), | |
| 28 m_frameSinkId(Platform::current()->generateFrameSinkId()) { | |
| 29 DCHECK(!m_service.is_bound()); | |
| 30 mojom::blink::OffscreenCanvasSurfaceFactoryPtr serviceFactory; | |
| 31 Platform::current()->interfaceProvider()->getInterface( | |
| 32 mojo::GetProxy(&serviceFactory)); | |
| 33 serviceFactory->CreateOffscreenCanvasSurface( | |
| 34 m_frameSinkId, m_binding.CreateInterfacePtrAndBind(), | |
| 35 mojo::GetProxy(&m_service)); | |
| 36 } | |
| 23 | 37 |
| 24 CanvasSurfaceLayerBridge::~CanvasSurfaceLayerBridge() {} | 38 CanvasSurfaceLayerBridge::~CanvasSurfaceLayerBridge() { |
| 39 m_observer = nullptr; | |
| 40 } | |
| 25 | 41 |
| 26 bool CanvasSurfaceLayerBridge::createSurfaceLayer(int canvasWidth, | 42 void CanvasSurfaceLayerBridge::createSolidColorLayer() { |
| 27 int canvasHeight) { | 43 m_CCLayer = cc::SolidColorLayer::Create(); |
| 28 if (!m_service->GetSurfaceId(&m_surfaceId)) | 44 m_CCLayer->SetBackgroundColor(SK_ColorTRANSPARENT); |
| 29 return false; | 45 m_webLayer = Platform::current()->compositorSupport()->createLayerFromCCLayer( |
| 46 m_CCLayer.get()); | |
| 47 GraphicsLayer::registerContentsLayer(m_webLayer.get()); | |
| 48 } | |
| 30 | 49 |
| 31 cc::SurfaceLayer::SatisfyCallback satisfyCallback = | 50 void CanvasSurfaceLayerBridge::OnSurfaceCreated(const cc::SurfaceId& surfaceId, |
| 32 convertToBaseCallback(WTF::bind( | 51 int32_t width, |
|
jbauman
2016/12/16 02:19:26
I guess this could still glitch if the surface cre
xlai (Olivia)
2016/12/16 21:34:06
Nope this is impossible to happen. Only when the f
| |
| 33 &CanvasSurfaceLayerBridge::satisfyCallback, WTF::unretained(this))); | 52 int32_t height, |
| 34 cc::SurfaceLayer::RequireCallback requireCallback = | 53 float deviceScaleFactor) { |
| 35 convertToBaseCallback(WTF::bind( | 54 if (!m_currentSurfaceId.is_valid() && surfaceId.is_valid()) { |
| 36 &CanvasSurfaceLayerBridge::requireCallback, WTF::unretained(this))); | 55 m_currentSurfaceId = surfaceId; |
| 37 m_surfaceLayer = cc::SurfaceLayer::Create(std::move(satisfyCallback), | 56 GraphicsLayer::unregisterContentsLayer(m_webLayer.get()); |
| 38 std::move(requireCallback)); | 57 m_webLayer->removeFromParent(); |
| 39 m_surfaceLayer->SetSurfaceId(m_surfaceId, 1.f, | |
| 40 gfx::Size(canvasWidth, canvasHeight)); | |
| 41 | 58 |
| 42 m_webLayer = Platform::current()->compositorSupport()->createLayerFromCCLayer( | 59 cc::SurfaceLayer::SatisfyCallback satisfyCallback = |
| 43 m_surfaceLayer.get()); | 60 convertToBaseCallback(WTF::bind( |
| 44 GraphicsLayer::registerContentsLayer(m_webLayer.get()); | 61 &CanvasSurfaceLayerBridge::satisfyCallback, WTF::unretained(this))); |
| 45 return true; | 62 cc::SurfaceLayer::RequireCallback requireCallback = |
| 63 convertToBaseCallback(WTF::bind( | |
| 64 &CanvasSurfaceLayerBridge::requireCallback, WTF::unretained(this))); | |
| 65 scoped_refptr<cc::SurfaceLayer> surfaceLayer = cc::SurfaceLayer::Create( | |
| 66 std::move(satisfyCallback), std::move(requireCallback)); | |
| 67 surfaceLayer->SetSurfaceId(m_currentSurfaceId, deviceScaleFactor, | |
|
Fady Samuel
2016/12/15 22:55:51
nit: TODO(xlai): Update this on resize.
xlai (Olivia)
2016/12/16 21:34:06
Done.
| |
| 68 gfx::Size(width, height)); | |
| 69 m_CCLayer = surfaceLayer; | |
| 70 | |
| 71 m_webLayer = | |
| 72 Platform::current()->compositorSupport()->createLayerFromCCLayer( | |
| 73 m_CCLayer.get()); | |
| 74 GraphicsLayer::registerContentsLayer(m_webLayer.get()); | |
| 75 | |
| 76 m_observer->OnWebLayerReplaced(); | |
| 77 } | |
| 46 } | 78 } |
| 47 | 79 |
| 48 void CanvasSurfaceLayerBridge::satisfyCallback( | 80 void CanvasSurfaceLayerBridge::satisfyCallback( |
| 49 const cc::SurfaceSequence& sequence) { | 81 const cc::SurfaceSequence& sequence) { |
| 50 m_service->Satisfy(sequence); | 82 m_service->Satisfy(sequence); |
| 51 } | 83 } |
| 52 | 84 |
| 53 void CanvasSurfaceLayerBridge::requireCallback( | 85 void CanvasSurfaceLayerBridge::requireCallback( |
| 54 const cc::SurfaceId& surfaceId, | 86 const cc::SurfaceId& surfaceId, |
| 55 const cc::SurfaceSequence& sequence) { | 87 const cc::SurfaceSequence& sequence) { |
| 56 m_service->Require(surfaceId, sequence); | 88 m_service->Require(surfaceId, sequence); |
| 57 } | 89 } |
| 58 | 90 |
| 59 } // namespace blink | 91 } // namespace blink |
| OLD | NEW |