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

Side by Side Diff: content/common/gpu/media/rendering_helper.cc

Issue 804353003: Revert of Refactor Vaapi video decoder/encoder in preparation of Freon support (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years 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
« no previous file with comments | « content/common/gpu/media/rendering_helper.h ('k') | content/common/gpu/media/va.sigs » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/common/gpu/media/rendering_helper.h" 5 #include "content/common/gpu/media/rendering_helper.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <numeric> 8 #include <numeric>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/callback_helpers.h" 12 #include "base/callback_helpers.h"
13 #include "base/command_line.h" 13 #include "base/command_line.h"
14 #include "base/mac/scoped_nsautorelease_pool.h" 14 #include "base/mac/scoped_nsautorelease_pool.h"
15 #include "base/message_loop/message_loop.h" 15 #include "base/message_loop/message_loop.h"
16 #include "base/strings/stringize_macros.h" 16 #include "base/strings/stringize_macros.h"
17 #include "base/synchronization/waitable_event.h" 17 #include "base/synchronization/waitable_event.h"
18 #include "base/time/time.h" 18 #include "base/time/time.h"
19 #include "ui/gl/gl_context.h" 19 #include "ui/gl/gl_context.h"
20 #include "ui/gl/gl_implementation.h" 20 #include "ui/gl/gl_implementation.h"
21 #include "ui/gl/gl_surface.h" 21 #include "ui/gl/gl_surface.h"
22 #include "ui/gl/gl_surface_egl.h"
23 #include "ui/gl/gl_surface_glx.h"
22 24
23 #if defined(OS_WIN) 25 #if defined(OS_WIN)
24 #include <windows.h> 26 #include <windows.h>
25 #endif 27 #endif
26 28
27 #if defined(USE_X11) 29 #if defined(USE_X11)
28 #include "ui/gfx/x/x11_types.h" 30 #include "ui/gfx/x/x11_types.h"
29 #endif 31 #endif
30 32
31 #if defined(ARCH_CPU_X86_FAMILY) && defined(USE_X11) 33 #if !defined(OS_WIN) && defined(ARCH_CPU_X86_FAMILY)
32 #include "ui/gl/gl_surface_glx.h"
33 #define GL_VARIANT_GLX 1 34 #define GL_VARIANT_GLX 1
34 #else 35 #else
35 #include "ui/gl/gl_surface_egl.h"
36 #define GL_VARIANT_EGL 1 36 #define GL_VARIANT_EGL 1
37 #endif 37 #endif
38 38
39 // Helper for Shader creation. 39 // Helper for Shader creation.
40 static void CreateShader(GLuint program, 40 static void CreateShader(GLuint program,
41 GLenum type, 41 GLenum type,
42 const char* source, 42 const char* source,
43 int size) { 43 int size) {
44 GLuint shader = glCreateShader(type); 44 GLuint shader = glCreateShader(type);
45 glShaderSource(shader, 1, &source, &size); 45 glShaderSource(shader, 1, &source, &size);
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 base::Bind(&RenderingHelper::RenderContent, base::Unretained(this))); 120 base::Bind(&RenderingHelper::RenderContent, base::Unretained(this)));
121 121
122 frame_duration_ = params.rendering_fps > 0 122 frame_duration_ = params.rendering_fps > 0
123 ? base::TimeDelta::FromSeconds(1) / params.rendering_fps 123 ? base::TimeDelta::FromSeconds(1) / params.rendering_fps
124 : base::TimeDelta(); 124 : base::TimeDelta();
125 125
126 render_as_thumbnails_ = params.render_as_thumbnails; 126 render_as_thumbnails_ = params.render_as_thumbnails;
127 message_loop_ = base::MessageLoop::current(); 127 message_loop_ = base::MessageLoop::current();
128 128
129 #if defined(OS_WIN) 129 #if defined(OS_WIN)
130 screen_size_ =
131 gfx::Size(GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));
130 window_ = CreateWindowEx(0, 132 window_ = CreateWindowEx(0,
131 L"Static", 133 L"Static",
132 L"VideoDecodeAcceleratorTest", 134 L"VideoDecodeAcceleratorTest",
133 WS_OVERLAPPEDWINDOW | WS_VISIBLE, 135 WS_OVERLAPPEDWINDOW | WS_VISIBLE,
134 0, 136 0,
135 0, 137 0,
136 GetSystemMetrics(SM_CXSCREEN), 138 screen_size_.width(),
137 GetSystemMetrics(SM_CYSCREEN), 139 screen_size_.height(),
138 NULL, 140 NULL,
139 NULL, 141 NULL,
140 NULL, 142 NULL,
141 NULL); 143 NULL);
142 #elif defined(USE_X11) 144 #elif defined(USE_X11)
143 Display* display = gfx::GetXDisplay(); 145 Display* display = gfx::GetXDisplay();
144 Screen* screen = DefaultScreenOfDisplay(display); 146 Screen* screen = DefaultScreenOfDisplay(display);
147 screen_size_ = gfx::Size(XWidthOfScreen(screen), XHeightOfScreen(screen));
145 148
146 CHECK(display); 149 CHECK(display);
147 150
148 XSetWindowAttributes window_attributes; 151 XSetWindowAttributes window_attributes;
149 memset(&window_attributes, 0, sizeof(window_attributes)); 152 memset(&window_attributes, 0, sizeof(window_attributes));
150 window_attributes.background_pixel = 153 window_attributes.background_pixel =
151 BlackPixel(display, DefaultScreen(display)); 154 BlackPixel(display, DefaultScreen(display));
152 window_attributes.override_redirect = true; 155 window_attributes.override_redirect = true;
153 int depth = DefaultDepth(display, DefaultScreen(display)); 156 int depth = DefaultDepth(display, DefaultScreen(display));
154 157
155 window_ = XCreateWindow(display, 158 window_ = XCreateWindow(display,
156 DefaultRootWindow(display), 159 DefaultRootWindow(display),
157 0, 160 0,
158 0, 161 0,
159 XWidthOfScreen(screen), 162 screen_size_.width(),
160 XHeightOfScreen(screen), 163 screen_size_.height(),
161 0 /* border width */, 164 0 /* border width */,
162 depth, 165 depth,
163 CopyFromParent /* class */, 166 CopyFromParent /* class */,
164 CopyFromParent /* visual */, 167 CopyFromParent /* visual */,
165 (CWBackPixel | CWOverrideRedirect), 168 (CWBackPixel | CWOverrideRedirect),
166 &window_attributes); 169 &window_attributes);
167 XStoreName(display, window_, "VideoDecodeAcceleratorTest"); 170 XStoreName(display, window_, "VideoDecodeAcceleratorTest");
168 XSelectInput(display, window_, ExposureMask); 171 XSelectInput(display, window_, ExposureMask);
169 XMapWindow(display, window_); 172 XMapWindow(display, window_);
170 #else 173 #else
171 #error unknown platform 174 #error unknown platform
172 #endif 175 #endif
173 CHECK(window_ != gfx::kNullAcceleratedWidget); 176 CHECK(window_ != gfx::kNullAcceleratedWidget);
174 177
175 gl_surface_ = gfx::GLSurface::CreateViewGLSurface(window_); 178 gl_surface_ = gfx::GLSurface::CreateViewGLSurface(window_);
176 screen_size_ = gl_surface_->GetSize();
177
178 gl_context_ = gfx::GLContext::CreateGLContext( 179 gl_context_ = gfx::GLContext::CreateGLContext(
179 NULL, gl_surface_.get(), gfx::PreferIntegratedGpu); 180 NULL, gl_surface_.get(), gfx::PreferIntegratedGpu);
180 CHECK(gl_context_->MakeCurrent(gl_surface_.get())); 181 gl_context_->MakeCurrent(gl_surface_.get());
181 182
182 CHECK_GT(params.window_sizes.size(), 0U); 183 CHECK_GT(params.window_sizes.size(), 0U);
183 videos_.resize(params.window_sizes.size()); 184 videos_.resize(params.window_sizes.size());
184 LayoutRenderingAreas(params.window_sizes); 185 LayoutRenderingAreas(params.window_sizes);
185 186
186 if (render_as_thumbnails_) { 187 if (render_as_thumbnails_) {
187 CHECK_EQ(videos_.size(), 1U); 188 CHECK_EQ(videos_.size(), 1U);
188 189
189 GLint max_texture_size; 190 GLint max_texture_size;
190 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max_texture_size); 191 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max_texture_size);
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 if (tex_external != -1) { 297 if (tex_external != -1) {
297 glUniform1i(tex_external, 1); 298 glUniform1i(tex_external, 1);
298 } 299 }
299 int pos_location = glGetAttribLocation(program_, "in_pos"); 300 int pos_location = glGetAttribLocation(program_, "in_pos");
300 glEnableVertexAttribArray(pos_location); 301 glEnableVertexAttribArray(pos_location);
301 glVertexAttribPointer(pos_location, 2, GL_FLOAT, GL_FALSE, 0, kVertices); 302 glVertexAttribPointer(pos_location, 2, GL_FLOAT, GL_FALSE, 0, kVertices);
302 int tc_location = glGetAttribLocation(program_, "in_tc"); 303 int tc_location = glGetAttribLocation(program_, "in_tc");
303 glEnableVertexAttribArray(tc_location); 304 glEnableVertexAttribArray(tc_location);
304 glVertexAttribPointer(tc_location, 2, GL_FLOAT, GL_FALSE, 0, kTextureCoords); 305 glVertexAttribPointer(tc_location, 2, GL_FLOAT, GL_FALSE, 0, kTextureCoords);
305 306
306 if (frame_duration_ != base::TimeDelta()) { 307 if (frame_duration_ != base::TimeDelta())
307 int warm_up_iterations = params.warm_up_iterations; 308 WarmUpRendering(params.warm_up_iterations);
308 WarmUpRendering(warm_up_iterations);
309 }
310 309
311 // It's safe to use Unretained here since |rendering_thread_| will be stopped 310 // It's safe to use Unretained here since |rendering_thread_| will be stopped
312 // in VideoDecodeAcceleratorTest.TearDown(), while the |rendering_helper_| is 311 // in VideoDecodeAcceleratorTest.TearDown(), while the |rendering_helper_| is
313 // a member of that class. (See video_decode_accelerator_unittest.cc.) 312 // a member of that class. (See video_decode_accelerator_unittest.cc.)
314 gfx::VSyncProvider* vsync_provider = gl_surface_->GetVSyncProvider(); 313 gfx::VSyncProvider* vsync_provider = gl_surface_->GetVSyncProvider();
315 if (vsync_provider && frame_duration_ != base::TimeDelta()) 314 if (vsync_provider)
316 vsync_provider->GetVSyncParameters(base::Bind( 315 vsync_provider->GetVSyncParameters(base::Bind(
317 &RenderingHelper::UpdateVSyncParameters, base::Unretained(this), done)); 316 &RenderingHelper::UpdateVSyncParameters, base::Unretained(this), done));
318 else 317 else
319 done->Signal(); 318 done->Signal();
320 } 319 }
321 320
322 // The rendering for the first few frames is slow (e.g., 100ms on Peach Pit). 321 // The rendering for the first few frames is slow (e.g., 100ms on Peach Pit).
323 // This affects the numbers measured in the performance test. We try to render 322 // This affects the numbers measured in the performance test. We try to render
324 // several frames here to warm up the rendering. 323 // several frames here to warm up the rendering.
325 void RenderingHelper::WarmUpRendering(int warm_up_iterations) { 324 void RenderingHelper::WarmUpRendering(int warm_up_iterations) {
326 unsigned int texture_id; 325 unsigned int texture_id;
327 scoped_ptr<GLubyte[]> emptyData(new GLubyte[screen_size_.GetArea() * 2]()); 326 scoped_ptr<GLubyte[]> emptyData(new GLubyte[screen_size_.GetArea() * 2]);
328 glGenTextures(1, &texture_id); 327 glGenTextures(1, &texture_id);
329 glBindTexture(GL_TEXTURE_2D, texture_id); 328 glBindTexture(GL_TEXTURE_2D, texture_id);
330 glTexImage2D(GL_TEXTURE_2D, 329 glTexImage2D(GL_TEXTURE_2D,
331 0, 330 0,
332 GL_RGB, 331 GL_RGB,
333 screen_size_.width(), 332 screen_size_.width(),
334 screen_size_.height(), 333 screen_size_.height(),
335 0, 334 0,
336 GL_RGB, 335 GL_RGB,
337 GL_UNSIGNED_SHORT_5_6_5, 336 GL_UNSIGNED_SHORT_5_6_5,
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 glBindTexture(texture_target, 0); 460 glBindTexture(texture_target, 0);
462 CHECK_EQ(static_cast<int>(glGetError()), GL_NO_ERROR); 461 CHECK_EQ(static_cast<int>(glGetError()), GL_NO_ERROR);
463 } 462 }
464 463
465 void RenderingHelper::DeleteTexture(uint32 texture_id) { 464 void RenderingHelper::DeleteTexture(uint32 texture_id) {
466 CHECK_EQ(base::MessageLoop::current(), message_loop_); 465 CHECK_EQ(base::MessageLoop::current(), message_loop_);
467 glDeleteTextures(1, &texture_id); 466 glDeleteTextures(1, &texture_id);
468 CHECK_EQ(static_cast<int>(glGetError()), GL_NO_ERROR); 467 CHECK_EQ(static_cast<int>(glGetError()), GL_NO_ERROR);
469 } 468 }
470 469
471 scoped_refptr<gfx::GLContext> RenderingHelper::GetGLContext() { 470 void* RenderingHelper::GetGLContext() {
472 return gl_context_;
473 }
474
475 void* RenderingHelper::GetGLContextHandle() {
476 return gl_context_->GetHandle(); 471 return gl_context_->GetHandle();
477 } 472 }
478 473
479 void* RenderingHelper::GetGLDisplay() { 474 void* RenderingHelper::GetGLDisplay() {
480 return gl_surface_->GetDisplay(); 475 return gl_surface_->GetDisplay();
481 } 476 }
482 477
483 void RenderingHelper::Clear() { 478 void RenderingHelper::Clear() {
484 videos_.clear(); 479 videos_.clear();
485 message_loop_ = NULL; 480 message_loop_ = NULL;
486 gl_context_ = NULL; 481 gl_context_ = NULL;
487 gl_surface_ = NULL; 482 gl_surface_ = NULL;
488 483
489 render_as_thumbnails_ = false; 484 render_as_thumbnails_ = false;
490 frame_count_ = 0; 485 frame_count_ = 0;
491 thumbnails_fbo_id_ = 0; 486 thumbnails_fbo_id_ = 0;
492 thumbnails_texture_id_ = 0; 487 thumbnails_texture_id_ = 0;
493 488
494 #if defined(OS_WIN) 489 #if defined(OS_WIN)
495 if (window_) 490 if (window_)
496 DestroyWindow(window_); 491 DestroyWindow(window_);
497 #elif defined(USE_X11) 492 #else
498 // Destroy resources acquired in Initialize, in reverse-acquisition order. 493 // Destroy resources acquired in Initialize, in reverse-acquisition order.
499 if (window_) { 494 if (window_) {
500 CHECK(XUnmapWindow(gfx::GetXDisplay(), window_)); 495 CHECK(XUnmapWindow(gfx::GetXDisplay(), window_));
501 CHECK(XDestroyWindow(gfx::GetXDisplay(), window_)); 496 CHECK(XDestroyWindow(gfx::GetXDisplay(), window_));
502 } 497 }
503 #endif 498 #endif
504 window_ = gfx::kNullAcceleratedWidget; 499 window_ = gfx::kNullAcceleratedWidget;
505 } 500 }
506 501
507 void RenderingHelper::GetThumbnailsAsRGB(std::vector<unsigned char>* rgb, 502 void RenderingHelper::GetThumbnailsAsRGB(std::vector<unsigned char>* rgb,
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
692 // When the rendering falls behind, drops frames. 687 // When the rendering falls behind, drops frames.
693 while (scheduled_render_time_ < target) { 688 while (scheduled_render_time_ < target) {
694 scheduled_render_time_ += frame_duration_; 689 scheduled_render_time_ += frame_duration_;
695 DropOneFrameForAllVideos(); 690 DropOneFrameForAllVideos();
696 } 691 }
697 692
698 message_loop_->PostDelayedTask( 693 message_loop_->PostDelayedTask(
699 FROM_HERE, render_task_.callback(), target - now); 694 FROM_HERE, render_task_.callback(), target - now);
700 } 695 }
701 } // namespace content 696 } // namespace content
OLDNEW
« no previous file with comments | « content/common/gpu/media/rendering_helper.h ('k') | content/common/gpu/media/va.sigs » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698