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

Side by Side Diff: third_party/WebKit/Source/core/paint/VideoPainterTest.cpp

Issue 2124893002: [SPv2] Use foreign layer support to enable composited video. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merge with master, integration test Created 4 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "core/paint/VideoPainter.h"
6
7 #include "core/frame/FrameView.h"
8 #include "core/frame/Settings.h"
9 #include "core/html/HTMLMediaElement.h"
10 #include "core/loader/EmptyClients.h"
11 #include "core/testing/DummyPageHolder.h"
12 #include "platform/graphics/compositing/PaintArtifactCompositor.h"
13 #include "platform/testing/UnitTestHelpers.h"
14 #include "platform/testing/WebLayerTreeViewImplForTesting.h"
15 #include "public/platform/Platform.h"
16 #include "public/platform/WebCompositorSupport.h"
17 #include "public/platform/WebLayer.h"
18 #include "public/platform/WebMediaPlayer.h"
19 #include "public/platform/WebSize.h"
20 #include "testing/gtest/include/gtest/gtest.h"
21
22 // Integration tests of video painting code (in SPv2 mode).
23
24 namespace blink {
25 namespace {
26
27 class StubChromeClient : public EmptyChromeClient {
28 public:
29 StubChromeClient(WebLayerTreeViewImplForTesting::LayerListPolicy layerListPo licy)
30 : m_layerTreeView(layerListPolicy)
31 {
32 m_layerTreeView.setRootLayer(*m_paintArtifactCompositor.getWebLayer());
33 }
34
35 bool hasLayer(const WebLayer& layer) { return m_layerTreeView.hasLayer(layer ); }
36
37 // ChromeClient
38 void didPaint(const PaintArtifact& artifact)
39 {
40 m_paintArtifactCompositor.update(artifact);
41 }
42
43 private:
44 WebLayerTreeViewImplForTesting m_layerTreeView;
45 PaintArtifactCompositor m_paintArtifactCompositor;
46 };
47
48 class StubWebMediaPlayer : public WebMediaPlayer {
49 public:
50 StubWebMediaPlayer(WebMediaPlayerClient* client)
51 : m_client(client) {}
52
53 const WebLayer* getWebLayer() { return m_webLayer.get(); }
54
55 // WebMediaPlayer
56 void load(LoadType, const WebMediaPlayerSource&, CORSMode)
57 {
58 m_networkState = NetworkStateLoaded;
59 m_client->networkStateChanged();
60 m_readyState = ReadyStateHaveEnoughData;
61 m_client->readyStateChanged();
62 m_webLayer = wrapUnique(Platform::current()->compositorSupport()->create Layer());
63 m_client->setWebLayer(m_webLayer.get());
64 }
65 void play() override {}
66 void pause() override {}
67 bool supportsSave() const override { return false; }
68 void seek(double seconds) override {}
69 void setRate(double) override {}
70 void setVolume(double) override {}
71 WebTimeRanges buffered() const override { return WebTimeRanges(); }
72 WebTimeRanges seekable() const override { return WebTimeRanges(); }
73 void setSinkId(const WebString& sinkId, const WebSecurityOrigin&, WebSetSink IdCallbacks*) override {}
74 bool hasVideo() const override { return false; }
75 bool hasAudio() const override { return false; }
76 WebSize naturalSize() const override { return WebSize(0, 0); }
77 bool paused() const override { return false; }
78 bool seeking() const override { return false; }
79 double duration() const override { return 0.0; }
80 double currentTime() const override { return 0.0; }
81 NetworkState getNetworkState() const override { return m_networkState; }
82 ReadyState getReadyState() const override { return m_readyState; }
83 WebString getErrorMessage() override { return WebString(); }
84 bool didLoadingProgress() override { return false; }
85 bool hasSingleSecurityOrigin() const override { return true; }
86 bool didPassCORSAccessCheck() const override { return true; }
87 double mediaTimeForTimeValue(double timeValue) const override { return timeV alue; }
88 unsigned decodedFrameCount() const override { return 0; }
89 unsigned droppedFrameCount() const override { return 0; }
90 size_t audioDecodedByteCount() const override { return 0; }
91 size_t videoDecodedByteCount() const override { return 0; }
92 void paint(WebCanvas*, const WebRect&, unsigned char alpha, SkXfermode::Mode ) override {}
93
94 private:
95 WebMediaPlayerClient* m_client;
96 std::unique_ptr<WebLayer> m_webLayer;
97 NetworkState m_networkState = NetworkStateEmpty;
98 ReadyState m_readyState = ReadyStateHaveNothing;
99 };
100
101 class StubFrameLoaderClient : public EmptyFrameLoaderClient {
102 public:
103 // FrameLoaderClient
104 std::unique_ptr<WebMediaPlayer> createWebMediaPlayer(HTMLMediaElement&, cons t WebMediaPlayerSource&, WebMediaPlayerClient* client) override
105 {
106 return wrapUnique(new StubWebMediaPlayer(client));
107 }
108 };
109
110 class VideoPainterTestForSPv2 : public ::testing::TestWithParam<WebLayerTreeView ImplForTesting::LayerListPolicy> {
111 protected:
112 void SetUp() override
113 {
114 RuntimeEnabledFeatures::setSlimmingPaintV2Enabled(true);
115 m_chromeClient = new StubChromeClient(GetParam());
116 m_frameLoaderClient = new StubFrameLoaderClient;
117 Page::PageClients clients;
118 fillWithEmptyClients(clients);
119 clients.chromeClient = m_chromeClient.get();
120 m_pageHolder = DummyPageHolder::create(IntSize(800, 600), &clients, m_fr ameLoaderClient.get(),
121 [](Settings& settings) { settings.setAcceleratedCompositingEnabled(t rue); });
122 document().view()->setParentVisible(true);
123 document().view()->setSelfVisible(true);
124 document().setURL(KURL(KURL(), "https://example.com/"));
125 }
126
127 void TearDown() override
128 {
129 m_featuresBackup.restore();
130 }
131
132 Document& document() { return m_pageHolder->document(); }
133 bool hasLayerAttached(const WebLayer& layer) { return m_chromeClient->hasLay er(layer); }
134
135 private:
136 RuntimeEnabledFeatures::Backup m_featuresBackup;
137 Persistent<StubChromeClient> m_chromeClient;
138 Persistent<StubFrameLoaderClient> m_frameLoaderClient;
139 std::unique_ptr<DummyPageHolder> m_pageHolder;
140 };
141
142 INSTANTIATE_TEST_CASE_P(, VideoPainterTestForSPv2, ::testing::Values(
143 WebLayerTreeViewImplForTesting::DontUseLayerLists,
144 WebLayerTreeViewImplForTesting::UseLayerLists));
145
146 TEST_P(VideoPainterTestForSPv2, VideoLayerAppearsInLayerTree)
147 {
148 // Insert a <video> and allow it to begin loading.
149 document().body()->setInnerHTML("<video width=300 height=200 src=test.ogv>", ASSERT_NO_EXCEPTION);
150 testing::runPendingTasks();
151
152 // Force the page to paint.
153 document().view()->updateAllLifecyclePhases();
154
155 // Fetch the layer associated with the <video>, and check that it was
156 // correctly configured in the layer tree.
157 HTMLMediaElement* element = toHTMLMediaElement(document().body()->firstChild ());
158 StubWebMediaPlayer* player = static_cast<StubWebMediaPlayer*>(element->webMe diaPlayer());
159 const WebLayer* layer = player->getWebLayer();
160 ASSERT_TRUE(layer);
161 EXPECT_TRUE(hasLayerAttached(*layer));
162 EXPECT_EQ(WebSize(300, 200), layer->bounds());
163 }
164
165 } // namespace
166 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/paint/VideoPainter.cpp ('k') | third_party/WebKit/Source/platform/graphics/paint/DisplayItem.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698