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

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

Issue 2956713003: Replaces VideoLayer with a SurfaceLayer in WebMediaPlayerImpl (Closed)
Patch Set: Replaces VideoLayer with SurfaceLayer. Created 3 years, 5 months 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 2017 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/VideoSurfaceLayerBridge.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"
11 #include "cc/surfaces/surface_id.h" 11 #include "cc/surfaces/surface_id.h"
12 #include "cc/surfaces/surface_info.h" 12 #include "cc/surfaces/surface_info.h"
13 #include "cc/surfaces/surface_sequence.h" 13 #include "cc/surfaces/surface_sequence.h"
14 #include "platform/graphics/GraphicsLayer.h" 14 #include "platform/graphics/GraphicsLayer.h"
15 #include "platform/mojo/MojoHelper.h" 15 #include "platform/mojo/MojoHelper.h"
16 #include "platform/wtf/Functional.h" 16 #include "platform/wtf/Functional.h"
17 #include "public/platform/InterfaceProvider.h" 17 #include "public/platform/InterfaceProvider.h"
18 #include "public/platform/Platform.h" 18 #include "public/platform/Platform.h"
19 #include "public/platform/WebCompositorSupport.h" 19 #include "public/platform/WebCompositorSupport.h"
20 #include "public/platform/WebLayer.h" 20 #include "public/platform/WebLayer.h"
21 #include "public/platform/WebLayerTreeView.h" 21 #include "public/platform/WebLayerTreeView.h"
22 #include "public/platform/modules/offscreencanvas/offscreen_canvas_surface.mojom -blink.h" 22 #include "public/platform/modules/offscreencanvas/offscreen_canvas_surface.mojom -blink.h"
23 #include "ui/gfx/geometry/size.h" 23 #include "ui/gfx/geometry/size.h"
24 24
25 namespace blink { 25 namespace blink {
26 26
27 namespace { 27 VideoSurfaceLayerBridge::VideoSurfaceLayerBridge(
28 28 WebSurfaceLayerBridgeObserver* observer)
29 class OffscreenCanvasSurfaceReferenceFactory
30 : public cc::SequenceSurfaceReferenceFactory {
31 public:
32 OffscreenCanvasSurfaceReferenceFactory(
33 base::WeakPtr<CanvasSurfaceLayerBridge> bridge)
34 : bridge_(bridge) {}
35
36 private:
37 ~OffscreenCanvasSurfaceReferenceFactory() override = default;
38
39 // cc::SequenceSurfaceReferenceFactory implementation:
40 void RequireSequence(const cc::SurfaceId& id,
41 const cc::SurfaceSequence& sequence) const override {
42 DCHECK(bridge_);
43 bridge_->RequireCallback(id, sequence);
44 }
45
46 void SatisfySequence(const cc::SurfaceSequence& sequence) const override {
47 if (bridge_)
48 bridge_->SatisfyCallback(sequence);
49 }
50
51 base::WeakPtr<CanvasSurfaceLayerBridge> bridge_;
52
53 DISALLOW_COPY_AND_ASSIGN(OffscreenCanvasSurfaceReferenceFactory);
54 };
55
56 } // namespace
57
58 CanvasSurfaceLayerBridge::CanvasSurfaceLayerBridge(
59 CanvasSurfaceLayerBridgeObserver* observer,
60 WebLayerTreeView* layer_tree_view)
61 : weak_factory_(this), 29 : weak_factory_(this),
62 observer_(observer), 30 observer_(observer),
63 binding_(this), 31 binding_(this),
64 frame_sink_id_(Platform::Current()->GenerateFrameSinkId()), 32 frame_sink_id_(Platform::Current()->GenerateFrameSinkId()),
65 parent_frame_sink_id_(layer_tree_view ? layer_tree_view->GetFrameSinkId() 33 parent_frame_sink_id_(cc::FrameSinkId()) {
66 : cc::FrameSinkId()) {
67 ref_factory_ = 34 ref_factory_ =
68 new OffscreenCanvasSurfaceReferenceFactory(weak_factory_.GetWeakPtr()); 35 new SequenceSurfaceReferenceFactoryImpl(weak_factory_.GetWeakPtr());
69 36
70 DCHECK(!service_.is_bound()); 37 DCHECK(!service_.is_bound());
71 mojom::blink::OffscreenCanvasProviderPtr provider; 38 mojom::blink::OffscreenCanvasProviderPtr provider;
liberato (no reviews please) 2017/06/26 22:39:30 do you know yet if the the OffscreenCanvasProvider
CJ 2017/06/29 19:51:33 Not sure, was gonna handle that in another CL
72 Platform::Current()->GetInterfaceProvider()->GetInterface( 39 Platform::Current()->GetInterfaceProvider()->GetInterface(
73 mojo::MakeRequest(&provider)); 40 mojo::MakeRequest(&provider));
74 // TODO(xlai): Ensure OffscreenCanvas commit() is still functional when a 41 // TODO(xlai): Ensure OffscreenCanvas commit() is still functional when a
75 // frame-less HTML canvas's document is reparenting under another frame. 42 // frame-less HTML canvas's document is reparenting under another frame.
76 // See crbug.com/683172. 43 // See crbug.com/683172.
77 blink::mojom::blink::OffscreenCanvasSurfaceClientPtr client; 44 blink::mojom::blink::OffscreenCanvasSurfaceClientPtr client;
78 binding_.Bind(mojo::MakeRequest(&client)); 45 binding_.Bind(mojo::MakeRequest(&client));
79 provider->CreateOffscreenCanvasSurface(parent_frame_sink_id_, frame_sink_id_, 46 provider->CreateOffscreenCanvasSurface(parent_frame_sink_id_, frame_sink_id_,
80 std::move(client), 47 std::move(client),
81 mojo::MakeRequest(&service_)); 48 mojo::MakeRequest(&service_));
49 cc_layer_ = cc::SolidColorLayer::Create();
82 } 50 }
83 51
84 CanvasSurfaceLayerBridge::~CanvasSurfaceLayerBridge() { 52 VideoSurfaceLayerBridge::~VideoSurfaceLayerBridge() {
85 observer_ = nullptr; 53 observer_ = nullptr;
86 if (web_layer_) {
87 GraphicsLayer::UnregisterContentsLayer(web_layer_.get());
88 }
89 } 54 }
90 55
91 void CanvasSurfaceLayerBridge::CreateSolidColorLayer() { 56 void VideoSurfaceLayerBridge::CreateSolidColorLayer() {
92 cc_layer_ = cc::SolidColorLayer::Create(); 57 cc_layer_ = cc::SolidColorLayer::Create();
93 cc_layer_->SetBackgroundColor(SK_ColorTRANSPARENT); 58 cc_layer_->SetBackgroundColor(SK_ColorTRANSPARENT);
94 web_layer_ = Platform::Current()->CompositorSupport()->CreateLayerFromCCLayer(
95 cc_layer_.get());
96 GraphicsLayer::RegisterContentsLayer(web_layer_.get());
97 } 59 }
98 60
99 void CanvasSurfaceLayerBridge::OnSurfaceCreated( 61 void VideoSurfaceLayerBridge::OnSurfaceCreated(
100 const cc::SurfaceInfo& surface_info) { 62 const cc::SurfaceInfo& surface_info) {
101 if (!current_surface_id_.is_valid() && surface_info.is_valid()) { 63 if (!current_surface_id_.is_valid() && surface_info.is_valid()) {
102 // First time a SurfaceId is received 64 // First time a SurfaceId is received
103 current_surface_id_ = surface_info.id(); 65 current_surface_id_ = surface_info.id();
104 GraphicsLayer::UnregisterContentsLayer(web_layer_.get());
105 web_layer_->RemoveFromParent();
106 66
107 scoped_refptr<cc::SurfaceLayer> surface_layer = 67 scoped_refptr<cc::SurfaceLayer> surface_layer =
108 cc::SurfaceLayer::Create(ref_factory_); 68 cc::SurfaceLayer::Create(ref_factory_);
109 surface_layer->SetPrimarySurfaceInfo(surface_info); 69 surface_layer->SetPrimarySurfaceInfo(surface_info);
110 surface_layer->SetFallbackSurfaceInfo(surface_info); 70 surface_layer->SetFallbackSurfaceInfo(surface_info);
111 surface_layer->SetStretchContentToFillBounds(true); 71 surface_layer->SetStretchContentToFillBounds(true);
112 cc_layer_ = surface_layer; 72 cc_layer_ = surface_layer;
113 73
114 web_layer_ =
115 Platform::Current()->CompositorSupport()->CreateLayerFromCCLayer(
116 cc_layer_.get());
117 GraphicsLayer::RegisterContentsLayer(web_layer_.get());
118 } else if (current_surface_id_ != surface_info.id()) { 74 } else if (current_surface_id_ != surface_info.id()) {
119 // A different SurfaceId is received, prompting change to existing 75 // A different SurfaceId is received, prompting change to existing
120 // SurfaceLayer 76 // SurfaceLayer
121 current_surface_id_ = surface_info.id(); 77 current_surface_id_ = surface_info.id();
122 cc::SurfaceLayer* surface_layer = 78 cc::SurfaceLayer* surface_layer =
123 static_cast<cc::SurfaceLayer*>(cc_layer_.get()); 79 static_cast<cc::SurfaceLayer*>(cc_layer_.get());
124 surface_layer->SetPrimarySurfaceInfo(surface_info); 80 surface_layer->SetPrimarySurfaceInfo(surface_info);
125 surface_layer->SetFallbackSurfaceInfo(surface_info); 81 surface_layer->SetFallbackSurfaceInfo(surface_info);
126 } 82 }
127 83
128 observer_->OnWebLayerReplaced(); 84 observer_->OnWebLayerReplaced();
liberato (no reviews please) 2017/06/26 15:04:03 i'm not at all sure why the canvas impl calls this
CJ 2017/06/29 19:51:33 If changing the CCLayer has no effect on the WebLa
enne (OOO) 2017/06/29 20:29:29 I think the canvas bridge calls OnWebLayerReplaced
CJ 2017/06/29 20:46:06 Makes sense. Going to remove the Observer pattern
129 cc_layer_->SetBounds(surface_info.size_in_pixels()); 85 cc_layer_->SetBounds(surface_info.size_in_pixels());
130 } 86 }
131 87
132 void CanvasSurfaceLayerBridge::SatisfyCallback( 88 void VideoSurfaceLayerBridge::SatisfyCallback(
133 const cc::SurfaceSequence& sequence) { 89 const cc::SurfaceSequence& sequence) {
134 service_->Satisfy(sequence); 90 service_->Satisfy(sequence);
135 } 91 }
136 92
137 void CanvasSurfaceLayerBridge::RequireCallback( 93 void VideoSurfaceLayerBridge::RequireCallback(
138 const cc::SurfaceId& surface_id, 94 const cc::SurfaceId& surface_id,
139 const cc::SurfaceSequence& sequence) { 95 const cc::SurfaceSequence& sequence) {
140 service_->Require(surface_id, sequence); 96 service_->Require(surface_id, sequence);
141 } 97 }
142 98
143 } // namespace blink 99 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698