Chromium Code Reviews| 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); |
| 194 #if defined(OS_WIN) | |
| 195 // DXVA on Windows replaces our precious RGBA with BGRA. Undo that here. | |
| 196 gles2->ReadPixels(0, 0, size.width(), size.height(), GL_BGRA_EXT, | |
| 197 GL_UNSIGNED_BYTE, pixels); | |
|
piman
2012/10/02 19:38:50
Shouldn't that be fixed in the GPU process? It loo
Ami GONE FROM CHROMIUM
2012/10/02 19:49:23
Agreed with the "should" there, but not sure how.
| |
| 198 #else | |
| 191 gles2->ReadPixels(0, 0, size.width(), size.height(), GL_RGBA, | 199 gles2->ReadPixels(0, 0, size.width(), size.height(), GL_RGBA, |
| 192 GL_UNSIGNED_BYTE, pixels); | 200 GL_UNSIGNED_BYTE, pixels); |
| 201 #endif | |
| 193 gles2->DeleteFramebuffers(1, &fb); | 202 gles2->DeleteFramebuffers(1, &fb); |
| 203 gles2->DeleteTextures(1, &tmp_texture); | |
| 194 DCHECK_EQ(gles2->GetError(), static_cast<GLenum>(GL_NO_ERROR)); | 204 DCHECK_EQ(gles2->GetError(), static_cast<GLenum>(GL_NO_ERROR)); |
| 195 waiter->Signal(); | 205 waiter->Signal(); |
| 196 } | 206 } |
| 197 | 207 |
| 198 base::SharedMemory* RendererGpuVideoDecoderFactories::CreateSharedMemory( | 208 base::SharedMemory* RendererGpuVideoDecoderFactories::CreateSharedMemory( |
| 199 size_t size) { | 209 size_t size) { |
| 200 DCHECK_NE(MessageLoop::current(), ChildThread::current()->message_loop()); | 210 DCHECK_NE(MessageLoop::current(), ChildThread::current()->message_loop()); |
| 201 base::SharedMemory* shm = NULL; | 211 base::SharedMemory* shm = NULL; |
| 202 base::WaitableEvent waiter(false, false); | 212 base::WaitableEvent waiter(false, false); |
| 203 ChildThread::current()->message_loop()->PostTask(FROM_HERE, base::Bind( | 213 ChildThread::current()->message_loop()->PostTask(FROM_HERE, base::Bind( |
| 204 &RendererGpuVideoDecoderFactories::AsyncCreateSharedMemory, this, | 214 &RendererGpuVideoDecoderFactories::AsyncCreateSharedMemory, this, |
| 205 size, &shm, &waiter)); | 215 size, &shm, &waiter)); |
| 206 waiter.Wait(); | 216 waiter.Wait(); |
| 207 return shm; | 217 return shm; |
| 208 } | 218 } |
| 209 | 219 |
| 210 void RendererGpuVideoDecoderFactories::AsyncCreateSharedMemory( | 220 void RendererGpuVideoDecoderFactories::AsyncCreateSharedMemory( |
| 211 size_t size, base::SharedMemory** shm, base::WaitableEvent* waiter) { | 221 size_t size, base::SharedMemory** shm, base::WaitableEvent* waiter) { |
| 212 DCHECK_EQ(MessageLoop::current(), ChildThread::current()->message_loop()); | 222 DCHECK_EQ(MessageLoop::current(), ChildThread::current()->message_loop()); |
| 213 *shm = ChildThread::current()->AllocateSharedMemory(size); | 223 *shm = ChildThread::current()->AllocateSharedMemory(size); |
| 214 waiter->Signal(); | 224 waiter->Signal(); |
| 215 } | 225 } |
| OLD | NEW |