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

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

Issue 850993002: gpu video: optimize HW video to SW canvas and implement it for WebRTC. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix android build fail Created 5 years, 10 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_impl.h" 11 #include "content/child/child_thread_impl.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/gl_helper.h" 13 #include "content/common/gpu/client/gl_helper.h"
14 #include "content/common/gpu/client/gpu_channel_host.h" 14 #include "content/common/gpu/client/gpu_channel_host.h"
15 #include "content/common/gpu/client/gpu_video_encode_accelerator_host.h" 15 #include "content/common/gpu/client/gpu_video_encode_accelerator_host.h"
16 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" 16 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
17 #include "content/renderer/render_thread_impl.h" 17 #include "content/renderer/render_thread_impl.h"
18 #include "gpu/command_buffer/client/gles2_implementation.h" 18 #include "gpu/command_buffer/client/gles2_implementation.h"
19 #include "media/video/video_decode_accelerator.h" 19 #include "media/video/video_decode_accelerator.h"
20 #include "media/video/video_encode_accelerator.h" 20 #include "media/video/video_encode_accelerator.h"
21 #include "third_party/skia/include/core/SkBitmap.h"
22 #include "third_party/skia/include/core/SkPixelRef.h"
23 21
24 namespace content { 22 namespace content {
25 23
26 // static 24 // static
27 scoped_refptr<RendererGpuVideoAcceleratorFactories> 25 scoped_refptr<RendererGpuVideoAcceleratorFactories>
28 RendererGpuVideoAcceleratorFactories::Create( 26 RendererGpuVideoAcceleratorFactories::Create(
29 GpuChannelHost* gpu_channel_host, 27 GpuChannelHost* gpu_channel_host,
30 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, 28 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
31 const scoped_refptr<ContextProviderCommandBuffer>& context_provider) { 29 const scoped_refptr<ContextProviderCommandBuffer>& context_provider) {
32 scoped_refptr<RendererGpuVideoAcceleratorFactories> factories = 30 scoped_refptr<RendererGpuVideoAcceleratorFactories> factories =
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 return; 178 return;
181 179
182 gpu::gles2::GLES2Implementation* gles2 = context->GetImplementation(); 180 gpu::gles2::GLES2Implementation* gles2 = context->GetImplementation();
183 gles2->WaitSyncPointCHROMIUM(sync_point); 181 gles2->WaitSyncPointCHROMIUM(sync_point);
184 182
185 // Callers expect the WaitSyncPoint to affect the next IPCs. Make sure to 183 // Callers expect the WaitSyncPoint to affect the next IPCs. Make sure to
186 // flush the command buffers to ensure that. 184 // flush the command buffers to ensure that.
187 gles2->ShallowFlushCHROMIUM(); 185 gles2->ShallowFlushCHROMIUM();
188 } 186 }
189 187
190 void RendererGpuVideoAcceleratorFactories::ReadPixels(
191 uint32 texture_id,
192 const gfx::Rect& visible_rect,
193 const SkBitmap& pixels) {
194 DCHECK(task_runner_->BelongsToCurrentThread());
195
196 GLHelper* gl_helper = GetGLHelper();
197 WebGraphicsContext3DCommandBufferImpl* context = GetContext3d();
198
199 if (!gl_helper || !context)
200 return;
201
202 // Copy texture from texture_id to tmp_texture as texture might be external
203 // (GL_TEXTURE_EXTERNAL_OES)
204 GLuint tmp_texture;
205 tmp_texture = gl_helper->CreateTexture();
206 context->copyTextureCHROMIUM(
207 GL_TEXTURE_2D, texture_id, tmp_texture, 0, GL_RGBA, GL_UNSIGNED_BYTE);
208
209 unsigned char* pixel_data =
210 static_cast<unsigned char*>(pixels.pixelRef()->pixels());
211
212 if (gl_helper->IsReadbackConfigSupported(pixels.colorType())) {
213 gl_helper->ReadbackTextureSync(
214 tmp_texture, visible_rect, pixel_data, pixels.colorType());
215 } else if (pixels.colorType() == kN32_SkColorType) {
216 gl_helper->ReadbackTextureSync(
217 tmp_texture, visible_rect, pixel_data, kRGBA_8888_SkColorType);
218
219 int pixel_count = visible_rect.width() * visible_rect.height();
220 uint32_t* pixels_ptr = static_cast<uint32_t*>(pixels.pixelRef()->pixels());
221 for (int i = 0; i < pixel_count; ++i) {
222 uint32_t r = pixels_ptr[i] & 0xFF;
223 uint32_t g = (pixels_ptr[i] >> 8) & 0xFF;
224 uint32_t b = (pixels_ptr[i] >> 16) & 0xFF;
225 uint32_t a = (pixels_ptr[i] >> 24) & 0xFF;
226 pixels_ptr[i] = (r << SK_R32_SHIFT) |
227 (g << SK_G32_SHIFT) |
228 (b << SK_B32_SHIFT) |
229 (a << SK_A32_SHIFT);
230 }
231 } else {
232 NOTREACHED();
233 }
234
235 gl_helper->DeleteTexture(tmp_texture);
236 }
237
238 scoped_ptr<base::SharedMemory> 188 scoped_ptr<base::SharedMemory>
239 RendererGpuVideoAcceleratorFactories::CreateSharedMemory(size_t size) { 189 RendererGpuVideoAcceleratorFactories::CreateSharedMemory(size_t size) {
240 DCHECK(task_runner_->BelongsToCurrentThread()); 190 DCHECK(task_runner_->BelongsToCurrentThread());
241 scoped_ptr<base::SharedMemory> mem( 191 scoped_ptr<base::SharedMemory> mem(
242 ChildThreadImpl::AllocateSharedMemory(size, thread_safe_sender_.get())); 192 ChildThreadImpl::AllocateSharedMemory(size, thread_safe_sender_.get()));
243 if (mem && !mem->Map(size)) 193 if (mem && !mem->Map(size))
244 return nullptr; 194 return nullptr;
245 return mem; 195 return mem;
246 } 196 }
247 197
248 scoped_refptr<base::SingleThreadTaskRunner> 198 scoped_refptr<base::SingleThreadTaskRunner>
249 RendererGpuVideoAcceleratorFactories::GetTaskRunner() { 199 RendererGpuVideoAcceleratorFactories::GetTaskRunner() {
250 return task_runner_; 200 return task_runner_;
251 } 201 }
252 202
253 std::vector<media::VideoEncodeAccelerator::SupportedProfile> 203 std::vector<media::VideoEncodeAccelerator::SupportedProfile>
254 RendererGpuVideoAcceleratorFactories:: 204 RendererGpuVideoAcceleratorFactories::
255 GetVideoEncodeAcceleratorSupportedProfiles() { 205 GetVideoEncodeAcceleratorSupportedProfiles() {
256 return GpuVideoEncodeAcceleratorHost::ConvertGpuToMediaProfiles( 206 return GpuVideoEncodeAcceleratorHost::ConvertGpuToMediaProfiles(
257 gpu_channel_host_->gpu_info() 207 gpu_channel_host_->gpu_info()
258 .video_encode_accelerator_supported_profiles); 208 .video_encode_accelerator_supported_profiles);
259 } 209 }
260 210
261 } // namespace content 211 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/renderer_gpu_video_accelerator_factories.h ('k') | content/renderer/media/rtc_video_decoder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698