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

Side by Side Diff: cc/video_layer_impl.cc

Issue 11232051: Remove static thread pointers from CC (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 1 month 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 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 "cc/video_layer_impl.h" 7 #include "cc/video_layer_impl.h"
8 8
9 #include "CCIOSurfaceDrawQuad.h" 9 #include "CCIOSurfaceDrawQuad.h"
10 #include "NotImplemented.h" 10 #include "NotImplemented.h"
11 #include "cc/layer_tree_host_impl.h" 11 #include "cc/layer_tree_host_impl.h"
12 #include "cc/proxy.h" 12 #include "cc/proxy.h"
13 #include "cc/quad_sink.h" 13 #include "cc/quad_sink.h"
14 #include "cc/resource_provider.h" 14 #include "cc/resource_provider.h"
15 #include "cc/stream_video_draw_quad.h" 15 #include "cc/stream_video_draw_quad.h"
16 #include "cc/texture_draw_quad.h" 16 #include "cc/texture_draw_quad.h"
17 #include "cc/yuv_video_draw_quad.h" 17 #include "cc/yuv_video_draw_quad.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 #include <public/WebVideoFrame.h> 20 #include <public/WebVideoFrame.h>
21 21
22 namespace cc { 22 namespace cc {
23 23
24 CCVideoLayerImpl::CCVideoLayerImpl(int id, WebKit::WebVideoFrameProvider* provid er) 24 CCVideoLayerImpl::CCVideoLayerImpl(int id, WebKit::WebVideoFrameProvider* provid er, CCProxy* proxy)
25 : CCLayerImpl(id) 25 : CCLayerImpl(id)
26 , m_proxy(proxy)
26 , m_provider(provider) 27 , m_provider(provider)
27 , m_frame(0) 28 , m_frame(0)
28 , m_externalTextureResource(0) 29 , m_externalTextureResource(0)
29 { 30 {
30 // 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.
31 m_streamTextureMatrix = WebKit::WebTransformationMatrix( 32 m_streamTextureMatrix = WebKit::WebTransformationMatrix(
32 1, 0, 0, 0, 33 1, 0, 0, 0,
33 0, -1, 0, 0, 34 0, -1, 0, 0,
34 0, 0, 1, 0, 35 0, 0, 1, 0,
35 0, 1, 0, 1); 36 0, 1, 0, 1);
36 37
37 // 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
38 // 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
39 // 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
40 // the call in the destructor. 41 // the call in the destructor.
41 DCHECK(CCProxy::isMainThreadBlocked()); 42 DCHECK(m_proxy->isMainThreadBlocked());
42 m_provider->setVideoFrameProviderClient(this); 43 m_provider->setVideoFrameProviderClient(this);
43 } 44 }
44 45
45 CCVideoLayerImpl::~CCVideoLayerImpl() 46 CCVideoLayerImpl::~CCVideoLayerImpl()
46 { 47 {
47 // See comment in constructor for why this doesn't need a lock. 48 // See comment in constructor for why this doesn't need a lock.
48 DCHECK(CCProxy::isMainThreadBlocked()); 49 DCHECK(m_proxy->isMainThreadBlocked());
49 if (m_provider) { 50 if (m_provider) {
50 m_provider->setVideoFrameProviderClient(0); 51 m_provider->setVideoFrameProviderClient(0);
51 m_provider = 0; 52 m_provider = 0;
52 } 53 }
53 freePlaneData(layerTreeHostImpl()->resourceProvider()); 54 freePlaneData(layerTreeHostImpl()->resourceProvider());
54 55
55 #ifndef NDEBUG 56 #ifndef NDEBUG
56 for (unsigned i = 0; i < WebKit::WebVideoFrame::maxPlanes; ++i) 57 for (unsigned i = 0; i < WebKit::WebVideoFrame::maxPlanes; ++i)
57 DCHECK(!m_framePlanes[i].resourceId); 58 DCHECK(!m_framePlanes[i].resourceId);
58 DCHECK(!m_externalTextureResource); 59 DCHECK(!m_externalTextureResource);
(...skipping 22 matching lines...) Expand all
81 case WebKit::WebVideoFrame::FormatRGB32: 82 case WebKit::WebVideoFrame::FormatRGB32:
82 case WebKit::WebVideoFrame::FormatEmpty: 83 case WebKit::WebVideoFrame::FormatEmpty:
83 case WebKit::WebVideoFrame::FormatI420: 84 case WebKit::WebVideoFrame::FormatI420:
84 notImplemented(); 85 notImplemented();
85 } 86 }
86 return GL_INVALID_VALUE; 87 return GL_INVALID_VALUE;
87 } 88 }
88 89
89 void CCVideoLayerImpl::willDraw(CCResourceProvider* resourceProvider) 90 void CCVideoLayerImpl::willDraw(CCResourceProvider* resourceProvider)
90 { 91 {
91 DCHECK(CCProxy::isImplThread()); 92 DCHECK(m_proxy->isImplThread());
92 CCLayerImpl::willDraw(resourceProvider); 93 CCLayerImpl::willDraw(resourceProvider);
93 94
94 // Explicitly acquire and release the provider mutex so it can be held from 95 // 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 96 // willDraw to didDraw. Since the compositor thread is in the middle of
96 // drawing, the layer will not be destroyed before didDraw is called. 97 // drawing, the layer will not be destroyed before didDraw is called.
97 // Therefore, the only thing that will prevent this lock from being released 98 // 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 99 // is the GPU process locking it. As the GPU process can't cause the
99 // destruction of the provider (calling stopUsingProvider), holding this 100 // destruction of the provider (calling stopUsingProvider), holding this
100 // lock should not cause a deadlock. 101 // lock should not cause a deadlock.
101 m_providerLock.Acquire(); 102 m_providerLock.Acquire();
102 103
103 willDrawInternal(resourceProvider); 104 willDrawInternal(resourceProvider);
104 freeUnusedPlaneData(resourceProvider); 105 freeUnusedPlaneData(resourceProvider);
105 106
106 if (!m_frame) 107 if (!m_frame)
107 m_providerLock.Release(); 108 m_providerLock.Release();
108 } 109 }
109 110
110 void CCVideoLayerImpl::willDrawInternal(CCResourceProvider* resourceProvider) 111 void CCVideoLayerImpl::willDrawInternal(CCResourceProvider* resourceProvider)
111 { 112 {
112 DCHECK(CCProxy::isImplThread()); 113 DCHECK(m_proxy->isImplThread());
113 DCHECK(!m_externalTextureResource); 114 DCHECK(!m_externalTextureResource);
114 115
115 if (!m_provider) { 116 if (!m_provider) {
116 m_frame = 0; 117 m_frame = 0;
117 return; 118 return;
118 } 119 }
119 120
120 m_frame = m_provider->getCurrentFrame(); 121 m_frame = m_provider->getCurrentFrame();
121 122
122 if (!m_frame) 123 if (!m_frame)
(...skipping 24 matching lines...) Expand all
147 m_frame = 0; 148 m_frame = 0;
148 return; 149 return;
149 } 150 }
150 151
151 if (m_format == GL_TEXTURE_2D) 152 if (m_format == GL_TEXTURE_2D)
152 m_externalTextureResource = resourceProvider->createResourceFromExternal Texture(m_frame->textureId()); 153 m_externalTextureResource = resourceProvider->createResourceFromExternal Texture(m_frame->textureId());
153 } 154 }
154 155
155 void CCVideoLayerImpl::appendQuads(CCQuadSink& quadSink, CCAppendQuadsData& appe ndQuadsData) 156 void CCVideoLayerImpl::appendQuads(CCQuadSink& quadSink, CCAppendQuadsData& appe ndQuadsData)
156 { 157 {
157 DCHECK(CCProxy::isImplThread()); 158 DCHECK(m_proxy->isImplThread());
158 159
159 if (!m_frame) 160 if (!m_frame)
160 return; 161 return;
161 162
162 CCSharedQuadState* sharedQuadState = quadSink.useSharedQuadState(createShare dQuadState()); 163 CCSharedQuadState* sharedQuadState = quadSink.useSharedQuadState(createShare dQuadState());
163 appendDebugBorderQuad(quadSink, sharedQuadState, appendQuadsData); 164 appendDebugBorderQuad(quadSink, sharedQuadState, appendQuadsData);
164 165
165 // FIXME: When we pass quads out of process, we need to double-buffer, or 166 // FIXME: When we pass quads out of process, we need to double-buffer, or
166 // otherwise synchonize use of all textures in the quad. 167 // otherwise synchonize use of all textures in the quad.
167 168
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 quadSink.append(streamVideoQuad.PassAs<CCDrawQuad>(), appendQuadsData); 211 quadSink.append(streamVideoQuad.PassAs<CCDrawQuad>(), appendQuadsData);
211 break; 212 break;
212 } 213 }
213 default: 214 default:
214 CRASH(); // Someone updated convertVFCFormatToGC3DFormat above but updat e this! 215 CRASH(); // Someone updated convertVFCFormatToGC3DFormat above but updat e this!
215 } 216 }
216 } 217 }
217 218
218 void CCVideoLayerImpl::didDraw(CCResourceProvider* resourceProvider) 219 void CCVideoLayerImpl::didDraw(CCResourceProvider* resourceProvider)
219 { 220 {
220 DCHECK(CCProxy::isImplThread()); 221 DCHECK(m_proxy->isImplThread());
221 CCLayerImpl::didDraw(resourceProvider); 222 CCLayerImpl::didDraw(resourceProvider);
222 223
223 if (!m_frame) 224 if (!m_frame)
224 return; 225 return;
225 226
226 if (m_format == GL_TEXTURE_2D) { 227 if (m_format == GL_TEXTURE_2D) {
227 DCHECK(m_externalTextureResource); 228 DCHECK(m_externalTextureResource);
228 // FIXME: the following assert will not be true when sending resources t o a 229 // 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 230 // parent compositor. We will probably need to hold on to m_frame for
230 // longer, and have several "current frames" in the pipeline. 231 // longer, and have several "current frames" in the pipeline.
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 str->append("video layer\n"); 379 str->append("video layer\n");
379 CCLayerImpl::dumpLayerProperties(str, indent); 380 CCLayerImpl::dumpLayerProperties(str, indent);
380 } 381 }
381 382
382 const char* CCVideoLayerImpl::layerTypeAsString() const 383 const char* CCVideoLayerImpl::layerTypeAsString() const
383 { 384 {
384 return "VideoLayer"; 385 return "VideoLayer";
385 } 386 }
386 387
387 } 388 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698