| 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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 } | 77 } |
| 78 | 78 |
| 79 void CanvasSurfaceLayerBridge::createSolidColorLayer() { | 79 void CanvasSurfaceLayerBridge::createSolidColorLayer() { |
| 80 m_CCLayer = cc::SolidColorLayer::Create(); | 80 m_CCLayer = cc::SolidColorLayer::Create(); |
| 81 m_CCLayer->SetBackgroundColor(SK_ColorTRANSPARENT); | 81 m_CCLayer->SetBackgroundColor(SK_ColorTRANSPARENT); |
| 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( |
| 88 int32_t width, | 88 const cc::SurfaceInfo& surfaceInfo) { |
| 89 int32_t height, | 89 if (!m_currentSurfaceId.is_valid() && surfaceInfo.id().is_valid()) { |
| 90 float deviceScaleFactor) { | |
| 91 if (!m_currentSurfaceId.is_valid() && surfaceId.is_valid()) { | |
| 92 // First time a SurfaceId is received | 90 // First time a SurfaceId is received |
| 93 m_currentSurfaceId = surfaceId; | 91 m_currentSurfaceId = surfaceInfo.id(); |
| 94 GraphicsLayer::unregisterContentsLayer(m_webLayer.get()); | 92 GraphicsLayer::unregisterContentsLayer(m_webLayer.get()); |
| 95 m_webLayer->removeFromParent(); | 93 m_webLayer->removeFromParent(); |
| 96 | 94 |
| 97 scoped_refptr<cc::SurfaceLayer> surfaceLayer = | 95 scoped_refptr<cc::SurfaceLayer> surfaceLayer = |
| 98 cc::SurfaceLayer::Create(m_refFactory); | 96 cc::SurfaceLayer::Create(m_refFactory); |
| 99 cc::SurfaceInfo info(surfaceId, deviceScaleFactor, | |
| 100 gfx::Size(width, height)); | |
| 101 surfaceLayer->SetSurfaceInfo( | 97 surfaceLayer->SetSurfaceInfo( |
| 102 info, true /* scale layer bounds with surface size */); | 98 surfaceInfo, true /* scale layer bounds with surface size */); |
| 103 m_CCLayer = surfaceLayer; | 99 m_CCLayer = surfaceLayer; |
| 104 | 100 |
| 105 m_webLayer = | 101 m_webLayer = |
| 106 Platform::current()->compositorSupport()->createLayerFromCCLayer( | 102 Platform::current()->compositorSupport()->createLayerFromCCLayer( |
| 107 m_CCLayer.get()); | 103 m_CCLayer.get()); |
| 108 GraphicsLayer::registerContentsLayer(m_webLayer.get()); | 104 GraphicsLayer::registerContentsLayer(m_webLayer.get()); |
| 109 } else if (m_currentSurfaceId != surfaceId) { | 105 } else if (m_currentSurfaceId != surfaceInfo.id()) { |
| 110 // A different SurfaceId is received, prompting change to existing | 106 // A different SurfaceId is received, prompting change to existing |
| 111 // SurfaceLayer | 107 // SurfaceLayer |
| 112 m_currentSurfaceId = surfaceId; | 108 m_currentSurfaceId = surfaceInfo.id(); |
| 113 cc::SurfaceInfo info(m_currentSurfaceId, deviceScaleFactor, | |
| 114 gfx::Size(width, height)); | |
| 115 cc::SurfaceLayer* surfaceLayer = | 109 cc::SurfaceLayer* surfaceLayer = |
| 116 static_cast<cc::SurfaceLayer*>(m_CCLayer.get()); | 110 static_cast<cc::SurfaceLayer*>(m_CCLayer.get()); |
| 117 surfaceLayer->SetSurfaceInfo( | 111 surfaceLayer->SetSurfaceInfo( |
| 118 info, true /* scale layer bounds with surface size */); | 112 surfaceInfo, true /* scale layer bounds with surface size */); |
| 119 } | 113 } |
| 120 | 114 |
| 121 m_observer->OnWebLayerReplaced(); | 115 m_observer->OnWebLayerReplaced(); |
| 122 m_CCLayer->SetBounds(gfx::Size(width, height)); | 116 m_CCLayer->SetBounds(surfaceInfo.size_in_pixels()); |
| 123 } | 117 } |
| 124 | 118 |
| 125 void CanvasSurfaceLayerBridge::satisfyCallback( | 119 void CanvasSurfaceLayerBridge::satisfyCallback( |
| 126 const cc::SurfaceSequence& sequence) { | 120 const cc::SurfaceSequence& sequence) { |
| 127 m_service->Satisfy(sequence); | 121 m_service->Satisfy(sequence); |
| 128 } | 122 } |
| 129 | 123 |
| 130 void CanvasSurfaceLayerBridge::requireCallback( | 124 void CanvasSurfaceLayerBridge::requireCallback( |
| 131 const cc::SurfaceId& surfaceId, | 125 const cc::SurfaceId& surfaceId, |
| 132 const cc::SurfaceSequence& sequence) { | 126 const cc::SurfaceSequence& sequence) { |
| 133 m_service->Require(surfaceId, sequence); | 127 m_service->Require(surfaceId, sequence); |
| 134 } | 128 } |
| 135 | 129 |
| 136 } // namespace blink | 130 } // namespace blink |
| OLD | NEW |