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 "cc/video_layer_impl.h" | 5 #include "cc/video_layer_impl.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "cc/io_surface_draw_quad.h" | 8 #include "cc/io_surface_draw_quad.h" |
9 #include "cc/layer_tree_impl.h" | 9 #include "cc/layer_tree_impl.h" |
10 #include "cc/math_util.h" | 10 #include "cc/math_util.h" |
11 #include "cc/quad_sink.h" | 11 #include "cc/quad_sink.h" |
12 #include "cc/renderer.h" | 12 #include "cc/renderer.h" |
13 #include "cc/resource_provider.h" | 13 #include "cc/resource_provider.h" |
14 #include "cc/stream_video_draw_quad.h" | 14 #include "cc/stream_video_draw_quad.h" |
15 #include "cc/texture_draw_quad.h" | 15 #include "cc/texture_draw_quad.h" |
16 #include "cc/yuv_video_draw_quad.h" | 16 #include "cc/yuv_video_draw_quad.h" |
17 #include "media/filters/skcanvas_video_renderer.h" | 17 #include "media/filters/skcanvas_video_renderer.h" |
18 #include "third_party/khronos/GLES2/gl2.h" | 18 #include "third_party/khronos/GLES2/gl2.h" |
19 #include "third_party/khronos/GLES2/gl2ext.h" | 19 #include "third_party/khronos/GLES2/gl2ext.h" |
20 | 20 |
21 namespace cc { | 21 namespace cc { |
22 | 22 |
23 VideoLayerImpl::VideoLayerImpl(LayerTreeImpl* treeImpl, int id, WebKit::WebVideo
FrameProvider* provider, | 23 VideoLayerImpl::VideoLayerImpl(LayerTreeImpl* treeImpl, int id, VideoFrameProvid
er* provider) |
24 const FrameUnwrapper& unwrapper) | |
25 : LayerImpl(treeImpl, id) | 24 : LayerImpl(treeImpl, id) |
26 , m_provider(provider) | 25 , m_provider(provider) |
27 , m_unwrapper(unwrapper) | |
28 , m_webFrame(0) | |
29 , m_frame(0) | 26 , m_frame(0) |
30 , m_format(GL_INVALID_VALUE) | 27 , m_format(GL_INVALID_VALUE) |
31 , m_convertYUV(false) | 28 , m_convertYUV(false) |
32 , m_externalTextureResource(0) | 29 , m_externalTextureResource(0) |
33 { | 30 { |
34 // This matrix is the default transformation for stream textures, and flips
on the Y axis. | 31 // This matrix is the default transformation for stream textures, and flips
on the Y axis. |
35 m_streamTextureMatrix = MathUtil::createGfxTransform( | 32 m_streamTextureMatrix = MathUtil::createGfxTransform( |
36 1, 0, 0, 0, | 33 1, 0, 0, 0, |
37 0, -1, 0, 0, | 34 0, -1, 0, 0, |
38 0, 0, 1, 0, | 35 0, 0, 1, 0, |
39 0, 1, 0, 1); | 36 0, 1, 0, 1); |
40 | 37 |
41 // This only happens during a commit on the compositor thread while the main | 38 // This only happens during a commit on the compositor thread while the main |
42 // thread is blocked. That makes this a thread-safe call to set the video | 39 // thread is blocked. That makes this a thread-safe call to set the video |
43 // frame provider client that does not require a lock. The same is true of | 40 // frame provider client that does not require a lock. The same is true of |
44 // the call in the destructor. | 41 // the call in the destructor. |
45 m_provider->setVideoFrameProviderClient(this); | 42 m_provider->SetVideoFrameProviderClient(this); |
46 } | 43 } |
47 | 44 |
48 VideoLayerImpl::~VideoLayerImpl() | 45 VideoLayerImpl::~VideoLayerImpl() |
49 { | 46 { |
50 // 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. |
51 if (m_provider) { | 48 if (m_provider) { |
52 m_provider->setVideoFrameProviderClient(0); | 49 m_provider->SetVideoFrameProviderClient(0); |
53 m_provider = 0; | 50 m_provider = 0; |
54 } | 51 } |
55 freePlaneData(layerTreeImpl()->resource_provider()); | 52 freePlaneData(layerTreeImpl()->resource_provider()); |
56 | 53 |
57 #ifndef NDEBUG | 54 #ifndef NDEBUG |
58 for (size_t i = 0; i < media::VideoFrame::kMaxPlanes; ++i) | 55 for (size_t i = 0; i < media::VideoFrame::kMaxPlanes; ++i) |
59 DCHECK(!m_framePlanes[i].resourceId); | 56 DCHECK(!m_framePlanes[i].resourceId); |
60 DCHECK(!m_externalTextureResource); | 57 DCHECK(!m_externalTextureResource); |
61 #endif | 58 #endif |
62 } | 59 } |
63 | 60 |
64 void VideoLayerImpl::stopUsingProvider() | 61 void VideoLayerImpl::StopUsingProvider() |
65 { | 62 { |
66 // Block the provider from shutting down until this client is done | 63 // Block the provider from shutting down until this client is done |
67 // using the frame. | 64 // using the frame. |
68 base::AutoLock locker(m_providerLock); | 65 base::AutoLock locker(m_providerLock); |
69 DCHECK(!m_frame); | 66 DCHECK(!m_frame); |
70 m_provider = 0; | 67 m_provider = 0; |
71 } | 68 } |
72 | 69 |
73 // Convert media::VideoFrame::Format to OpenGL enum values. | 70 // Convert media::VideoFrame::Format to OpenGL enum values. |
74 static GLenum convertVFCFormatToGLenum(const media::VideoFrame& frame) | 71 static GLenum convertVFCFormatToGLenum(const media::VideoFrame& frame) |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 | 133 |
137 void VideoLayerImpl::willDrawInternal(ResourceProvider* resourceProvider) | 134 void VideoLayerImpl::willDrawInternal(ResourceProvider* resourceProvider) |
138 { | 135 { |
139 DCHECK(!m_externalTextureResource); | 136 DCHECK(!m_externalTextureResource); |
140 | 137 |
141 if (!m_provider) { | 138 if (!m_provider) { |
142 m_frame = 0; | 139 m_frame = 0; |
143 return; | 140 return; |
144 } | 141 } |
145 | 142 |
146 m_webFrame = m_provider->getCurrentFrame(); | 143 m_frame = m_provider->GetCurrentFrame(); |
147 m_frame = m_unwrapper.Run(m_webFrame); | |
148 | 144 |
149 if (!m_frame) | 145 if (!m_frame) |
150 return; | 146 return; |
151 | 147 |
152 m_format = convertVFCFormatToGLenum(*m_frame); | 148 m_format = convertVFCFormatToGLenum(*m_frame); |
153 | 149 |
154 // If these fail, we'll have to add draw logic that handles offset bitmap/ | 150 // If these fail, we'll have to add draw logic that handles offset bitmap/ |
155 // texture UVs. For now, just expect (0, 0) offset, since all our decoders | 151 // texture UVs. For now, just expect (0, 0) offset, since all our decoders |
156 // so far don't offset. | 152 // so far don't offset. |
157 DCHECK_EQ(m_frame->visible_rect().x(), 0); | 153 DCHECK_EQ(m_frame->visible_rect().x(), 0); |
158 DCHECK_EQ(m_frame->visible_rect().y(), 0); | 154 DCHECK_EQ(m_frame->visible_rect().y(), 0); |
159 | 155 |
160 if (m_format == GL_INVALID_VALUE) { | 156 if (m_format == GL_INVALID_VALUE) { |
161 m_provider->putCurrentFrame(m_webFrame); | 157 m_provider->PutCurrentFrame(m_frame); |
162 m_frame = 0; | 158 m_frame = 0; |
163 return; | 159 return; |
164 } | 160 } |
165 | 161 |
166 // FIXME: If we're in software compositing mode, we do the YUV -> RGB | 162 // FIXME: If we're in software compositing mode, we do the YUV -> RGB |
167 // conversion here. That involves an extra copy of each frame to a bitmap. | 163 // conversion here. That involves an extra copy of each frame to a bitmap. |
168 // Obviously, this is suboptimal and should be addressed once ubercompositor | 164 // Obviously, this is suboptimal and should be addressed once ubercompositor |
169 // starts shaping up. | 165 // starts shaping up. |
170 m_convertYUV = resourceProvider->defaultResourceType() == ResourceProvider::
Bitmap && | 166 m_convertYUV = resourceProvider->defaultResourceType() == ResourceProvider::
Bitmap && |
171 (m_frame->format() == media::VideoFrame::YV12 || | 167 (m_frame->format() == media::VideoFrame::YV12 || |
172 m_frame->format() == media::VideoFrame::YV16); | 168 m_frame->format() == media::VideoFrame::YV16); |
173 | 169 |
174 if (m_convertYUV) | 170 if (m_convertYUV) |
175 m_format = GL_RGBA; | 171 m_format = GL_RGBA; |
176 | 172 |
177 if (!allocatePlaneData(resourceProvider)) { | 173 if (!allocatePlaneData(resourceProvider)) { |
178 m_provider->putCurrentFrame(m_webFrame); | 174 m_provider->PutCurrentFrame(m_frame); |
179 m_frame = 0; | 175 m_frame = 0; |
180 return; | 176 return; |
181 } | 177 } |
182 | 178 |
183 if (!copyPlaneData(resourceProvider)) { | 179 if (!copyPlaneData(resourceProvider)) { |
184 m_provider->putCurrentFrame(m_webFrame); | 180 m_provider->PutCurrentFrame(m_frame); |
185 m_frame = 0; | 181 m_frame = 0; |
186 return; | 182 return; |
187 } | 183 } |
188 | 184 |
189 if (m_format == GL_TEXTURE_2D) | 185 if (m_format == GL_TEXTURE_2D) |
190 m_externalTextureResource = resourceProvider->createResourceFromExternal
Texture(m_frame->texture_id()); | 186 m_externalTextureResource = resourceProvider->createResourceFromExternal
Texture(m_frame->texture_id()); |
191 } | 187 } |
192 | 188 |
193 void VideoLayerImpl::appendQuads(QuadSink& quadSink, AppendQuadsData& appendQuad
sData) | 189 void VideoLayerImpl::appendQuads(QuadSink& quadSink, AppendQuadsData& appendQuad
sData) |
194 { | 190 { |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 if (m_format == GL_TEXTURE_2D) { | 275 if (m_format == GL_TEXTURE_2D) { |
280 DCHECK(m_externalTextureResource); | 276 DCHECK(m_externalTextureResource); |
281 // FIXME: the following assert will not be true when sending resources t
o a | 277 // FIXME: the following assert will not be true when sending resources t
o a |
282 // parent compositor. We will probably need to hold on to m_frame for | 278 // parent compositor. We will probably need to hold on to m_frame for |
283 // longer, and have several "current frames" in the pipeline. | 279 // longer, and have several "current frames" in the pipeline. |
284 DCHECK(!resourceProvider->inUseByConsumer(m_externalTextureResource)); | 280 DCHECK(!resourceProvider->inUseByConsumer(m_externalTextureResource)); |
285 resourceProvider->deleteResource(m_externalTextureResource); | 281 resourceProvider->deleteResource(m_externalTextureResource); |
286 m_externalTextureResource = 0; | 282 m_externalTextureResource = 0; |
287 } | 283 } |
288 | 284 |
289 m_provider->putCurrentFrame(m_webFrame); | 285 m_provider->PutCurrentFrame(m_frame); |
290 m_frame = 0; | 286 m_frame = 0; |
291 | 287 |
292 m_providerLock.Release(); | 288 m_providerLock.Release(); |
293 } | 289 } |
294 | 290 |
295 static gfx::Size videoFrameDimension(media::VideoFrame* frame, int plane) { | 291 static gfx::Size videoFrameDimension(media::VideoFrame* frame, int plane) { |
296 gfx::Size dimensions = frame->coded_size(); | 292 gfx::Size dimensions = frame->coded_size(); |
297 switch (frame->format()) { | 293 switch (frame->format()) { |
298 case media::VideoFrame::YV12: | 294 case media::VideoFrame::YV12: |
299 if (plane != media::VideoFrame::kYPlane) { | 295 if (plane != media::VideoFrame::kYPlane) { |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 m_framePlanes[i].freeData(resourceProvider); | 387 m_framePlanes[i].freeData(resourceProvider); |
392 } | 388 } |
393 | 389 |
394 void VideoLayerImpl::freeUnusedPlaneData(ResourceProvider* resourceProvider) | 390 void VideoLayerImpl::freeUnusedPlaneData(ResourceProvider* resourceProvider) |
395 { | 391 { |
396 size_t firstUnusedPlane = numPlanes(); | 392 size_t firstUnusedPlane = numPlanes(); |
397 for (size_t i = firstUnusedPlane; i < media::VideoFrame::kMaxPlanes; ++i) | 393 for (size_t i = firstUnusedPlane; i < media::VideoFrame::kMaxPlanes; ++i) |
398 m_framePlanes[i].freeData(resourceProvider); | 394 m_framePlanes[i].freeData(resourceProvider); |
399 } | 395 } |
400 | 396 |
401 void VideoLayerImpl::didReceiveFrame() | 397 void VideoLayerImpl::DidReceiveFrame() |
402 { | 398 { |
403 setNeedsRedraw(); | 399 setNeedsRedraw(); |
404 } | 400 } |
405 | 401 |
406 void VideoLayerImpl::didUpdateMatrix(const float matrix[16]) | 402 void VideoLayerImpl::DidUpdateMatrix(const float matrix[16]) |
407 { | 403 { |
408 m_streamTextureMatrix = MathUtil::createGfxTransform( | 404 m_streamTextureMatrix = MathUtil::createGfxTransform( |
409 matrix[0], matrix[1], matrix[2], matrix[3], | 405 matrix[0], matrix[1], matrix[2], matrix[3], |
410 matrix[4], matrix[5], matrix[6], matrix[7], | 406 matrix[4], matrix[5], matrix[6], matrix[7], |
411 matrix[8], matrix[9], matrix[10], matrix[11], | 407 matrix[8], matrix[9], matrix[10], matrix[11], |
412 matrix[12], matrix[13], matrix[14], matrix[15]); | 408 matrix[12], matrix[13], matrix[14], matrix[15]); |
413 setNeedsRedraw(); | 409 setNeedsRedraw(); |
414 } | 410 } |
415 | 411 |
416 void VideoLayerImpl::didLoseOutputSurface() | 412 void VideoLayerImpl::didLoseOutputSurface() |
417 { | 413 { |
418 freePlaneData(layerTreeImpl()->resource_provider()); | 414 freePlaneData(layerTreeImpl()->resource_provider()); |
419 } | 415 } |
420 | 416 |
421 void VideoLayerImpl::setNeedsRedraw() | 417 void VideoLayerImpl::setNeedsRedraw() |
422 { | 418 { |
423 layerTreeImpl()->SetNeedsRedraw(); | 419 layerTreeImpl()->SetNeedsRedraw(); |
424 } | 420 } |
425 | 421 |
426 const char* VideoLayerImpl::layerTypeAsString() const | 422 const char* VideoLayerImpl::layerTypeAsString() const |
427 { | 423 { |
428 return "VideoLayer"; | 424 return "VideoLayer"; |
429 } | 425 } |
430 | 426 |
431 } // namespace cc | 427 } // namespace cc |
OLD | NEW |