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