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

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

Issue 940903002: video_decode_accelerator_unittest: enable test on ozone surfaceless (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix remaining thumbnail issues Created 5 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/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/run_loop.h" 16 #include "base/run_loop.h"
17 #include "base/strings/stringize_macros.h" 17 #include "base/strings/stringize_macros.h"
18 #include "base/synchronization/waitable_event.h" 18 #include "base/synchronization/waitable_event.h"
19 #include "base/time/time.h" 19 #include "base/time/time.h"
20 #include "content/common/gpu/media/gl_renderer.h"
20 #include "ui/gl/gl_context.h" 21 #include "ui/gl/gl_context.h"
21 #include "ui/gl/gl_implementation.h" 22 #include "ui/gl/gl_implementation.h"
22 #include "ui/gl/gl_surface.h" 23 #include "ui/gl/gl_surface.h"
23 24
24 #if defined(OS_WIN) 25 #if defined(OS_WIN)
25 #include <windows.h> 26 #include <windows.h>
26 #endif 27 #endif
27 28
28 #if defined(USE_X11) 29 #if defined(USE_X11)
29 #include "ui/gfx/x/x11_types.h" 30 #include "ui/gfx/x/x11_types.h"
30 #endif 31 #endif
31 32
32 #if defined(ARCH_CPU_X86_FAMILY) && defined(USE_X11) 33 #if defined(ARCH_CPU_X86_FAMILY) && defined(USE_X11)
33 #include "ui/gl/gl_surface_glx.h" 34 #include "ui/gl/gl_surface_glx.h"
34 #define GL_VARIANT_GLX 1 35 #define GL_VARIANT_GLX 1
35 #else 36 #else
36 #include "ui/gl/gl_surface_egl.h" 37 #include "ui/gl/gl_surface_egl.h"
37 #define GL_VARIANT_EGL 1 38 #define GL_VARIANT_EGL 1
38 #endif 39 #endif
39 40
40 #if defined(USE_OZONE) 41 #if defined(USE_OZONE)
42 #include "content/common/gpu/media/surfaceless_gl_renderer.h"
41 #if defined(OS_CHROMEOS) 43 #if defined(OS_CHROMEOS)
42 #include "ui/display/chromeos/display_configurator.h" 44 #include "ui/display/chromeos/display_configurator.h"
43 #endif // defined(OS_CHROMEOS) 45 #endif // defined(OS_CHROMEOS)
46 #include "ui/ozone/gpu/gpu_memory_buffer_factory_ozone_native_buffer.h"
44 #include "ui/ozone/public/ozone_platform.h" 47 #include "ui/ozone/public/ozone_platform.h"
48 #include "ui/ozone/public/ozone_switches.h"
45 #include "ui/platform_window/platform_window.h" 49 #include "ui/platform_window/platform_window.h"
46 #include "ui/platform_window/platform_window_delegate.h" 50 #include "ui/platform_window/platform_window_delegate.h"
47 #endif // defined(USE_OZONE) 51 #endif // defined(USE_OZONE)
48 52
49 // Helper for Shader creation. 53 // Helper for Shader creation.
50 static void CreateShader(GLuint program, 54 static void CreateShader(GLuint program,
51 GLenum type, 55 GLenum type,
52 const char* source, 56 const char* source,
53 int size) { 57 int size) {
54 GLuint shader = glCreateShader(type); 58 GLuint shader = glCreateShader(type);
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 void OnActivationChanged(bool active) override {}; 127 void OnActivationChanged(bool active) override {};
124 128
125 gfx::AcceleratedWidget accelerated_widget() const { 129 gfx::AcceleratedWidget accelerated_widget() const {
126 return accelerated_widget_; 130 return accelerated_widget_;
127 } 131 }
128 132
129 gfx::Size GetSize() { return platform_window_->GetBounds().size(); } 133 gfx::Size GetSize() { return platform_window_->GetBounds().size(); }
130 134
131 ui::PlatformWindow* platform_window() const { return platform_window_.get(); } 135 ui::PlatformWindow* platform_window() const { return platform_window_.get(); }
132 136
137 ui::GpuMemoryBufferFactoryOzoneNativeBuffer* buffer_factory() {
138 return &buffer_factory_;
139 }
140
133 private: 141 private:
142 // Used by the surfaceless renderers to allocate buffers.
143 ui::GpuMemoryBufferFactoryOzoneNativeBuffer buffer_factory_;
144
134 scoped_ptr<ui::PlatformWindow> platform_window_; 145 scoped_ptr<ui::PlatformWindow> platform_window_;
135 gfx::AcceleratedWidget accelerated_widget_; 146 gfx::AcceleratedWidget accelerated_widget_;
136 147
137 DISALLOW_COPY_AND_ASSIGN(StubOzoneDelegate); 148 DISALLOW_COPY_AND_ASSIGN(StubOzoneDelegate);
138 }; 149 };
139 150
140 #endif // defined(USE_OZONE) 151 #endif // defined(USE_OZONE)
141 152
142 RenderingHelperParams::RenderingHelperParams() 153 RenderingHelperParams::RenderingHelperParams()
143 : rendering_fps(0), warm_up_iterations(0), render_as_thumbnails(false) { 154 : rendering_fps(0), warm_up_iterations(0), render_as_thumbnails(false) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 done->Signal(); 191 done->Signal();
181 } 192 }
182 193
183 RenderingHelper::RenderingHelper() { 194 RenderingHelper::RenderingHelper() {
184 window_ = gfx::kNullAcceleratedWidget; 195 window_ = gfx::kNullAcceleratedWidget;
185 Clear(); 196 Clear();
186 } 197 }
187 198
188 RenderingHelper::~RenderingHelper() { 199 RenderingHelper::~RenderingHelper() {
189 CHECK_EQ(videos_.size(), 0U) << "Must call UnInitialize before dtor."; 200 CHECK_EQ(videos_.size(), 0U) << "Must call UnInitialize before dtor.";
190 Clear(); 201 CHECK(!gl_renderer_);
191 } 202 }
192 203
193 void RenderingHelper::Setup() { 204 void RenderingHelper::Setup() {
194 #if defined(OS_WIN) 205 #if defined(OS_WIN)
206 screen_size_ = gfx::Size(GetSystemMetrics(SM_CXSCREEN),
207 GetSystemMetrics(SM_CYSCREEN));
195 window_ = CreateWindowEx(0, 208 window_ = CreateWindowEx(0,
196 L"Static", 209 L"Static",
197 L"VideoDecodeAcceleratorTest", 210 L"VideoDecodeAcceleratorTest",
198 WS_OVERLAPPEDWINDOW | WS_VISIBLE, 211 WS_OVERLAPPEDWINDOW | WS_VISIBLE,
199 0, 212 0,
200 0, 213 0,
201 GetSystemMetrics(SM_CXSCREEN), 214 screen_size_.width(),
202 GetSystemMetrics(SM_CYSCREEN), 215 screen_size_.height(),
203 NULL, 216 NULL,
204 NULL, 217 NULL,
205 NULL, 218 NULL,
206 NULL); 219 NULL);
207 #elif defined(USE_X11) 220 #elif defined(USE_X11)
208 Display* display = gfx::GetXDisplay(); 221 Display* display = gfx::GetXDisplay();
209 Screen* screen = DefaultScreenOfDisplay(display); 222 Screen* screen = DefaultScreenOfDisplay(display);
210 223
211 CHECK(display); 224 CHECK(display);
212 225
213 XSetWindowAttributes window_attributes; 226 XSetWindowAttributes window_attributes;
214 memset(&window_attributes, 0, sizeof(window_attributes)); 227 memset(&window_attributes, 0, sizeof(window_attributes));
215 window_attributes.background_pixel = 228 window_attributes.background_pixel =
216 BlackPixel(display, DefaultScreen(display)); 229 BlackPixel(display, DefaultScreen(display));
217 window_attributes.override_redirect = true; 230 window_attributes.override_redirect = true;
218 int depth = DefaultDepth(display, DefaultScreen(display)); 231 int depth = DefaultDepth(display, DefaultScreen(display));
219 232
233 screen_size_ = gfx::Size(XWidthOfScreen(screen), XHeightOfScreen(screen));
234
220 window_ = XCreateWindow(display, 235 window_ = XCreateWindow(display,
221 DefaultRootWindow(display), 236 DefaultRootWindow(display),
222 0, 237 0,
223 0, 238 0,
224 XWidthOfScreen(screen), 239 screen_size_.width(),
225 XHeightOfScreen(screen), 240 screen_size_.height(),
226 0 /* border width */, 241 0 /* border width */,
227 depth, 242 depth,
228 CopyFromParent /* class */, 243 CopyFromParent /* class */,
229 CopyFromParent /* visual */, 244 CopyFromParent /* visual */,
230 (CWBackPixel | CWOverrideRedirect), 245 (CWBackPixel | CWOverrideRedirect),
231 &window_attributes); 246 &window_attributes);
232 XStoreName(display, window_, "VideoDecodeAcceleratorTest"); 247 XStoreName(display, window_, "VideoDecodeAcceleratorTest");
233 XSelectInput(display, window_, ExposureMask); 248 XSelectInput(display, window_, ExposureMask);
234 XMapWindow(display, window_); 249 XMapWindow(display, window_);
235 #elif defined(USE_OZONE) 250 #elif defined(USE_OZONE)
(...skipping 10 matching lines...) Expand all
246 base::RunLoop wait_display_setup; 261 base::RunLoop wait_display_setup;
247 DisplayConfiguratorObserver display_setup_observer(&wait_display_setup); 262 DisplayConfiguratorObserver display_setup_observer(&wait_display_setup);
248 display_configurator_.reset(new ui::DisplayConfigurator()); 263 display_configurator_.reset(new ui::DisplayConfigurator());
249 display_configurator_->AddObserver(&display_setup_observer); 264 display_configurator_->AddObserver(&display_setup_observer);
250 display_configurator_->Init(true); 265 display_configurator_->Init(true);
251 display_configurator_->ForceInitialConfigure(0); 266 display_configurator_->ForceInitialConfigure(0);
252 // Make sure all the display configuration is applied. 267 // Make sure all the display configuration is applied.
253 wait_display_setup.Run(); 268 wait_display_setup.Run();
254 display_configurator_->RemoveObserver(&display_setup_observer); 269 display_configurator_->RemoveObserver(&display_setup_observer);
255 270
271 screen_size_ = display_configurator_->framebuffer_size();
272 #else
273 screen_size_ = gfx::Size(800, 600));
274 #endif
256 platform_window_delegate_->platform_window()->SetBounds( 275 platform_window_delegate_->platform_window()->SetBounds(
257 gfx::Rect(display_configurator_->framebuffer_size())); 276 gfx::Rect(screen_size_));
258 #else
259 platform_window_delegate_->platform_window()->SetBounds(gfx::Rect(800, 600));
260 #endif
261 277
262 // On Ozone/DRI, platform windows are associated with the physical 278 // On Ozone/DRI, platform windows are associated with the physical
263 // outputs. Association is achieved by matching the bounds of the 279 // outputs. Association is achieved by matching the bounds of the
264 // window with the origin & modeset of the display output. Until a 280 // window with the origin & modeset of the display output. Until a
265 // window is associated with a display output, we cannot get vsync 281 // window is associated with a display output, we cannot get vsync
266 // events, because there is no hardware to get events from. Here we 282 // events, because there is no hardware to get events from. Here we
267 // wait for the window to resized and therefore associated with 283 // wait for the window to resized and therefore associated with
268 // display output to be sure that we will get such events. 284 // display output to be sure that we will get such events.
269 wait_window_resize.RunUntilIdle(); 285 wait_window_resize.RunUntilIdle();
270 #else 286 #else
(...skipping 25 matching lines...) Expand all
296 void RenderingHelper::Initialize(const RenderingHelperParams& params, 312 void RenderingHelper::Initialize(const RenderingHelperParams& params,
297 base::WaitableEvent* done) { 313 base::WaitableEvent* done) {
298 // Use videos_.size() != 0 as a proxy for the class having already been 314 // Use videos_.size() != 0 as a proxy for the class having already been
299 // Initialize()'d, and UnInitialize() before continuing. 315 // Initialize()'d, and UnInitialize() before continuing.
300 if (videos_.size()) { 316 if (videos_.size()) {
301 base::WaitableEvent done(false, false); 317 base::WaitableEvent done(false, false);
302 UnInitialize(&done); 318 UnInitialize(&done);
303 done.Wait(); 319 done.Wait();
304 } 320 }
305 321
322 #if defined(USE_OZONE)
323 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
324 if (command_line->HasSwitch(switches::kOzoneUseSurfaceless))
325 gl_renderer_.reset(new SurfacelessGlRenderer(
326 window_, screen_size_, platform_window_delegate_->buffer_factory()));
327 else
328 gl_renderer_.reset(new GlRenderer(window_, screen_size_));
329 #else
330 gl_renderer_.reset(new GlRenderer(window_, screen_size_));
331 #endif
332
333 CHECK(gl_renderer_->Initialize());
334
306 render_task_.Reset( 335 render_task_.Reset(
307 base::Bind(&RenderingHelper::RenderContent, base::Unretained(this))); 336 base::Bind(&RenderingHelper::RenderContent, base::Unretained(this)));
308 337
309 frame_duration_ = params.rendering_fps > 0 338 frame_duration_ = params.rendering_fps > 0
310 ? base::TimeDelta::FromSeconds(1) / params.rendering_fps 339 ? base::TimeDelta::FromSeconds(1) / params.rendering_fps
311 : base::TimeDelta(); 340 : base::TimeDelta();
312 341
313 render_as_thumbnails_ = params.render_as_thumbnails; 342 render_as_thumbnails_ = params.render_as_thumbnails;
314 message_loop_ = base::MessageLoop::current(); 343 message_loop_ = base::MessageLoop::current();
315 344
316 gl_surface_ = gfx::GLSurface::CreateViewGLSurface(window_); 345 CHECK(gl_renderer_->MakeCurrent());
317 screen_size_ = gl_surface_->GetSize();
318
319 gl_context_ = gfx::GLContext::CreateGLContext(
320 NULL, gl_surface_.get(), gfx::PreferIntegratedGpu);
321 CHECK(gl_context_->MakeCurrent(gl_surface_.get()));
322 346
323 CHECK_GT(params.window_sizes.size(), 0U); 347 CHECK_GT(params.window_sizes.size(), 0U);
324 videos_.resize(params.window_sizes.size()); 348 videos_.resize(params.window_sizes.size());
325 LayoutRenderingAreas(params.window_sizes); 349 LayoutRenderingAreas(params.window_sizes);
326 350
327 if (render_as_thumbnails_) { 351 if (render_as_thumbnails_) {
328 CHECK_EQ(videos_.size(), 1U); 352 CHECK_EQ(videos_.size(), 1U);
329 353
330 GLint max_texture_size; 354 GLint max_texture_size;
331 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max_texture_size); 355 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max_texture_size);
(...skipping 14 matching lines...) Expand all
346 0, 370 0,
347 GL_RGB, 371 GL_RGB,
348 GL_UNSIGNED_SHORT_5_6_5, 372 GL_UNSIGNED_SHORT_5_6_5,
349 NULL); 373 NULL);
350 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 374 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
351 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 375 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
352 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 376 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
353 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 377 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
354 glBindTexture(GL_TEXTURE_2D, 0); 378 glBindTexture(GL_TEXTURE_2D, 0);
355 379
356 glBindFramebufferEXT(GL_FRAMEBUFFER, thumbnails_fbo_id_); 380 gl_renderer_->BindFramebuffer(thumbnails_fbo_id_);
357 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, 381 glFramebufferTexture2DEXT(GL_FRAMEBUFFER,
358 GL_COLOR_ATTACHMENT0, 382 GL_COLOR_ATTACHMENT0,
359 GL_TEXTURE_2D, 383 GL_TEXTURE_2D,
360 thumbnails_texture_id_, 384 thumbnails_texture_id_,
361 0); 385 0);
362 386
363 GLenum fb_status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER); 387 GLenum fb_status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER);
364 CHECK(fb_status == GL_FRAMEBUFFER_COMPLETE) << fb_status; 388 CHECK(fb_status == GL_FRAMEBUFFER_COMPLETE) << fb_status;
365 glClearColor(0.0f, 0.0f, 0.0f, 1.0f); 389 glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
366 glClear(GL_COLOR_BUFFER_BIT); 390 glClear(GL_COLOR_BUFFER_BIT);
367 glBindFramebufferEXT(GL_FRAMEBUFFER, 0); 391 gl_renderer_->UnbindFramebuffer();
368 } 392 }
369 393
370 // These vertices and texture coords. map (0,0) in the texture to the 394 // These vertices and texture coords. map (0,0) in the texture to the
371 // bottom left of the viewport. Since we get the video frames with the 395 // bottom left of the viewport. Since we get the video frames with the
372 // the top left at (0,0) we need to flip the texture y coordinate 396 // the top left at (0,0) we need to flip the texture y coordinate
373 // in the vertex shader for this to be rendered the right way up. 397 // in the vertex shader for this to be rendered the right way up.
374 // In the case of thumbnail rendering we use the same vertex shader 398 // In the case of thumbnail rendering we use the same vertex shader
375 // to render the FBO the screen, where we do not want this flipping. 399 // to render the FBO the screen, where we do not want this flipping.
376 static const float kVertices[] = 400 static const float kVertices[] =
377 { -1.f, 1.f, -1.f, -1.f, 1.f, 1.f, 1.f, -1.f, }; 401 { -1.f, 1.f, -1.f, -1.f, 1.f, 1.f, 1.f, -1.f, };
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 int result = GL_FALSE; 448 int result = GL_FALSE;
425 glGetProgramiv(program_, GL_LINK_STATUS, &result); 449 glGetProgramiv(program_, GL_LINK_STATUS, &result);
426 if (!result) { 450 if (!result) {
427 char log[4096]; 451 char log[4096];
428 glGetShaderInfoLog(program_, arraysize(log), NULL, log); 452 glGetShaderInfoLog(program_, arraysize(log), NULL, log);
429 LOG(FATAL) << log; 453 LOG(FATAL) << log;
430 } 454 }
431 glUseProgram(program_); 455 glUseProgram(program_);
432 glDeleteProgram(program_); 456 glDeleteProgram(program_);
433 457
434 glUniform1i(glGetUniformLocation(program_, "tex_flip"), 0); 458 glUniform1i(glGetUniformLocation(program_, "tex_flip"),
459 gl_renderer_->IsFlipped() ? 0 : 1);
435 glUniform1i(glGetUniformLocation(program_, "tex"), 0); 460 glUniform1i(glGetUniformLocation(program_, "tex"), 0);
436 GLint tex_external = glGetUniformLocation(program_, "tex_external"); 461 GLint tex_external = glGetUniformLocation(program_, "tex_external");
437 if (tex_external != -1) { 462 if (tex_external != -1) {
438 glUniform1i(tex_external, 1); 463 glUniform1i(tex_external, 1);
439 } 464 }
440 int pos_location = glGetAttribLocation(program_, "in_pos"); 465 int pos_location = glGetAttribLocation(program_, "in_pos");
441 glEnableVertexAttribArray(pos_location); 466 glEnableVertexAttribArray(pos_location);
442 glVertexAttribPointer(pos_location, 2, GL_FLOAT, GL_FALSE, 0, kVertices); 467 glVertexAttribPointer(pos_location, 2, GL_FLOAT, GL_FALSE, 0, kVertices);
443 int tc_location = glGetAttribLocation(program_, "in_tc"); 468 int tc_location = glGetAttribLocation(program_, "in_tc");
444 glEnableVertexAttribArray(tc_location); 469 glEnableVertexAttribArray(tc_location);
(...skipping 10 matching lines...) Expand all
455 // test's last frames, so we set warm up iterations to 2, to clear 480 // test's last frames, so we set warm up iterations to 2, to clear
456 // the front and back buffers. 481 // the front and back buffers.
457 warm_up_iterations = std::max(2, warm_up_iterations); 482 warm_up_iterations = std::max(2, warm_up_iterations);
458 #endif 483 #endif
459 WarmUpRendering(warm_up_iterations); 484 WarmUpRendering(warm_up_iterations);
460 } 485 }
461 486
462 // It's safe to use Unretained here since |rendering_thread_| will be stopped 487 // It's safe to use Unretained here since |rendering_thread_| will be stopped
463 // in VideoDecodeAcceleratorTest.TearDown(), while the |rendering_helper_| is 488 // in VideoDecodeAcceleratorTest.TearDown(), while the |rendering_helper_| is
464 // a member of that class. (See video_decode_accelerator_unittest.cc.) 489 // a member of that class. (See video_decode_accelerator_unittest.cc.)
465 gfx::VSyncProvider* vsync_provider = gl_surface_->GetVSyncProvider(); 490 gfx::VSyncProvider* vsync_provider =
491 gl_renderer_->gl_surface()->GetVSyncProvider();
466 if (vsync_provider && frame_duration_ != base::TimeDelta()) 492 if (vsync_provider && frame_duration_ != base::TimeDelta())
467 vsync_provider->GetVSyncParameters(base::Bind( 493 vsync_provider->GetVSyncParameters(base::Bind(
468 &RenderingHelper::UpdateVSyncParameters, base::Unretained(this), done)); 494 &RenderingHelper::UpdateVSyncParameters, base::Unretained(this), done));
469 else 495 else
470 done->Signal(); 496 done->Signal();
471 } 497 }
472 498
473 // The rendering for the first few frames is slow (e.g., 100ms on Peach Pit). 499 // The rendering for the first few frames is slow (e.g., 100ms on Peach Pit).
474 // This affects the numbers measured in the performance test. We try to render 500 // This affects the numbers measured in the performance test. We try to render
475 // several frames here to warm up the rendering. 501 // several frames here to warm up the rendering.
476 void RenderingHelper::WarmUpRendering(int warm_up_iterations) { 502 void RenderingHelper::WarmUpRendering(int warm_up_iterations) {
477 unsigned int texture_id; 503 unsigned int texture_id;
478 scoped_ptr<GLubyte[]> emptyData(new GLubyte[screen_size_.GetArea() * 2]()); 504 scoped_ptr<GLubyte[]> emptyData(new GLubyte[screen_size_.GetArea() * 2]());
479 glGenTextures(1, &texture_id); 505 glGenTextures(1, &texture_id);
480 glBindTexture(GL_TEXTURE_2D, texture_id); 506 glBindTexture(GL_TEXTURE_2D, texture_id);
481 glTexImage2D(GL_TEXTURE_2D, 507 glTexImage2D(GL_TEXTURE_2D,
482 0, 508 0,
483 GL_RGB, 509 GL_RGB,
484 screen_size_.width(), 510 screen_size_.width(),
485 screen_size_.height(), 511 screen_size_.height(),
486 0, 512 0,
487 GL_RGB, 513 GL_RGB,
488 GL_UNSIGNED_SHORT_5_6_5, 514 GL_UNSIGNED_SHORT_5_6_5,
489 emptyData.get()); 515 emptyData.get());
490 for (int i = 0; i < warm_up_iterations; ++i) { 516 for (int i = 0; i < warm_up_iterations; ++i) {
491 RenderTexture(GL_TEXTURE_2D, texture_id); 517 RenderTexture(GL_TEXTURE_2D, texture_id);
492 gl_surface_->SwapBuffers(); 518 gl_renderer_->SwapBuffers();
493 } 519 }
494 glDeleteTextures(1, &texture_id); 520 glDeleteTextures(1, &texture_id);
495 } 521 }
496 522
497 void RenderingHelper::UnInitialize(base::WaitableEvent* done) { 523 void RenderingHelper::UnInitialize(base::WaitableEvent* done) {
498 CHECK_EQ(base::MessageLoop::current(), message_loop_); 524 CHECK_EQ(base::MessageLoop::current(), message_loop_);
499 525
500 render_task_.Cancel(); 526 render_task_.Cancel();
501 527
502 if (render_as_thumbnails_) { 528 if (render_as_thumbnails_) {
503 glDeleteTextures(1, &thumbnails_texture_id_); 529 glDeleteTextures(1, &thumbnails_texture_id_);
504 glDeleteFramebuffersEXT(1, &thumbnails_fbo_id_); 530 glDeleteFramebuffersEXT(1, &thumbnails_fbo_id_);
505 } 531 }
506 532
507 gl_context_->ReleaseCurrent(gl_surface_.get()); 533 Clear();
508 gl_context_ = NULL;
509 gl_surface_ = NULL;
510 534
511 Clear();
512 done->Signal(); 535 done->Signal();
513 } 536 }
514 537
515 void RenderingHelper::CreateTexture(uint32 texture_target, 538 void RenderingHelper::CreateTexture(uint32 texture_target,
516 uint32* texture_id, 539 uint32* texture_id,
517 const gfx::Size& size, 540 const gfx::Size& size,
518 base::WaitableEvent* done) { 541 base::WaitableEvent* done) {
519 if (base::MessageLoop::current() != message_loop_) { 542 if (base::MessageLoop::current() != message_loop_) {
520 message_loop_->PostTask(FROM_HERE, 543 message_loop_->PostTask(FROM_HERE,
521 base::Bind(&RenderingHelper::CreateTexture, 544 base::Bind(&RenderingHelper::CreateTexture,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 const int width = thumbnail_size_.width(); 583 const int width = thumbnail_size_.width();
561 const int height = thumbnail_size_.height(); 584 const int height = thumbnail_size_.height();
562 const int thumbnails_in_row = thumbnails_fbo_size_.width() / width; 585 const int thumbnails_in_row = thumbnails_fbo_size_.width() / width;
563 const int thumbnails_in_column = thumbnails_fbo_size_.height() / height; 586 const int thumbnails_in_column = thumbnails_fbo_size_.height() / height;
564 const int row = (frame_count_ / thumbnails_in_row) % thumbnails_in_column; 587 const int row = (frame_count_ / thumbnails_in_row) % thumbnails_in_column;
565 const int col = frame_count_ % thumbnails_in_row; 588 const int col = frame_count_ % thumbnails_in_row;
566 589
567 gfx::Rect area(col * width, row * height, width, height); 590 gfx::Rect area(col * width, row * height, width, height);
568 591
569 glUniform1i(glGetUniformLocation(program_, "tex_flip"), 0); 592 glUniform1i(glGetUniformLocation(program_, "tex_flip"), 0);
570 glBindFramebufferEXT(GL_FRAMEBUFFER, thumbnails_fbo_id_); 593 gl_renderer_->BindFramebuffer(thumbnails_fbo_id_);
571 GLSetViewPort(area); 594 GLSetViewPort(area);
572 RenderTexture(texture_target, texture_id); 595 RenderTexture(texture_target, texture_id);
573 glBindFramebufferEXT(GL_FRAMEBUFFER, 0); 596 gl_renderer_->UnbindFramebuffer();
574 597
575 // Need to flush the GL commands before we return the tnumbnail texture to 598 // Need to flush the GL commands before we return the tnumbnail texture to
576 // the decoder. 599 // the decoder.
577 glFlush(); 600 glFlush();
578 ++frame_count_; 601 ++frame_count_;
579 } 602 }
580 603
581 void RenderingHelper::QueueVideoFrame( 604 void RenderingHelper::QueueVideoFrame(
582 size_t window_id, 605 size_t window_id,
583 scoped_refptr<VideoFrameTexture> video_frame) { 606 scoped_refptr<VideoFrameTexture> video_frame) {
(...skipping 29 matching lines...) Expand all
613 CHECK_EQ(static_cast<int>(glGetError()), GL_NO_ERROR); 636 CHECK_EQ(static_cast<int>(glGetError()), GL_NO_ERROR);
614 } 637 }
615 638
616 void RenderingHelper::DeleteTexture(uint32 texture_id) { 639 void RenderingHelper::DeleteTexture(uint32 texture_id) {
617 CHECK_EQ(base::MessageLoop::current(), message_loop_); 640 CHECK_EQ(base::MessageLoop::current(), message_loop_);
618 glDeleteTextures(1, &texture_id); 641 glDeleteTextures(1, &texture_id);
619 CHECK_EQ(static_cast<int>(glGetError()), GL_NO_ERROR); 642 CHECK_EQ(static_cast<int>(glGetError()), GL_NO_ERROR);
620 } 643 }
621 644
622 scoped_refptr<gfx::GLContext> RenderingHelper::GetGLContext() { 645 scoped_refptr<gfx::GLContext> RenderingHelper::GetGLContext() {
623 return gl_context_; 646 return gl_renderer_->gl_context();
624 } 647 }
625 648
626 void* RenderingHelper::GetGLContextHandle() { 649 void* RenderingHelper::GetGLContextHandle() {
627 return gl_context_->GetHandle(); 650 return gl_renderer_->gl_context()->GetHandle();
628 } 651 }
629 652
630 void* RenderingHelper::GetGLDisplay() { 653 void* RenderingHelper::GetGLDisplay() {
631 return gl_surface_->GetDisplay(); 654 return gl_renderer_->gl_surface()->GetDisplay();
632 } 655 }
633 656
634 void RenderingHelper::Clear() { 657 void RenderingHelper::Clear() {
635 videos_.clear(); 658 videos_.clear();
636 message_loop_ = NULL; 659 message_loop_ = NULL;
637 gl_context_ = NULL;
638 gl_surface_ = NULL;
639 660
640 render_as_thumbnails_ = false; 661 render_as_thumbnails_ = false;
641 frame_count_ = 0; 662 frame_count_ = 0;
642 thumbnails_fbo_id_ = 0; 663 thumbnails_fbo_id_ = 0;
643 thumbnails_texture_id_ = 0; 664 thumbnails_texture_id_ = 0;
665
666 gl_renderer_.reset();
644 } 667 }
645 668
646 void RenderingHelper::GetThumbnailsAsRGB(std::vector<unsigned char>* rgb, 669 void RenderingHelper::GetThumbnailsAsRGB(std::vector<unsigned char>* rgb,
647 bool* alpha_solid, 670 bool* alpha_solid,
648 base::WaitableEvent* done) { 671 base::WaitableEvent* done) {
649 CHECK(render_as_thumbnails_); 672 CHECK(render_as_thumbnails_);
650 673
651 const size_t num_pixels = thumbnails_fbo_size_.GetArea(); 674 const size_t num_pixels = thumbnails_fbo_size_.GetArea();
652 std::vector<unsigned char> rgba; 675 std::vector<unsigned char> rgba;
653 rgba.resize(num_pixels * 4); 676 rgba.resize(num_pixels * 4);
654 glBindFramebufferEXT(GL_FRAMEBUFFER, thumbnails_fbo_id_); 677 gl_renderer_->BindFramebuffer(thumbnails_fbo_id_);
655 glPixelStorei(GL_PACK_ALIGNMENT, 1); 678 glPixelStorei(GL_PACK_ALIGNMENT, 1);
656 // We can only count on GL_RGBA/GL_UNSIGNED_BYTE support. 679 // We can only count on GL_RGBA/GL_UNSIGNED_BYTE support.
657 glReadPixels(0, 680 glReadPixels(0,
658 0, 681 0,
659 thumbnails_fbo_size_.width(), 682 thumbnails_fbo_size_.width(),
660 thumbnails_fbo_size_.height(), 683 thumbnails_fbo_size_.height(),
661 GL_RGBA, 684 GL_RGBA,
662 GL_UNSIGNED_BYTE, 685 GL_UNSIGNED_BYTE,
663 &rgba[0]); 686 &rgba[0]);
664 glBindFramebufferEXT(GL_FRAMEBUFFER, 0); 687 gl_renderer_->UnbindFramebuffer();
665 rgb->resize(num_pixels * 3); 688 rgb->resize(num_pixels * 3);
666 // Drop the alpha channel, but check as we go that it is all 0xff. 689 // Drop the alpha channel, but check as we go that it is all 0xff.
667 bool solid = true; 690 bool solid = true;
668 unsigned char* rgb_ptr = &((*rgb)[0]); 691 unsigned char* rgb_ptr = &((*rgb)[0]);
669 unsigned char* rgba_ptr = &rgba[0]; 692 unsigned char* rgba_ptr = &rgba[0];
670 for (size_t i = 0; i < num_pixels; ++i) { 693 for (size_t i = 0; i < num_pixels; ++i) {
671 *rgb_ptr++ = *rgba_ptr++; 694 *rgb_ptr++ = *rgba_ptr++;
672 *rgb_ptr++ = *rgba_ptr++; 695 *rgb_ptr++ = *rgba_ptr++;
673 *rgb_ptr++ = *rgba_ptr++; 696 *rgb_ptr++ = *rgba_ptr++;
674 solid = solid && (*rgba_ptr == 0xff); 697 solid = solid && (*rgba_ptr == 0xff);
675 rgba_ptr++; 698 rgba_ptr++;
676 } 699 }
677 *alpha_solid = solid; 700 *alpha_solid = solid;
678 701
679 done->Signal(); 702 done->Signal();
680 } 703 }
681 704
682 void RenderingHelper::Flush(size_t window_id) { 705 void RenderingHelper::Flush(size_t window_id) {
683 videos_[window_id].is_flushing = true; 706 videos_[window_id].is_flushing = true;
684 } 707 }
685 708
686 void RenderingHelper::RenderContent() { 709 void RenderingHelper::RenderContent() {
687 CHECK_EQ(base::MessageLoop::current(), message_loop_); 710 CHECK_EQ(base::MessageLoop::current(), message_loop_);
688 711
689 // Update the VSync params. 712 // Update the VSync params.
690 // 713 //
691 // It's safe to use Unretained here since |rendering_thread_| will be stopped 714 // It's safe to use Unretained here since |rendering_thread_| will be stopped
692 // in VideoDecodeAcceleratorTest.TearDown(), while the |rendering_helper_| is 715 // in VideoDecodeAcceleratorTest.TearDown(), while the |rendering_helper_| is
693 // a member of that class. (See video_decode_accelerator_unittest.cc.) 716 // a member of that class. (See video_decode_accelerator_unittest.cc.)
694 gfx::VSyncProvider* vsync_provider = gl_surface_->GetVSyncProvider(); 717 gfx::VSyncProvider* vsync_provider =
718 gl_renderer_->gl_surface()->GetVSyncProvider();
695 if (vsync_provider) { 719 if (vsync_provider) {
696 vsync_provider->GetVSyncParameters(base::Bind( 720 vsync_provider->GetVSyncParameters(base::Bind(
697 &RenderingHelper::UpdateVSyncParameters, base::Unretained(this), 721 &RenderingHelper::UpdateVSyncParameters, base::Unretained(this),
698 static_cast<base::WaitableEvent*>(NULL))); 722 static_cast<base::WaitableEvent*>(NULL)));
699 } 723 }
700 724
701 glUniform1i(glGetUniformLocation(program_, "tex_flip"), 1); 725 glUniform1i(glGetUniformLocation(program_, "tex_flip"),
726 gl_renderer_->IsFlipped() ? 0 : 1);
702 727
703 // Frames that will be returned to the client (via the no_longer_needed_cb) 728 // Frames that will be returned to the client (via the no_longer_needed_cb)
704 // after this vector falls out of scope at the end of this method. We need 729 // after this vector falls out of scope at the end of this method. We need
705 // to keep references to them until after SwapBuffers() call below. 730 // to keep references to them until after SwapBuffers() call below.
706 std::vector<scoped_refptr<VideoFrameTexture> > frames_to_be_returned; 731 std::vector<scoped_refptr<VideoFrameTexture> > frames_to_be_returned;
707 bool need_swap_buffer = false; 732 bool need_swap_buffer = false;
708 if (render_as_thumbnails_) { 733 if (render_as_thumbnails_) {
709 // In render_as_thumbnails_ mode, we render the FBO content on the 734 // In render_as_thumbnails_ mode, we render the FBO content on the
710 // screen instead of the decoded textures. 735 // screen instead of the decoded textures.
711 GLSetViewPort(videos_[0].render_area); 736 GLSetViewPort(videos_[0].render_area);
(...skipping 11 matching lines...) Expand all
723 if (video.pending_frames.size() > 1 || video.is_flushing) { 748 if (video.pending_frames.size() > 1 || video.is_flushing) {
724 frames_to_be_returned.push_back(video.pending_frames.front()); 749 frames_to_be_returned.push_back(video.pending_frames.front());
725 video.pending_frames.pop(); 750 video.pending_frames.pop();
726 } else { 751 } else {
727 ++video.frames_to_drop; 752 ++video.frames_to_drop;
728 } 753 }
729 } 754 }
730 } 755 }
731 756
732 if (need_swap_buffer) 757 if (need_swap_buffer)
733 gl_surface_->SwapBuffers(); 758 gl_renderer_->SwapBuffers();
734 759
735 ScheduleNextRenderContent(); 760 ScheduleNextRenderContent();
736 } 761 }
737 762
738 // Helper function for the LayoutRenderingAreas(). The |lengths| are the 763 // Helper function for the LayoutRenderingAreas(). The |lengths| are the
739 // heights(widths) of the rows(columns). It scales the elements in 764 // heights(widths) of the rows(columns). It scales the elements in
740 // |lengths| proportionally so that the sum of them equal to |total_length|. 765 // |lengths| proportionally so that the sum of them equal to |total_length|.
741 // It also outputs the coordinates of the rows(columns) to |offsets|. 766 // It also outputs the coordinates of the rows(columns) to |offsets|.
742 static void ScaleAndCalculateOffsets(std::vector<int>* lengths, 767 static void ScaleAndCalculateOffsets(std::vector<int>* lengths,
743 std::vector<int>* offsets, 768 std::vector<int>* offsets,
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
831 // When the rendering falls behind, drops frames. 856 // When the rendering falls behind, drops frames.
832 while (scheduled_render_time_ < target) { 857 while (scheduled_render_time_ < target) {
833 scheduled_render_time_ += frame_duration_; 858 scheduled_render_time_ += frame_duration_;
834 DropOneFrameForAllVideos(); 859 DropOneFrameForAllVideos();
835 } 860 }
836 861
837 message_loop_->PostDelayedTask( 862 message_loop_->PostDelayedTask(
838 FROM_HERE, render_task_.callback(), target - now); 863 FROM_HERE, render_task_.callback(), target - now);
839 } 864 }
840 } // namespace content 865 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698