| 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 "media/gpu/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 <memory> | 10 #include <memory> |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 Clear(); | 204 Clear(); |
| 205 } | 205 } |
| 206 | 206 |
| 207 RenderingHelper::~RenderingHelper() { | 207 RenderingHelper::~RenderingHelper() { |
| 208 CHECK_EQ(videos_.size(), 0U) << "Must call UnInitialize before dtor."; | 208 CHECK_EQ(videos_.size(), 0U) << "Must call UnInitialize before dtor."; |
| 209 Clear(); | 209 Clear(); |
| 210 } | 210 } |
| 211 | 211 |
| 212 void RenderingHelper::Setup() { | 212 void RenderingHelper::Setup() { |
| 213 #if defined(OS_WIN) | 213 #if defined(OS_WIN) |
| 214 window_ = CreateWindowEx( | 214 window_ = CreateWindowEx(0, |
| 215 0, L"Static", L"VideoDecodeAcceleratorTest", | 215 L"Static", |
| 216 WS_OVERLAPPEDWINDOW | WS_VISIBLE, 0, 0, GetSystemMetrics(SM_CXSCREEN), | 216 L"VideoDecodeAcceleratorTest", |
| 217 GetSystemMetrics(SM_CYSCREEN), NULL, NULL, NULL, NULL); | 217 WS_OVERLAPPEDWINDOW | WS_VISIBLE, |
| 218 0, 0, |
| 219 GetSystemMetrics(SM_CXSCREEN), |
| 220 GetSystemMetrics(SM_CYSCREEN), |
| 221 NULL, NULL, NULL, NULL); |
| 218 #elif defined(USE_X11) | 222 #elif defined(USE_X11) |
| 219 Display* display = gfx::GetXDisplay(); | 223 Display* display = gfx::GetXDisplay(); |
| 220 Screen* screen = DefaultScreenOfDisplay(display); | 224 Screen* screen = DefaultScreenOfDisplay(display); |
| 221 | 225 |
| 222 CHECK(display); | 226 CHECK(display); |
| 223 | 227 |
| 224 XSetWindowAttributes window_attributes; | 228 XSetWindowAttributes window_attributes; |
| 225 memset(&window_attributes, 0, sizeof(window_attributes)); | 229 memset(&window_attributes, 0, sizeof(window_attributes)); |
| 226 window_attributes.background_pixel = | 230 window_attributes.background_pixel = |
| 227 BlackPixel(display, DefaultScreen(display)); | 231 BlackPixel(display, DefaultScreen(display)); |
| 228 window_attributes.override_redirect = true; | 232 window_attributes.override_redirect = true; |
| 229 int depth = DefaultDepth(display, DefaultScreen(display)); | 233 int depth = DefaultDepth(display, DefaultScreen(display)); |
| 230 | 234 |
| 231 window_ = XCreateWindow( | 235 window_ = XCreateWindow(display, |
| 232 display, DefaultRootWindow(display), 0, 0, XWidthOfScreen(screen), | 236 DefaultRootWindow(display), |
| 233 XHeightOfScreen(screen), 0 /* border width */, depth, | 237 0, 0, |
| 234 CopyFromParent /* class */, CopyFromParent /* visual */, | 238 XWidthOfScreen(screen), |
| 235 (CWBackPixel | CWOverrideRedirect), &window_attributes); | 239 XHeightOfScreen(screen), |
| 240 0 /* border width */, |
| 241 depth, |
| 242 CopyFromParent /* class */, |
| 243 CopyFromParent /* visual */, |
| 244 (CWBackPixel | CWOverrideRedirect), |
| 245 &window_attributes); |
| 236 XStoreName(display, window_, "VideoDecodeAcceleratorTest"); | 246 XStoreName(display, window_, "VideoDecodeAcceleratorTest"); |
| 237 XSelectInput(display, window_, ExposureMask); | 247 XSelectInput(display, window_, ExposureMask); |
| 238 XMapWindow(display, window_); | 248 XMapWindow(display, window_); |
| 239 #elif defined(USE_OZONE) | 249 #elif defined(USE_OZONE) |
| 240 base::MessageLoop::ScopedNestableTaskAllower nest_loop( | 250 base::MessageLoop::ScopedNestableTaskAllower nest_loop( |
| 241 base::MessageLoop::current()); | 251 base::MessageLoop::current()); |
| 242 base::RunLoop wait_window_resize; | 252 base::RunLoop wait_window_resize; |
| 243 | 253 |
| 244 platform_window_delegate_.reset(new RenderingHelper::StubOzoneDelegate()); | 254 platform_window_delegate_.reset(new RenderingHelper::StubOzoneDelegate()); |
| 245 window_ = platform_window_delegate_->accelerated_widget(); | 255 window_ = platform_window_delegate_->accelerated_widget(); |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max_texture_size); | 360 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max_texture_size); |
| 351 CHECK_GE(max_texture_size, params.thumbnails_page_size.width()); | 361 CHECK_GE(max_texture_size, params.thumbnails_page_size.width()); |
| 352 CHECK_GE(max_texture_size, params.thumbnails_page_size.height()); | 362 CHECK_GE(max_texture_size, params.thumbnails_page_size.height()); |
| 353 | 363 |
| 354 thumbnails_fbo_size_ = params.thumbnails_page_size; | 364 thumbnails_fbo_size_ = params.thumbnails_page_size; |
| 355 thumbnail_size_ = params.thumbnail_size; | 365 thumbnail_size_ = params.thumbnail_size; |
| 356 | 366 |
| 357 glGenFramebuffersEXT(1, &thumbnails_fbo_id_); | 367 glGenFramebuffersEXT(1, &thumbnails_fbo_id_); |
| 358 glGenTextures(1, &thumbnails_texture_id_); | 368 glGenTextures(1, &thumbnails_texture_id_); |
| 359 glBindTexture(GL_TEXTURE_2D, thumbnails_texture_id_); | 369 glBindTexture(GL_TEXTURE_2D, thumbnails_texture_id_); |
| 360 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, thumbnails_fbo_size_.width(), | 370 glTexImage2D(GL_TEXTURE_2D, |
| 361 thumbnails_fbo_size_.height(), 0, GL_RGB, | 371 0, |
| 362 GL_UNSIGNED_SHORT_5_6_5, NULL); | 372 GL_RGB, |
| 373 thumbnails_fbo_size_.width(), thumbnails_fbo_size_.height(), |
| 374 0, |
| 375 GL_RGB, |
| 376 GL_UNSIGNED_SHORT_5_6_5, |
| 377 NULL); |
| 363 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 378 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 364 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 379 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 365 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | 380 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 366 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | 381 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 367 glBindTexture(GL_TEXTURE_2D, 0); | 382 glBindTexture(GL_TEXTURE_2D, 0); |
| 368 | 383 |
| 369 glBindFramebufferEXT(GL_FRAMEBUFFER, thumbnails_fbo_id_); | 384 glBindFramebufferEXT(GL_FRAMEBUFFER, thumbnails_fbo_id_); |
| 370 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, | 385 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, |
| 371 GL_TEXTURE_2D, thumbnails_texture_id_, 0); | 386 GL_TEXTURE_2D, thumbnails_texture_id_, 0); |
| 372 | 387 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 "#endif\n" | 426 "#endif\n" |
| 412 "void main() {\n" | 427 "void main() {\n" |
| 413 " vec4 color = texture2D(tex, interp_tc);\n" | 428 " vec4 color = texture2D(tex, interp_tc);\n" |
| 414 "#ifdef GL_OES_EGL_image_external\n" | 429 "#ifdef GL_OES_EGL_image_external\n" |
| 415 " color += texture2D(tex_external, interp_tc);\n" | 430 " color += texture2D(tex_external, interp_tc);\n" |
| 416 "#endif\n" | 431 "#endif\n" |
| 417 " gl_FragColor = color;\n" | 432 " gl_FragColor = color;\n" |
| 418 "}\n"; | 433 "}\n"; |
| 419 #else | 434 #else |
| 420 static const char kFragmentShader[] = | 435 static const char kFragmentShader[] = |
| 421 STRINGIZE(varying vec2 interp_tc; uniform sampler2D tex; | 436 STRINGIZE(varying vec2 interp_tc; |
| 422 void main() { gl_FragColor = texture2D(tex, interp_tc); }); | 437 uniform sampler2D tex; |
| 438 void main() { |
| 439 gl_FragColor = texture2D(tex, interp_tc); |
| 440 }); |
| 423 #endif | 441 #endif |
| 424 program_ = glCreateProgram(); | 442 program_ = glCreateProgram(); |
| 425 CreateShader(program_, GL_VERTEX_SHADER, kVertexShader, | 443 CreateShader(program_, GL_VERTEX_SHADER, kVertexShader, |
| 426 arraysize(kVertexShader)); | 444 arraysize(kVertexShader)); |
| 427 CreateShader(program_, GL_FRAGMENT_SHADER, kFragmentShader, | 445 CreateShader(program_, GL_FRAGMENT_SHADER, kFragmentShader, |
| 428 arraysize(kFragmentShader)); | 446 arraysize(kFragmentShader)); |
| 429 glLinkProgram(program_); | 447 glLinkProgram(program_); |
| 430 int result = GL_FALSE; | 448 int result = GL_FALSE; |
| 431 glGetProgramiv(program_, GL_LINK_STATUS, &result); | 449 glGetProgramiv(program_, GL_LINK_STATUS, &result); |
| 432 if (!result) { | 450 if (!result) { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 483 | 501 |
| 484 // The rendering for the first few frames is slow (e.g., 100ms on Peach Pit). | 502 // The rendering for the first few frames is slow (e.g., 100ms on Peach Pit). |
| 485 // This affects the numbers measured in the performance test. We try to render | 503 // This affects the numbers measured in the performance test. We try to render |
| 486 // several frames here to warm up the rendering. | 504 // several frames here to warm up the rendering. |
| 487 void RenderingHelper::WarmUpRendering(int warm_up_iterations) { | 505 void RenderingHelper::WarmUpRendering(int warm_up_iterations) { |
| 488 unsigned int texture_id; | 506 unsigned int texture_id; |
| 489 std::unique_ptr<GLubyte[]> emptyData( | 507 std::unique_ptr<GLubyte[]> emptyData( |
| 490 new GLubyte[screen_size_.GetArea() * 2]()); | 508 new GLubyte[screen_size_.GetArea() * 2]()); |
| 491 glGenTextures(1, &texture_id); | 509 glGenTextures(1, &texture_id); |
| 492 glBindTexture(GL_TEXTURE_2D, texture_id); | 510 glBindTexture(GL_TEXTURE_2D, texture_id); |
| 493 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, screen_size_.width(), | 511 glTexImage2D(GL_TEXTURE_2D, |
| 494 screen_size_.height(), 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, | 512 0, |
| 513 GL_RGB, |
| 514 screen_size_.width(), screen_size_.height(), |
| 515 0, |
| 516 GL_RGB, |
| 517 GL_UNSIGNED_SHORT_5_6_5, |
| 495 emptyData.get()); | 518 emptyData.get()); |
| 496 for (int i = 0; i < warm_up_iterations; ++i) { | 519 for (int i = 0; i < warm_up_iterations; ++i) { |
| 497 RenderTexture(GL_TEXTURE_2D, texture_id); | 520 RenderTexture(GL_TEXTURE_2D, texture_id); |
| 498 | 521 |
| 499 // Need to allow nestable tasks since WarmUpRendering() is called from | 522 // Need to allow nestable tasks since WarmUpRendering() is called from |
| 500 // within another task on the renderer thread. | 523 // within another task on the renderer thread. |
| 501 base::MessageLoop::ScopedNestableTaskAllower allow( | 524 base::MessageLoop::ScopedNestableTaskAllower allow( |
| 502 base::MessageLoop::current()); | 525 base::MessageLoop::current()); |
| 503 base::RunLoop wait_for_swap_ack; | 526 base::RunLoop wait_for_swap_ack; |
| 504 gl_surface_->SwapBuffersAsync( | 527 gl_surface_->SwapBuffersAsync( |
| (...skipping 28 matching lines...) Expand all Loading... |
| 533 if (base::MessageLoop::current() != message_loop_) { | 556 if (base::MessageLoop::current() != message_loop_) { |
| 534 message_loop_->PostTask( | 557 message_loop_->PostTask( |
| 535 FROM_HERE, | 558 FROM_HERE, |
| 536 base::Bind(&RenderingHelper::CreateTexture, base::Unretained(this), | 559 base::Bind(&RenderingHelper::CreateTexture, base::Unretained(this), |
| 537 texture_target, texture_id, size, done)); | 560 texture_target, texture_id, size, done)); |
| 538 return; | 561 return; |
| 539 } | 562 } |
| 540 glGenTextures(1, texture_id); | 563 glGenTextures(1, texture_id); |
| 541 glBindTexture(texture_target, *texture_id); | 564 glBindTexture(texture_target, *texture_id); |
| 542 if (texture_target == GL_TEXTURE_2D) { | 565 if (texture_target == GL_TEXTURE_2D) { |
| 543 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, size.width(), size.height(), 0, | 566 glTexImage2D(GL_TEXTURE_2D, |
| 544 GL_RGBA, GL_UNSIGNED_BYTE, NULL); | 567 0, |
| 568 GL_RGBA, |
| 569 size.width(), size.height(), |
| 570 0, |
| 571 GL_RGBA, |
| 572 GL_UNSIGNED_BYTE, |
| 573 NULL); |
| 545 } | 574 } |
| 546 glTexParameteri(texture_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | 575 glTexParameteri(texture_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 547 glTexParameteri(texture_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | 576 glTexParameteri(texture_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 548 // OpenGLES2.0.25 section 3.8.2 requires CLAMP_TO_EDGE for NPOT textures. | 577 // OpenGLES2.0.25 section 3.8.2 requires CLAMP_TO_EDGE for NPOT textures. |
| 549 glTexParameteri(texture_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 578 glTexParameteri(texture_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 550 glTexParameteri(texture_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 579 glTexParameteri(texture_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 551 CHECK_EQ(static_cast<int>(glGetError()), GL_NO_ERROR); | 580 CHECK_EQ(static_cast<int>(glGetError()), GL_NO_ERROR); |
| 552 done->Signal(); | 581 done->Signal(); |
| 553 } | 582 } |
| 554 | 583 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 649 bool* alpha_solid, | 678 bool* alpha_solid, |
| 650 base::WaitableEvent* done) { | 679 base::WaitableEvent* done) { |
| 651 CHECK(render_as_thumbnails_); | 680 CHECK(render_as_thumbnails_); |
| 652 | 681 |
| 653 const size_t num_pixels = thumbnails_fbo_size_.GetArea(); | 682 const size_t num_pixels = thumbnails_fbo_size_.GetArea(); |
| 654 std::vector<unsigned char> rgba; | 683 std::vector<unsigned char> rgba; |
| 655 rgba.resize(num_pixels * 4); | 684 rgba.resize(num_pixels * 4); |
| 656 glBindFramebufferEXT(GL_FRAMEBUFFER, thumbnails_fbo_id_); | 685 glBindFramebufferEXT(GL_FRAMEBUFFER, thumbnails_fbo_id_); |
| 657 glPixelStorei(GL_PACK_ALIGNMENT, 1); | 686 glPixelStorei(GL_PACK_ALIGNMENT, 1); |
| 658 // We can only count on GL_RGBA/GL_UNSIGNED_BYTE support. | 687 // We can only count on GL_RGBA/GL_UNSIGNED_BYTE support. |
| 659 glReadPixels(0, 0, thumbnails_fbo_size_.width(), | 688 glReadPixels(0, 0, |
| 660 thumbnails_fbo_size_.height(), GL_RGBA, GL_UNSIGNED_BYTE, | 689 thumbnails_fbo_size_.width(), thumbnails_fbo_size_.height(), |
| 690 GL_RGBA, |
| 691 GL_UNSIGNED_BYTE, |
| 661 &rgba[0]); | 692 &rgba[0]); |
| 662 glBindFramebufferEXT(GL_FRAMEBUFFER, | 693 glBindFramebufferEXT(GL_FRAMEBUFFER, |
| 663 gl_surface_->GetBackingFrameBufferObject()); | 694 gl_surface_->GetBackingFrameBufferObject()); |
| 664 rgb->resize(num_pixels * 3); | 695 rgb->resize(num_pixels * 3); |
| 665 // Drop the alpha channel, but check as we go that it is all 0xff. | 696 // Drop the alpha channel, but check as we go that it is all 0xff. |
| 666 bool solid = true; | 697 bool solid = true; |
| 667 unsigned char* rgb_ptr = &((*rgb)[0]); | 698 unsigned char* rgb_ptr = &((*rgb)[0]); |
| 668 unsigned char* rgba_ptr = &rgba[0]; | 699 unsigned char* rgba_ptr = &rgba[0]; |
| 669 for (size_t i = 0; i < num_pixels; ++i) { | 700 for (size_t i = 0; i < num_pixels; ++i) { |
| 670 *rgb_ptr++ = *rgba_ptr++; | 701 *rgb_ptr++ = *rgba_ptr++; |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 840 // When the rendering falls behind, drops frames. | 871 // When the rendering falls behind, drops frames. |
| 841 while (scheduled_render_time_ < target) { | 872 while (scheduled_render_time_ < target) { |
| 842 scheduled_render_time_ += frame_duration_; | 873 scheduled_render_time_ += frame_duration_; |
| 843 DropOneFrameForAllVideos(); | 874 DropOneFrameForAllVideos(); |
| 844 } | 875 } |
| 845 | 876 |
| 846 message_loop_->PostDelayedTask(FROM_HERE, render_task_.callback(), | 877 message_loop_->PostDelayedTask(FROM_HERE, render_task_.callback(), |
| 847 target - now); | 878 target - now); |
| 848 } | 879 } |
| 849 } // namespace media | 880 } // namespace media |
| OLD | NEW |