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 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 | 168 |
169 void RendererGpuVideoDecoderFactories::AsyncReadPixels( | 169 void RendererGpuVideoDecoderFactories::AsyncReadPixels( |
170 uint32 texture_id, uint32 texture_target, const gfx::Size& size, | 170 uint32 texture_id, uint32 texture_target, const gfx::Size& size, |
171 void* pixels, base::WaitableEvent* waiter) { | 171 void* pixels, base::WaitableEvent* waiter) { |
172 DCHECK(message_loop_->BelongsToCurrentThread()); | 172 DCHECK(message_loop_->BelongsToCurrentThread()); |
173 if (!context_) | 173 if (!context_) |
174 return; | 174 return; |
175 | 175 |
176 gpu::gles2::GLES2Implementation* gles2 = context_->GetImplementation(); | 176 gpu::gles2::GLES2Implementation* gles2 = context_->GetImplementation(); |
177 | 177 |
178 gles2->ActiveTexture(GL_TEXTURE0); | 178 GLuint tmp_texture; |
179 gles2->BindTexture(texture_target, texture_id); | 179 gles2->GenTextures(1, &tmp_texture); |
180 gles2->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | 180 gles2->BindTexture(texture_target, tmp_texture); |
181 gles2->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | 181 gles2->TexParameteri(texture_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
182 gles2->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 182 gles2->TexParameteri(texture_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
183 gles2->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 183 gles2->TexParameteri(texture_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 184 gles2->TexParameteri(texture_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 185 context_->copyTextureCHROMIUM( |
| 186 texture_target, texture_id, tmp_texture, 0, GL_RGBA); |
184 | 187 |
185 GLuint fb; | 188 GLuint fb; |
186 gles2->GenFramebuffers(1, &fb); | 189 gles2->GenFramebuffers(1, &fb); |
187 gles2->BindFramebuffer(GL_FRAMEBUFFER, fb); | 190 gles2->BindFramebuffer(GL_FRAMEBUFFER, fb); |
188 gles2->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, | 191 gles2->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, |
189 texture_target, texture_id, 0); | 192 texture_target, tmp_texture, 0); |
190 gles2->PixelStorei(GL_PACK_ALIGNMENT, 4); | 193 gles2->PixelStorei(GL_PACK_ALIGNMENT, 4); |
191 gles2->ReadPixels(0, 0, size.width(), size.height(), GL_RGBA, | 194 gles2->ReadPixels(0, 0, size.width(), size.height(), GL_BGRA_EXT, |
192 GL_UNSIGNED_BYTE, pixels); | 195 GL_UNSIGNED_BYTE, pixels); |
193 gles2->DeleteFramebuffers(1, &fb); | 196 gles2->DeleteFramebuffers(1, &fb); |
| 197 gles2->DeleteTextures(1, &tmp_texture); |
194 DCHECK_EQ(gles2->GetError(), static_cast<GLenum>(GL_NO_ERROR)); | 198 DCHECK_EQ(gles2->GetError(), static_cast<GLenum>(GL_NO_ERROR)); |
195 waiter->Signal(); | 199 waiter->Signal(); |
196 } | 200 } |
197 | 201 |
198 base::SharedMemory* RendererGpuVideoDecoderFactories::CreateSharedMemory( | 202 base::SharedMemory* RendererGpuVideoDecoderFactories::CreateSharedMemory( |
199 size_t size) { | 203 size_t size) { |
200 DCHECK_NE(MessageLoop::current(), ChildThread::current()->message_loop()); | 204 DCHECK_NE(MessageLoop::current(), ChildThread::current()->message_loop()); |
201 base::SharedMemory* shm = NULL; | 205 base::SharedMemory* shm = NULL; |
202 base::WaitableEvent waiter(false, false); | 206 base::WaitableEvent waiter(false, false); |
203 ChildThread::current()->message_loop()->PostTask(FROM_HERE, base::Bind( | 207 ChildThread::current()->message_loop()->PostTask(FROM_HERE, base::Bind( |
204 &RendererGpuVideoDecoderFactories::AsyncCreateSharedMemory, this, | 208 &RendererGpuVideoDecoderFactories::AsyncCreateSharedMemory, this, |
205 size, &shm, &waiter)); | 209 size, &shm, &waiter)); |
206 waiter.Wait(); | 210 waiter.Wait(); |
207 return shm; | 211 return shm; |
208 } | 212 } |
209 | 213 |
210 void RendererGpuVideoDecoderFactories::AsyncCreateSharedMemory( | 214 void RendererGpuVideoDecoderFactories::AsyncCreateSharedMemory( |
211 size_t size, base::SharedMemory** shm, base::WaitableEvent* waiter) { | 215 size_t size, base::SharedMemory** shm, base::WaitableEvent* waiter) { |
212 DCHECK_EQ(MessageLoop::current(), ChildThread::current()->message_loop()); | 216 DCHECK_EQ(MessageLoop::current(), ChildThread::current()->message_loop()); |
213 *shm = ChildThread::current()->AllocateSharedMemory(size); | 217 *shm = ChildThread::current()->AllocateSharedMemory(size); |
214 waiter->Signal(); | 218 waiter->Signal(); |
215 } | 219 } |
OLD | NEW |