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

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

Issue 94963003: Take GL version and extensions correctly into account when binding functions (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Improve Windows initialization and renderBufferMultisample explanation Created 7 years 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
« no previous file with comments | « content/common/gpu/gpu_channel_manager.cc ('k') | gpu/command_buffer/common/unittest_main.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/bind.h" 7 #include "base/bind.h"
8 #include "base/mac/scoped_nsautorelease_pool.h" 8 #include "base/mac/scoped_nsautorelease_pool.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/strings/stringize_macros.h" 10 #include "base/strings/stringize_macros.h"
11 #include "base/synchronization/waitable_event.h" 11 #include "base/synchronization/waitable_event.h"
12 #include "ui/gl/gl_context.h" 12 #include "ui/gl/gl_context.h"
13 #include "ui/gl/gl_context_stub.h" 13 #include "ui/gl/gl_context_stub_with_extensions.h"
14 #include "ui/gl/gl_implementation.h" 14 #include "ui/gl/gl_implementation.h"
15 #include "ui/gl/gl_surface.h" 15 #include "ui/gl/gl_surface.h"
16 16
17 #ifdef GL_VARIANT_GLX 17 #ifdef GL_VARIANT_GLX
18 typedef GLXWindow NativeWindowType; 18 typedef GLXWindow NativeWindowType;
19 struct ScopedPtrXFree { 19 struct ScopedPtrXFree {
20 void operator()(void* x) const { ::XFree(x); } 20 void operator()(void* x) const { ::XFree(x); }
21 }; 21 };
22 #else // EGL 22 #else // EGL
23 typedef EGLNativeWindowType NativeWindowType; 23 typedef EGLNativeWindowType NativeWindowType;
(...skipping 12 matching lines...) Expand all
36 if (!result) { 36 if (!result) {
37 char log[4096]; 37 char log[4096];
38 glGetShaderInfoLog(shader, arraysize(log), NULL, log); 38 glGetShaderInfoLog(shader, arraysize(log), NULL, log);
39 LOG(FATAL) << log; 39 LOG(FATAL) << log;
40 } 40 }
41 glAttachShader(program, shader); 41 glAttachShader(program, shader);
42 glDeleteShader(shader); 42 glDeleteShader(shader);
43 CHECK_EQ(static_cast<int>(glGetError()), GL_NO_ERROR); 43 CHECK_EQ(static_cast<int>(glGetError()), GL_NO_ERROR);
44 } 44 }
45 45
46 namespace {
47
48 // Lightweight GLContext stub implementation that returns a constructed
49 // extensions string. We use this to create a context that we can use to
50 // initialize GL extensions with, without actually creating a platform context.
51 class GLContextStubWithExtensions : public gfx::GLContextStub {
52 public:
53 GLContextStubWithExtensions() {}
54 virtual std::string GetExtensions() OVERRIDE;
55
56 void AddExtensionsString(const char* extensions);
57
58 protected:
59 virtual ~GLContextStubWithExtensions() {}
60
61 private:
62 std::string extensions_;
63
64 DISALLOW_COPY_AND_ASSIGN(GLContextStubWithExtensions);
65 };
66
67 void GLContextStubWithExtensions::AddExtensionsString(const char* extensions) {
68 if (extensions == NULL)
69 return;
70
71 if (extensions_.size() != 0)
72 extensions_ += ' ';
73 extensions_ += extensions;
74 }
75
76 std::string GLContextStubWithExtensions::GetExtensions() {
77 return extensions_;
78 }
79
80 } // anonymous
81
82 namespace content { 46 namespace content {
83 47
84 RenderingHelperParams::RenderingHelperParams() {} 48 RenderingHelperParams::RenderingHelperParams() {}
85 49
86 RenderingHelperParams::~RenderingHelperParams() {} 50 RenderingHelperParams::~RenderingHelperParams() {}
87 51
88 static const gfx::GLImplementation kGLImplementation = 52 static const gfx::GLImplementation kGLImplementation =
89 #if defined(GL_VARIANT_GLX) 53 #if defined(GL_VARIANT_GLX)
90 gfx::kGLImplementationDesktopGL; 54 gfx::kGLImplementationDesktopGL;
91 #elif defined(GL_VARIANT_EGL) 55 #elif defined(GL_VARIANT_EGL)
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 void RenderingHelper::Initialize(const RenderingHelperParams& params, 92 void RenderingHelper::Initialize(const RenderingHelperParams& params,
129 base::WaitableEvent* done) { 93 base::WaitableEvent* done) {
130 // Use window_dimensions_.size() != 0 as a proxy for the class having already 94 // Use window_dimensions_.size() != 0 as a proxy for the class having already
131 // been Initialize()'d, and UnInitialize() before continuing. 95 // been Initialize()'d, and UnInitialize() before continuing.
132 if (window_dimensions_.size()) { 96 if (window_dimensions_.size()) {
133 base::WaitableEvent done(false, false); 97 base::WaitableEvent done(false, false);
134 UnInitialize(&done); 98 UnInitialize(&done);
135 done.Wait(); 99 done.Wait();
136 } 100 }
137 101
138 gfx::InitializeGLBindings(kGLImplementation); 102 gfx::InitializeStaticGLBindings(kGLImplementation);
139 scoped_refptr<GLContextStubWithExtensions> stub_context( 103 scoped_refptr<gfx::GLContextStubWithExtensions> stub_context(
140 new GLContextStubWithExtensions()); 104 new gfx::GLContextStubWithExtensions());
141 105
142 CHECK_GT(params.window_dimensions.size(), 0U); 106 CHECK_GT(params.window_dimensions.size(), 0U);
143 CHECK_EQ(params.frame_dimensions.size(), params.window_dimensions.size()); 107 CHECK_EQ(params.frame_dimensions.size(), params.window_dimensions.size());
144 window_dimensions_ = params.window_dimensions; 108 window_dimensions_ = params.window_dimensions;
145 frame_dimensions_ = params.frame_dimensions; 109 frame_dimensions_ = params.frame_dimensions;
146 render_as_thumbnails_ = params.render_as_thumbnails; 110 render_as_thumbnails_ = params.render_as_thumbnails;
147 message_loop_ = base::MessageLoop::current(); 111 message_loop_ = base::MessageLoop::current();
148 CHECK_GT(params.num_windows, 0); 112 CHECK_GT(params.num_windows, 0);
149 113
150 #if GL_VARIANT_GLX 114 #if GL_VARIANT_GLX
(...skipping 13 matching lines...) Expand all
164 glXChooseFBConfig(x_display_, DefaultScreen(x_display_), fbconfig_attr, 128 glXChooseFBConfig(x_display_, DefaultScreen(x_display_), fbconfig_attr,
165 &num_fbconfigs)); 129 &num_fbconfigs));
166 CHECK(glx_fb_configs.get()); 130 CHECK(glx_fb_configs.get());
167 CHECK_GT(num_fbconfigs, 0); 131 CHECK_GT(num_fbconfigs, 0);
168 x_visual_ = glXGetVisualFromFBConfig(x_display_, glx_fb_configs.get()[0]); 132 x_visual_ = glXGetVisualFromFBConfig(x_display_, glx_fb_configs.get()[0]);
169 CHECK(x_visual_); 133 CHECK(x_visual_);
170 gl_context_ = glXCreateContext(x_display_, x_visual_, 0, true); 134 gl_context_ = glXCreateContext(x_display_, x_visual_, 0, true);
171 CHECK(gl_context_); 135 CHECK(gl_context_);
172 stub_context->AddExtensionsString( 136 stub_context->AddExtensionsString(
173 reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS))); 137 reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS)));
138 stub_context->SetGLVersionString(
139 reinterpret_cast<const char*>(glGetString(GL_VERSION)));
174 140
175 #else // EGL 141 #else // EGL
176 EGLNativeDisplayType native_display; 142 EGLNativeDisplayType native_display;
177 143
178 #if defined(OS_WIN) 144 #if defined(OS_WIN)
179 native_display = EGL_DEFAULT_DISPLAY; 145 native_display = EGL_DEFAULT_DISPLAY;
180 #else 146 #else
181 x_display_ = base::MessagePumpForUI::GetDefaultXDisplay(); 147 x_display_ = base::MessagePumpForUI::GetDefaultXDisplay();
182 CHECK(x_display_); 148 CHECK(x_display_);
183 native_display = x_display_; 149 native_display = x_display_;
(...skipping 17 matching lines...) Expand all
201 << eglGetError(); 167 << eglGetError();
202 CHECK_GE(num_configs, 1); 168 CHECK_GE(num_configs, 1);
203 static EGLint context_attribs[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE}; 169 static EGLint context_attribs[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE};
204 gl_context_ = eglCreateContext( 170 gl_context_ = eglCreateContext(
205 gl_display_, egl_config, EGL_NO_CONTEXT, context_attribs); 171 gl_display_, egl_config, EGL_NO_CONTEXT, context_attribs);
206 CHECK_NE(gl_context_, EGL_NO_CONTEXT) << eglGetError(); 172 CHECK_NE(gl_context_, EGL_NO_CONTEXT) << eglGetError();
207 stub_context->AddExtensionsString( 173 stub_context->AddExtensionsString(
208 reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS))); 174 reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS)));
209 stub_context->AddExtensionsString( 175 stub_context->AddExtensionsString(
210 eglQueryString(gl_display_, EGL_EXTENSIONS)); 176 eglQueryString(gl_display_, EGL_EXTENSIONS));
177 stub_context->SetGLVersionString(
178 reinterpret_cast<const char*>(glGetString(GL_VERSION)));
211 #endif 179 #endif
212 180
213 // Per-window/surface X11 & EGL initialization. 181 // Per-window/surface X11 & EGL initialization.
214 for (int i = 0; i < params.num_windows; ++i) { 182 for (int i = 0; i < params.num_windows; ++i) {
215 // Arrange X windows whimsically, with some padding. 183 // Arrange X windows whimsically, with some padding.
216 int j = i % window_dimensions_.size(); 184 int j = i % window_dimensions_.size();
217 int width = window_dimensions_[j].width(); 185 int width = window_dimensions_[j].width();
218 int height = window_dimensions_[j].height(); 186 int height = window_dimensions_[j].height();
219 CHECK_GT(width, 0); 187 CHECK_GT(width, 0);
220 CHECK_GT(height, 0); 188 CHECK_GT(height, 0);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 #if GL_VARIANT_EGL 224 #if GL_VARIANT_EGL
257 EGLSurface egl_surface = 225 EGLSurface egl_surface =
258 eglCreateWindowSurface(gl_display_, egl_config, window, NULL); 226 eglCreateWindowSurface(gl_display_, egl_config, window, NULL);
259 gl_surfaces_.push_back(egl_surface); 227 gl_surfaces_.push_back(egl_surface);
260 CHECK_NE(egl_surface, EGL_NO_SURFACE); 228 CHECK_NE(egl_surface, EGL_NO_SURFACE);
261 #endif 229 #endif
262 MakeCurrent(i); 230 MakeCurrent(i);
263 } 231 }
264 232
265 // Must be done after a context is made current. 233 // Must be done after a context is made current.
266 gfx::InitializeGLExtensionBindings(kGLImplementation, stub_context.get()); 234 gfx::InitializeDynamicGLBindings(kGLImplementation, stub_context.get());
267 235
268 if (render_as_thumbnails_) { 236 if (render_as_thumbnails_) {
269 CHECK_EQ(window_dimensions_.size(), 1U); 237 CHECK_EQ(window_dimensions_.size(), 1U);
270 238
271 GLint max_texture_size; 239 GLint max_texture_size;
272 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max_texture_size); 240 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max_texture_size);
273 CHECK_GE(max_texture_size, params.thumbnails_page_size.width()); 241 CHECK_GE(max_texture_size, params.thumbnails_page_size.width());
274 CHECK_GE(max_texture_size, params.thumbnails_page_size.height()); 242 CHECK_GE(max_texture_size, params.thumbnails_page_size.height());
275 243
276 thumbnails_fbo_size_ = params.thumbnails_page_size; 244 thumbnails_fbo_size_ = params.thumbnails_page_size;
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
591 *rgb_ptr++ = *rgba_ptr++; 559 *rgb_ptr++ = *rgba_ptr++;
592 solid = solid && (*rgba_ptr == 0xff); 560 solid = solid && (*rgba_ptr == 0xff);
593 rgba_ptr++; 561 rgba_ptr++;
594 } 562 }
595 *alpha_solid = solid; 563 *alpha_solid = solid;
596 564
597 done->Signal(); 565 done->Signal();
598 } 566 }
599 567
600 } // namespace content 568 } // namespace content
OLDNEW
« no previous file with comments | « content/common/gpu/gpu_channel_manager.cc ('k') | gpu/command_buffer/common/unittest_main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698