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

Side by Side Diff: content/renderer/media/renderer_gpu_video_accelerator_factories.cc

Issue 175223003: HW Video: Make media::VideoFrame handle the sync point of the compositor as well as webgl (Closed) Base URL: https://git.chromium.org/chromium/src.git@master
Patch Set: previous patchset has unrelated code by mistake. Created 6 years, 9 months 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 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 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 uint32 texture_id,
170 const gfx::Rect& visible_rect, 171 const scoped_refptr<media::VideoFrame>& video_frame,
danakj 2014/03/06 19:31:31 Is it a bit weird that this method takes a texture
dshwang 2014/03/06 19:51:37 That's very good point. This method is used by gpu
171 const SkBitmap& pixels) { 172 const SkBitmap& pixels) {
172 DCHECK(task_runner_->BelongsToCurrentThread()); 173 DCHECK(task_runner_->BelongsToCurrentThread());
173 174
174 WebGraphicsContext3DCommandBufferImpl* context = GetContext3d(); 175 WebGraphicsContext3DCommandBufferImpl* context = GetContext3d();
175 if (!context) 176 if (!context)
176 return; 177 return;
177 178
178 gpu::gles2::GLES2Implementation* gles2 = context->GetImplementation(); 179 gpu::gles2::GLES2Implementation* gles2 = context->GetImplementation();
180 gles2->WaitSyncPointCHROMIUM(video_frame->mailbox_holder()->sync_point);
179 181
180 GLuint tmp_texture; 182 GLuint tmp_texture;
181 gles2->GenTextures(1, &tmp_texture); 183 gles2->GenTextures(1, &tmp_texture);
182 gles2->BindTexture(GL_TEXTURE_2D, tmp_texture); 184 gles2->BindTexture(GL_TEXTURE_2D, tmp_texture);
183 gles2->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 185 gles2->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
184 gles2->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 186 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); 187 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); 188 gles2->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
187 context->copyTextureCHROMIUM( 189 context->copyTextureCHROMIUM(
188 GL_TEXTURE_2D, texture_id, tmp_texture, 0, GL_RGBA, GL_UNSIGNED_BYTE); 190 GL_TEXTURE_2D, texture_id, tmp_texture, 0, GL_RGBA, GL_UNSIGNED_BYTE);
189 191
190 GLuint fb; 192 GLuint fb;
191 gles2->GenFramebuffers(1, &fb); 193 gles2->GenFramebuffers(1, &fb);
192 gles2->BindFramebuffer(GL_FRAMEBUFFER, fb); 194 gles2->BindFramebuffer(GL_FRAMEBUFFER, fb);
193 gles2->FramebufferTexture2D( 195 gles2->FramebufferTexture2D(
194 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tmp_texture, 0); 196 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tmp_texture, 0);
195 gles2->PixelStorei(GL_PACK_ALIGNMENT, 4); 197 gles2->PixelStorei(GL_PACK_ALIGNMENT, 4);
196 #if SK_B32_SHIFT == 0 && SK_G32_SHIFT == 8 && SK_R32_SHIFT == 16 && \ 198 #if SK_B32_SHIFT == 0 && SK_G32_SHIFT == 8 && SK_R32_SHIFT == 16 && \
197 SK_A32_SHIFT == 24 199 SK_A32_SHIFT == 24
198 GLenum skia_format = GL_BGRA_EXT; 200 GLenum skia_format = GL_BGRA_EXT;
199 #elif SK_R32_SHIFT == 0 && SK_G32_SHIFT == 8 && SK_B32_SHIFT == 16 && \ 201 #elif SK_R32_SHIFT == 0 && SK_G32_SHIFT == 8 && SK_B32_SHIFT == 16 && \
200 SK_A32_SHIFT == 24 202 SK_A32_SHIFT == 24
201 GLenum skia_format = GL_RGBA; 203 GLenum skia_format = GL_RGBA;
202 #else 204 #else
203 #error Unexpected Skia ARGB_8888 layout! 205 #error Unexpected Skia ARGB_8888 layout!
204 #endif 206 #endif
207 gfx::Rect visible_rect = video_frame->visible_rect();
danakj 2014/03/06 19:31:31 Unrelated change, do this separately?
205 gles2->ReadPixels(visible_rect.x(), 208 gles2->ReadPixels(visible_rect.x(),
206 visible_rect.y(), 209 visible_rect.y(),
207 visible_rect.width(), 210 visible_rect.width(),
208 visible_rect.height(), 211 visible_rect.height(),
209 skia_format, 212 skia_format,
210 GL_UNSIGNED_BYTE, 213 GL_UNSIGNED_BYTE,
211 pixels.pixelRef()->pixels()); 214 pixels.pixelRef()->pixels());
212 gles2->DeleteFramebuffers(1, &fb); 215 gles2->DeleteFramebuffers(1, &fb);
213 gles2->DeleteTextures(1, &tmp_texture); 216 gles2->DeleteTextures(1, &tmp_texture);
217 gles2->Flush();
danakj 2014/03/06 19:31:31 Why is this flush needed?
dshwang 2014/03/06 19:51:37 I use flush as idiom. As I mentioned above, I'll r
218 video_frame->AppendReleaseSyncPoint(gles2->InsertSyncPointCHROMIUM());
214 DCHECK_EQ(gles2->GetError(), static_cast<GLenum>(GL_NO_ERROR)); 219 DCHECK_EQ(gles2->GetError(), static_cast<GLenum>(GL_NO_ERROR));
215 } 220 }
216 221
217 base::SharedMemory* RendererGpuVideoAcceleratorFactories::CreateSharedMemory( 222 base::SharedMemory* RendererGpuVideoAcceleratorFactories::CreateSharedMemory(
218 size_t size) { 223 size_t size) {
219 DCHECK(task_runner_->BelongsToCurrentThread()); 224 DCHECK(task_runner_->BelongsToCurrentThread());
220 return ChildThread::AllocateSharedMemory(size, thread_safe_sender_.get()); 225 return ChildThread::AllocateSharedMemory(size, thread_safe_sender_.get());
221 } 226 }
222 227
223 scoped_refptr<base::SingleThreadTaskRunner> 228 scoped_refptr<base::SingleThreadTaskRunner>
224 RendererGpuVideoAcceleratorFactories::GetTaskRunner() { 229 RendererGpuVideoAcceleratorFactories::GetTaskRunner() {
225 return task_runner_; 230 return task_runner_;
226 } 231 }
227 232
228 } // namespace content 233 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698