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

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

Issue 2956713003: Replaces VideoLayer with a SurfaceLayer in WebMediaPlayerImpl (Closed)
Patch Set: Addresses comment #13. 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
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), 28 : weak_factory_(this),
62 observer_(observer),
63 binding_(this), 29 binding_(this),
64 frame_sink_id_(Platform::Current()->GenerateFrameSinkId()), 30 frame_sink_id_(Platform::Current()->GenerateFrameSinkId()),
65 parent_frame_sink_id_(layer_tree_view ? layer_tree_view->GetFrameSinkId() 31 parent_frame_sink_id_(cc::FrameSinkId()) {
66 : cc::FrameSinkId()) {
67 ref_factory_ = 32 ref_factory_ =
68 new OffscreenCanvasSurfaceReferenceFactory(weak_factory_.GetWeakPtr()); 33 new SequenceSurfaceReferenceFactoryImpl(weak_factory_.GetWeakPtr());
69 34
70 DCHECK(!service_.is_bound()); 35 DCHECK(!service_.is_bound());
71 mojom::blink::OffscreenCanvasProviderPtr provider; 36 mojom::blink::OffscreenCanvasProviderPtr provider;
72 Platform::Current()->GetInterfaceProvider()->GetInterface( 37 Platform::Current()->GetInterfaceProvider()->GetInterface(
73 mojo::MakeRequest(&provider)); 38 mojo::MakeRequest(&provider));
74 // TODO(xlai): Ensure OffscreenCanvas commit() is still functional when a 39 // TODO(xlai): Ensure OffscreenCanvas commit() is still functional when a
75 // frame-less HTML canvas's document is reparenting under another frame. 40 // frame-less HTML canvas's document is reparenting under another frame.
76 // See crbug.com/683172. 41 // See crbug.com/683172.
77 blink::mojom::blink::OffscreenCanvasSurfaceClientPtr client; 42 blink::mojom::blink::OffscreenCanvasSurfaceClientPtr client;
78 binding_.Bind(mojo::MakeRequest(&client)); 43 binding_.Bind(mojo::MakeRequest(&client));
79 provider->CreateOffscreenCanvasSurface(parent_frame_sink_id_, frame_sink_id_, 44 provider->CreateOffscreenCanvasSurface(parent_frame_sink_id_, frame_sink_id_,
80 std::move(client), 45 std::move(client),
81 mojo::MakeRequest(&service_)); 46 mojo::MakeRequest(&service_));
47 cc_layer_ = cc::SolidColorLayer::Create();
82 } 48 }
83 49
84 CanvasSurfaceLayerBridge::~CanvasSurfaceLayerBridge() { 50 VideoSurfaceLayerBridge::~VideoSurfaceLayerBridge() {}
85 observer_ = nullptr; 51
86 if (web_layer_) { 52 void VideoSurfaceLayerBridge::CreateSolidColorLayer() {
liberato (no reviews please) 2017/06/30 22:27:16 is this used?
CJ 2017/06/30 23:38:14 No. I originally thought it might have something t
87 GraphicsLayer::UnregisterContentsLayer(web_layer_.get()); 53 cc_layer_ = cc::SolidColorLayer::Create();
88 } 54 cc_layer_->SetBackgroundColor(SK_ColorTRANSPARENT);
89 } 55 }
90 56
91 void CanvasSurfaceLayerBridge::CreateSolidColorLayer() { 57 void VideoSurfaceLayerBridge::OnSurfaceCreated(
92 cc_layer_ = cc::SolidColorLayer::Create();
93 cc_layer_->SetBackgroundColor(SK_ColorTRANSPARENT);
94 web_layer_ = Platform::Current()->CompositorSupport()->CreateLayerFromCCLayer(
95 cc_layer_.get());
96 GraphicsLayer::RegisterContentsLayer(web_layer_.get());
97 }
98
99 void CanvasSurfaceLayerBridge::OnSurfaceCreated(
100 const cc::SurfaceInfo& surface_info) { 58 const cc::SurfaceInfo& surface_info) {
101 if (!current_surface_id_.is_valid() && surface_info.is_valid()) { 59 if (!current_surface_id_.is_valid() && surface_info.is_valid()) {
102 // First time a SurfaceId is received 60 // First time a SurfaceId is received
103 current_surface_id_ = surface_info.id(); 61 current_surface_id_ = surface_info.id();
104 GraphicsLayer::UnregisterContentsLayer(web_layer_.get());
105 web_layer_->RemoveFromParent();
106 62
107 scoped_refptr<cc::SurfaceLayer> surface_layer = 63 scoped_refptr<cc::SurfaceLayer> surface_layer =
108 cc::SurfaceLayer::Create(ref_factory_); 64 cc::SurfaceLayer::Create(ref_factory_);
109 surface_layer->SetPrimarySurfaceInfo(surface_info); 65 surface_layer->SetPrimarySurfaceInfo(surface_info);
110 surface_layer->SetFallbackSurfaceInfo(surface_info); 66 surface_layer->SetFallbackSurfaceInfo(surface_info);
111 surface_layer->SetStretchContentToFillBounds(true); 67 surface_layer->SetStretchContentToFillBounds(true);
112 cc_layer_ = surface_layer; 68 cc_layer_ = surface_layer;
113 69
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()) { 70 } else if (current_surface_id_ != surface_info.id()) {
119 // A different SurfaceId is received, prompting change to existing 71 // A different SurfaceId is received, prompting change to existing
120 // SurfaceLayer 72 // SurfaceLayer
121 current_surface_id_ = surface_info.id(); 73 current_surface_id_ = surface_info.id();
122 cc::SurfaceLayer* surface_layer = 74 cc::SurfaceLayer* surface_layer =
123 static_cast<cc::SurfaceLayer*>(cc_layer_.get()); 75 static_cast<cc::SurfaceLayer*>(cc_layer_.get());
124 surface_layer->SetPrimarySurfaceInfo(surface_info); 76 surface_layer->SetPrimarySurfaceInfo(surface_info);
125 surface_layer->SetFallbackSurfaceInfo(surface_info); 77 surface_layer->SetFallbackSurfaceInfo(surface_info);
126 } 78 }
127 79
128 observer_->OnWebLayerReplaced();
129 cc_layer_->SetBounds(surface_info.size_in_pixels()); 80 cc_layer_->SetBounds(surface_info.size_in_pixels());
130 } 81 }
131 82
132 void CanvasSurfaceLayerBridge::SatisfyCallback( 83 void VideoSurfaceLayerBridge::SatisfyCallback(
liberato (no reviews please) 2017/06/30 22:27:16 these look like they could move to the base class.
133 const cc::SurfaceSequence& sequence) { 84 const cc::SurfaceSequence& sequence) {
134 service_->Satisfy(sequence); 85 service_->Satisfy(sequence);
135 } 86 }
136 87
137 void CanvasSurfaceLayerBridge::RequireCallback( 88 void VideoSurfaceLayerBridge::RequireCallback(
138 const cc::SurfaceId& surface_id, 89 const cc::SurfaceId& surface_id,
139 const cc::SurfaceSequence& sequence) { 90 const cc::SurfaceSequence& sequence) {
140 service_->Require(surface_id, sequence); 91 service_->Require(surface_id, sequence);
141 } 92 }
142 93
143 } // namespace blink 94 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698