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

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

Issue 825163004: Add Vaapi support on Ozone/Freon (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: Created 5 years, 12 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
(...skipping 18 matching lines...) Expand all
29 #endif 29 #endif
30 30
31 #if defined(ARCH_CPU_X86_FAMILY) && defined(USE_X11) 31 #if defined(ARCH_CPU_X86_FAMILY) && defined(USE_X11)
32 #include "ui/gl/gl_surface_glx.h" 32 #include "ui/gl/gl_surface_glx.h"
33 #define GL_VARIANT_GLX 1 33 #define GL_VARIANT_GLX 1
34 #else 34 #else
35 #include "ui/gl/gl_surface_egl.h" 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 #if defined(USE_OZONE)
40 #if defined(OS_CHROMEOS)
41 #include "ui/display/chromeos/display_configurator.h"
42 #endif // defined(OS_CHROMEOS)
43 #include "ui/ozone/public/ozone_platform.h"
44 #include "ui/ozone/public/ui_thread_gpu.h"
45 #include "ui/platform_window/platform_window.h"
46 #include "ui/platform_window/platform_window_delegate.h"
47 #endif // defined(USE_OZONE)
48
39 // Helper for Shader creation. 49 // Helper for Shader creation.
40 static void CreateShader(GLuint program, 50 static void CreateShader(GLuint program,
41 GLenum type, 51 GLenum type,
42 const char* source, 52 const char* source,
43 int size) { 53 int size) {
44 GLuint shader = glCreateShader(type); 54 GLuint shader = glCreateShader(type);
45 glShaderSource(shader, 1, &source, &size); 55 glShaderSource(shader, 1, &source, &size);
46 glCompileShader(shader); 56 glCompileShader(shader);
47 int result = GL_FALSE; 57 int result = GL_FALSE;
48 glGetShaderiv(shader, GL_COMPILE_STATUS, &result); 58 glGetShaderiv(shader, GL_COMPILE_STATUS, &result);
49 if (!result) { 59 if (!result) {
50 char log[4096]; 60 char log[4096];
51 glGetShaderInfoLog(shader, arraysize(log), NULL, log); 61 glGetShaderInfoLog(shader, arraysize(log), NULL, log);
52 LOG(FATAL) << log; 62 LOG(FATAL) << log;
53 } 63 }
54 glAttachShader(program, shader); 64 glAttachShader(program, shader);
55 glDeleteShader(shader); 65 glDeleteShader(shader);
56 CHECK_EQ(static_cast<int>(glGetError()), GL_NO_ERROR); 66 CHECK_EQ(static_cast<int>(glGetError()), GL_NO_ERROR);
57 } 67 }
58 68
59 namespace content { 69 namespace content {
60 70
71 #if defined(USE_OZONE)
72
73 class RenderingHelper::StubOzoneDelegate : public ui::PlatformWindowDelegate {
74 public:
75 StubOzoneDelegate() : accelerated_widget_(gfx::kNullAcceleratedWidget) {
76 ui_thread_gpu_.Initialize();
77 platform_window_ = ui::OzonePlatform::GetInstance()->CreatePlatformWindow(
78 this, gfx::Rect());
79 }
80 virtual ~StubOzoneDelegate() {}
81
82 void OnBoundsChanged(const gfx::Rect& new_bounds) override {}
83
84 void OnDamageRect(const gfx::Rect& damaged_region) override {}
85
86 void DispatchEvent(ui::Event* event) override {}
87
88 void OnCloseRequest() override {}
89 void OnClosed() override {}
90
91 void OnWindowStateChanged(ui::PlatformWindowState new_state) override {}
92
93 void OnLostCapture() override {};
94
95 void OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget) override {
96 accelerated_widget_ = widget;
97 };
98
99 void OnActivationChanged(bool active) override {};
100
101 gfx::AcceleratedWidget accelerated_widget() const {
102 return accelerated_widget_;
103 }
104
105 gfx::Size GetSize() { return platform_window_->GetBounds().size(); }
106
107 ui::PlatformWindow* platform_window() const { return platform_window_.get(); }
108
109 private:
110 ui::UiThreadGpu ui_thread_gpu_;
111 scoped_ptr<ui::PlatformWindow> platform_window_;
112 gfx::AcceleratedWidget accelerated_widget_;
113
114 DISALLOW_COPY_AND_ASSIGN(StubOzoneDelegate);
115 };
116
117 #endif // defined(USE_OZONE)
118
61 RenderingHelperParams::RenderingHelperParams() 119 RenderingHelperParams::RenderingHelperParams()
62 : rendering_fps(0), warm_up_iterations(0), render_as_thumbnails(false) { 120 : rendering_fps(0), warm_up_iterations(0), render_as_thumbnails(false) {
63 } 121 }
64 122
65 RenderingHelperParams::~RenderingHelperParams() {} 123 RenderingHelperParams::~RenderingHelperParams() {}
66 124
67 VideoFrameTexture::VideoFrameTexture(uint32 texture_target, 125 VideoFrameTexture::VideoFrameTexture(uint32 texture_target,
68 uint32 texture_id, 126 uint32 texture_id,
69 const base::Closure& no_longer_needed_cb) 127 const base::Closure& no_longer_needed_cb)
70 : texture_target_(texture_target), 128 : texture_target_(texture_target),
(...skipping 15 matching lines...) Expand all
86 144
87 // static 145 // static
88 bool RenderingHelper::InitializeOneOff() { 146 bool RenderingHelper::InitializeOneOff() {
89 base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); 147 base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess();
90 #if GL_VARIANT_GLX 148 #if GL_VARIANT_GLX
91 cmd_line->AppendSwitchASCII(switches::kUseGL, 149 cmd_line->AppendSwitchASCII(switches::kUseGL,
92 gfx::kGLImplementationDesktopName); 150 gfx::kGLImplementationDesktopName);
93 #else 151 #else
94 cmd_line->AppendSwitchASCII(switches::kUseGL, gfx::kGLImplementationEGLName); 152 cmd_line->AppendSwitchASCII(switches::kUseGL, gfx::kGLImplementationEGLName);
95 #endif 153 #endif
154 #if defined(USE_OZONE)
155 ui::OzonePlatform::InitializeForUI();
156 #endif
96 return gfx::GLSurface::InitializeOneOff(); 157 return gfx::GLSurface::InitializeOneOff();
97 } 158 }
98 159
99 RenderingHelper::RenderingHelper() { 160 RenderingHelper::RenderingHelper() {
100 window_ = gfx::kNullAcceleratedWidget; 161 window_ = gfx::kNullAcceleratedWidget;
101 Clear(); 162 Clear();
102 } 163 }
103 164
104 RenderingHelper::~RenderingHelper() { 165 RenderingHelper::~RenderingHelper() {
105 CHECK_EQ(videos_.size(), 0U) << "Must call UnInitialize before dtor."; 166 CHECK_EQ(videos_.size(), 0U) << "Must call UnInitialize before dtor.";
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 XHeightOfScreen(screen), 221 XHeightOfScreen(screen),
161 0 /* border width */, 222 0 /* border width */,
162 depth, 223 depth,
163 CopyFromParent /* class */, 224 CopyFromParent /* class */,
164 CopyFromParent /* visual */, 225 CopyFromParent /* visual */,
165 (CWBackPixel | CWOverrideRedirect), 226 (CWBackPixel | CWOverrideRedirect),
166 &window_attributes); 227 &window_attributes);
167 XStoreName(display, window_, "VideoDecodeAcceleratorTest"); 228 XStoreName(display, window_, "VideoDecodeAcceleratorTest");
168 XSelectInput(display, window_, ExposureMask); 229 XSelectInput(display, window_, ExposureMask);
169 XMapWindow(display, window_); 230 XMapWindow(display, window_);
231 #elif defined(USE_OZONE)
232 platform_window_delegate_.reset(new RenderingHelper::StubOzoneDelegate());
233 window_ = platform_window_delegate_->accelerated_widget();
234 #if defined(OS_CHROMEOS)
235 display_configurator_.reset(new ui::DisplayConfigurator());
236 display_configurator_->Init(true);
237 display_configurator_->ForceInitialConfigure(0);
238 platform_window_delegate_->platform_window()->SetBounds(
239 gfx::Rect(display_configurator_->framebuffer_size()));
240 #else
241 platform_window_delegate_->platform_window()->SetBounds(gfx::Rect(800, 600));
242 #endif
170 #else 243 #else
171 #error unknown platform 244 #error unknown platform
172 #endif 245 #endif
173 CHECK(window_ != gfx::kNullAcceleratedWidget); 246 CHECK(window_ != gfx::kNullAcceleratedWidget);
174 247
175 gl_surface_ = gfx::GLSurface::CreateViewGLSurface(window_); 248 gl_surface_ = gfx::GLSurface::CreateViewGLSurface(window_);
176 screen_size_ = gl_surface_->GetSize(); 249 screen_size_ = gl_surface_->GetSize();
177 250
178 gl_context_ = gfx::GLContext::CreateGLContext( 251 gl_context_ = gfx::GLContext::CreateGLContext(
179 NULL, gl_surface_.get(), gfx::PreferIntegratedGpu); 252 NULL, gl_surface_.get(), gfx::PreferIntegratedGpu);
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 } 371 }
299 int pos_location = glGetAttribLocation(program_, "in_pos"); 372 int pos_location = glGetAttribLocation(program_, "in_pos");
300 glEnableVertexAttribArray(pos_location); 373 glEnableVertexAttribArray(pos_location);
301 glVertexAttribPointer(pos_location, 2, GL_FLOAT, GL_FALSE, 0, kVertices); 374 glVertexAttribPointer(pos_location, 2, GL_FLOAT, GL_FALSE, 0, kVertices);
302 int tc_location = glGetAttribLocation(program_, "in_tc"); 375 int tc_location = glGetAttribLocation(program_, "in_tc");
303 glEnableVertexAttribArray(tc_location); 376 glEnableVertexAttribArray(tc_location);
304 glVertexAttribPointer(tc_location, 2, GL_FLOAT, GL_FALSE, 0, kTextureCoords); 377 glVertexAttribPointer(tc_location, 2, GL_FLOAT, GL_FALSE, 0, kTextureCoords);
305 378
306 if (frame_duration_ != base::TimeDelta()) { 379 if (frame_duration_ != base::TimeDelta()) {
307 int warm_up_iterations = params.warm_up_iterations; 380 int warm_up_iterations = params.warm_up_iterations;
381 #if defined(USE_OZONE)
382 // On Ozone the VSyncProvider can't provide a vsync_internal until
Pawel Osciak 2014/12/26 00:38:55 s/vsync_internal/vsync interval/
llandwerlin-old 2014/12/26 02:50:00 Done.
383 // we render at least a frame, so we warm up with at least one
384 // frame.
385 // On top of this, we want to make sure all the buffers backing
386 // the GL surface are cleared, otherwise we can see the previous
387 // test's last frames, so we set warm up iterations to 2, to clear
388 // the front and back buffers.
389 warm_up_iterations = std::max(2, warm_up_iterations);
390 #endif
308 WarmUpRendering(warm_up_iterations); 391 WarmUpRendering(warm_up_iterations);
309 } 392 }
310 393
311 // It's safe to use Unretained here since |rendering_thread_| will be stopped 394 // It's safe to use Unretained here since |rendering_thread_| will be stopped
312 // in VideoDecodeAcceleratorTest.TearDown(), while the |rendering_helper_| is 395 // in VideoDecodeAcceleratorTest.TearDown(), while the |rendering_helper_| is
313 // a member of that class. (See video_decode_accelerator_unittest.cc.) 396 // a member of that class. (See video_decode_accelerator_unittest.cc.)
314 gfx::VSyncProvider* vsync_provider = gl_surface_->GetVSyncProvider(); 397 gfx::VSyncProvider* vsync_provider = gl_surface_->GetVSyncProvider();
315 if (vsync_provider && frame_duration_ != base::TimeDelta()) 398 if (vsync_provider && frame_duration_ != base::TimeDelta())
316 vsync_provider->GetVSyncParameters(base::Bind( 399 vsync_provider->GetVSyncParameters(base::Bind(
317 &RenderingHelper::UpdateVSyncParameters, base::Unretained(this), done)); 400 &RenderingHelper::UpdateVSyncParameters, base::Unretained(this), done));
(...skipping 21 matching lines...) Expand all
339 for (int i = 0; i < warm_up_iterations; ++i) { 422 for (int i = 0; i < warm_up_iterations; ++i) {
340 RenderTexture(GL_TEXTURE_2D, texture_id); 423 RenderTexture(GL_TEXTURE_2D, texture_id);
341 gl_surface_->SwapBuffers(); 424 gl_surface_->SwapBuffers();
342 } 425 }
343 glDeleteTextures(1, &texture_id); 426 glDeleteTextures(1, &texture_id);
344 } 427 }
345 428
346 void RenderingHelper::UnInitialize(base::WaitableEvent* done) { 429 void RenderingHelper::UnInitialize(base::WaitableEvent* done) {
347 CHECK_EQ(base::MessageLoop::current(), message_loop_); 430 CHECK_EQ(base::MessageLoop::current(), message_loop_);
348 431
432 #if defined(USE_OZONE) && defined(OS_CHROMEOS)
433 display_configurator_->PrepareForExit();
434 #endif
435
349 render_task_.Cancel(); 436 render_task_.Cancel();
350 437
351 if (render_as_thumbnails_) { 438 if (render_as_thumbnails_) {
352 glDeleteTextures(1, &thumbnails_texture_id_); 439 glDeleteTextures(1, &thumbnails_texture_id_);
353 glDeleteFramebuffersEXT(1, &thumbnails_fbo_id_); 440 glDeleteFramebuffersEXT(1, &thumbnails_fbo_id_);
354 } 441 }
355 442
356 gl_context_->ReleaseCurrent(gl_surface_.get()); 443 gl_context_->ReleaseCurrent(gl_surface_.get());
357 gl_context_ = NULL; 444 gl_context_ = NULL;
358 gl_surface_ = NULL; 445 gl_surface_ = NULL;
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 580
494 #if defined(OS_WIN) 581 #if defined(OS_WIN)
495 if (window_) 582 if (window_)
496 DestroyWindow(window_); 583 DestroyWindow(window_);
497 #elif defined(USE_X11) 584 #elif defined(USE_X11)
498 // Destroy resources acquired in Initialize, in reverse-acquisition order. 585 // Destroy resources acquired in Initialize, in reverse-acquisition order.
499 if (window_) { 586 if (window_) {
500 CHECK(XUnmapWindow(gfx::GetXDisplay(), window_)); 587 CHECK(XUnmapWindow(gfx::GetXDisplay(), window_));
501 CHECK(XDestroyWindow(gfx::GetXDisplay(), window_)); 588 CHECK(XDestroyWindow(gfx::GetXDisplay(), window_));
502 } 589 }
590 #elif defined(USE_OZONE)
591 platform_window_delegate_.reset();
503 #endif 592 #endif
504 window_ = gfx::kNullAcceleratedWidget; 593 window_ = gfx::kNullAcceleratedWidget;
505 } 594 }
506 595
507 void RenderingHelper::GetThumbnailsAsRGB(std::vector<unsigned char>* rgb, 596 void RenderingHelper::GetThumbnailsAsRGB(std::vector<unsigned char>* rgb,
508 bool* alpha_solid, 597 bool* alpha_solid,
509 base::WaitableEvent* done) { 598 base::WaitableEvent* done) {
510 CHECK(render_as_thumbnails_); 599 CHECK(render_as_thumbnails_);
511 600
512 const size_t num_pixels = thumbnails_fbo_size_.GetArea(); 601 const size_t num_pixels = thumbnails_fbo_size_.GetArea();
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
692 // When the rendering falls behind, drops frames. 781 // When the rendering falls behind, drops frames.
693 while (scheduled_render_time_ < target) { 782 while (scheduled_render_time_ < target) {
694 scheduled_render_time_ += frame_duration_; 783 scheduled_render_time_ += frame_duration_;
695 DropOneFrameForAllVideos(); 784 DropOneFrameForAllVideos();
696 } 785 }
697 786
698 message_loop_->PostDelayedTask( 787 message_loop_->PostDelayedTask(
699 FROM_HERE, render_task_.callback(), target - now); 788 FROM_HERE, render_task_.callback(), target - now);
700 } 789 }
701 } // namespace content 790 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698