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

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

Issue 1882373004: Migrate content/common/gpu/media code to media/gpu (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix prefix to content references in content_gpu.gypi Created 4 years, 8 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 "media/gpu/rendering_helper.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <numeric> 10 #include <numeric>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/bind.h" 13 #include "base/bind.h"
14 #include "base/callback_helpers.h" 14 #include "base/callback_helpers.h"
15 #include "base/command_line.h" 15 #include "base/command_line.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 if (!result) { 64 if (!result) {
65 char log[4096]; 65 char log[4096];
66 glGetShaderInfoLog(shader, arraysize(log), NULL, log); 66 glGetShaderInfoLog(shader, arraysize(log), NULL, log);
67 LOG(FATAL) << log; 67 LOG(FATAL) << log;
68 } 68 }
69 glAttachShader(program, shader); 69 glAttachShader(program, shader);
70 glDeleteShader(shader); 70 glDeleteShader(shader);
71 CHECK_EQ(static_cast<int>(glGetError()), GL_NO_ERROR); 71 CHECK_EQ(static_cast<int>(glGetError()), GL_NO_ERROR);
72 } 72 }
73 73
74 namespace content { 74 namespace media {
75 namespace { 75 namespace {
76 76
77 void WaitForSwapAck(const base::Closure& callback, gfx::SwapResult result) { 77 void WaitForSwapAck(const base::Closure& callback, gfx::SwapResult result) {
78 callback.Run(); 78 callback.Run();
79 } 79 }
80 80
81 } // namespace 81 } // namespace
82 82
83 #if defined(USE_OZONE) 83 #if defined(USE_OZONE)
84 84
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 119
120 void OnDamageRect(const gfx::Rect& damaged_region) override {} 120 void OnDamageRect(const gfx::Rect& damaged_region) override {}
121 121
122 void DispatchEvent(ui::Event* event) override {} 122 void DispatchEvent(ui::Event* event) override {}
123 123
124 void OnCloseRequest() override {} 124 void OnCloseRequest() override {}
125 void OnClosed() override {} 125 void OnClosed() override {}
126 126
127 void OnWindowStateChanged(ui::PlatformWindowState new_state) override {} 127 void OnWindowStateChanged(ui::PlatformWindowState new_state) override {}
128 128
129 void OnLostCapture() override {}; 129 void OnLostCapture() override{};
130 130
131 void OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget, 131 void OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget,
132 float device_pixel_ratio) override { 132 float device_pixel_ratio) override {
133 accelerated_widget_ = widget; 133 accelerated_widget_ = widget;
134 } 134 }
135 135
136 void OnAcceleratedWidgetDestroyed() override { 136 void OnAcceleratedWidgetDestroyed() override { NOTREACHED(); }
137 NOTREACHED();
138 }
139 137
140 void OnActivationChanged(bool active) override {}; 138 void OnActivationChanged(bool active) override{};
141 139
142 gfx::AcceleratedWidget accelerated_widget() const { 140 gfx::AcceleratedWidget accelerated_widget() const {
143 return accelerated_widget_; 141 return accelerated_widget_;
144 } 142 }
145 143
146 gfx::Size GetSize() { return platform_window_->GetBounds().size(); } 144 gfx::Size GetSize() { return platform_window_->GetBounds().size(); }
147 145
148 ui::PlatformWindow* platform_window() const { return platform_window_.get(); } 146 ui::PlatformWindow* platform_window() const { return platform_window_.get(); }
149 147
150 private: 148 private:
151 std::unique_ptr<ui::PlatformWindow> platform_window_; 149 std::unique_ptr<ui::PlatformWindow> platform_window_;
152 gfx::AcceleratedWidget accelerated_widget_; 150 gfx::AcceleratedWidget accelerated_widget_;
153 151
154 DISALLOW_COPY_AND_ASSIGN(StubOzoneDelegate); 152 DISALLOW_COPY_AND_ASSIGN(StubOzoneDelegate);
155 }; 153 };
156 154
157 #endif // defined(USE_OZONE) 155 #endif // defined(USE_OZONE)
158 156
159 RenderingHelperParams::RenderingHelperParams() 157 RenderingHelperParams::RenderingHelperParams()
160 : rendering_fps(0), warm_up_iterations(0), render_as_thumbnails(false) { 158 : rendering_fps(0), warm_up_iterations(0), render_as_thumbnails(false) {}
161 }
162 159
163 RenderingHelperParams::RenderingHelperParams( 160 RenderingHelperParams::RenderingHelperParams(
164 const RenderingHelperParams& other) = default; 161 const RenderingHelperParams& other) = default;
165 162
166 RenderingHelperParams::~RenderingHelperParams() {} 163 RenderingHelperParams::~RenderingHelperParams() {}
167 164
168 VideoFrameTexture::VideoFrameTexture(uint32_t texture_target, 165 VideoFrameTexture::VideoFrameTexture(uint32_t texture_target,
169 uint32_t texture_id, 166 uint32_t texture_id,
170 const base::Closure& no_longer_needed_cb) 167 const base::Closure& no_longer_needed_cb)
171 : texture_target_(texture_target), 168 : texture_target_(texture_target),
172 texture_id_(texture_id), 169 texture_id_(texture_id),
173 no_longer_needed_cb_(no_longer_needed_cb) { 170 no_longer_needed_cb_(no_longer_needed_cb) {
174 DCHECK(!no_longer_needed_cb_.is_null()); 171 DCHECK(!no_longer_needed_cb_.is_null());
175 } 172 }
176 173
177 VideoFrameTexture::~VideoFrameTexture() { 174 VideoFrameTexture::~VideoFrameTexture() {
178 base::ResetAndReturn(&no_longer_needed_cb_).Run(); 175 base::ResetAndReturn(&no_longer_needed_cb_).Run();
179 } 176 }
180 177
181 RenderingHelper::RenderedVideo::RenderedVideo() 178 RenderingHelper::RenderedVideo::RenderedVideo()
182 : is_flushing(false), frames_to_drop(0) { 179 : is_flushing(false), frames_to_drop(0) {}
183 }
184 180
185 RenderingHelper::RenderedVideo::RenderedVideo(const RenderedVideo& other) = 181 RenderingHelper::RenderedVideo::RenderedVideo(const RenderedVideo& other) =
186 default; 182 default;
187 183
188 RenderingHelper::RenderedVideo::~RenderedVideo() { 184 RenderingHelper::RenderedVideo::~RenderedVideo() {}
189 }
190 185
191 // static 186 // static
192 void RenderingHelper::InitializeOneOff(base::WaitableEvent* done) { 187 void RenderingHelper::InitializeOneOff(base::WaitableEvent* done) {
193 base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); 188 base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess();
194 #if GL_VARIANT_GLX 189 #if GL_VARIANT_GLX
195 cmd_line->AppendSwitchASCII(switches::kUseGL, 190 cmd_line->AppendSwitchASCII(switches::kUseGL,
196 gfx::kGLImplementationDesktopName); 191 gfx::kGLImplementationDesktopName);
197 #else 192 #else
198 cmd_line->AppendSwitchASCII(switches::kUseGL, gfx::kGLImplementationEGLName); 193 cmd_line->AppendSwitchASCII(switches::kUseGL, gfx::kGLImplementationEGLName);
199 #endif 194 #endif
200 195
201 if (!gfx::GLSurface::InitializeOneOff()) 196 if (!gfx::GLSurface::InitializeOneOff())
202 LOG(FATAL) << "Could not initialize GL"; 197 LOG(FATAL) << "Could not initialize GL";
203 done->Signal(); 198 done->Signal();
204 } 199 }
205 200
206 RenderingHelper::RenderingHelper() : ignore_vsync_(false) { 201 RenderingHelper::RenderingHelper() : ignore_vsync_(false) {
207 window_ = gfx::kNullAcceleratedWidget; 202 window_ = gfx::kNullAcceleratedWidget;
208 Clear(); 203 Clear();
209 } 204 }
210 205
211 RenderingHelper::~RenderingHelper() { 206 RenderingHelper::~RenderingHelper() {
212 CHECK_EQ(videos_.size(), 0U) << "Must call UnInitialize before dtor."; 207 CHECK_EQ(videos_.size(), 0U) << "Must call UnInitialize before dtor.";
213 Clear(); 208 Clear();
214 } 209 }
215 210
216 void RenderingHelper::Setup() { 211 void RenderingHelper::Setup() {
217 #if defined(OS_WIN) 212 #if defined(OS_WIN)
218 window_ = CreateWindowEx(0, 213 window_ = CreateWindowEx(
219 L"Static", 214 0, L"Static", L"VideoDecodeAcceleratorTest",
220 L"VideoDecodeAcceleratorTest", 215 WS_OVERLAPPEDWINDOW | WS_VISIBLE, 0, 0, GetSystemMetrics(SM_CXSCREEN),
221 WS_OVERLAPPEDWINDOW | WS_VISIBLE, 216 GetSystemMetrics(SM_CYSCREEN), NULL, NULL, NULL, NULL);
222 0,
223 0,
224 GetSystemMetrics(SM_CXSCREEN),
225 GetSystemMetrics(SM_CYSCREEN),
226 NULL,
227 NULL,
228 NULL,
229 NULL);
230 #elif defined(USE_X11) 217 #elif defined(USE_X11)
231 Display* display = gfx::GetXDisplay(); 218 Display* display = gfx::GetXDisplay();
232 Screen* screen = DefaultScreenOfDisplay(display); 219 Screen* screen = DefaultScreenOfDisplay(display);
233 220
234 CHECK(display); 221 CHECK(display);
235 222
236 XSetWindowAttributes window_attributes; 223 XSetWindowAttributes window_attributes;
237 memset(&window_attributes, 0, sizeof(window_attributes)); 224 memset(&window_attributes, 0, sizeof(window_attributes));
238 window_attributes.background_pixel = 225 window_attributes.background_pixel =
239 BlackPixel(display, DefaultScreen(display)); 226 BlackPixel(display, DefaultScreen(display));
240 window_attributes.override_redirect = true; 227 window_attributes.override_redirect = true;
241 int depth = DefaultDepth(display, DefaultScreen(display)); 228 int depth = DefaultDepth(display, DefaultScreen(display));
242 229
243 window_ = XCreateWindow(display, 230 window_ = XCreateWindow(
244 DefaultRootWindow(display), 231 display, DefaultRootWindow(display), 0, 0, XWidthOfScreen(screen),
245 0, 232 XHeightOfScreen(screen), 0 /* border width */, depth,
246 0, 233 CopyFromParent /* class */, CopyFromParent /* visual */,
247 XWidthOfScreen(screen), 234 (CWBackPixel | CWOverrideRedirect), &window_attributes);
248 XHeightOfScreen(screen),
249 0 /* border width */,
250 depth,
251 CopyFromParent /* class */,
252 CopyFromParent /* visual */,
253 (CWBackPixel | CWOverrideRedirect),
254 &window_attributes);
255 XStoreName(display, window_, "VideoDecodeAcceleratorTest"); 235 XStoreName(display, window_, "VideoDecodeAcceleratorTest");
256 XSelectInput(display, window_, ExposureMask); 236 XSelectInput(display, window_, ExposureMask);
257 XMapWindow(display, window_); 237 XMapWindow(display, window_);
258 #elif defined(USE_OZONE) 238 #elif defined(USE_OZONE)
259 base::MessageLoop::ScopedNestableTaskAllower nest_loop( 239 base::MessageLoop::ScopedNestableTaskAllower nest_loop(
260 base::MessageLoop::current()); 240 base::MessageLoop::current());
261 base::RunLoop wait_window_resize; 241 base::RunLoop wait_window_resize;
262 242
263 platform_window_delegate_.reset(new RenderingHelper::StubOzoneDelegate()); 243 platform_window_delegate_.reset(new RenderingHelper::StubOzoneDelegate());
264 window_ = platform_window_delegate_->accelerated_widget(); 244 window_ = platform_window_delegate_->accelerated_widget();
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 328
349 render_as_thumbnails_ = params.render_as_thumbnails; 329 render_as_thumbnails_ = params.render_as_thumbnails;
350 message_loop_ = base::MessageLoop::current(); 330 message_loop_ = base::MessageLoop::current();
351 331
352 gl_surface_ = gfx::GLSurface::CreateViewGLSurface(window_); 332 gl_surface_ = gfx::GLSurface::CreateViewGLSurface(window_);
353 #if defined(USE_OZONE) 333 #if defined(USE_OZONE)
354 gl_surface_->Resize(platform_window_delegate_->GetSize(), 1.f, true); 334 gl_surface_->Resize(platform_window_delegate_->GetSize(), 1.f, true);
355 #endif // defined(USE_OZONE) 335 #endif // defined(USE_OZONE)
356 screen_size_ = gl_surface_->GetSize(); 336 screen_size_ = gl_surface_->GetSize();
357 337
358 gl_context_ = gfx::GLContext::CreateGLContext( 338 gl_context_ = gfx::GLContext::CreateGLContext(NULL, gl_surface_.get(),
359 NULL, gl_surface_.get(), gfx::PreferIntegratedGpu); 339 gfx::PreferIntegratedGpu);
360 CHECK(gl_context_->MakeCurrent(gl_surface_.get())); 340 CHECK(gl_context_->MakeCurrent(gl_surface_.get()));
361 341
362 CHECK_GT(params.window_sizes.size(), 0U); 342 CHECK_GT(params.window_sizes.size(), 0U);
363 videos_.resize(params.window_sizes.size()); 343 videos_.resize(params.window_sizes.size());
364 LayoutRenderingAreas(params.window_sizes); 344 LayoutRenderingAreas(params.window_sizes);
365 345
366 if (render_as_thumbnails_) { 346 if (render_as_thumbnails_) {
367 CHECK_EQ(videos_.size(), 1U); 347 CHECK_EQ(videos_.size(), 1U);
368 348
369 GLint max_texture_size; 349 GLint max_texture_size;
370 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max_texture_size); 350 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max_texture_size);
371 CHECK_GE(max_texture_size, params.thumbnails_page_size.width()); 351 CHECK_GE(max_texture_size, params.thumbnails_page_size.width());
372 CHECK_GE(max_texture_size, params.thumbnails_page_size.height()); 352 CHECK_GE(max_texture_size, params.thumbnails_page_size.height());
373 353
374 thumbnails_fbo_size_ = params.thumbnails_page_size; 354 thumbnails_fbo_size_ = params.thumbnails_page_size;
375 thumbnail_size_ = params.thumbnail_size; 355 thumbnail_size_ = params.thumbnail_size;
376 356
377 glGenFramebuffersEXT(1, &thumbnails_fbo_id_); 357 glGenFramebuffersEXT(1, &thumbnails_fbo_id_);
378 glGenTextures(1, &thumbnails_texture_id_); 358 glGenTextures(1, &thumbnails_texture_id_);
379 glBindTexture(GL_TEXTURE_2D, thumbnails_texture_id_); 359 glBindTexture(GL_TEXTURE_2D, thumbnails_texture_id_);
380 glTexImage2D(GL_TEXTURE_2D, 360 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, thumbnails_fbo_size_.width(),
381 0, 361 thumbnails_fbo_size_.height(), 0, GL_RGB,
382 GL_RGB, 362 GL_UNSIGNED_SHORT_5_6_5, NULL);
383 thumbnails_fbo_size_.width(),
384 thumbnails_fbo_size_.height(),
385 0,
386 GL_RGB,
387 GL_UNSIGNED_SHORT_5_6_5,
388 NULL);
389 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 363 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
390 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 364 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
391 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 365 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
392 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 366 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
393 glBindTexture(GL_TEXTURE_2D, 0); 367 glBindTexture(GL_TEXTURE_2D, 0);
394 368
395 glBindFramebufferEXT(GL_FRAMEBUFFER, thumbnails_fbo_id_); 369 glBindFramebufferEXT(GL_FRAMEBUFFER, thumbnails_fbo_id_);
396 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, 370 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
397 GL_COLOR_ATTACHMENT0, 371 GL_TEXTURE_2D, thumbnails_texture_id_, 0);
398 GL_TEXTURE_2D,
399 thumbnails_texture_id_,
400 0);
401 372
402 GLenum fb_status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER); 373 GLenum fb_status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER);
403 CHECK(fb_status == GL_FRAMEBUFFER_COMPLETE) << fb_status; 374 CHECK(fb_status == GL_FRAMEBUFFER_COMPLETE) << fb_status;
404 glClearColor(0.0f, 0.0f, 0.0f, 1.0f); 375 glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
405 glClear(GL_COLOR_BUFFER_BIT); 376 glClear(GL_COLOR_BUFFER_BIT);
406 glBindFramebufferEXT(GL_FRAMEBUFFER, 377 glBindFramebufferEXT(GL_FRAMEBUFFER,
407 gl_surface_->GetBackingFrameBufferObject()); 378 gl_surface_->GetBackingFrameBufferObject());
408 } 379 }
409 380
410 // These vertices and texture coords. map (0,0) in the texture to the 381 // These vertices and texture coords. map (0,0) in the texture to the
411 // bottom left of the viewport. Since we get the video frames with the 382 // bottom left of the viewport. Since we get the video frames with the
412 // the top left at (0,0) we need to flip the texture y coordinate 383 // the top left at (0,0) we need to flip the texture y coordinate
413 // in the vertex shader for this to be rendered the right way up. 384 // in the vertex shader for this to be rendered the right way up.
414 // In the case of thumbnail rendering we use the same vertex shader 385 // In the case of thumbnail rendering we use the same vertex shader
415 // to render the FBO the screen, where we do not want this flipping. 386 // to render the FBO the screen, where we do not want this flipping.
416 static const float kVertices[] = 387 static const float kVertices[] = {
417 { -1.f, 1.f, -1.f, -1.f, 1.f, 1.f, 1.f, -1.f, }; 388 -1.f, 1.f, -1.f, -1.f, 1.f, 1.f, 1.f, -1.f,
418 static const float kTextureCoords[] = { 0, 1, 0, 0, 1, 1, 1, 0, }; 389 };
419 static const char kVertexShader[] = STRINGIZE( 390 static const float kTextureCoords[] = {
420 varying vec2 interp_tc; 391 0, 1, 0, 0, 1, 1, 1, 0,
421 attribute vec4 in_pos; 392 };
422 attribute vec2 in_tc; 393 static const char kVertexShader[] =
423 uniform bool tex_flip; 394 STRINGIZE(varying vec2 interp_tc; attribute vec4 in_pos;
424 void main() { 395 attribute vec2 in_tc; uniform bool tex_flip; void main() {
425 if (tex_flip) 396 if (tex_flip)
426 interp_tc = vec2(in_tc.x, 1.0 - in_tc.y); 397 interp_tc = vec2(in_tc.x, 1.0 - in_tc.y);
427 else 398 else
428 interp_tc = in_tc; 399 interp_tc = in_tc;
429 gl_Position = in_pos; 400 gl_Position = in_pos;
430 }); 401 });
431 402
432 #if GL_VARIANT_EGL 403 #if GL_VARIANT_EGL
433 static const char kFragmentShader[] = 404 static const char kFragmentShader[] =
434 "#extension GL_OES_EGL_image_external : enable\n" 405 "#extension GL_OES_EGL_image_external : enable\n"
435 "precision mediump float;\n" 406 "precision mediump float;\n"
436 "varying vec2 interp_tc;\n" 407 "varying vec2 interp_tc;\n"
437 "uniform sampler2D tex;\n" 408 "uniform sampler2D tex;\n"
438 "#ifdef GL_OES_EGL_image_external\n" 409 "#ifdef GL_OES_EGL_image_external\n"
439 "uniform samplerExternalOES tex_external;\n" 410 "uniform samplerExternalOES tex_external;\n"
440 "#endif\n" 411 "#endif\n"
441 "void main() {\n" 412 "void main() {\n"
442 " vec4 color = texture2D(tex, interp_tc);\n" 413 " vec4 color = texture2D(tex, interp_tc);\n"
443 "#ifdef GL_OES_EGL_image_external\n" 414 "#ifdef GL_OES_EGL_image_external\n"
444 " color += texture2D(tex_external, interp_tc);\n" 415 " color += texture2D(tex_external, interp_tc);\n"
445 "#endif\n" 416 "#endif\n"
446 " gl_FragColor = color;\n" 417 " gl_FragColor = color;\n"
447 "}\n"; 418 "}\n";
448 #else 419 #else
449 static const char kFragmentShader[] = STRINGIZE( 420 static const char kFragmentShader[] =
450 varying vec2 interp_tc; 421 STRINGIZE(varying vec2 interp_tc; uniform sampler2D tex;
451 uniform sampler2D tex; 422 void main() { gl_FragColor = texture2D(tex, interp_tc); });
452 void main() {
453 gl_FragColor = texture2D(tex, interp_tc);
454 });
455 #endif 423 #endif
456 program_ = glCreateProgram(); 424 program_ = glCreateProgram();
457 CreateShader( 425 CreateShader(program_, GL_VERTEX_SHADER, kVertexShader,
458 program_, GL_VERTEX_SHADER, kVertexShader, arraysize(kVertexShader)); 426 arraysize(kVertexShader));
459 CreateShader(program_, 427 CreateShader(program_, GL_FRAGMENT_SHADER, kFragmentShader,
460 GL_FRAGMENT_SHADER,
461 kFragmentShader,
462 arraysize(kFragmentShader)); 428 arraysize(kFragmentShader));
463 glLinkProgram(program_); 429 glLinkProgram(program_);
464 int result = GL_FALSE; 430 int result = GL_FALSE;
465 glGetProgramiv(program_, GL_LINK_STATUS, &result); 431 glGetProgramiv(program_, GL_LINK_STATUS, &result);
466 if (!result) { 432 if (!result) {
467 char log[4096]; 433 char log[4096];
468 glGetShaderInfoLog(program_, arraysize(log), NULL, log); 434 glGetShaderInfoLog(program_, arraysize(log), NULL, log);
469 LOG(FATAL) << log; 435 LOG(FATAL) << log;
470 } 436 }
471 glUseProgram(program_); 437 glUseProgram(program_);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 482
517 // The rendering for the first few frames is slow (e.g., 100ms on Peach Pit). 483 // The rendering for the first few frames is slow (e.g., 100ms on Peach Pit).
518 // This affects the numbers measured in the performance test. We try to render 484 // This affects the numbers measured in the performance test. We try to render
519 // several frames here to warm up the rendering. 485 // several frames here to warm up the rendering.
520 void RenderingHelper::WarmUpRendering(int warm_up_iterations) { 486 void RenderingHelper::WarmUpRendering(int warm_up_iterations) {
521 unsigned int texture_id; 487 unsigned int texture_id;
522 std::unique_ptr<GLubyte[]> emptyData( 488 std::unique_ptr<GLubyte[]> emptyData(
523 new GLubyte[screen_size_.GetArea() * 2]()); 489 new GLubyte[screen_size_.GetArea() * 2]());
524 glGenTextures(1, &texture_id); 490 glGenTextures(1, &texture_id);
525 glBindTexture(GL_TEXTURE_2D, texture_id); 491 glBindTexture(GL_TEXTURE_2D, texture_id);
526 glTexImage2D(GL_TEXTURE_2D, 492 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, screen_size_.width(),
527 0, 493 screen_size_.height(), 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5,
528 GL_RGB,
529 screen_size_.width(),
530 screen_size_.height(),
531 0,
532 GL_RGB,
533 GL_UNSIGNED_SHORT_5_6_5,
534 emptyData.get()); 494 emptyData.get());
535 for (int i = 0; i < warm_up_iterations; ++i) { 495 for (int i = 0; i < warm_up_iterations; ++i) {
536 RenderTexture(GL_TEXTURE_2D, texture_id); 496 RenderTexture(GL_TEXTURE_2D, texture_id);
537 497
538 // Need to allow nestable tasks since WarmUpRendering() is called from 498 // Need to allow nestable tasks since WarmUpRendering() is called from
539 // within another task on the renderer thread. 499 // within another task on the renderer thread.
540 base::MessageLoop::ScopedNestableTaskAllower allow( 500 base::MessageLoop::ScopedNestableTaskAllower allow(
541 base::MessageLoop::current()); 501 base::MessageLoop::current());
542 base::RunLoop wait_for_swap_ack; 502 base::RunLoop wait_for_swap_ack;
543 gl_surface_->SwapBuffersAsync( 503 gl_surface_->SwapBuffersAsync(
(...skipping 19 matching lines...) Expand all
563 523
564 Clear(); 524 Clear();
565 done->Signal(); 525 done->Signal();
566 } 526 }
567 527
568 void RenderingHelper::CreateTexture(uint32_t texture_target, 528 void RenderingHelper::CreateTexture(uint32_t texture_target,
569 uint32_t* texture_id, 529 uint32_t* texture_id,
570 const gfx::Size& size, 530 const gfx::Size& size,
571 base::WaitableEvent* done) { 531 base::WaitableEvent* done) {
572 if (base::MessageLoop::current() != message_loop_) { 532 if (base::MessageLoop::current() != message_loop_) {
573 message_loop_->PostTask(FROM_HERE, 533 message_loop_->PostTask(
574 base::Bind(&RenderingHelper::CreateTexture, 534 FROM_HERE,
575 base::Unretained(this), 535 base::Bind(&RenderingHelper::CreateTexture, base::Unretained(this),
576 texture_target, 536 texture_target, texture_id, size, done));
577 texture_id,
578 size,
579 done));
580 return; 537 return;
581 } 538 }
582 glGenTextures(1, texture_id); 539 glGenTextures(1, texture_id);
583 glBindTexture(texture_target, *texture_id); 540 glBindTexture(texture_target, *texture_id);
584 if (texture_target == GL_TEXTURE_2D) { 541 if (texture_target == GL_TEXTURE_2D) {
585 glTexImage2D(GL_TEXTURE_2D, 542 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, size.width(), size.height(), 0,
586 0, 543 GL_RGBA, GL_UNSIGNED_BYTE, NULL);
587 GL_RGBA,
588 size.width(),
589 size.height(),
590 0,
591 GL_RGBA,
592 GL_UNSIGNED_BYTE,
593 NULL);
594 } 544 }
595 glTexParameteri(texture_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 545 glTexParameteri(texture_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
596 glTexParameteri(texture_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 546 glTexParameteri(texture_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
597 // OpenGLES2.0.25 section 3.8.2 requires CLAMP_TO_EDGE for NPOT textures. 547 // OpenGLES2.0.25 section 3.8.2 requires CLAMP_TO_EDGE for NPOT textures.
598 glTexParameteri(texture_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 548 glTexParameteri(texture_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
599 glTexParameteri(texture_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 549 glTexParameteri(texture_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
600 CHECK_EQ(static_cast<int>(glGetError()), GL_NO_ERROR); 550 CHECK_EQ(static_cast<int>(glGetError()), GL_NO_ERROR);
601 done->Signal(); 551 done->Signal();
602 } 552 }
603 553
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
698 bool* alpha_solid, 648 bool* alpha_solid,
699 base::WaitableEvent* done) { 649 base::WaitableEvent* done) {
700 CHECK(render_as_thumbnails_); 650 CHECK(render_as_thumbnails_);
701 651
702 const size_t num_pixels = thumbnails_fbo_size_.GetArea(); 652 const size_t num_pixels = thumbnails_fbo_size_.GetArea();
703 std::vector<unsigned char> rgba; 653 std::vector<unsigned char> rgba;
704 rgba.resize(num_pixels * 4); 654 rgba.resize(num_pixels * 4);
705 glBindFramebufferEXT(GL_FRAMEBUFFER, thumbnails_fbo_id_); 655 glBindFramebufferEXT(GL_FRAMEBUFFER, thumbnails_fbo_id_);
706 glPixelStorei(GL_PACK_ALIGNMENT, 1); 656 glPixelStorei(GL_PACK_ALIGNMENT, 1);
707 // We can only count on GL_RGBA/GL_UNSIGNED_BYTE support. 657 // We can only count on GL_RGBA/GL_UNSIGNED_BYTE support.
708 glReadPixels(0, 658 glReadPixels(0, 0, thumbnails_fbo_size_.width(),
709 0, 659 thumbnails_fbo_size_.height(), GL_RGBA, GL_UNSIGNED_BYTE,
710 thumbnails_fbo_size_.width(),
711 thumbnails_fbo_size_.height(),
712 GL_RGBA,
713 GL_UNSIGNED_BYTE,
714 &rgba[0]); 660 &rgba[0]);
715 glBindFramebufferEXT(GL_FRAMEBUFFER, 661 glBindFramebufferEXT(GL_FRAMEBUFFER,
716 gl_surface_->GetBackingFrameBufferObject()); 662 gl_surface_->GetBackingFrameBufferObject());
717 rgb->resize(num_pixels * 3); 663 rgb->resize(num_pixels * 3);
718 // Drop the alpha channel, but check as we go that it is all 0xff. 664 // Drop the alpha channel, but check as we go that it is all 0xff.
719 bool solid = true; 665 bool solid = true;
720 unsigned char* rgb_ptr = &((*rgb)[0]); 666 unsigned char* rgb_ptr = &((*rgb)[0]);
721 unsigned char* rgba_ptr = &rgba[0]; 667 unsigned char* rgba_ptr = &rgba[0];
722 for (size_t i = 0; i < num_pixels; ++i) { 668 for (size_t i = 0; i < num_pixels; ++i) {
723 *rgb_ptr++ = *rgba_ptr++; 669 *rgb_ptr++ = *rgba_ptr++;
(...skipping 30 matching lines...) Expand all
754 #if defined(USE_OZONE) 700 #if defined(USE_OZONE)
755 // Ozone surfaceless renders flipped from normal GL, so there's no need to 701 // Ozone surfaceless renders flipped from normal GL, so there's no need to
756 // do an extra flip. 702 // do an extra flip.
757 tex_flip = 0; 703 tex_flip = 0;
758 #endif // defined(USE_OZONE) 704 #endif // defined(USE_OZONE)
759 glUniform1i(glGetUniformLocation(program_, "tex_flip"), tex_flip); 705 glUniform1i(glGetUniformLocation(program_, "tex_flip"), tex_flip);
760 706
761 // Frames that will be returned to the client (via the no_longer_needed_cb) 707 // Frames that will be returned to the client (via the no_longer_needed_cb)
762 // after this vector falls out of scope at the end of this method. We need 708 // after this vector falls out of scope at the end of this method. We need
763 // to keep references to them until after SwapBuffers() call below. 709 // to keep references to them until after SwapBuffers() call below.
764 std::vector<scoped_refptr<VideoFrameTexture> > frames_to_be_returned; 710 std::vector<scoped_refptr<VideoFrameTexture>> frames_to_be_returned;
765 bool need_swap_buffer = false; 711 bool need_swap_buffer = false;
766 if (render_as_thumbnails_) { 712 if (render_as_thumbnails_) {
767 // In render_as_thumbnails_ mode, we render the FBO content on the 713 // In render_as_thumbnails_ mode, we render the FBO content on the
768 // screen instead of the decoded textures. 714 // screen instead of the decoded textures.
769 GLSetViewPort(videos_[0].render_area); 715 GLSetViewPort(videos_[0].render_area);
770 RenderTexture(GL_TEXTURE_2D, thumbnails_texture_id_); 716 RenderTexture(GL_TEXTURE_2D, thumbnails_texture_id_);
771 need_swap_buffer = true; 717 need_swap_buffer = true;
772 } else { 718 } else {
773 for (RenderedVideo& video : videos_) { 719 for (RenderedVideo& video : videos_) {
774 if (video.pending_frames.empty()) 720 if (video.pending_frames.empty())
(...skipping 12 matching lines...) Expand all
787 } 733 }
788 } 734 }
789 735
790 base::Closure schedule_frame = base::Bind( 736 base::Closure schedule_frame = base::Bind(
791 &RenderingHelper::ScheduleNextRenderContent, base::Unretained(this)); 737 &RenderingHelper::ScheduleNextRenderContent, base::Unretained(this));
792 if (!need_swap_buffer) { 738 if (!need_swap_buffer) {
793 schedule_frame.Run(); 739 schedule_frame.Run();
794 return; 740 return;
795 } 741 }
796 742
797 gl_surface_->SwapBuffersAsync( 743 gl_surface_->SwapBuffersAsync(base::Bind(&WaitForSwapAck, schedule_frame));
798 base::Bind(&WaitForSwapAck, schedule_frame));
799 } 744 }
800 745
801 // Helper function for the LayoutRenderingAreas(). The |lengths| are the 746 // Helper function for the LayoutRenderingAreas(). The |lengths| are the
802 // heights(widths) of the rows(columns). It scales the elements in 747 // heights(widths) of the rows(columns). It scales the elements in
803 // |lengths| proportionally so that the sum of them equal to |total_length|. 748 // |lengths| proportionally so that the sum of them equal to |total_length|.
804 // It also outputs the coordinates of the rows(columns) to |offsets|. 749 // It also outputs the coordinates of the rows(columns) to |offsets|.
805 static void ScaleAndCalculateOffsets(std::vector<int>* lengths, 750 static void ScaleAndCalculateOffsets(std::vector<int>* lengths,
806 std::vector<int>* offsets, 751 std::vector<int>* offsets,
807 int total_length) { 752 int total_length) {
808 int sum = std::accumulate(lengths->begin(), lengths->end(), 0); 753 int sum = std::accumulate(lengths->begin(), lengths->end(), 0);
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
890 } else { 835 } else {
891 target = std::max(now, scheduled_render_time_); 836 target = std::max(now, scheduled_render_time_);
892 } 837 }
893 838
894 // When the rendering falls behind, drops frames. 839 // When the rendering falls behind, drops frames.
895 while (scheduled_render_time_ < target) { 840 while (scheduled_render_time_ < target) {
896 scheduled_render_time_ += frame_duration_; 841 scheduled_render_time_ += frame_duration_;
897 DropOneFrameForAllVideos(); 842 DropOneFrameForAllVideos();
898 } 843 }
899 844
900 message_loop_->PostDelayedTask( 845 message_loop_->PostDelayedTask(FROM_HERE, render_task_.callback(),
901 FROM_HERE, render_task_.callback(), target - now); 846 target - now);
902 } 847 }
903 } // namespace content 848 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698