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

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: Address code review comments and fix all cc_unittests 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 "NotImplemented.h" 9 #include "NotImplemented.h"
10 #include "cc/io_surface_draw_quad.h" 10 #include "cc/io_surface_draw_quad.h"
11 #include "cc/layer_tree_host_impl.h" 11 #include "cc/layer_tree_host_impl.h"
12 #include "cc/proxy.h"
13 #include "cc/quad_sink.h" 12 #include "cc/quad_sink.h"
14 #include "cc/resource_provider.h" 13 #include "cc/resource_provider.h"
15 #include "cc/stream_video_draw_quad.h" 14 #include "cc/stream_video_draw_quad.h"
16 #include "cc/texture_draw_quad.h" 15 #include "cc/texture_draw_quad.h"
17 #include "cc/yuv_video_draw_quad.h" 16 #include "cc/yuv_video_draw_quad.h"
18 #include "third_party/khronos/GLES2/gl2.h" 17 #include "third_party/khronos/GLES2/gl2.h"
19 #include "third_party/khronos/GLES2/gl2ext.h" 18 #include "third_party/khronos/GLES2/gl2ext.h"
20 #include <public/WebVideoFrame.h> 19 #include <public/WebVideoFrame.h>
21 20
22 namespace cc { 21 namespace cc {
23 22
24 VideoLayerImpl::VideoLayerImpl(int id, WebKit::WebVideoFrameProvider* provider) 23 VideoLayerImpl::VideoLayerImpl(int id, WebKit::WebVideoFrameProvider* provider)
25 : LayerImpl(id) 24 : LayerImpl(id)
26 , m_provider(provider) 25 , m_provider(provider)
27 , m_frame(0) 26 , m_frame(0)
28 , m_externalTextureResource(0) 27 , m_externalTextureResource(0)
29 { 28 {
30 // This matrix is the default transformation for stream textures, and flips on the Y axis. 29 // This matrix is the default transformation for stream textures, and flips on the Y axis.
31 m_streamTextureMatrix = WebKit::WebTransformationMatrix( 30 m_streamTextureMatrix = WebKit::WebTransformationMatrix(
32 1, 0, 0, 0, 31 1, 0, 0, 0,
33 0, -1, 0, 0, 32 0, -1, 0, 0,
34 0, 0, 1, 0, 33 0, 0, 1, 0,
35 0, 1, 0, 1); 34 0, 1, 0, 1);
36 35
37 // This only happens during a commit on the compositor thread while the main 36 // 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 37 // 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 38 // frame provider client that does not require a lock. The same is true of
40 // the call in the destructor. 39 // the call in the destructor.
41 DCHECK(Proxy::isMainThreadBlocked());
42 m_provider->setVideoFrameProviderClient(this); 40 m_provider->setVideoFrameProviderClient(this);
43 } 41 }
44 42
45 VideoLayerImpl::~VideoLayerImpl() 43 VideoLayerImpl::~VideoLayerImpl()
46 { 44 {
47 // See comment in constructor for why this doesn't need a lock. 45 // See comment in constructor for why this doesn't need a lock.
48 DCHECK(Proxy::isMainThreadBlocked());
49 if (m_provider) { 46 if (m_provider) {
50 m_provider->setVideoFrameProviderClient(0); 47 m_provider->setVideoFrameProviderClient(0);
51 m_provider = 0; 48 m_provider = 0;
52 } 49 }
53 freePlaneData(layerTreeHostImpl()->resourceProvider()); 50 freePlaneData(layerTreeHostImpl()->resourceProvider());
54 51
55 #ifndef NDEBUG 52 #ifndef NDEBUG
56 for (unsigned i = 0; i < WebKit::WebVideoFrame::maxPlanes; ++i) 53 for (unsigned i = 0; i < WebKit::WebVideoFrame::maxPlanes; ++i)
57 DCHECK(!m_framePlanes[i].resourceId); 54 DCHECK(!m_framePlanes[i].resourceId);
58 DCHECK(!m_externalTextureResource); 55 DCHECK(!m_externalTextureResource);
(...skipping 22 matching lines...) Expand all
81 case WebKit::WebVideoFrame::FormatRGB32: 78 case WebKit::WebVideoFrame::FormatRGB32:
82 case WebKit::WebVideoFrame::FormatEmpty: 79 case WebKit::WebVideoFrame::FormatEmpty:
83 case WebKit::WebVideoFrame::FormatI420: 80 case WebKit::WebVideoFrame::FormatI420:
84 notImplemented(); 81 notImplemented();
85 } 82 }
86 return GL_INVALID_VALUE; 83 return GL_INVALID_VALUE;
87 } 84 }
88 85
89 void VideoLayerImpl::willDraw(ResourceProvider* resourceProvider) 86 void VideoLayerImpl::willDraw(ResourceProvider* resourceProvider)
90 { 87 {
91 DCHECK(Proxy::isImplThread());
92 LayerImpl::willDraw(resourceProvider); 88 LayerImpl::willDraw(resourceProvider);
93 89
94 // Explicitly acquire and release the provider mutex so it can be held from 90 // 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 91 // willDraw to didDraw. Since the compositor thread is in the middle of
96 // drawing, the layer will not be destroyed before didDraw is called. 92 // drawing, the layer will not be destroyed before didDraw is called.
97 // Therefore, the only thing that will prevent this lock from being released 93 // 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 94 // is the GPU process locking it. As the GPU process can't cause the
99 // destruction of the provider (calling stopUsingProvider), holding this 95 // destruction of the provider (calling stopUsingProvider), holding this
100 // lock should not cause a deadlock. 96 // lock should not cause a deadlock.
101 m_providerLock.Acquire(); 97 m_providerLock.Acquire();
102 98
103 willDrawInternal(resourceProvider); 99 willDrawInternal(resourceProvider);
104 freeUnusedPlaneData(resourceProvider); 100 freeUnusedPlaneData(resourceProvider);
105 101
106 if (!m_frame) 102 if (!m_frame)
107 m_providerLock.Release(); 103 m_providerLock.Release();
108 } 104 }
109 105
110 void VideoLayerImpl::willDrawInternal(ResourceProvider* resourceProvider) 106 void VideoLayerImpl::willDrawInternal(ResourceProvider* resourceProvider)
111 { 107 {
112 DCHECK(Proxy::isImplThread());
113 DCHECK(!m_externalTextureResource); 108 DCHECK(!m_externalTextureResource);
114 109
115 if (!m_provider) { 110 if (!m_provider) {
116 m_frame = 0; 111 m_frame = 0;
117 return; 112 return;
118 } 113 }
119 114
120 m_frame = m_provider->getCurrentFrame(); 115 m_frame = m_provider->getCurrentFrame();
121 116
122 if (!m_frame) 117 if (!m_frame)
(...skipping 24 matching lines...) Expand all
147 m_frame = 0; 142 m_frame = 0;
148 return; 143 return;
149 } 144 }
150 145
151 if (m_format == GL_TEXTURE_2D) 146 if (m_format == GL_TEXTURE_2D)
152 m_externalTextureResource = resourceProvider->createResourceFromExternal Texture(m_frame->textureId()); 147 m_externalTextureResource = resourceProvider->createResourceFromExternal Texture(m_frame->textureId());
153 } 148 }
154 149
155 void VideoLayerImpl::appendQuads(QuadSink& quadSink, AppendQuadsData& appendQuad sData) 150 void VideoLayerImpl::appendQuads(QuadSink& quadSink, AppendQuadsData& appendQuad sData)
156 { 151 {
157 DCHECK(Proxy::isImplThread());
158
159 if (!m_frame) 152 if (!m_frame)
160 return; 153 return;
161 154
162 SharedQuadState* sharedQuadState = quadSink.useSharedQuadState(createSharedQ uadState()); 155 SharedQuadState* sharedQuadState = quadSink.useSharedQuadState(createSharedQ uadState());
163 appendDebugBorderQuad(quadSink, sharedQuadState, appendQuadsData); 156 appendDebugBorderQuad(quadSink, sharedQuadState, appendQuadsData);
164 157
165 // FIXME: When we pass quads out of process, we need to double-buffer, or 158 // FIXME: When we pass quads out of process, we need to double-buffer, or
166 // otherwise synchonize use of all textures in the quad. 159 // otherwise synchonize use of all textures in the quad.
167 160
168 IntRect quadRect(IntPoint(), contentBounds()); 161 IntRect quadRect(IntPoint(), contentBounds());
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 quadSink.append(streamVideoQuad.PassAs<DrawQuad>(), appendQuadsData); 203 quadSink.append(streamVideoQuad.PassAs<DrawQuad>(), appendQuadsData);
211 break; 204 break;
212 } 205 }
213 default: 206 default:
214 CRASH(); // Someone updated convertVFCFormatToGC3DFormat above but updat e this! 207 CRASH(); // Someone updated convertVFCFormatToGC3DFormat above but updat e this!
215 } 208 }
216 } 209 }
217 210
218 void VideoLayerImpl::didDraw(ResourceProvider* resourceProvider) 211 void VideoLayerImpl::didDraw(ResourceProvider* resourceProvider)
219 { 212 {
220 DCHECK(Proxy::isImplThread());
221 LayerImpl::didDraw(resourceProvider); 213 LayerImpl::didDraw(resourceProvider);
222 214
223 if (!m_frame) 215 if (!m_frame)
224 return; 216 return;
225 217
226 if (m_format == GL_TEXTURE_2D) { 218 if (m_format == GL_TEXTURE_2D) {
227 DCHECK(m_externalTextureResource); 219 DCHECK(m_externalTextureResource);
228 // FIXME: the following assert will not be true when sending resources t o a 220 // 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 221 // parent compositor. We will probably need to hold on to m_frame for
230 // longer, and have several "current frames" in the pipeline. 222 // 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"); 370 str->append("video layer\n");
379 LayerImpl::dumpLayerProperties(str, indent); 371 LayerImpl::dumpLayerProperties(str, indent);
380 } 372 }
381 373
382 const char* VideoLayerImpl::layerTypeAsString() const 374 const char* VideoLayerImpl::layerTypeAsString() const
383 { 375 {
384 return "VideoLayer"; 376 return "VideoLayer";
385 } 377 }
386 378
387 } 379 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698