OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/renderer/media/renderer_gpu_video_decoder_factories.h" | 5 #include "content/renderer/media/renderer_gpu_video_decoder_factories.h" |
6 | 6 |
7 #include <GLES2/gl2.h> | 7 #include <GLES2/gl2.h> |
8 #include <GLES2/gl2ext.h> | 8 #include <GLES2/gl2ext.h> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
89 media::VideoDecodeAccelerator::Client* client) { | 89 media::VideoDecodeAccelerator::Client* client) { |
90 DCHECK(message_loop_->BelongsToCurrentThread()); | 90 DCHECK(message_loop_->BelongsToCurrentThread()); |
91 | 91 |
92 if (context_.get() && context_->GetCommandBufferProxy()) { | 92 if (context_.get() && context_->GetCommandBufferProxy()) { |
93 vda_ = gpu_channel_host_->CreateVideoDecoder( | 93 vda_ = gpu_channel_host_->CreateVideoDecoder( |
94 context_->GetCommandBufferProxy()->GetRouteID(), profile, client); | 94 context_->GetCommandBufferProxy()->GetRouteID(), profile, client); |
95 } | 95 } |
96 compositor_loop_async_waiter_.Signal(); | 96 compositor_loop_async_waiter_.Signal(); |
97 } | 97 } |
98 | 98 |
99 bool RendererGpuVideoDecoderFactories::CreateTextures( | 99 uint32 RendererGpuVideoDecoderFactories::CreateTextures( |
100 int32 count, const gfx::Size& size, | 100 int32 count, const gfx::Size& size, |
101 std::vector<uint32>* texture_ids, | 101 std::vector<uint32>* texture_ids, |
102 std::vector<gpu::Mailbox>* texture_mailboxes, | |
102 uint32 texture_target) { | 103 uint32 texture_target) { |
104 uint32 sync_point = 0; | |
105 | |
103 DCHECK(!message_loop_->BelongsToCurrentThread()); | 106 DCHECK(!message_loop_->BelongsToCurrentThread()); |
104 message_loop_->PostTask(FROM_HERE, base::Bind( | 107 message_loop_->PostTask(FROM_HERE, base::Bind( |
105 &RendererGpuVideoDecoderFactories::AsyncCreateTextures, this, | 108 &RendererGpuVideoDecoderFactories::AsyncCreateTextures, this, |
106 count, size, texture_target)); | 109 count, size, texture_target, &sync_point)); |
107 | 110 |
108 base::WaitableEvent* objects[] = {&aborted_waiter_, | 111 base::WaitableEvent* objects[] = {&aborted_waiter_, |
109 &compositor_loop_async_waiter_}; | 112 &compositor_loop_async_waiter_}; |
110 if (base::WaitableEvent::WaitMany(objects, arraysize(objects)) == 0) | 113 if (base::WaitableEvent::WaitMany(objects, arraysize(objects)) == 0) |
111 return false; | 114 return 0; |
112 texture_ids->swap(created_textures_); | 115 texture_ids->swap(created_textures_); |
113 return true; | 116 texture_mailboxes->swap(created_texture_mailboxes_); |
117 return sync_point; | |
114 } | 118 } |
115 | 119 |
116 void RendererGpuVideoDecoderFactories::AsyncCreateTextures( | 120 void RendererGpuVideoDecoderFactories::AsyncCreateTextures( |
117 int32 count, const gfx::Size& size, uint32 texture_target) { | 121 int32 count, const gfx::Size& size, uint32 texture_target, |
122 uint32* sync_point) { | |
118 DCHECK(message_loop_->BelongsToCurrentThread()); | 123 DCHECK(message_loop_->BelongsToCurrentThread()); |
119 DCHECK(texture_target); | 124 DCHECK(texture_target); |
120 | 125 |
121 if (!context_.get()) { | 126 if (!context_.get()) { |
122 compositor_loop_async_waiter_.Signal(); | 127 compositor_loop_async_waiter_.Signal(); |
123 return; | 128 return; |
124 } | 129 } |
125 gpu::gles2::GLES2Implementation* gles2 = context_->GetImplementation(); | 130 gpu::gles2::GLES2Implementation* gles2 = context_->GetImplementation(); |
126 created_textures_.resize(count); | 131 created_textures_.resize(count); |
132 created_texture_mailboxes_.resize(count); | |
127 gles2->GenTextures(count, &created_textures_[0]); | 133 gles2->GenTextures(count, &created_textures_[0]); |
128 for (int i = 0; i < count; ++i) { | 134 for (int i = 0; i < count; ++i) { |
129 gles2->ActiveTexture(GL_TEXTURE0); | 135 gles2->ActiveTexture(GL_TEXTURE0); |
130 uint32 texture_id = created_textures_[i]; | 136 uint32 texture_id = created_textures_[i]; |
131 gles2->BindTexture(texture_target, texture_id); | 137 gles2->BindTexture(texture_target, texture_id); |
132 gles2->TexParameteri(texture_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | 138 gles2->TexParameteri(texture_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
133 gles2->TexParameteri(texture_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | 139 gles2->TexParameteri(texture_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
134 gles2->TexParameteri(texture_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 140 gles2->TexParameteri(texture_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
135 gles2->TexParameteri(texture_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 141 gles2->TexParameteri(texture_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
136 if (texture_target == GL_TEXTURE_2D) { | 142 if (texture_target == GL_TEXTURE_2D) { |
137 gles2->TexImage2D(texture_target, 0, GL_RGBA, size.width(), size.height(), | 143 gles2->TexImage2D(texture_target, 0, GL_RGBA, size.width(), size.height(), |
138 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); | 144 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); |
139 } | 145 } |
146 gles2->GenMailboxCHROMIUM(created_texture_mailboxes_[i].name); | |
147 gles2->ProduceTextureCHROMIUM(texture_target, | |
148 created_texture_mailboxes_[i].name); | |
140 } | 149 } |
150 *sync_point = gles2->InsertSyncPointCHROMIUM(); | |
piman
2013/06/17 19:58:29
move the sync point after the flush (the other con
danakj
2013/06/18 16:54:12
Done.
| |
151 | |
141 // We need a glFlush here to guarantee the decoder (in the GPU process) can | 152 // We need a glFlush here to guarantee the decoder (in the GPU process) can |
142 // use the texture ids we return here. Since textures are expected to be | 153 // use the texture ids we return here. Since textures are expected to be |
143 // reused, this should not be unacceptably expensive. | 154 // reused, this should not be unacceptably expensive. |
144 gles2->Flush(); | 155 gles2->Flush(); |
145 DCHECK_EQ(gles2->GetError(), static_cast<GLenum>(GL_NO_ERROR)); | 156 DCHECK_EQ(gles2->GetError(), static_cast<GLenum>(GL_NO_ERROR)); |
146 compositor_loop_async_waiter_.Signal(); | 157 compositor_loop_async_waiter_.Signal(); |
147 } | 158 } |
148 | 159 |
149 void RendererGpuVideoDecoderFactories::DeleteTexture(uint32 texture_id) { | 160 void RendererGpuVideoDecoderFactories::DeleteTexture(uint32 texture_id) { |
150 DCHECK(!message_loop_->BelongsToCurrentThread()); | 161 DCHECK(!message_loop_->BelongsToCurrentThread()); |
151 message_loop_->PostTask(FROM_HERE, base::Bind( | 162 message_loop_->PostTask(FROM_HERE, base::Bind( |
152 &RendererGpuVideoDecoderFactories::AsyncDeleteTexture, this, texture_id)); | 163 &RendererGpuVideoDecoderFactories::AsyncDeleteTexture, this, texture_id)); |
153 } | 164 } |
154 | 165 |
155 void RendererGpuVideoDecoderFactories::AsyncDeleteTexture(uint32 texture_id) { | 166 void RendererGpuVideoDecoderFactories::AsyncDeleteTexture(uint32 texture_id) { |
156 DCHECK(message_loop_->BelongsToCurrentThread()); | 167 DCHECK(message_loop_->BelongsToCurrentThread()); |
157 if (!context_.get()) | 168 if (!context_.get()) |
158 return; | 169 return; |
159 | 170 |
160 gpu::gles2::GLES2Implementation* gles2 = context_->GetImplementation(); | 171 gpu::gles2::GLES2Implementation* gles2 = context_->GetImplementation(); |
161 gles2->DeleteTextures(1, &texture_id); | 172 gles2->DeleteTextures(1, &texture_id); |
162 DCHECK_EQ(gles2->GetError(), static_cast<GLenum>(GL_NO_ERROR)); | 173 DCHECK_EQ(gles2->GetError(), static_cast<GLenum>(GL_NO_ERROR)); |
163 } | 174 } |
164 | 175 |
176 void RendererGpuVideoDecoderFactories::WaitSyncPoint(uint32 sync_point) { | |
177 if (message_loop_->BelongsToCurrentThread()) { | |
178 AsyncWaitSyncPoint(sync_point); | |
179 return; | |
180 } | |
181 | |
182 message_loop_->PostTask(FROM_HERE, base::Bind( | |
183 &RendererGpuVideoDecoderFactories::AsyncWaitSyncPoint, | |
184 this, | |
185 sync_point)); | |
186 base::WaitableEvent* objects[] = {&aborted_waiter_, | |
187 &compositor_loop_async_waiter_}; | |
188 base::WaitableEvent::WaitMany(objects, arraysize(objects)); | |
189 } | |
190 | |
191 void RendererGpuVideoDecoderFactories::AsyncWaitSyncPoint(uint32 sync_point) { | |
192 DCHECK(message_loop_->BelongsToCurrentThread()); | |
193 if (!context_) { | |
194 compositor_loop_async_waiter_.Signal(); | |
195 return; | |
196 } | |
197 | |
198 gpu::gles2::GLES2Implementation* gles2 = context_->GetImplementation(); | |
199 gles2->WaitSyncPointCHROMIUM(sync_point); | |
200 compositor_loop_async_waiter_.Signal(); | |
201 } | |
202 | |
165 void RendererGpuVideoDecoderFactories::ReadPixels( | 203 void RendererGpuVideoDecoderFactories::ReadPixels( |
166 uint32 texture_id, uint32 texture_target, const gfx::Size& size, | 204 uint32 texture_id, uint32 texture_target, const gfx::Size& size, |
167 const SkBitmap& pixels) { | 205 const SkBitmap& pixels) { |
168 // SkBitmaps use the SkPixelRef object to refcount the underlying pixels. | 206 // SkBitmaps use the SkPixelRef object to refcount the underlying pixels. |
169 // Multiple SkBitmaps can share a SkPixelRef instance. We use this to | 207 // Multiple SkBitmaps can share a SkPixelRef instance. We use this to |
170 // ensure that the underlying pixels in the SkBitmap passed in remain valid | 208 // ensure that the underlying pixels in the SkBitmap passed in remain valid |
171 // until the AsyncReadPixels() call completes. | 209 // until the AsyncReadPixels() call completes. |
172 read_pixels_bitmap_.setPixelRef(pixels.pixelRef()); | 210 read_pixels_bitmap_.setPixelRef(pixels.pixelRef()); |
173 | 211 |
174 if (!message_loop_->BelongsToCurrentThread()) { | 212 if (!message_loop_->BelongsToCurrentThread()) { |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
256 return aborted_waiter_.IsSignaled(); | 294 return aborted_waiter_.IsSignaled(); |
257 } | 295 } |
258 | 296 |
259 void RendererGpuVideoDecoderFactories::AsyncDestroyVideoDecodeAccelerator() { | 297 void RendererGpuVideoDecoderFactories::AsyncDestroyVideoDecodeAccelerator() { |
260 // OK to release because Destroy() will delete the VDA instance. | 298 // OK to release because Destroy() will delete the VDA instance. |
261 if (vda_) | 299 if (vda_) |
262 vda_.release()->Destroy(); | 300 vda_.release()->Destroy(); |
263 } | 301 } |
264 | 302 |
265 } // namespace content | 303 } // namespace content |
OLD | NEW |