Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(928)

Side by Side Diff: third_party/WebKit/Source/platform/graphics/CanvasSurfaceLayerBridge.cpp

Issue 2584643002: Revamp OffscreenCanvas commit flow (Closed)
Patch Set: rebase and fix conflict Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/sequence_surface_reference_factory.h" 10 #include "cc/surfaces/sequence_surface_reference_factory.h"
9 #include "cc/surfaces/surface_id.h" 11 #include "cc/surfaces/surface_id.h"
10 #include "cc/surfaces/surface_info.h" 12 #include "cc/surfaces/surface_info.h"
11 #include "cc/surfaces/surface_sequence.h" 13 #include "cc/surfaces/surface_sequence.h"
12 #include "platform/graphics/GraphicsLayer.h" 14 #include "platform/graphics/GraphicsLayer.h"
13 #include "platform/mojo/MojoHelper.h" 15 #include "platform/mojo/MojoHelper.h"
16 #include "public/platform/InterfaceProvider.h"
14 #include "public/platform/Platform.h" 17 #include "public/platform/Platform.h"
15 #include "public/platform/WebCompositorSupport.h" 18 #include "public/platform/WebCompositorSupport.h"
16 #include "public/platform/WebLayer.h" 19 #include "public/platform/WebLayer.h"
20 #include "public/platform/modules/offscreencanvas/offscreen_canvas_surface.mojom -blink.h"
17 #include "ui/gfx/geometry/size.h" 21 #include "ui/gfx/geometry/size.h"
18 #include "wtf/Functional.h" 22 #include "wtf/Functional.h"
19 23
20 namespace blink { 24 namespace blink {
21 25
22 namespace { 26 namespace {
23 27
24 class OffscreenCanvasSurfaceReferenceFactory 28 class OffscreenCanvasSurfaceReferenceFactory
25 : public cc::SequenceSurfaceReferenceFactory { 29 : public cc::SequenceSurfaceReferenceFactory {
26 public: 30 public:
(...skipping 17 matching lines...) Expand all
44 } 48 }
45 49
46 base::WeakPtr<CanvasSurfaceLayerBridge> m_bridge; 50 base::WeakPtr<CanvasSurfaceLayerBridge> m_bridge;
47 51
48 DISALLOW_COPY_AND_ASSIGN(OffscreenCanvasSurfaceReferenceFactory); 52 DISALLOW_COPY_AND_ASSIGN(OffscreenCanvasSurfaceReferenceFactory);
49 }; 53 };
50 54
51 } // namespace 55 } // namespace
52 56
53 CanvasSurfaceLayerBridge::CanvasSurfaceLayerBridge( 57 CanvasSurfaceLayerBridge::CanvasSurfaceLayerBridge(
54 mojom::blink::OffscreenCanvasSurfacePtr service) 58 CanvasSurfaceLayerBridgeObserver* observer)
55 : m_service(std::move(service)), m_weakFactory(this) { 59 : m_weakFactory(this),
60 m_observer(observer),
61 m_binding(this),
62 m_frameSinkId(Platform::current()->generateFrameSinkId()) {
56 m_refFactory = 63 m_refFactory =
57 new OffscreenCanvasSurfaceReferenceFactory(m_weakFactory.GetWeakPtr()); 64 new OffscreenCanvasSurfaceReferenceFactory(m_weakFactory.GetWeakPtr());
65
66 DCHECK(!m_service.is_bound());
67 mojom::blink::OffscreenCanvasSurfaceFactoryPtr serviceFactory;
68 Platform::current()->interfaceProvider()->getInterface(
69 mojo::GetProxy(&serviceFactory));
70 serviceFactory->CreateOffscreenCanvasSurface(
71 m_frameSinkId, m_binding.CreateInterfacePtrAndBind(),
72 mojo::GetProxy(&m_service));
58 } 73 }
59 74
60 CanvasSurfaceLayerBridge::~CanvasSurfaceLayerBridge() {} 75 CanvasSurfaceLayerBridge::~CanvasSurfaceLayerBridge() {
76 m_observer = nullptr;
77 }
61 78
62 bool CanvasSurfaceLayerBridge::createSurfaceLayer(int canvasWidth, 79 void CanvasSurfaceLayerBridge::createSolidColorLayer() {
63 int canvasHeight) { 80 m_CCLayer = cc::SolidColorLayer::Create();
64 if (!m_service->GetSurfaceId(&m_surfaceId)) 81 m_CCLayer->SetBackgroundColor(SK_ColorTRANSPARENT);
65 return false; 82 m_webLayer = Platform::current()->compositorSupport()->createLayerFromCCLayer(
83 m_CCLayer.get());
84 GraphicsLayer::registerContentsLayer(m_webLayer.get());
85 }
66 86
67 m_surfaceLayer = cc::SurfaceLayer::Create(m_refFactory); 87 void CanvasSurfaceLayerBridge::OnSurfaceCreated(const cc::SurfaceId& surfaceId,
68 cc::SurfaceInfo info(m_surfaceId, 1.f, gfx::Size(canvasWidth, canvasHeight)); 88 int32_t width,
69 m_surfaceLayer->SetSurfaceInfo( 89 int32_t height,
70 info, true /* scale layer bounds with surface size */); 90 float deviceScaleFactor) {
91 if (!m_currentSurfaceId.is_valid() && surfaceId.is_valid()) {
92 m_currentSurfaceId = surfaceId;
93 GraphicsLayer::unregisterContentsLayer(m_webLayer.get());
94 m_webLayer->removeFromParent();
71 95
72 m_webLayer = Platform::current()->compositorSupport()->createLayerFromCCLayer( 96 scoped_refptr<cc::SurfaceLayer> surfaceLayer =
73 m_surfaceLayer.get()); 97 cc::SurfaceLayer::Create(m_refFactory);
74 GraphicsLayer::registerContentsLayer(m_webLayer.get()); 98 // TODO(xlai): Update this on resize.
75 return true; 99 cc::SurfaceInfo info(surfaceId, deviceScaleFactor,
100 gfx::Size(width, height));
101 surfaceLayer->SetSurfaceInfo(
102 info, true /* scale layer bounds with surface size */);
103 m_CCLayer = surfaceLayer;
104
105 m_webLayer =
106 Platform::current()->compositorSupport()->createLayerFromCCLayer(
107 m_CCLayer.get());
108 GraphicsLayer::registerContentsLayer(m_webLayer.get());
109
110 m_observer->OnWebLayerReplaced();
111 }
76 } 112 }
77 113
78 void CanvasSurfaceLayerBridge::satisfyCallback( 114 void CanvasSurfaceLayerBridge::satisfyCallback(
79 const cc::SurfaceSequence& sequence) { 115 const cc::SurfaceSequence& sequence) {
80 m_service->Satisfy(sequence); 116 m_service->Satisfy(sequence);
81 } 117 }
82 118
83 void CanvasSurfaceLayerBridge::requireCallback( 119 void CanvasSurfaceLayerBridge::requireCallback(
84 const cc::SurfaceId& surfaceId, 120 const cc::SurfaceId& surfaceId,
85 const cc::SurfaceSequence& sequence) { 121 const cc::SurfaceSequence& sequence) {
86 m_service->Require(surfaceId, sequence); 122 m_service->Require(surfaceId, sequence);
87 } 123 }
88 124
89 } // namespace blink 125 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698