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" | 7 #include "cc/layers/layer.h" |
8 #include "cc/layers/solid_color_layer.h" | 8 #include "cc/layers/solid_color_layer.h" |
9 #include "cc/layers/surface_layer.h" | 9 #include "cc/layers/surface_layer.h" |
10 #include "cc/surfaces/sequence_surface_reference_factory.h" | 10 #include "cc/surfaces/sequence_surface_reference_factory.h" |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 m_webLayer = Platform::current()->compositorSupport()->createLayerFromCCLayer( | 82 m_webLayer = Platform::current()->compositorSupport()->createLayerFromCCLayer( |
83 m_CCLayer.get()); | 83 m_CCLayer.get()); |
84 GraphicsLayer::registerContentsLayer(m_webLayer.get()); | 84 GraphicsLayer::registerContentsLayer(m_webLayer.get()); |
85 } | 85 } |
86 | 86 |
87 void CanvasSurfaceLayerBridge::OnSurfaceCreated(const cc::SurfaceId& surfaceId, | 87 void CanvasSurfaceLayerBridge::OnSurfaceCreated(const cc::SurfaceId& surfaceId, |
88 int32_t width, | 88 int32_t width, |
89 int32_t height, | 89 int32_t height, |
90 float deviceScaleFactor) { | 90 float deviceScaleFactor) { |
91 if (!m_currentSurfaceId.is_valid() && surfaceId.is_valid()) { | 91 if (!m_currentSurfaceId.is_valid() && surfaceId.is_valid()) { |
| 92 // First time a SurfaceId is received |
92 m_currentSurfaceId = surfaceId; | 93 m_currentSurfaceId = surfaceId; |
93 GraphicsLayer::unregisterContentsLayer(m_webLayer.get()); | 94 GraphicsLayer::unregisterContentsLayer(m_webLayer.get()); |
94 m_webLayer->removeFromParent(); | 95 m_webLayer->removeFromParent(); |
95 | 96 |
96 scoped_refptr<cc::SurfaceLayer> surfaceLayer = | 97 scoped_refptr<cc::SurfaceLayer> surfaceLayer = |
97 cc::SurfaceLayer::Create(m_refFactory); | 98 cc::SurfaceLayer::Create(m_refFactory); |
98 // TODO(xlai): Update this on resize. | |
99 cc::SurfaceInfo info(surfaceId, deviceScaleFactor, | 99 cc::SurfaceInfo info(surfaceId, deviceScaleFactor, |
100 gfx::Size(width, height)); | 100 gfx::Size(width, height)); |
101 surfaceLayer->SetSurfaceInfo( | 101 surfaceLayer->SetSurfaceInfo( |
102 info, true /* scale layer bounds with surface size */); | 102 info, true /* scale layer bounds with surface size */); |
103 m_CCLayer = surfaceLayer; | 103 m_CCLayer = surfaceLayer; |
104 | 104 |
105 m_webLayer = | 105 m_webLayer = |
106 Platform::current()->compositorSupport()->createLayerFromCCLayer( | 106 Platform::current()->compositorSupport()->createLayerFromCCLayer( |
107 m_CCLayer.get()); | 107 m_CCLayer.get()); |
108 GraphicsLayer::registerContentsLayer(m_webLayer.get()); | 108 GraphicsLayer::registerContentsLayer(m_webLayer.get()); |
| 109 } else if (m_currentSurfaceId != surfaceId) { |
| 110 // A different SurfaceId is received, prompting change to existing |
| 111 // SurfaceLayer |
| 112 m_currentSurfaceId = surfaceId; |
| 113 cc::SurfaceInfo info(m_currentSurfaceId, deviceScaleFactor, |
| 114 gfx::Size(width, height)); |
| 115 cc::SurfaceLayer* surfaceLayer = |
| 116 static_cast<cc::SurfaceLayer*>(m_CCLayer.get()); |
| 117 surfaceLayer->SetSurfaceInfo( |
| 118 info, true /* scale layer bounds with surface size */); |
| 119 } |
109 | 120 |
110 m_observer->OnWebLayerReplaced(); | 121 m_observer->OnWebLayerReplaced(); |
111 } | 122 m_CCLayer->SetBounds(gfx::Size(width, height)); |
112 } | 123 } |
113 | 124 |
114 void CanvasSurfaceLayerBridge::satisfyCallback( | 125 void CanvasSurfaceLayerBridge::satisfyCallback( |
115 const cc::SurfaceSequence& sequence) { | 126 const cc::SurfaceSequence& sequence) { |
116 m_service->Satisfy(sequence); | 127 m_service->Satisfy(sequence); |
117 } | 128 } |
118 | 129 |
119 void CanvasSurfaceLayerBridge::requireCallback( | 130 void CanvasSurfaceLayerBridge::requireCallback( |
120 const cc::SurfaceId& surfaceId, | 131 const cc::SurfaceId& surfaceId, |
121 const cc::SurfaceSequence& sequence) { | 132 const cc::SurfaceSequence& sequence) { |
122 m_service->Require(surfaceId, sequence); | 133 m_service->Require(surfaceId, sequence); |
123 } | 134 } |
124 | 135 |
125 } // namespace blink | 136 } // namespace blink |
OLD | NEW |