Commit cb41ac84 authored by owenlin@chromium.org's avatar owenlin@chromium.org

rendering_helper - Use real GLSurface and GLContext.

BUG=None
TEST=Run the vda_unitest on GLX and EGL machines.

Review URL: https://codereview.chromium.org/400353007

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@284628 0039d316-1c4b-4281-b951-d872f2087c98
parent 6ee72da1
...@@ -9,14 +9,16 @@ ...@@ -9,14 +9,16 @@
#include <vector> #include <vector>
#include "base/bind.h" #include "base/bind.h"
#include "base/command_line.h"
#include "base/mac/scoped_nsautorelease_pool.h" #include "base/mac/scoped_nsautorelease_pool.h"
#include "base/message_loop/message_loop.h" #include "base/message_loop/message_loop.h"
#include "base/strings/stringize_macros.h" #include "base/strings/stringize_macros.h"
#include "base/synchronization/waitable_event.h" #include "base/synchronization/waitable_event.h"
#include "ui/gl/gl_context.h" #include "ui/gl/gl_context.h"
#include "ui/gl/gl_context_stub_with_extensions.h"
#include "ui/gl/gl_implementation.h" #include "ui/gl/gl_implementation.h"
#include "ui/gl/gl_surface.h" #include "ui/gl/gl_surface.h"
#include "ui/gl/gl_surface_egl.h"
#include "ui/gl/gl_surface_glx.h"
#if defined(OS_WIN) #if defined(OS_WIN)
#include <windows.h> #include <windows.h>
...@@ -26,10 +28,10 @@ ...@@ -26,10 +28,10 @@
#include "ui/gfx/x/x11_types.h" #include "ui/gfx/x/x11_types.h"
#endif #endif
#ifdef GL_VARIANT_GLX #if !defined(OS_WIN) && defined(ARCH_CPU_X86_FAMILY)
struct XFreeDeleter { #define GL_VARIANT_GLX 1
void operator()(void* x) const { ::XFree(x); } #else
}; #define GL_VARIANT_EGL 1
#endif #endif
// Helper for Shader creation. // Helper for Shader creation.
...@@ -58,27 +60,20 @@ RenderingHelperParams::RenderingHelperParams() {} ...@@ -58,27 +60,20 @@ RenderingHelperParams::RenderingHelperParams() {}
RenderingHelperParams::~RenderingHelperParams() {} RenderingHelperParams::~RenderingHelperParams() {}
static const gfx::GLImplementation kGLImplementation = // static
#if defined(GL_VARIANT_GLX) bool RenderingHelper::InitializeOneOff() {
gfx::kGLImplementationDesktopGL; CommandLine* cmd_line = CommandLine::ForCurrentProcess();
#elif defined(GL_VARIANT_EGL) #if GL_VARIANT_GLX
gfx::kGLImplementationEGLGLES2; cmd_line->AppendSwitchASCII(switches::kUseGL,
gfx::kGLImplementationDesktopName);
#else #else
-1; cmd_line->AppendSwitchASCII(switches::kUseGL, gfx::kGLImplementationEGLName);
#error "Unknown GL implementation."
#endif #endif
return gfx::GLSurface::InitializeOneOff();
}
RenderingHelper::RenderingHelper() { RenderingHelper::RenderingHelper() {
#if defined(GL_VARIANT_EGL) window_ = gfx::kNullAcceleratedWidget;
gl_surface_ = EGL_NO_SURFACE;
#endif
#if defined(OS_WIN)
window_ = NULL;
#else
x_window_ = (Window)0;
#endif
Clear(); Clear();
} }
...@@ -101,90 +96,12 @@ void RenderingHelper::Initialize(const RenderingHelperParams& params, ...@@ -101,90 +96,12 @@ void RenderingHelper::Initialize(const RenderingHelperParams& params,
? base::TimeDelta::FromSeconds(1) / params.rendering_fps ? base::TimeDelta::FromSeconds(1) / params.rendering_fps
: base::TimeDelta(); : base::TimeDelta();
gfx::InitializeStaticGLBindings(kGLImplementation);
scoped_refptr<gfx::GLContextStubWithExtensions> stub_context(
new gfx::GLContextStubWithExtensions());
render_as_thumbnails_ = params.render_as_thumbnails; render_as_thumbnails_ = params.render_as_thumbnails;
message_loop_ = base::MessageLoop::current(); message_loop_ = base::MessageLoop::current();
#if GL_VARIANT_GLX
x_display_ = gfx::GetXDisplay();
CHECK(x_display_);
CHECK(glXQueryVersion(x_display_, NULL, NULL));
const int fbconfig_attr[] = {
GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT,
GLX_RENDER_TYPE, GLX_RGBA_BIT,
GLX_BIND_TO_TEXTURE_TARGETS_EXT, GLX_TEXTURE_2D_BIT_EXT,
GLX_BIND_TO_TEXTURE_RGB_EXT, GL_TRUE,
GLX_DOUBLEBUFFER, True,
GL_NONE,
};
int num_fbconfigs;
scoped_ptr<GLXFBConfig, XFreeDeleter> glx_fb_configs(
glXChooseFBConfig(x_display_, DefaultScreen(x_display_), fbconfig_attr,
&num_fbconfigs));
CHECK(glx_fb_configs.get());
CHECK_GT(num_fbconfigs, 0);
x_visual_ = glXGetVisualFromFBConfig(x_display_, glx_fb_configs.get()[0]);
CHECK(x_visual_);
gl_context_ = glXCreateContext(x_display_, x_visual_, 0, true);
CHECK(gl_context_);
stub_context->AddExtensionsString(
reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS)));
stub_context->SetGLVersionString(
reinterpret_cast<const char*>(glGetString(GL_VERSION)));
Screen* screen = DefaultScreenOfDisplay(x_display_);
screen_size_ = gfx::Size(XWidthOfScreen(screen), XHeightOfScreen(screen));
#else // EGL
EGLNativeDisplayType native_display;
#if defined(OS_WIN) #if defined(OS_WIN)
native_display = EGL_DEFAULT_DISPLAY;
screen_size_ = screen_size_ =
gfx::Size(GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN)); gfx::Size(GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));
#else
x_display_ = gfx::GetXDisplay();
CHECK(x_display_);
native_display = x_display_;
Screen* screen = DefaultScreenOfDisplay(x_display_);
screen_size_ = gfx::Size(XWidthOfScreen(screen), XHeightOfScreen(screen));
#endif
gl_display_ = eglGetDisplay(native_display);
CHECK(gl_display_);
CHECK(eglInitialize(gl_display_, NULL, NULL)) << eglGetError();
static EGLint rgba8888[] = {
EGL_RED_SIZE, 8,
EGL_GREEN_SIZE, 8,
EGL_BLUE_SIZE, 8,
EGL_ALPHA_SIZE, 8,
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
EGL_NONE,
};
EGLConfig egl_config;
int num_configs;
CHECK(eglChooseConfig(gl_display_, rgba8888, &egl_config, 1, &num_configs))
<< eglGetError();
CHECK_GE(num_configs, 1);
static EGLint context_attribs[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE};
gl_context_ = eglCreateContext(
gl_display_, egl_config, EGL_NO_CONTEXT, context_attribs);
CHECK_NE(gl_context_, EGL_NO_CONTEXT) << eglGetError();
stub_context->AddExtensionsString(
reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS)));
stub_context->AddExtensionsString(
eglQueryString(gl_display_, EGL_EXTENSIONS));
stub_context->SetGLVersionString(
reinterpret_cast<const char*>(glGetString(GL_VERSION)));
#endif
clients_ = params.clients;
CHECK_GT(clients_.size(), 0U);
LayoutRenderingAreas();
#if defined(OS_WIN)
window_ = CreateWindowEx(0, window_ = CreateWindowEx(0,
L"Static", L"Static",
L"VideoDecodeAcceleratorTest", L"VideoDecodeAcceleratorTest",
...@@ -197,21 +114,22 @@ void RenderingHelper::Initialize(const RenderingHelperParams& params, ...@@ -197,21 +114,22 @@ void RenderingHelper::Initialize(const RenderingHelperParams& params,
NULL, NULL,
NULL, NULL,
NULL); NULL);
CHECK(window_ != NULL); #elif defined(USE_X11)
#else Display* display = gfx::GetXDisplay();
int depth = DefaultDepth(x_display_, DefaultScreen(x_display_)); Screen* screen = DefaultScreenOfDisplay(display);
screen_size_ = gfx::Size(XWidthOfScreen(screen), XHeightOfScreen(screen));
#if defined(GL_VARIANT_GLX) CHECK(display);
CHECK_EQ(depth, x_visual_->depth);
#endif
XSetWindowAttributes window_attributes; XSetWindowAttributes window_attributes;
memset(&window_attributes, 0, sizeof(window_attributes));
window_attributes.background_pixel = window_attributes.background_pixel =
BlackPixel(x_display_, DefaultScreen(x_display_)); BlackPixel(display, DefaultScreen(display));
window_attributes.override_redirect = true; window_attributes.override_redirect = true;
int depth = DefaultDepth(display, DefaultScreen(display));
x_window_ = XCreateWindow(x_display_, window_ = XCreateWindow(display,
DefaultRootWindow(x_display_), DefaultRootWindow(display),
0, 0,
0, 0,
screen_size_.width(), screen_size_.width(),
...@@ -222,31 +140,22 @@ void RenderingHelper::Initialize(const RenderingHelperParams& params, ...@@ -222,31 +140,22 @@ void RenderingHelper::Initialize(const RenderingHelperParams& params,
CopyFromParent /* visual */, CopyFromParent /* visual */,
(CWBackPixel | CWOverrideRedirect), (CWBackPixel | CWOverrideRedirect),
&window_attributes); &window_attributes);
XStoreName(x_display_, x_window_, "VideoDecodeAcceleratorTest"); XStoreName(display, window_, "VideoDecodeAcceleratorTest");
XSelectInput(x_display_, x_window_, ExposureMask); XSelectInput(display, window_, ExposureMask);
XMapWindow(x_display_, x_window_); XMapWindow(display, window_);
#endif
#if GL_VARIANT_EGL
#if defined(OS_WIN)
gl_surface_ =
eglCreateWindowSurface(gl_display_, egl_config, window_, NULL);
#else #else
gl_surface_ = #error unknown platform
eglCreateWindowSurface(gl_display_, egl_config, x_window_, NULL);
#endif
CHECK_NE(gl_surface_, EGL_NO_SURFACE);
#endif #endif
CHECK(window_ != gfx::kNullAcceleratedWidget);
#if GL_VARIANT_GLX gl_surface_ = gfx::GLSurface::CreateViewGLSurface(window_);
CHECK(glXMakeContextCurrent(x_display_, x_window_, x_window_, gl_context_)); gl_context_ = gfx::GLContext::CreateGLContext(
#else // EGL NULL, gl_surface_, gfx::PreferIntegratedGpu);
CHECK(eglMakeCurrent(gl_display_, gl_surface_, gl_surface_, gl_context_)) gl_context_->MakeCurrent(gl_surface_);
<< eglGetError();
#endif
// Must be done after a context is made current. clients_ = params.clients;
gfx::InitializeDynamicGLBindings(kGLImplementation, stub_context.get()); CHECK_GT(clients_.size(), 0U);
LayoutRenderingAreas();
if (render_as_thumbnails_) { if (render_as_thumbnails_) {
CHECK_EQ(clients_.size(), 1U); CHECK_EQ(clients_.size(), 1U);
...@@ -386,18 +295,11 @@ void RenderingHelper::UnInitialize(base::WaitableEvent* done) { ...@@ -386,18 +295,11 @@ void RenderingHelper::UnInitialize(base::WaitableEvent* done) {
glDeleteTextures(1, &thumbnails_texture_id_); glDeleteTextures(1, &thumbnails_texture_id_);
glDeleteFramebuffersEXT(1, &thumbnails_fbo_id_); glDeleteFramebuffersEXT(1, &thumbnails_fbo_id_);
} }
#if GL_VARIANT_GLX
glXDestroyContext(x_display_, gl_context_); gl_context_->ReleaseCurrent(gl_surface_);
#else // EGL gl_context_ = NULL;
CHECK(eglMakeCurrent( gl_surface_ = NULL;
gl_display_, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT))
<< eglGetError();
CHECK(eglDestroyContext(gl_display_, gl_context_));
CHECK(eglDestroySurface(gl_display_, gl_surface_));
CHECK(eglTerminate(gl_display_));
#endif
gfx::ClearGLBindings();
Clear(); Clear();
done->Signal(); done->Signal();
} }
...@@ -483,44 +385,36 @@ void RenderingHelper::DeleteTexture(uint32 texture_id) { ...@@ -483,44 +385,36 @@ void RenderingHelper::DeleteTexture(uint32 texture_id) {
CHECK_EQ(static_cast<int>(glGetError()), GL_NO_ERROR); CHECK_EQ(static_cast<int>(glGetError()), GL_NO_ERROR);
} }
NativeContextType RenderingHelper::GetGLContext() { return gl_context_; } void* RenderingHelper::GetGLContext() {
return gl_context_->GetHandle();
}
void* RenderingHelper::GetGLDisplay() { void* RenderingHelper::GetGLDisplay() {
#if GL_VARIANT_GLX return gl_surface_->GetDisplay();
return x_display_;
#else // EGL
return gl_display_;
#endif
} }
void RenderingHelper::Clear() { void RenderingHelper::Clear() {
clients_.clear(); clients_.clear();
message_loop_ = NULL; message_loop_ = NULL;
gl_context_ = NULL; gl_context_ = NULL;
#if GL_VARIANT_EGL gl_surface_ = NULL;
gl_display_ = EGL_NO_DISPLAY;
gl_surface_ = EGL_NO_SURFACE;
#endif
render_as_thumbnails_ = false; render_as_thumbnails_ = false;
frame_count_ = 0; frame_count_ = 0;
thumbnails_fbo_id_ = 0; thumbnails_fbo_id_ = 0;
thumbnails_texture_id_ = 0; thumbnails_texture_id_ = 0;
#if defined(OS_WIN) #if defined(OS_WIN)
if (window_) { if (window_)
DestroyWindow(window_); DestroyWindow(window_);
window_ = NULL;
}
#else #else
// Destroy resources acquired in Initialize, in reverse-acquisition order. // Destroy resources acquired in Initialize, in reverse-acquisition order.
if (x_window_) { if (window_) {
CHECK(XUnmapWindow(x_display_, x_window_)); CHECK(XUnmapWindow(gfx::GetXDisplay(), window_));
CHECK(XDestroyWindow(x_display_, x_window_)); CHECK(XDestroyWindow(gfx::GetXDisplay(), window_));
x_window_ = (Window)0;
} }
// Mimic newly created object.
x_display_ = NULL;
#endif #endif
window_ = gfx::kNullAcceleratedWidget;
} }
void RenderingHelper::GetThumbnailsAsRGB(std::vector<unsigned char>* rgb, void RenderingHelper::GetThumbnailsAsRGB(std::vector<unsigned char>* rgb,
...@@ -577,12 +471,7 @@ void RenderingHelper::RenderContent() { ...@@ -577,12 +471,7 @@ void RenderingHelper::RenderContent() {
} }
} }
#if GL_VARIANT_GLX gl_surface_->SwapBuffers();
glXSwapBuffers(x_display_, x_window_);
#else // EGL
eglSwapBuffers(gl_display_, gl_surface_);
CHECK_EQ(static_cast<int>(eglGetError()), EGL_SUCCESS);
#endif
} }
// Helper function for the LayoutRenderingAreas(). The |lengths| are the // Helper function for the LayoutRenderingAreas(). The |lengths| are the
......
...@@ -14,20 +14,14 @@ ...@@ -14,20 +14,14 @@
#include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/size.h" #include "ui/gfx/geometry/size.h"
#include "ui/gl/gl_bindings.h" #include "ui/gl/gl_bindings.h"
#include "ui/gl/gl_context.h"
#include "ui/gl/gl_surface.h"
namespace base { namespace base {
class MessageLoop; class MessageLoop;
class WaitableEvent; class WaitableEvent;
} }
#if !defined(OS_WIN) && defined(ARCH_CPU_X86_FAMILY)
#define GL_VARIANT_GLX 1
typedef GLXContext NativeContextType;
#else
#define GL_VARIANT_EGL 1
typedef EGLContext NativeContextType;
#endif
namespace content { namespace content {
struct RenderingHelperParams; struct RenderingHelperParams;
...@@ -53,6 +47,8 @@ class RenderingHelper { ...@@ -53,6 +47,8 @@ class RenderingHelper {
RenderingHelper(); RenderingHelper();
~RenderingHelper(); ~RenderingHelper();
static bool InitializeOneOff();
// Create the render context and windows by the specified dimensions. // Create the render context and windows by the specified dimensions.
void Initialize(const RenderingHelperParams& params, void Initialize(const RenderingHelperParams& params,
base::WaitableEvent* done); base::WaitableEvent* done);
...@@ -82,7 +78,7 @@ class RenderingHelper { ...@@ -82,7 +78,7 @@ class RenderingHelper {
void* GetGLDisplay(); void* GetGLDisplay();
// Get the platform specific handle to the OpenGL context. // Get the platform specific handle to the OpenGL context.
NativeContextType GetGLContext(); void* GetGLContext();
// Get rendered thumbnails as RGB. // Get rendered thumbnails as RGB.
// Sets alpha_solid to true if the alpha channel is entirely 0xff. // Sets alpha_solid to true if the alpha channel is entirely 0xff.
...@@ -101,21 +97,10 @@ class RenderingHelper { ...@@ -101,21 +97,10 @@ class RenderingHelper {
scoped_ptr<base::RepeatingTimer<RenderingHelper> > render_timer_; scoped_ptr<base::RepeatingTimer<RenderingHelper> > render_timer_;
base::MessageLoop* message_loop_; base::MessageLoop* message_loop_;
NativeContextType gl_context_; scoped_refptr<gfx::GLContext> gl_context_;
scoped_refptr<gfx::GLSurface> gl_surface_;
#if defined(GL_VARIANT_EGL)
EGLDisplay gl_display_; gfx::AcceleratedWidget window_;
EGLSurface gl_surface_;
#else
XVisualInfo* x_visual_;
#endif
#if defined(OS_WIN)
HWND window_;
#else
Display* x_display_;
Window x_window_;
#endif
gfx::Size screen_size_; gfx::Size screen_size_;
......
...@@ -1460,6 +1460,7 @@ int main(int argc, char **argv) { ...@@ -1460,6 +1460,7 @@ int main(int argc, char **argv) {
} }
base::ShadowingAtExitManager at_exit_manager; base::ShadowingAtExitManager at_exit_manager;
content::RenderingHelper::InitializeOneOff();
return RUN_ALL_TESTS(); return RUN_ALL_TESTS();
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment