OLD | NEW |
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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 "config.h" | 5 #include "config.h" |
6 | 6 |
7 #if USE(ACCELERATED_COMPOSITING) | 7 #if USE(ACCELERATED_COMPOSITING) |
8 | 8 |
9 #include "CCVideoLayerImpl.h" | 9 #include "CCVideoLayerImpl.h" |
10 | 10 |
(...skipping 22 matching lines...) Expand all Loading... |
33 m_streamTextureMatrix = WebKit::WebTransformationMatrix( | 33 m_streamTextureMatrix = WebKit::WebTransformationMatrix( |
34 1, 0, 0, 0, | 34 1, 0, 0, 0, |
35 0, -1, 0, 0, | 35 0, -1, 0, 0, |
36 0, 0, 1, 0, | 36 0, 0, 1, 0, |
37 0, 1, 0, 1); | 37 0, 1, 0, 1); |
38 | 38 |
39 // This only happens during a commit on the compositor thread while the main | 39 // This only happens during a commit on the compositor thread while the main |
40 // thread is blocked. That makes this a thread-safe call to set the video | 40 // thread is blocked. That makes this a thread-safe call to set the video |
41 // frame provider client that does not require a lock. The same is true of | 41 // frame provider client that does not require a lock. The same is true of |
42 // the call in the destructor. | 42 // the call in the destructor. |
43 ASSERT(CCProxy::isMainThreadBlocked()); | 43 DCHECK(CCProxy::isMainThreadBlocked()); |
44 m_provider->setVideoFrameProviderClient(this); | 44 m_provider->setVideoFrameProviderClient(this); |
45 } | 45 } |
46 | 46 |
47 CCVideoLayerImpl::~CCVideoLayerImpl() | 47 CCVideoLayerImpl::~CCVideoLayerImpl() |
48 { | 48 { |
49 // See comment in constructor for why this doesn't need a lock. | 49 // See comment in constructor for why this doesn't need a lock. |
50 ASSERT(CCProxy::isMainThreadBlocked()); | 50 DCHECK(CCProxy::isMainThreadBlocked()); |
51 if (m_provider) { | 51 if (m_provider) { |
52 m_provider->setVideoFrameProviderClient(0); | 52 m_provider->setVideoFrameProviderClient(0); |
53 m_provider = 0; | 53 m_provider = 0; |
54 } | 54 } |
55 freePlaneData(layerTreeHostImpl()->resourceProvider()); | 55 freePlaneData(layerTreeHostImpl()->resourceProvider()); |
56 | 56 |
57 #if !ASSERT_DISABLED | 57 if (DCHECK_IS_ON()) { |
58 for (unsigned i = 0; i < WebKit::WebVideoFrame::maxPlanes; ++i) | 58 for (unsigned i = 0; i < WebKit::WebVideoFrame::maxPlanes; ++i) |
59 ASSERT(!m_framePlanes[i].resourceId); | 59 DCHECK(!m_framePlanes[i].resourceId); |
60 ASSERT(!m_externalTextureResource); | 60 DCHECK(!m_externalTextureResource); |
61 #endif | 61 } |
62 } | 62 } |
63 | 63 |
64 void CCVideoLayerImpl::stopUsingProvider() | 64 void CCVideoLayerImpl::stopUsingProvider() |
65 { | 65 { |
66 // Block the provider from shutting down until this client is done | 66 // Block the provider from shutting down until this client is done |
67 // using the frame. | 67 // using the frame. |
68 MutexLocker locker(m_providerMutex); | 68 MutexLocker locker(m_providerMutex); |
69 ASSERT(!m_frame); | 69 DCHECK(!m_frame); |
70 m_provider = 0; | 70 m_provider = 0; |
71 } | 71 } |
72 | 72 |
73 // Convert WebKit::WebVideoFrame::Format to GraphicsContext3D's format enum valu
es. | 73 // Convert WebKit::WebVideoFrame::Format to GraphicsContext3D's format enum valu
es. |
74 static GC3Denum convertVFCFormatToGC3DFormat(const WebKit::WebVideoFrame& frame) | 74 static GC3Denum convertVFCFormatToGC3DFormat(const WebKit::WebVideoFrame& frame) |
75 { | 75 { |
76 switch (frame.format()) { | 76 switch (frame.format()) { |
77 case WebKit::WebVideoFrame::FormatYV12: | 77 case WebKit::WebVideoFrame::FormatYV12: |
78 case WebKit::WebVideoFrame::FormatYV16: | 78 case WebKit::WebVideoFrame::FormatYV16: |
79 return GraphicsContext3D::LUMINANCE; | 79 return GraphicsContext3D::LUMINANCE; |
80 case WebKit::WebVideoFrame::FormatNativeTexture: | 80 case WebKit::WebVideoFrame::FormatNativeTexture: |
81 return frame.textureTarget(); | 81 return frame.textureTarget(); |
82 case WebKit::WebVideoFrame::FormatInvalid: | 82 case WebKit::WebVideoFrame::FormatInvalid: |
83 case WebKit::WebVideoFrame::FormatRGB32: | 83 case WebKit::WebVideoFrame::FormatRGB32: |
84 case WebKit::WebVideoFrame::FormatEmpty: | 84 case WebKit::WebVideoFrame::FormatEmpty: |
85 case WebKit::WebVideoFrame::FormatI420: | 85 case WebKit::WebVideoFrame::FormatI420: |
86 notImplemented(); | 86 notImplemented(); |
87 } | 87 } |
88 return GraphicsContext3D::INVALID_VALUE; | 88 return GraphicsContext3D::INVALID_VALUE; |
89 } | 89 } |
90 | 90 |
91 void CCVideoLayerImpl::willDraw(CCResourceProvider* resourceProvider) | 91 void CCVideoLayerImpl::willDraw(CCResourceProvider* resourceProvider) |
92 { | 92 { |
93 ASSERT(CCProxy::isImplThread()); | 93 DCHECK(CCProxy::isImplThread()); |
94 CCLayerImpl::willDraw(resourceProvider); | 94 CCLayerImpl::willDraw(resourceProvider); |
95 | 95 |
96 // Explicitly lock and unlock the provider mutex so it can be held from | 96 // Explicitly lock and unlock the provider mutex so it can be held from |
97 // willDraw to didDraw. Since the compositor thread is in the middle of | 97 // willDraw to didDraw. Since the compositor thread is in the middle of |
98 // drawing, the layer will not be destroyed before didDraw is called. | 98 // drawing, the layer will not be destroyed before didDraw is called. |
99 // Therefore, the only thing that will prevent this lock from being released | 99 // Therefore, the only thing that will prevent this lock from being released |
100 // is the GPU process locking it. As the GPU process can't cause the | 100 // is the GPU process locking it. As the GPU process can't cause the |
101 // destruction of the provider (calling stopUsingProvider), holding this | 101 // destruction of the provider (calling stopUsingProvider), holding this |
102 // lock should not cause a deadlock. | 102 // lock should not cause a deadlock. |
103 m_providerMutex.lock(); | 103 m_providerMutex.lock(); |
104 | 104 |
105 willDrawInternal(resourceProvider); | 105 willDrawInternal(resourceProvider); |
106 freeUnusedPlaneData(resourceProvider); | 106 freeUnusedPlaneData(resourceProvider); |
107 | 107 |
108 if (!m_frame) | 108 if (!m_frame) |
109 m_providerMutex.unlock(); | 109 m_providerMutex.unlock(); |
110 } | 110 } |
111 | 111 |
112 void CCVideoLayerImpl::willDrawInternal(CCResourceProvider* resourceProvider) | 112 void CCVideoLayerImpl::willDrawInternal(CCResourceProvider* resourceProvider) |
113 { | 113 { |
114 ASSERT(CCProxy::isImplThread()); | 114 DCHECK(CCProxy::isImplThread()); |
115 ASSERT(!m_externalTextureResource); | 115 DCHECK(!m_externalTextureResource); |
116 | 116 |
117 if (!m_provider) { | 117 if (!m_provider) { |
118 m_frame = 0; | 118 m_frame = 0; |
119 return; | 119 return; |
120 } | 120 } |
121 | 121 |
122 m_frame = m_provider->getCurrentFrame(); | 122 m_frame = m_provider->getCurrentFrame(); |
123 | 123 |
124 if (!m_frame) | 124 if (!m_frame) |
125 return; | 125 return; |
(...skipping 23 matching lines...) Expand all Loading... |
149 m_frame = 0; | 149 m_frame = 0; |
150 return; | 150 return; |
151 } | 151 } |
152 | 152 |
153 if (m_format == GraphicsContext3D::TEXTURE_2D) | 153 if (m_format == GraphicsContext3D::TEXTURE_2D) |
154 m_externalTextureResource = resourceProvider->createResourceFromExternal
Texture(m_frame->textureId()); | 154 m_externalTextureResource = resourceProvider->createResourceFromExternal
Texture(m_frame->textureId()); |
155 } | 155 } |
156 | 156 |
157 void CCVideoLayerImpl::appendQuads(CCQuadSink& quadSink, CCAppendQuadsData& appe
ndQuadsData) | 157 void CCVideoLayerImpl::appendQuads(CCQuadSink& quadSink, CCAppendQuadsData& appe
ndQuadsData) |
158 { | 158 { |
159 ASSERT(CCProxy::isImplThread()); | 159 DCHECK(CCProxy::isImplThread()); |
160 | 160 |
161 if (!m_frame) | 161 if (!m_frame) |
162 return; | 162 return; |
163 | 163 |
164 CCSharedQuadState* sharedQuadState = quadSink.useSharedQuadState(createShare
dQuadState()); | 164 CCSharedQuadState* sharedQuadState = quadSink.useSharedQuadState(createShare
dQuadState()); |
165 appendDebugBorderQuad(quadSink, sharedQuadState, appendQuadsData); | 165 appendDebugBorderQuad(quadSink, sharedQuadState, appendQuadsData); |
166 | 166 |
167 // FIXME: When we pass quads out of process, we need to double-buffer, or | 167 // FIXME: When we pass quads out of process, we need to double-buffer, or |
168 // otherwise synchonize use of all textures in the quad. | 168 // otherwise synchonize use of all textures in the quad. |
169 | 169 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 quadSink.append(streamVideoQuad.PassAs<CCDrawQuad>(), appendQuadsData); | 212 quadSink.append(streamVideoQuad.PassAs<CCDrawQuad>(), appendQuadsData); |
213 break; | 213 break; |
214 } | 214 } |
215 default: | 215 default: |
216 CRASH(); // Someone updated convertVFCFormatToGC3DFormat above but updat
e this! | 216 CRASH(); // Someone updated convertVFCFormatToGC3DFormat above but updat
e this! |
217 } | 217 } |
218 } | 218 } |
219 | 219 |
220 void CCVideoLayerImpl::didDraw(CCResourceProvider* resourceProvider) | 220 void CCVideoLayerImpl::didDraw(CCResourceProvider* resourceProvider) |
221 { | 221 { |
222 ASSERT(CCProxy::isImplThread()); | 222 DCHECK(CCProxy::isImplThread()); |
223 CCLayerImpl::didDraw(resourceProvider); | 223 CCLayerImpl::didDraw(resourceProvider); |
224 | 224 |
225 if (!m_frame) | 225 if (!m_frame) |
226 return; | 226 return; |
227 | 227 |
228 if (m_format == GraphicsContext3D::TEXTURE_2D) { | 228 if (m_format == GraphicsContext3D::TEXTURE_2D) { |
229 ASSERT(m_externalTextureResource); | 229 DCHECK(m_externalTextureResource); |
230 // FIXME: the following assert will not be true when sending resources t
o a | 230 // FIXME: the following assert will not be true when sending resources t
o a |
231 // parent compositor. We will probably need to hold on to m_frame for | 231 // parent compositor. We will probably need to hold on to m_frame for |
232 // longer, and have several "current frames" in the pipeline. | 232 // longer, and have several "current frames" in the pipeline. |
233 ASSERT(!resourceProvider->inUseByConsumer(m_externalTextureResource)); | 233 DCHECK(!resourceProvider->inUseByConsumer(m_externalTextureResource)); |
234 resourceProvider->deleteResource(m_externalTextureResource); | 234 resourceProvider->deleteResource(m_externalTextureResource); |
235 m_externalTextureResource = 0; | 235 m_externalTextureResource = 0; |
236 } | 236 } |
237 | 237 |
238 m_provider->putCurrentFrame(m_frame); | 238 m_provider->putCurrentFrame(m_frame); |
239 m_frame = 0; | 239 m_frame = 0; |
240 | 240 |
241 m_providerMutex.unlock(); | 241 m_providerMutex.unlock(); |
242 } | 242 } |
243 | 243 |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 } | 382 } |
383 | 383 |
384 const char* CCVideoLayerImpl::layerTypeAsString() const | 384 const char* CCVideoLayerImpl::layerTypeAsString() const |
385 { | 385 { |
386 return "VideoLayer"; | 386 return "VideoLayer"; |
387 } | 387 } |
388 | 388 |
389 } | 389 } |
390 | 390 |
391 #endif // USE(ACCELERATED_COMPOSITING) | 391 #endif // USE(ACCELERATED_COMPOSITING) |
OLD | NEW |