OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_accelerator_factories.h" | 5 #include "content/renderer/media/renderer_gpu_video_accelerator_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" |
11 #include "content/child/child_thread.h" | 11 #include "content/child/child_thread.h" |
12 #include "content/common/gpu/client/context_provider_command_buffer.h" | 12 #include "content/common/gpu/client/context_provider_command_buffer.h" |
13 #include "content/common/gpu/client/gpu_channel_host.h" | 13 #include "content/common/gpu/client/gpu_channel_host.h" |
14 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" | 14 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" |
15 #include "content/renderer/render_thread_impl.h" | 15 #include "content/renderer/render_thread_impl.h" |
16 #include "gpu/command_buffer/client/gles2_implementation.h" | 16 #include "gpu/command_buffer/client/gles2_implementation.h" |
17 #include "gpu/command_buffer/common/mailbox_holder.h" | |
17 #include "third_party/skia/include/core/SkBitmap.h" | 18 #include "third_party/skia/include/core/SkBitmap.h" |
18 #include "third_party/skia/include/core/SkPixelRef.h" | 19 #include "third_party/skia/include/core/SkPixelRef.h" |
19 | 20 |
20 namespace content { | 21 namespace content { |
21 | 22 |
22 // static | 23 // static |
23 scoped_refptr<RendererGpuVideoAcceleratorFactories> | 24 scoped_refptr<RendererGpuVideoAcceleratorFactories> |
24 RendererGpuVideoAcceleratorFactories::Create( | 25 RendererGpuVideoAcceleratorFactories::Create( |
25 GpuChannelHost* gpu_channel_host, | 26 GpuChannelHost* gpu_channel_host, |
26 const scoped_refptr<base::MessageLoopProxy>& message_loop_proxy, | 27 const scoped_refptr<base::MessageLoopProxy>& message_loop_proxy, |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
159 | 160 |
160 gpu::gles2::GLES2Implementation* gles2 = context->GetImplementation(); | 161 gpu::gles2::GLES2Implementation* gles2 = context->GetImplementation(); |
161 gles2->WaitSyncPointCHROMIUM(sync_point); | 162 gles2->WaitSyncPointCHROMIUM(sync_point); |
162 | 163 |
163 // Callers expect the WaitSyncPoint to affect the next IPCs. Make sure to | 164 // Callers expect the WaitSyncPoint to affect the next IPCs. Make sure to |
164 // flush the command buffers to ensure that. | 165 // flush the command buffers to ensure that. |
165 gles2->ShallowFlushCHROMIUM(); | 166 gles2->ShallowFlushCHROMIUM(); |
166 } | 167 } |
167 | 168 |
168 void RendererGpuVideoAcceleratorFactories::ReadPixels( | 169 void RendererGpuVideoAcceleratorFactories::ReadPixels( |
169 uint32 texture_id, | 170 const scoped_refptr<media::VideoFrame>& video_frame, |
dshwang
2014/03/10 17:38:08
This CL changes GpuVideoAcceleratorFactories::Read
| |
170 const gfx::Rect& visible_rect, | |
171 const SkBitmap& pixels) { | 171 const SkBitmap& pixels) { |
172 DCHECK(task_runner_->BelongsToCurrentThread()); | 172 DCHECK(task_runner_->BelongsToCurrentThread()); |
173 | 173 |
174 WebGraphicsContext3DCommandBufferImpl* context = GetContext3d(); | 174 WebGraphicsContext3DCommandBufferImpl* context = GetContext3d(); |
175 if (!context) | 175 if (!context) |
176 return; | 176 return; |
177 | 177 |
178 DCHECK_EQ(media::VideoFrame::NATIVE_TEXTURE, video_frame->format()); | |
179 gpu::MailboxHolder* mailbox_holder = video_frame->mailbox_holder(); | |
180 DCHECK(mailbox_holder); | |
178 gpu::gles2::GLES2Implementation* gles2 = context->GetImplementation(); | 181 gpu::gles2::GLES2Implementation* gles2 = context->GetImplementation(); |
179 | 182 |
183 uint32 texture_id = 0; | |
184 gles2->GenTextures(1, &texture_id); | |
185 gles2->WaitSyncPointCHROMIUM(mailbox_holder->sync_point); | |
186 // Currently, Android doesn't use this. | |
187 DCHECK_EQ(GL_TEXTURE_2D, mailbox_holder->texture_target); | |
188 gles2->BindTexture(GL_TEXTURE_2D, texture_id); | |
189 gles2->ConsumeTextureCHROMIUM(GL_TEXTURE_2D, mailbox_holder->mailbox.name); | |
190 | |
180 GLuint tmp_texture; | 191 GLuint tmp_texture; |
181 gles2->GenTextures(1, &tmp_texture); | 192 gles2->GenTextures(1, &tmp_texture); |
182 gles2->BindTexture(GL_TEXTURE_2D, tmp_texture); | 193 gles2->BindTexture(GL_TEXTURE_2D, tmp_texture); |
183 gles2->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | 194 gles2->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
184 gles2->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | 195 gles2->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
185 gles2->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 196 gles2->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
186 gles2->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 197 gles2->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
187 context->copyTextureCHROMIUM( | 198 context->copyTextureCHROMIUM( |
188 GL_TEXTURE_2D, texture_id, tmp_texture, 0, GL_RGBA, GL_UNSIGNED_BYTE); | 199 GL_TEXTURE_2D, texture_id, tmp_texture, 0, GL_RGBA, GL_UNSIGNED_BYTE); |
200 gles2->DeleteTextures(1, &texture_id); | |
189 | 201 |
190 GLuint fb; | 202 GLuint fb; |
191 gles2->GenFramebuffers(1, &fb); | 203 gles2->GenFramebuffers(1, &fb); |
192 gles2->BindFramebuffer(GL_FRAMEBUFFER, fb); | 204 gles2->BindFramebuffer(GL_FRAMEBUFFER, fb); |
193 gles2->FramebufferTexture2D( | 205 gles2->FramebufferTexture2D( |
194 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tmp_texture, 0); | 206 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tmp_texture, 0); |
195 gles2->PixelStorei(GL_PACK_ALIGNMENT, 4); | 207 gles2->PixelStorei(GL_PACK_ALIGNMENT, 4); |
196 #if SK_B32_SHIFT == 0 && SK_G32_SHIFT == 8 && SK_R32_SHIFT == 16 && \ | 208 #if SK_B32_SHIFT == 0 && SK_G32_SHIFT == 8 && SK_R32_SHIFT == 16 && \ |
197 SK_A32_SHIFT == 24 | 209 SK_A32_SHIFT == 24 |
198 GLenum skia_format = GL_BGRA_EXT; | 210 GLenum skia_format = GL_BGRA_EXT; |
199 #elif SK_R32_SHIFT == 0 && SK_G32_SHIFT == 8 && SK_B32_SHIFT == 16 && \ | 211 #elif SK_R32_SHIFT == 0 && SK_G32_SHIFT == 8 && SK_B32_SHIFT == 16 && \ |
200 SK_A32_SHIFT == 24 | 212 SK_A32_SHIFT == 24 |
201 GLenum skia_format = GL_RGBA; | 213 GLenum skia_format = GL_RGBA; |
202 #else | 214 #else |
203 #error Unexpected Skia ARGB_8888 layout! | 215 #error Unexpected Skia ARGB_8888 layout! |
204 #endif | 216 #endif |
217 gfx::Rect visible_rect = video_frame->visible_rect(); | |
205 gles2->ReadPixels(visible_rect.x(), | 218 gles2->ReadPixels(visible_rect.x(), |
206 visible_rect.y(), | 219 visible_rect.y(), |
207 visible_rect.width(), | 220 visible_rect.width(), |
208 visible_rect.height(), | 221 visible_rect.height(), |
209 skia_format, | 222 skia_format, |
210 GL_UNSIGNED_BYTE, | 223 GL_UNSIGNED_BYTE, |
211 pixels.pixelRef()->pixels()); | 224 pixels.pixelRef()->pixels()); |
212 gles2->DeleteFramebuffers(1, &fb); | 225 gles2->DeleteFramebuffers(1, &fb); |
213 gles2->DeleteTextures(1, &tmp_texture); | 226 gles2->DeleteTextures(1, &tmp_texture); |
227 gles2->Flush(); | |
dshwang
2014/03/10 17:38:08
Now, this API can be called for the video frame th
| |
228 video_frame->AppendReleaseSyncPoint(gles2->InsertSyncPointCHROMIUM()); | |
214 DCHECK_EQ(gles2->GetError(), static_cast<GLenum>(GL_NO_ERROR)); | 229 DCHECK_EQ(gles2->GetError(), static_cast<GLenum>(GL_NO_ERROR)); |
215 } | 230 } |
216 | 231 |
217 base::SharedMemory* RendererGpuVideoAcceleratorFactories::CreateSharedMemory( | 232 base::SharedMemory* RendererGpuVideoAcceleratorFactories::CreateSharedMemory( |
218 size_t size) { | 233 size_t size) { |
219 DCHECK(task_runner_->BelongsToCurrentThread()); | 234 DCHECK(task_runner_->BelongsToCurrentThread()); |
220 return ChildThread::AllocateSharedMemory(size, thread_safe_sender_.get()); | 235 return ChildThread::AllocateSharedMemory(size, thread_safe_sender_.get()); |
221 } | 236 } |
222 | 237 |
223 scoped_refptr<base::SingleThreadTaskRunner> | 238 scoped_refptr<base::SingleThreadTaskRunner> |
224 RendererGpuVideoAcceleratorFactories::GetTaskRunner() { | 239 RendererGpuVideoAcceleratorFactories::GetTaskRunner() { |
225 return task_runner_; | 240 return task_runner_; |
226 } | 241 } |
227 | 242 |
228 } // namespace content | 243 } // namespace content |
OLD | NEW |