Chromium Code Reviews| 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/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" | 22 #include "ui/gl/gl_surface_egl.h" |
|
Pawel Osciak
2014/11/03 01:36:51
Should this be under GL_VARIANT_EGL below?
| |
| 23 #include "ui/gl/gl_surface_glx.h" | |
| 24 | 23 |
| 25 #if defined(OS_WIN) | 24 #if defined(OS_WIN) |
| 26 #include <windows.h> | 25 #include <windows.h> |
| 27 #endif | 26 #endif |
| 28 | 27 |
| 29 #if defined(USE_X11) | 28 #if defined(USE_X11) |
| 30 #include "ui/gfx/x/x11_types.h" | 29 #include "ui/gfx/x/x11_types.h" |
| 31 #endif | 30 #include "ui/gl/gl_surface_glx.h" |
| 32 | |
| 33 #if !defined(OS_WIN) && defined(ARCH_CPU_X86_FAMILY) | |
| 34 #define GL_VARIANT_GLX 1 | 31 #define GL_VARIANT_GLX 1 |
| 35 #else | 32 #else |
| 36 #define GL_VARIANT_EGL 1 | 33 #define GL_VARIANT_EGL 1 |
| 37 #endif | 34 #endif |
| 38 | 35 |
| 36 #if defined(USE_OZONE) | |
| 37 #include "ui/ozone/public/ozone_platform.h" | |
| 38 #include "ui/ozone/public/ui_thread_gpu.h" | |
| 39 #include "ui/platform_window/platform_window.h" | |
| 40 #include "ui/platform_window/platform_window_delegate.h" | |
| 41 #endif | |
| 42 | |
| 39 // Helper for Shader creation. | 43 // Helper for Shader creation. |
| 40 static void CreateShader(GLuint program, | 44 static void CreateShader(GLuint program, |
| 41 GLenum type, | 45 GLenum type, |
| 42 const char* source, | 46 const char* source, |
| 43 int size) { | 47 int size) { |
| 44 GLuint shader = glCreateShader(type); | 48 GLuint shader = glCreateShader(type); |
| 45 glShaderSource(shader, 1, &source, &size); | 49 glShaderSource(shader, 1, &source, &size); |
| 46 glCompileShader(shader); | 50 glCompileShader(shader); |
| 47 int result = GL_FALSE; | 51 int result = GL_FALSE; |
| 48 glGetShaderiv(shader, GL_COMPILE_STATUS, &result); | 52 glGetShaderiv(shader, GL_COMPILE_STATUS, &result); |
| 49 if (!result) { | 53 if (!result) { |
| 50 char log[4096]; | 54 char log[4096]; |
| 51 glGetShaderInfoLog(shader, arraysize(log), NULL, log); | 55 glGetShaderInfoLog(shader, arraysize(log), NULL, log); |
| 52 LOG(FATAL) << log; | 56 LOG(FATAL) << log; |
| 53 } | 57 } |
| 54 glAttachShader(program, shader); | 58 glAttachShader(program, shader); |
| 55 glDeleteShader(shader); | 59 glDeleteShader(shader); |
| 56 CHECK_EQ(static_cast<int>(glGetError()), GL_NO_ERROR); | 60 CHECK_EQ(static_cast<int>(glGetError()), GL_NO_ERROR); |
| 57 } | 61 } |
| 58 | 62 |
| 59 namespace content { | 63 namespace content { |
| 60 | 64 |
| 65 #if defined(USE_OZONE) | |
| 66 | |
| 67 const int kTestWindowWidth = 800; | |
|
Pawel Osciak
2014/11/03 01:36:51
I realized, could we use a fullscreen window?
Owen Lin
2014/11/03 06:59:05
The performance on a non-fullscreen window is not
| |
| 68 const int kTestWindowHeight = 600; | |
| 69 | |
| 70 class RenderingHelper::StubOzoneDelegate : public ui::PlatformWindowDelegate { | |
| 71 public: | |
| 72 StubOzoneDelegate() : widget_(gfx::kNullAcceleratedWidget) { | |
| 73 platform_window_ = ui::OzonePlatform::GetInstance()->CreatePlatformWindow( | |
| 74 this, gfx::Rect(kTestWindowWidth, kTestWindowHeight)); | |
| 75 } | |
| 76 virtual ~StubOzoneDelegate() {} | |
| 77 | |
| 78 virtual void OnBoundsChanged(const gfx::Rect& new_bounds) override {} | |
| 79 | |
| 80 virtual void OnDamageRect(const gfx::Rect& damaged_region) override {} | |
| 81 | |
| 82 virtual void DispatchEvent(ui::Event* event) override {} | |
| 83 | |
| 84 virtual void OnCloseRequest() override {} | |
| 85 virtual void OnClosed() override {} | |
| 86 | |
| 87 virtual void OnWindowStateChanged( | |
| 88 ui::PlatformWindowState new_state) override{}; | |
|
Pawel Osciak
2014/11/03 01:36:51
Some methods have spaces after override and before
llandwerlin-old
2014/11/04 16:16:28
Acknowledged.
| |
| 89 | |
| 90 virtual void OnLostCapture() override{}; | |
| 91 | |
| 92 virtual void OnAcceleratedWidgetAvailable( | |
| 93 gfx::AcceleratedWidget widget) override { | |
| 94 widget_ = widget; | |
| 95 }; | |
| 96 | |
| 97 virtual void OnActivationChanged(bool active) override{}; | |
| 98 | |
| 99 gfx::AcceleratedWidget GetAcceleratedWidget() const { return widget_; } | |
| 100 | |
| 101 gfx::Size GetSize() { return platform_window_->GetBounds().size(); } | |
| 102 | |
| 103 private: | |
| 104 scoped_ptr<ui::PlatformWindow> platform_window_; | |
| 105 gfx::AcceleratedWidget widget_; | |
| 106 }; | |
| 107 | |
| 108 #endif // defined(USE_OZONE) | |
| 109 | |
| 61 RenderingHelperParams::RenderingHelperParams() | 110 RenderingHelperParams::RenderingHelperParams() |
| 62 : rendering_fps(0), warm_up_iterations(0), render_as_thumbnails(false) { | 111 : rendering_fps(0), warm_up_iterations(0), render_as_thumbnails(false) { |
| 63 } | 112 } |
| 64 | 113 |
| 65 RenderingHelperParams::~RenderingHelperParams() {} | 114 RenderingHelperParams::~RenderingHelperParams() {} |
| 66 | 115 |
| 67 VideoFrameTexture::VideoFrameTexture(uint32 texture_target, | 116 VideoFrameTexture::VideoFrameTexture(uint32 texture_target, |
| 68 uint32 texture_id, | 117 uint32 texture_id, |
| 69 const base::Closure& no_longer_needed_cb) | 118 const base::Closure& no_longer_needed_cb) |
| 70 : texture_target_(texture_target), | 119 : texture_target_(texture_target), |
| 71 texture_id_(texture_id), | 120 texture_id_(texture_id), |
| 72 no_longer_needed_cb_(no_longer_needed_cb) { | 121 no_longer_needed_cb_(no_longer_needed_cb) { |
| 73 DCHECK(!no_longer_needed_cb_.is_null()); | 122 DCHECK(!no_longer_needed_cb_.is_null()); |
| 74 } | 123 } |
| 75 | 124 |
| 76 VideoFrameTexture::~VideoFrameTexture() { | 125 VideoFrameTexture::~VideoFrameTexture() { |
| 77 base::ResetAndReturn(&no_longer_needed_cb_).Run(); | 126 base::ResetAndReturn(&no_longer_needed_cb_).Run(); |
| 78 } | 127 } |
| 79 | 128 |
| 80 RenderingHelper::RenderedVideo::RenderedVideo() | 129 RenderingHelper::RenderedVideo::RenderedVideo() |
| 81 : is_flushing(false), frames_to_drop(0) { | 130 : is_flushing(false), frames_to_drop(0) { |
| 82 } | 131 } |
| 83 | 132 |
| 84 RenderingHelper::RenderedVideo::~RenderedVideo() { | 133 RenderingHelper::RenderedVideo::~RenderedVideo() { |
| 85 } | 134 } |
| 86 | 135 |
| 87 // static | 136 // static |
| 88 bool RenderingHelper::InitializeOneOff() { | 137 bool RenderingHelper::InitializeOneOff() { |
| 89 base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); | 138 base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); |
| 139 | |
| 90 #if GL_VARIANT_GLX | 140 #if GL_VARIANT_GLX |
| 91 cmd_line->AppendSwitchASCII(switches::kUseGL, | 141 cmd_line->AppendSwitchASCII(switches::kUseGL, |
| 92 gfx::kGLImplementationDesktopName); | 142 gfx::kGLImplementationDesktopName); |
| 93 #else | 143 #else |
| 94 cmd_line->AppendSwitchASCII(switches::kUseGL, gfx::kGLImplementationEGLName); | 144 cmd_line->AppendSwitchASCII(switches::kUseGL, gfx::kGLImplementationEGLName); |
| 95 #endif | 145 #endif |
| 146 | |
| 147 #if defined(USE_OZONE) | |
| 148 static ui::UiThreadGpu ui_thread_gpu; | |
| 149 ui::OzonePlatform::InitializeForUI(); | |
| 150 return gfx::GLSurface::InitializeOneOff() && ui_thread_gpu.Initialize(); | |
| 151 #else | |
| 96 return gfx::GLSurface::InitializeOneOff(); | 152 return gfx::GLSurface::InitializeOneOff(); |
| 153 #endif | |
| 97 } | 154 } |
| 98 | 155 |
| 99 RenderingHelper::RenderingHelper() { | 156 RenderingHelper::RenderingHelper() { |
| 100 window_ = gfx::kNullAcceleratedWidget; | 157 window_ = gfx::kNullAcceleratedWidget; |
| 101 Clear(); | 158 Clear(); |
| 102 } | 159 } |
| 103 | 160 |
| 104 RenderingHelper::~RenderingHelper() { | 161 RenderingHelper::~RenderingHelper() { |
| 105 CHECK_EQ(videos_.size(), 0U) << "Must call UnInitialize before dtor."; | 162 CHECK_EQ(videos_.size(), 0U) << "Must call UnInitialize before dtor."; |
| 106 Clear(); | 163 Clear(); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 163 screen_size_.height(), | 220 screen_size_.height(), |
| 164 0 /* border width */, | 221 0 /* border width */, |
| 165 depth, | 222 depth, |
| 166 CopyFromParent /* class */, | 223 CopyFromParent /* class */, |
| 167 CopyFromParent /* visual */, | 224 CopyFromParent /* visual */, |
| 168 (CWBackPixel | CWOverrideRedirect), | 225 (CWBackPixel | CWOverrideRedirect), |
| 169 &window_attributes); | 226 &window_attributes); |
| 170 XStoreName(display, window_, "VideoDecodeAcceleratorTest"); | 227 XStoreName(display, window_, "VideoDecodeAcceleratorTest"); |
| 171 XSelectInput(display, window_, ExposureMask); | 228 XSelectInput(display, window_, ExposureMask); |
| 172 XMapWindow(display, window_); | 229 XMapWindow(display, window_); |
| 230 #elif defined(USE_OZONE) | |
| 231 platform_window_delegate_.reset(new RenderingHelper::StubOzoneDelegate()); | |
| 232 window_ = platform_window_delegate_->GetAcceleratedWidget(); | |
|
Owen Lin
2014/11/03 06:59:05
How could you make sure the widget_ is available n
llandwerlin-old
2014/11/04 16:16:28
When the DriWindow is created and initialized, it
| |
| 233 | |
| 234 screen_size_ = platform_window_delegate_->GetSize(); | |
| 173 #else | 235 #else |
| 174 #error unknown platform | 236 #error unknown platform |
| 175 #endif | 237 #endif |
| 176 CHECK(window_ != gfx::kNullAcceleratedWidget); | 238 CHECK(window_ != gfx::kNullAcceleratedWidget); |
| 177 | 239 |
| 178 gl_surface_ = gfx::GLSurface::CreateViewGLSurface(window_); | 240 gl_surface_ = gfx::GLSurface::CreateViewGLSurface(window_); |
| 179 gl_context_ = gfx::GLContext::CreateGLContext( | 241 gl_context_ = gfx::GLContext::CreateGLContext( |
| 180 NULL, gl_surface_.get(), gfx::PreferIntegratedGpu); | 242 NULL, gl_surface_.get(), gfx::PreferIntegratedGpu); |
|
Pawel Osciak
2014/11/03 01:36:51
ozone_demo also calls gl_surface_->Resize() here,
llandwerlin-old
2014/11/04 16:16:28
I haven't identified an ozone api to return the si
| |
| 181 gl_context_->MakeCurrent(gl_surface_.get()); | 243 gl_context_->MakeCurrent(gl_surface_.get()); |
|
Pawel Osciak
2014/11/03 01:36:50
Should we verify this succeeded?
llandwerlin-old
2014/11/04 16:16:28
Acknowledged.
| |
| 182 | 244 |
| 183 CHECK_GT(params.window_sizes.size(), 0U); | 245 CHECK_GT(params.window_sizes.size(), 0U); |
| 184 videos_.resize(params.window_sizes.size()); | 246 videos_.resize(params.window_sizes.size()); |
| 185 LayoutRenderingAreas(params.window_sizes); | 247 LayoutRenderingAreas(params.window_sizes); |
| 186 | 248 |
| 187 if (render_as_thumbnails_) { | 249 if (render_as_thumbnails_) { |
| 188 CHECK_EQ(videos_.size(), 1U); | 250 CHECK_EQ(videos_.size(), 1U); |
| 189 | 251 |
| 190 GLint max_texture_size; | 252 GLint max_texture_size; |
| 191 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max_texture_size); | 253 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max_texture_size); |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 297 if (tex_external != -1) { | 359 if (tex_external != -1) { |
| 298 glUniform1i(tex_external, 1); | 360 glUniform1i(tex_external, 1); |
| 299 } | 361 } |
| 300 int pos_location = glGetAttribLocation(program_, "in_pos"); | 362 int pos_location = glGetAttribLocation(program_, "in_pos"); |
| 301 glEnableVertexAttribArray(pos_location); | 363 glEnableVertexAttribArray(pos_location); |
| 302 glVertexAttribPointer(pos_location, 2, GL_FLOAT, GL_FALSE, 0, kVertices); | 364 glVertexAttribPointer(pos_location, 2, GL_FLOAT, GL_FALSE, 0, kVertices); |
| 303 int tc_location = glGetAttribLocation(program_, "in_tc"); | 365 int tc_location = glGetAttribLocation(program_, "in_tc"); |
| 304 glEnableVertexAttribArray(tc_location); | 366 glEnableVertexAttribArray(tc_location); |
| 305 glVertexAttribPointer(tc_location, 2, GL_FLOAT, GL_FALSE, 0, kTextureCoords); | 367 glVertexAttribPointer(tc_location, 2, GL_FLOAT, GL_FALSE, 0, kTextureCoords); |
| 306 | 368 |
| 307 if (frame_duration_ != base::TimeDelta()) | 369 WarmUpRendering(params.warm_up_iterations); |
|
Pawel Osciak
2014/11/03 01:36:51
Why is that if not needed anymore?
llandwerlin-old
2014/11/03 09:30:10
That seems to be a workaround for drivers that are
Owen Lin
2014/11/04 08:47:49
I think you still need the if. We use frame_durati
| |
| 308 WarmUpRendering(params.warm_up_iterations); | |
| 309 | 370 |
| 310 // It's safe to use Unretained here since |rendering_thread_| will be stopped | 371 // If this test doesn't do any rendering, just signal we're ready. |
| 311 // in VideoDecodeAcceleratorTest.TearDown(), while the |rendering_helper_| is | 372 if (params.suppress_rendering) |
|
Owen Lin
2014/11/03 06:59:06
We use "frame_duration == base::TimeDelta()" to de
llandwerlin-old
2014/11/03 09:30:10
To get a vsync_internal value, we need to render a
Owen Lin
2014/11/04 08:47:49
But it is not what I saw. In vda_unittest, there i
| |
| 312 // a member of that class. (See video_decode_accelerator_unittest.cc.) | 373 done->Signal(); |
| 313 gl_surface_->GetVSyncProvider()->GetVSyncParameters(base::Bind( | 374 else |
|
Pawel Osciak
2014/11/03 01:36:51
You could just drop else.
llandwerlin-old
2014/11/03 09:30:10
Ok, I would need to remove the done pointer too.
| |
| 314 &RenderingHelper::UpdateVSyncParameters, base::Unretained(this), done)); | 375 // It's safe to use Unretained here since |rendering_thread_| will be |
| 376 // stopped | |
| 377 // in VideoDecodeAcceleratorTest.TearDown(), while the |rendering_helper_| | |
| 378 // is | |
| 379 // a member of that class. (See video_decode_accelerator_unittest.cc.) | |
| 380 gl_surface_->GetVSyncProvider()->GetVSyncParameters(base::Bind( | |
| 381 &RenderingHelper::UpdateVSyncParameters, base::Unretained(this), done)); | |
| 315 } | 382 } |
| 316 | 383 |
| 317 // The rendering for the first few frames is slow (e.g., 100ms on Peach Pit). | 384 // The rendering for the first few frames is slow (e.g., 100ms on Peach Pit). |
| 318 // This affects the numbers measured in the performance test. We try to render | 385 // This affects the numbers measured in the performance test. We try to render |
| 319 // several frames here to warm up the rendering. | 386 // several frames here to warm up the rendering. |
| 320 void RenderingHelper::WarmUpRendering(int warm_up_iterations) { | 387 void RenderingHelper::WarmUpRendering(int warm_up_iterations) { |
| 321 unsigned int texture_id; | 388 unsigned int texture_id; |
| 322 scoped_ptr<GLubyte[]> emptyData(new GLubyte[screen_size_.GetArea() * 2]); | 389 scoped_ptr<GLubyte[]> emptyData(new GLubyte[screen_size_.GetArea() * 2]); |
| 323 glGenTextures(1, &texture_id); | 390 glGenTextures(1, &texture_id); |
| 324 glBindTexture(GL_TEXTURE_2D, texture_id); | 391 glBindTexture(GL_TEXTURE_2D, texture_id); |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 456 glBindTexture(texture_target, 0); | 523 glBindTexture(texture_target, 0); |
| 457 CHECK_EQ(static_cast<int>(glGetError()), GL_NO_ERROR); | 524 CHECK_EQ(static_cast<int>(glGetError()), GL_NO_ERROR); |
| 458 } | 525 } |
| 459 | 526 |
| 460 void RenderingHelper::DeleteTexture(uint32 texture_id) { | 527 void RenderingHelper::DeleteTexture(uint32 texture_id) { |
| 461 CHECK_EQ(base::MessageLoop::current(), message_loop_); | 528 CHECK_EQ(base::MessageLoop::current(), message_loop_); |
| 462 glDeleteTextures(1, &texture_id); | 529 glDeleteTextures(1, &texture_id); |
| 463 CHECK_EQ(static_cast<int>(glGetError()), GL_NO_ERROR); | 530 CHECK_EQ(static_cast<int>(glGetError()), GL_NO_ERROR); |
| 464 } | 531 } |
| 465 | 532 |
| 466 void* RenderingHelper::GetGLContext() { | 533 scoped_refptr<gfx::GLContext> RenderingHelper::GetGLContext() { |
| 534 return gl_context_; | |
| 535 } | |
| 536 | |
| 537 void* RenderingHelper::GetGLContextHandle() { | |
| 467 return gl_context_->GetHandle(); | 538 return gl_context_->GetHandle(); |
| 468 } | 539 } |
| 469 | 540 |
| 470 void* RenderingHelper::GetGLDisplay() { | 541 void* RenderingHelper::GetGLDisplay() { |
| 471 return gl_surface_->GetDisplay(); | 542 return gl_surface_->GetDisplay(); |
| 472 } | 543 } |
| 473 | 544 |
| 474 void RenderingHelper::Clear() { | 545 void RenderingHelper::Clear() { |
| 475 videos_.clear(); | 546 videos_.clear(); |
| 476 message_loop_ = NULL; | 547 message_loop_ = NULL; |
| 477 gl_context_ = NULL; | 548 gl_context_ = NULL; |
| 478 gl_surface_ = NULL; | 549 gl_surface_ = NULL; |
| 479 | 550 |
| 480 render_as_thumbnails_ = false; | 551 render_as_thumbnails_ = false; |
| 481 frame_count_ = 0; | 552 frame_count_ = 0; |
| 482 thumbnails_fbo_id_ = 0; | 553 thumbnails_fbo_id_ = 0; |
| 483 thumbnails_texture_id_ = 0; | 554 thumbnails_texture_id_ = 0; |
| 484 | 555 |
| 485 #if defined(OS_WIN) | 556 #if defined(OS_WIN) |
| 486 if (window_) | 557 if (window_) |
| 487 DestroyWindow(window_); | 558 DestroyWindow(window_); |
| 488 #else | 559 #elif defined(USE_X11) |
| 489 // Destroy resources acquired in Initialize, in reverse-acquisition order. | 560 // Destroy resources acquired in Initialize, in reverse-acquisition order. |
| 490 if (window_) { | 561 if (window_) { |
| 491 CHECK(XUnmapWindow(gfx::GetXDisplay(), window_)); | 562 CHECK(XUnmapWindow(gfx::GetXDisplay(), window_)); |
| 492 CHECK(XDestroyWindow(gfx::GetXDisplay(), window_)); | 563 CHECK(XDestroyWindow(gfx::GetXDisplay(), window_)); |
| 493 } | 564 } |
| 494 #endif | 565 #endif |
| 495 window_ = gfx::kNullAcceleratedWidget; | 566 window_ = gfx::kNullAcceleratedWidget; |
| 496 } | 567 } |
| 497 | 568 |
| 498 void RenderingHelper::GetThumbnailsAsRGB(std::vector<unsigned char>* rgb, | 569 void RenderingHelper::GetThumbnailsAsRGB(std::vector<unsigned char>* rgb, |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 552 | 623 |
| 553 // Frames that will be returned to the client (via the no_longer_needed_cb) | 624 // Frames that will be returned to the client (via the no_longer_needed_cb) |
| 554 // after this vector falls out of scope at the end of this method. We need | 625 // after this vector falls out of scope at the end of this method. We need |
| 555 // to keep references to them until after SwapBuffers() call below. | 626 // to keep references to them until after SwapBuffers() call below. |
| 556 std::vector<scoped_refptr<VideoFrameTexture> > frames_to_be_returned; | 627 std::vector<scoped_refptr<VideoFrameTexture> > frames_to_be_returned; |
| 557 bool need_swap_buffer = false; | 628 bool need_swap_buffer = false; |
| 558 if (render_as_thumbnails_) { | 629 if (render_as_thumbnails_) { |
| 559 // In render_as_thumbnails_ mode, we render the FBO content on the | 630 // In render_as_thumbnails_ mode, we render the FBO content on the |
| 560 // screen instead of the decoded textures. | 631 // screen instead of the decoded textures. |
| 561 GLSetViewPort(videos_[0].render_area); | 632 GLSetViewPort(videos_[0].render_area); |
| 633 glClearColor(0.0f, 0.0f, 0.0f, 1.0f); | |
|
Owen Lin
2014/11/03 06:59:06
Why we need to clear the color buffer, (I think vi
llandwerlin-old
2014/11/03 09:30:10
This was to workaround a bug in Mesa :
http://cgi
llandwerlin-old
2014/11/04 16:16:28
I need to leave it for the non thumbnail case, oth
| |
| 634 glClear(GL_COLOR_BUFFER_BIT); | |
| 562 RenderTexture(GL_TEXTURE_2D, thumbnails_texture_id_); | 635 RenderTexture(GL_TEXTURE_2D, thumbnails_texture_id_); |
| 563 need_swap_buffer = true; | 636 need_swap_buffer = true; |
| 564 } else { | 637 } else { |
| 638 GLSetViewPort(gfx::Rect(screen_size_)); | |
| 639 glClearColor(0.0f, 0.0f, 0.0f, 1.0f); | |
| 640 glClear(GL_COLOR_BUFFER_BIT); | |
| 565 for (RenderedVideo& video : videos_) { | 641 for (RenderedVideo& video : videos_) { |
| 566 if (video.pending_frames.empty()) | 642 if (video.pending_frames.empty()) |
| 567 continue; | 643 continue; |
| 568 need_swap_buffer = true; | 644 need_swap_buffer = true; |
| 569 scoped_refptr<VideoFrameTexture> frame = video.pending_frames.front(); | 645 scoped_refptr<VideoFrameTexture> frame = video.pending_frames.front(); |
| 570 GLSetViewPort(video.render_area); | 646 GLSetViewPort(video.render_area); |
| 571 RenderTexture(frame->texture_target(), frame->texture_id()); | 647 RenderTexture(frame->texture_target(), frame->texture_id()); |
| 572 | 648 |
| 573 if (video.pending_frames.size() > 1 || video.is_flushing) { | 649 if (video.pending_frames.size() > 1 || video.is_flushing) { |
| 574 frames_to_be_returned.push_back(video.pending_frames.front()); | 650 frames_to_be_returned.push_back(video.pending_frames.front()); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 658 video.pending_frames.pop(); | 734 video.pending_frames.pop(); |
| 659 } else { | 735 } else { |
| 660 ++video.frames_to_drop; | 736 ++video.frames_to_drop; |
| 661 } | 737 } |
| 662 } | 738 } |
| 663 } | 739 } |
| 664 | 740 |
| 665 void RenderingHelper::ScheduleNextRenderContent() { | 741 void RenderingHelper::ScheduleNextRenderContent() { |
| 666 scheduled_render_time_ += frame_duration_; | 742 scheduled_render_time_ += frame_duration_; |
| 667 | 743 |
| 668 // Schedules the next RenderContent() at latest VSYNC before the | 744 // If we couldn't figure out the vsync interval, just render as |
| 669 // |scheduled_render_time_|. | 745 // quick as possible. |
|
Pawel Osciak
2014/11/03 01:36:51
What if we are falling behind even if we are rende
Owen Lin
2014/11/03 06:59:05
Are you saying there won't be vsync info on ozone
llandwerlin-old
2014/11/03 09:30:10
As explained in another comment, we won't get a vs
Owen Lin
2014/11/04 08:47:49
We will wait forever on getting the vsync info in
| |
| 670 base::TimeTicks now = base::TimeTicks::Now(); | 746 if (vsync_interval_ > base::TimeDelta()) { |
| 671 base::TimeTicks target = | 747 // Schedules the next RenderContent() at latest VSYNC before the |
| 672 std::max(now + vsync_interval_, scheduled_render_time_); | 748 // |scheduled_render_time_|. |
| 749 base::TimeTicks now = base::TimeTicks::Now(); | |
| 750 base::TimeTicks target = | |
| 751 std::max(now + vsync_interval_, scheduled_render_time_); | |
| 673 | 752 |
| 674 int64 intervals = (target - vsync_timebase_) / vsync_interval_; | 753 int64 intervals = (target - vsync_timebase_) / vsync_interval_; |
| 675 target = vsync_timebase_ + intervals * vsync_interval_; | 754 target = vsync_timebase_ + intervals * vsync_interval_; |
| 676 | 755 |
| 677 // When the rendering falls behind, drops frames. | 756 // When the rendering falls behind, drops frames. |
| 678 while (scheduled_render_time_ < target) { | 757 while (scheduled_render_time_ < target) { |
| 679 scheduled_render_time_ += frame_duration_; | 758 scheduled_render_time_ += frame_duration_; |
| 680 DropOneFrameForAllVideos(); | 759 DropOneFrameForAllVideos(); |
| 760 } | |
| 761 message_loop_->PostDelayedTask( | |
| 762 FROM_HERE, render_task_.callback(), target - now); | |
| 763 } else { | |
| 764 message_loop_->PostTask(FROM_HERE, render_task_.callback()); | |
| 681 } | 765 } |
| 682 | |
| 683 message_loop_->PostDelayedTask( | |
| 684 FROM_HERE, render_task_.callback(), target - now); | |
| 685 } | 766 } |
| 686 } // namespace content | 767 } // namespace content |
| OLD | NEW |