| Index: media/gpu/rendering_helper.cc
|
| diff --git a/content/common/gpu/media/rendering_helper.cc b/media/gpu/rendering_helper.cc
|
| similarity index 86%
|
| rename from content/common/gpu/media/rendering_helper.cc
|
| rename to media/gpu/rendering_helper.cc
|
| index cabe3fbbf82b333a3768c88a0c020ab262d1f6ea..64630ecf2d981c22c3c9a7d3c59737c0d64754aa 100644
|
| --- a/content/common/gpu/media/rendering_helper.cc
|
| +++ b/media/gpu/rendering_helper.cc
|
| @@ -2,7 +2,7 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#include "content/common/gpu/media/rendering_helper.h"
|
| +#include "media/gpu/rendering_helper.h"
|
|
|
| #include <string.h>
|
|
|
| @@ -72,7 +72,7 @@ static void CreateShader(GLuint program,
|
| CHECK_EQ(static_cast<int>(glGetError()), GL_NO_ERROR);
|
| }
|
|
|
| -namespace content {
|
| +namespace media {
|
| namespace {
|
|
|
| void WaitForSwapAck(const base::Closure& callback, gfx::SwapResult result) {
|
| @@ -127,18 +127,16 @@ class RenderingHelper::StubOzoneDelegate : public ui::PlatformWindowDelegate {
|
|
|
| void OnWindowStateChanged(ui::PlatformWindowState new_state) override {}
|
|
|
| - void OnLostCapture() override {};
|
| + void OnLostCapture() override{};
|
|
|
| void OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget,
|
| float device_pixel_ratio) override {
|
| accelerated_widget_ = widget;
|
| }
|
|
|
| - void OnAcceleratedWidgetDestroyed() override {
|
| - NOTREACHED();
|
| - }
|
| + void OnAcceleratedWidgetDestroyed() override { NOTREACHED(); }
|
|
|
| - void OnActivationChanged(bool active) override {};
|
| + void OnActivationChanged(bool active) override{};
|
|
|
| gfx::AcceleratedWidget accelerated_widget() const {
|
| return accelerated_widget_;
|
| @@ -158,8 +156,7 @@ class RenderingHelper::StubOzoneDelegate : public ui::PlatformWindowDelegate {
|
| #endif // defined(USE_OZONE)
|
|
|
| RenderingHelperParams::RenderingHelperParams()
|
| - : rendering_fps(0), warm_up_iterations(0), render_as_thumbnails(false) {
|
| -}
|
| + : rendering_fps(0), warm_up_iterations(0), render_as_thumbnails(false) {}
|
|
|
| RenderingHelperParams::RenderingHelperParams(
|
| const RenderingHelperParams& other) = default;
|
| @@ -180,14 +177,12 @@ VideoFrameTexture::~VideoFrameTexture() {
|
| }
|
|
|
| RenderingHelper::RenderedVideo::RenderedVideo()
|
| - : is_flushing(false), frames_to_drop(0) {
|
| -}
|
| + : is_flushing(false), frames_to_drop(0) {}
|
|
|
| RenderingHelper::RenderedVideo::RenderedVideo(const RenderedVideo& other) =
|
| default;
|
|
|
| -RenderingHelper::RenderedVideo::~RenderedVideo() {
|
| -}
|
| +RenderingHelper::RenderedVideo::~RenderedVideo() {}
|
|
|
| // static
|
| void RenderingHelper::InitializeOneOff(base::WaitableEvent* done) {
|
| @@ -216,18 +211,10 @@ RenderingHelper::~RenderingHelper() {
|
|
|
| void RenderingHelper::Setup() {
|
| #if defined(OS_WIN)
|
| - window_ = CreateWindowEx(0,
|
| - L"Static",
|
| - L"VideoDecodeAcceleratorTest",
|
| - WS_OVERLAPPEDWINDOW | WS_VISIBLE,
|
| - 0,
|
| - 0,
|
| - GetSystemMetrics(SM_CXSCREEN),
|
| - GetSystemMetrics(SM_CYSCREEN),
|
| - NULL,
|
| - NULL,
|
| - NULL,
|
| - NULL);
|
| + window_ = CreateWindowEx(
|
| + 0, L"Static", L"VideoDecodeAcceleratorTest",
|
| + WS_OVERLAPPEDWINDOW | WS_VISIBLE, 0, 0, GetSystemMetrics(SM_CXSCREEN),
|
| + GetSystemMetrics(SM_CYSCREEN), NULL, NULL, NULL, NULL);
|
| #elif defined(USE_X11)
|
| Display* display = gfx::GetXDisplay();
|
| Screen* screen = DefaultScreenOfDisplay(display);
|
| @@ -241,18 +228,11 @@ void RenderingHelper::Setup() {
|
| window_attributes.override_redirect = true;
|
| int depth = DefaultDepth(display, DefaultScreen(display));
|
|
|
| - window_ = XCreateWindow(display,
|
| - DefaultRootWindow(display),
|
| - 0,
|
| - 0,
|
| - XWidthOfScreen(screen),
|
| - XHeightOfScreen(screen),
|
| - 0 /* border width */,
|
| - depth,
|
| - CopyFromParent /* class */,
|
| - CopyFromParent /* visual */,
|
| - (CWBackPixel | CWOverrideRedirect),
|
| - &window_attributes);
|
| + window_ = XCreateWindow(
|
| + display, DefaultRootWindow(display), 0, 0, XWidthOfScreen(screen),
|
| + XHeightOfScreen(screen), 0 /* border width */, depth,
|
| + CopyFromParent /* class */, CopyFromParent /* visual */,
|
| + (CWBackPixel | CWOverrideRedirect), &window_attributes);
|
| XStoreName(display, window_, "VideoDecodeAcceleratorTest");
|
| XSelectInput(display, window_, ExposureMask);
|
| XMapWindow(display, window_);
|
| @@ -356,8 +336,8 @@ void RenderingHelper::Initialize(const RenderingHelperParams& params,
|
| #endif // defined(USE_OZONE)
|
| screen_size_ = gl_surface_->GetSize();
|
|
|
| - gl_context_ = gfx::GLContext::CreateGLContext(
|
| - NULL, gl_surface_.get(), gfx::PreferIntegratedGpu);
|
| + gl_context_ = gfx::GLContext::CreateGLContext(NULL, gl_surface_.get(),
|
| + gfx::PreferIntegratedGpu);
|
| CHECK(gl_context_->MakeCurrent(gl_surface_.get()));
|
|
|
| CHECK_GT(params.window_sizes.size(), 0U);
|
| @@ -378,15 +358,9 @@ void RenderingHelper::Initialize(const RenderingHelperParams& params,
|
| glGenFramebuffersEXT(1, &thumbnails_fbo_id_);
|
| glGenTextures(1, &thumbnails_texture_id_);
|
| glBindTexture(GL_TEXTURE_2D, thumbnails_texture_id_);
|
| - glTexImage2D(GL_TEXTURE_2D,
|
| - 0,
|
| - GL_RGB,
|
| - thumbnails_fbo_size_.width(),
|
| - thumbnails_fbo_size_.height(),
|
| - 0,
|
| - GL_RGB,
|
| - GL_UNSIGNED_SHORT_5_6_5,
|
| - NULL);
|
| + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, thumbnails_fbo_size_.width(),
|
| + thumbnails_fbo_size_.height(), 0, GL_RGB,
|
| + GL_UNSIGNED_SHORT_5_6_5, NULL);
|
| glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
| glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
| glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
| @@ -394,11 +368,8 @@ void RenderingHelper::Initialize(const RenderingHelperParams& params,
|
| glBindTexture(GL_TEXTURE_2D, 0);
|
|
|
| glBindFramebufferEXT(GL_FRAMEBUFFER, thumbnails_fbo_id_);
|
| - glFramebufferTexture2DEXT(GL_FRAMEBUFFER,
|
| - GL_COLOR_ATTACHMENT0,
|
| - GL_TEXTURE_2D,
|
| - thumbnails_texture_id_,
|
| - 0);
|
| + glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
|
| + GL_TEXTURE_2D, thumbnails_texture_id_, 0);
|
|
|
| GLenum fb_status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER);
|
| CHECK(fb_status == GL_FRAMEBUFFER_COMPLETE) << fb_status;
|
| @@ -414,21 +385,21 @@ void RenderingHelper::Initialize(const RenderingHelperParams& params,
|
| // in the vertex shader for this to be rendered the right way up.
|
| // In the case of thumbnail rendering we use the same vertex shader
|
| // to render the FBO the screen, where we do not want this flipping.
|
| - static const float kVertices[] =
|
| - { -1.f, 1.f, -1.f, -1.f, 1.f, 1.f, 1.f, -1.f, };
|
| - static const float kTextureCoords[] = { 0, 1, 0, 0, 1, 1, 1, 0, };
|
| - static const char kVertexShader[] = STRINGIZE(
|
| - varying vec2 interp_tc;
|
| - attribute vec4 in_pos;
|
| - attribute vec2 in_tc;
|
| - uniform bool tex_flip;
|
| - void main() {
|
| - if (tex_flip)
|
| - interp_tc = vec2(in_tc.x, 1.0 - in_tc.y);
|
| - else
|
| - interp_tc = in_tc;
|
| - gl_Position = in_pos;
|
| - });
|
| + static const float kVertices[] = {
|
| + -1.f, 1.f, -1.f, -1.f, 1.f, 1.f, 1.f, -1.f,
|
| + };
|
| + static const float kTextureCoords[] = {
|
| + 0, 1, 0, 0, 1, 1, 1, 0,
|
| + };
|
| + static const char kVertexShader[] =
|
| + STRINGIZE(varying vec2 interp_tc; attribute vec4 in_pos;
|
| + attribute vec2 in_tc; uniform bool tex_flip; void main() {
|
| + if (tex_flip)
|
| + interp_tc = vec2(in_tc.x, 1.0 - in_tc.y);
|
| + else
|
| + interp_tc = in_tc;
|
| + gl_Position = in_pos;
|
| + });
|
|
|
| #if GL_VARIANT_EGL
|
| static const char kFragmentShader[] =
|
| @@ -447,19 +418,14 @@ void RenderingHelper::Initialize(const RenderingHelperParams& params,
|
| " gl_FragColor = color;\n"
|
| "}\n";
|
| #else
|
| - static const char kFragmentShader[] = STRINGIZE(
|
| - varying vec2 interp_tc;
|
| - uniform sampler2D tex;
|
| - void main() {
|
| - gl_FragColor = texture2D(tex, interp_tc);
|
| - });
|
| + static const char kFragmentShader[] =
|
| + STRINGIZE(varying vec2 interp_tc; uniform sampler2D tex;
|
| + void main() { gl_FragColor = texture2D(tex, interp_tc); });
|
| #endif
|
| program_ = glCreateProgram();
|
| - CreateShader(
|
| - program_, GL_VERTEX_SHADER, kVertexShader, arraysize(kVertexShader));
|
| - CreateShader(program_,
|
| - GL_FRAGMENT_SHADER,
|
| - kFragmentShader,
|
| + CreateShader(program_, GL_VERTEX_SHADER, kVertexShader,
|
| + arraysize(kVertexShader));
|
| + CreateShader(program_, GL_FRAGMENT_SHADER, kFragmentShader,
|
| arraysize(kFragmentShader));
|
| glLinkProgram(program_);
|
| int result = GL_FALSE;
|
| @@ -525,14 +491,8 @@ void RenderingHelper::WarmUpRendering(int warm_up_iterations) {
|
| new GLubyte[screen_size_.GetArea() * 2]());
|
| glGenTextures(1, &texture_id);
|
| glBindTexture(GL_TEXTURE_2D, texture_id);
|
| - glTexImage2D(GL_TEXTURE_2D,
|
| - 0,
|
| - GL_RGB,
|
| - screen_size_.width(),
|
| - screen_size_.height(),
|
| - 0,
|
| - GL_RGB,
|
| - GL_UNSIGNED_SHORT_5_6_5,
|
| + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, screen_size_.width(),
|
| + screen_size_.height(), 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5,
|
| emptyData.get());
|
| for (int i = 0; i < warm_up_iterations; ++i) {
|
| RenderTexture(GL_TEXTURE_2D, texture_id);
|
| @@ -572,27 +532,17 @@ void RenderingHelper::CreateTexture(uint32_t texture_target,
|
| const gfx::Size& size,
|
| base::WaitableEvent* done) {
|
| if (base::MessageLoop::current() != message_loop_) {
|
| - message_loop_->PostTask(FROM_HERE,
|
| - base::Bind(&RenderingHelper::CreateTexture,
|
| - base::Unretained(this),
|
| - texture_target,
|
| - texture_id,
|
| - size,
|
| - done));
|
| + message_loop_->PostTask(
|
| + FROM_HERE,
|
| + base::Bind(&RenderingHelper::CreateTexture, base::Unretained(this),
|
| + texture_target, texture_id, size, done));
|
| return;
|
| }
|
| glGenTextures(1, texture_id);
|
| glBindTexture(texture_target, *texture_id);
|
| if (texture_target == GL_TEXTURE_2D) {
|
| - glTexImage2D(GL_TEXTURE_2D,
|
| - 0,
|
| - GL_RGBA,
|
| - size.width(),
|
| - size.height(),
|
| - 0,
|
| - GL_RGBA,
|
| - GL_UNSIGNED_BYTE,
|
| - NULL);
|
| + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, size.width(), size.height(), 0,
|
| + GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
| }
|
| glTexParameteri(texture_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
| glTexParameteri(texture_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
| @@ -707,12 +657,8 @@ void RenderingHelper::GetThumbnailsAsRGB(std::vector<unsigned char>* rgb,
|
| glBindFramebufferEXT(GL_FRAMEBUFFER, thumbnails_fbo_id_);
|
| glPixelStorei(GL_PACK_ALIGNMENT, 1);
|
| // We can only count on GL_RGBA/GL_UNSIGNED_BYTE support.
|
| - glReadPixels(0,
|
| - 0,
|
| - thumbnails_fbo_size_.width(),
|
| - thumbnails_fbo_size_.height(),
|
| - GL_RGBA,
|
| - GL_UNSIGNED_BYTE,
|
| + glReadPixels(0, 0, thumbnails_fbo_size_.width(),
|
| + thumbnails_fbo_size_.height(), GL_RGBA, GL_UNSIGNED_BYTE,
|
| &rgba[0]);
|
| glBindFramebufferEXT(GL_FRAMEBUFFER,
|
| gl_surface_->GetBackingFrameBufferObject());
|
| @@ -763,7 +709,7 @@ void RenderingHelper::RenderContent() {
|
| // Frames that will be returned to the client (via the no_longer_needed_cb)
|
| // after this vector falls out of scope at the end of this method. We need
|
| // to keep references to them until after SwapBuffers() call below.
|
| - std::vector<scoped_refptr<VideoFrameTexture> > frames_to_be_returned;
|
| + std::vector<scoped_refptr<VideoFrameTexture>> frames_to_be_returned;
|
| bool need_swap_buffer = false;
|
| if (render_as_thumbnails_) {
|
| // In render_as_thumbnails_ mode, we render the FBO content on the
|
| @@ -796,8 +742,7 @@ void RenderingHelper::RenderContent() {
|
| return;
|
| }
|
|
|
| - gl_surface_->SwapBuffersAsync(
|
| - base::Bind(&WaitForSwapAck, schedule_frame));
|
| + gl_surface_->SwapBuffersAsync(base::Bind(&WaitForSwapAck, schedule_frame));
|
| }
|
|
|
| // Helper function for the LayoutRenderingAreas(). The |lengths| are the
|
| @@ -899,7 +844,7 @@ void RenderingHelper::ScheduleNextRenderContent() {
|
| DropOneFrameForAllVideos();
|
| }
|
|
|
| - message_loop_->PostDelayedTask(
|
| - FROM_HERE, render_task_.callback(), target - now);
|
| + message_loop_->PostDelayedTask(FROM_HERE, render_task_.callback(),
|
| + target - now);
|
| }
|
| -} // namespace content
|
| +} // namespace media
|
|
|