Index: third_party/WebKit/Source/platform/graphics/CanvasSurfaceLayerBridge.cpp |
diff --git a/third_party/WebKit/Source/platform/graphics/CanvasSurfaceLayerBridge.cpp b/third_party/WebKit/Source/platform/graphics/CanvasSurfaceLayerBridge.cpp |
index 4355caed2a27dd712a886705e5bd9e97539d3cf5..0b93b88a7dd728a992615038f64c80274b25fc03 100644 |
--- a/third_party/WebKit/Source/platform/graphics/CanvasSurfaceLayerBridge.cpp |
+++ b/third_party/WebKit/Source/platform/graphics/CanvasSurfaceLayerBridge.cpp |
@@ -4,6 +4,7 @@ |
#include "platform/graphics/CanvasSurfaceLayerBridge.h" |
+#include "cc/layers/solid_color_layer.h" |
#include "cc/layers/surface_layer.h" |
#include "cc/surfaces/surface_id.h" |
#include "cc/surfaces/surface_sequence.h" |
@@ -18,31 +19,56 @@ |
namespace blink { |
CanvasSurfaceLayerBridge::CanvasSurfaceLayerBridge( |
- mojom::blink::OffscreenCanvasSurfacePtr service) |
- : m_service(std::move(service)) {} |
- |
-CanvasSurfaceLayerBridge::~CanvasSurfaceLayerBridge() {} |
- |
-bool CanvasSurfaceLayerBridge::createSurfaceLayer(int canvasWidth, |
- int canvasHeight) { |
- if (!m_service->GetSurfaceId(&m_surfaceId)) |
- return false; |
- |
- cc::SurfaceLayer::SatisfyCallback satisfyCallback = |
- convertToBaseCallback(WTF::bind( |
- &CanvasSurfaceLayerBridge::satisfyCallback, WTF::unretained(this))); |
- cc::SurfaceLayer::RequireCallback requireCallback = |
- convertToBaseCallback(WTF::bind( |
- &CanvasSurfaceLayerBridge::requireCallback, WTF::unretained(this))); |
- m_surfaceLayer = cc::SurfaceLayer::Create(std::move(satisfyCallback), |
- std::move(requireCallback)); |
- m_surfaceLayer->SetSurfaceId(m_surfaceId, 1.f, |
- gfx::Size(canvasWidth, canvasHeight)); |
+ mojom::blink::OffscreenCanvasSurfacePtr service, |
+ CanvasSurfaceLayerBridgeObserver* observer) |
+ : m_observer(observer), |
+ m_service(std::move(service)), |
+ m_binding(this), |
+ m_frameSinkId(Platform::current()->generateFrameSinkId()) { |
+ // This FrameSinkId will be used throughout the lifecycle of this canvas. |
+ m_service->SetClient(m_binding.CreateInterfacePtrAndBind(), m_frameSinkId); |
+} |
+ |
+CanvasSurfaceLayerBridge::~CanvasSurfaceLayerBridge() { |
+ m_observer = nullptr; |
+} |
+void CanvasSurfaceLayerBridge::createSolidColorLayer() { |
+ m_solidColorLayer = cc::SolidColorLayer::Create(); |
+ m_solidColorLayer->SetBackgroundColor(SK_ColorTRANSPARENT); |
m_webLayer = Platform::current()->compositorSupport()->createLayerFromCCLayer( |
- m_surfaceLayer.get()); |
+ m_solidColorLayer.get()); |
GraphicsLayer::registerContentsLayer(m_webLayer.get()); |
- return true; |
+} |
+ |
+void CanvasSurfaceLayerBridge::OnSurfaceCreated(const cc::SurfaceId& surfaceId, |
+ int32_t width, |
+ int32_t height, |
+ float deviceScaleFactor) { |
+ if (!m_currentSurfaceId.is_valid() || surfaceId != m_currentSurfaceId) { |
+ m_currentSurfaceId = surfaceId; |
+ |
+ cc::SurfaceLayer::SatisfyCallback satisfyCallback = |
+ convertToBaseCallback(WTF::bind( |
+ &CanvasSurfaceLayerBridge::satisfyCallback, WTF::unretained(this))); |
+ cc::SurfaceLayer::RequireCallback requireCallback = |
+ convertToBaseCallback(WTF::bind( |
+ &CanvasSurfaceLayerBridge::requireCallback, WTF::unretained(this))); |
+ m_surfaceLayer = cc::SurfaceLayer::Create(std::move(satisfyCallback), |
+ std::move(requireCallback)); |
+ m_surfaceLayer->SetSurfaceId(m_currentSurfaceId, deviceScaleFactor, |
+ gfx::Size(width, height)); |
+ |
+ GraphicsLayer::unregisterContentsLayer(m_webLayer.get()); |
+ m_webLayer->removeFromParent(); |
+ |
+ 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
|
+ Platform::current()->compositorSupport()->createLayerFromCCLayer( |
+ m_surfaceLayer.get()); |
+ GraphicsLayer::registerContentsLayer(m_webLayer.get()); |
+ |
+ m_observer->OnWebLayerReplaced(); |
+ } |
} |
void CanvasSurfaceLayerBridge::satisfyCallback( |