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

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: Addressed review feedback and Mac build failure 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
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"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 47
48 // Lightweight GLContext stub implementation that returns a constructed 48 // Lightweight GLContext stub implementation that returns a constructed
49 // extensions string. We use this to create a context that we can use to 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. 50 // initialize GL extensions with, without actually creating a platform context.
51 class GLContextStubWithExtensions : public gfx::GLContextStub { 51 class GLContextStubWithExtensions : public gfx::GLContextStub {
52 public: 52 public:
53 GLContextStubWithExtensions() {} 53 GLContextStubWithExtensions() {}
54 virtual std::string GetExtensions() OVERRIDE; 54 virtual std::string GetExtensions() OVERRIDE;
55 55
56 void AddExtensionsString(const char* extensions); 56 void AddExtensionsString(const char* extensions);
57 void SetGLVersionString(const char* version_str);
57 58
58 protected: 59 protected:
60 virtual std::string GetGLVersion() OVERRIDE;
61
59 virtual ~GLContextStubWithExtensions() {} 62 virtual ~GLContextStubWithExtensions() {}
60 63
61 private: 64 private:
62 std::string extensions_; 65 std::string extensions_;
66 std::string version_str_;
63 67
64 DISALLOW_COPY_AND_ASSIGN(GLContextStubWithExtensions); 68 DISALLOW_COPY_AND_ASSIGN(GLContextStubWithExtensions);
65 }; 69 };
66 70
67 void GLContextStubWithExtensions::AddExtensionsString(const char* extensions) { 71 void GLContextStubWithExtensions::AddExtensionsString(const char* extensions) {
68 if (extensions == NULL) 72 if (extensions == NULL)
69 return; 73 return;
70 74
71 if (extensions_.size() != 0) 75 if (extensions_.size() != 0)
72 extensions_ += ' '; 76 extensions_ += ' ';
73 extensions_ += extensions; 77 extensions_ += extensions;
74 } 78 }
75 79
76 std::string GLContextStubWithExtensions::GetExtensions() { 80 std::string GLContextStubWithExtensions::GetExtensions() {
77 return extensions_; 81 return extensions_;
78 } 82 }
79 83
84 void GLContextStubWithExtensions::SetGLVersionString(const char* version_str) {
85 version_str_ = std::string(version_str ? version_str : "");
86 }
87
88 std::string GLContextStubWithExtensions::GetGLVersion() {
89 return version_str_;
90 }
91
80 } // anonymous 92 } // anonymous
81 93
82 namespace content { 94 namespace content {
83 95
84 RenderingHelperParams::RenderingHelperParams() {} 96 RenderingHelperParams::RenderingHelperParams() {}
85 97
86 RenderingHelperParams::~RenderingHelperParams() {} 98 RenderingHelperParams::~RenderingHelperParams() {}
87 99
88 static const gfx::GLImplementation kGLImplementation = 100 static const gfx::GLImplementation kGLImplementation =
89 #if defined(GL_VARIANT_GLX) 101 #if defined(GL_VARIANT_GLX)
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 void RenderingHelper::Initialize(const RenderingHelperParams& params, 140 void RenderingHelper::Initialize(const RenderingHelperParams& params,
129 base::WaitableEvent* done) { 141 base::WaitableEvent* done) {
130 // Use window_dimensions_.size() != 0 as a proxy for the class having already 142 // Use window_dimensions_.size() != 0 as a proxy for the class having already
131 // been Initialize()'d, and UnInitialize() before continuing. 143 // been Initialize()'d, and UnInitialize() before continuing.
132 if (window_dimensions_.size()) { 144 if (window_dimensions_.size()) {
133 base::WaitableEvent done(false, false); 145 base::WaitableEvent done(false, false);
134 UnInitialize(&done); 146 UnInitialize(&done);
135 done.Wait(); 147 done.Wait();
136 } 148 }
137 149
138 gfx::InitializeGLBindings(kGLImplementation); 150 gfx::InitializeStaticGLBindings(kGLImplementation);
139 scoped_refptr<GLContextStubWithExtensions> stub_context( 151 scoped_refptr<GLContextStubWithExtensions> stub_context(
140 new GLContextStubWithExtensions()); 152 new GLContextStubWithExtensions());
141 153
142 CHECK_GT(params.window_dimensions.size(), 0U); 154 CHECK_GT(params.window_dimensions.size(), 0U);
143 CHECK_EQ(params.frame_dimensions.size(), params.window_dimensions.size()); 155 CHECK_EQ(params.frame_dimensions.size(), params.window_dimensions.size());
144 window_dimensions_ = params.window_dimensions; 156 window_dimensions_ = params.window_dimensions;
145 frame_dimensions_ = params.frame_dimensions; 157 frame_dimensions_ = params.frame_dimensions;
146 render_as_thumbnails_ = params.render_as_thumbnails; 158 render_as_thumbnails_ = params.render_as_thumbnails;
147 message_loop_ = base::MessageLoop::current(); 159 message_loop_ = base::MessageLoop::current();
148 CHECK_GT(params.num_windows, 0); 160 CHECK_GT(params.num_windows, 0);
(...skipping 15 matching lines...) Expand all
164 glXChooseFBConfig(x_display_, DefaultScreen(x_display_), fbconfig_attr, 176 glXChooseFBConfig(x_display_, DefaultScreen(x_display_), fbconfig_attr,
165 &num_fbconfigs)); 177 &num_fbconfigs));
166 CHECK(glx_fb_configs.get()); 178 CHECK(glx_fb_configs.get());
167 CHECK_GT(num_fbconfigs, 0); 179 CHECK_GT(num_fbconfigs, 0);
168 x_visual_ = glXGetVisualFromFBConfig(x_display_, glx_fb_configs.get()[0]); 180 x_visual_ = glXGetVisualFromFBConfig(x_display_, glx_fb_configs.get()[0]);
169 CHECK(x_visual_); 181 CHECK(x_visual_);
170 gl_context_ = glXCreateContext(x_display_, x_visual_, 0, true); 182 gl_context_ = glXCreateContext(x_display_, x_visual_, 0, true);
171 CHECK(gl_context_); 183 CHECK(gl_context_);
172 stub_context->AddExtensionsString( 184 stub_context->AddExtensionsString(
173 reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS))); 185 reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS)));
186 stub_context->SetGLVersionString(
187 reinterpret_cast<const char*>(glGetString(GL_VERSION)));
174 188
175 #else // EGL 189 #else // EGL
176 EGLNativeDisplayType native_display; 190 EGLNativeDisplayType native_display;
177 191
178 #if defined(OS_WIN) 192 #if defined(OS_WIN)
179 native_display = EGL_DEFAULT_DISPLAY; 193 native_display = EGL_DEFAULT_DISPLAY;
180 #else 194 #else
181 x_display_ = base::MessagePumpForUI::GetDefaultXDisplay(); 195 x_display_ = base::MessagePumpForUI::GetDefaultXDisplay();
182 CHECK(x_display_); 196 CHECK(x_display_);
183 native_display = x_display_; 197 native_display = x_display_;
(...skipping 17 matching lines...) Expand all
201 << eglGetError(); 215 << eglGetError();
202 CHECK_GE(num_configs, 1); 216 CHECK_GE(num_configs, 1);
203 static EGLint context_attribs[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE}; 217 static EGLint context_attribs[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE};
204 gl_context_ = eglCreateContext( 218 gl_context_ = eglCreateContext(
205 gl_display_, egl_config, EGL_NO_CONTEXT, context_attribs); 219 gl_display_, egl_config, EGL_NO_CONTEXT, context_attribs);
206 CHECK_NE(gl_context_, EGL_NO_CONTEXT) << eglGetError(); 220 CHECK_NE(gl_context_, EGL_NO_CONTEXT) << eglGetError();
207 stub_context->AddExtensionsString( 221 stub_context->AddExtensionsString(
208 reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS))); 222 reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS)));
209 stub_context->AddExtensionsString( 223 stub_context->AddExtensionsString(
210 eglQueryString(gl_display_, EGL_EXTENSIONS)); 224 eglQueryString(gl_display_, EGL_EXTENSIONS));
225 stub_context->SetGLVersionString(
226 reinterpret_cast<const char*>(glGetString(GL_VERSION)));
211 #endif 227 #endif
212 228
213 // Per-window/surface X11 & EGL initialization. 229 // Per-window/surface X11 & EGL initialization.
214 for (int i = 0; i < params.num_windows; ++i) { 230 for (int i = 0; i < params.num_windows; ++i) {
215 // Arrange X windows whimsically, with some padding. 231 // Arrange X windows whimsically, with some padding.
216 int j = i % window_dimensions_.size(); 232 int j = i % window_dimensions_.size();
217 int width = window_dimensions_[j].width(); 233 int width = window_dimensions_[j].width();
218 int height = window_dimensions_[j].height(); 234 int height = window_dimensions_[j].height();
219 CHECK_GT(width, 0); 235 CHECK_GT(width, 0);
220 CHECK_GT(height, 0); 236 CHECK_GT(height, 0);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 #if GL_VARIANT_EGL 272 #if GL_VARIANT_EGL
257 EGLSurface egl_surface = 273 EGLSurface egl_surface =
258 eglCreateWindowSurface(gl_display_, egl_config, window, NULL); 274 eglCreateWindowSurface(gl_display_, egl_config, window, NULL);
259 gl_surfaces_.push_back(egl_surface); 275 gl_surfaces_.push_back(egl_surface);
260 CHECK_NE(egl_surface, EGL_NO_SURFACE); 276 CHECK_NE(egl_surface, EGL_NO_SURFACE);
261 #endif 277 #endif
262 MakeCurrent(i); 278 MakeCurrent(i);
263 } 279 }
264 280
265 // Must be done after a context is made current. 281 // Must be done after a context is made current.
266 gfx::InitializeGLExtensionBindings(kGLImplementation, stub_context.get()); 282 gfx::InitializeDynamicGLBindings(kGLImplementation, stub_context.get());
267 283
268 if (render_as_thumbnails_) { 284 if (render_as_thumbnails_) {
269 CHECK_EQ(window_dimensions_.size(), 1U); 285 CHECK_EQ(window_dimensions_.size(), 1U);
270 286
271 GLint max_texture_size; 287 GLint max_texture_size;
272 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max_texture_size); 288 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max_texture_size);
273 CHECK_GE(max_texture_size, params.thumbnails_page_size.width()); 289 CHECK_GE(max_texture_size, params.thumbnails_page_size.width());
274 CHECK_GE(max_texture_size, params.thumbnails_page_size.height()); 290 CHECK_GE(max_texture_size, params.thumbnails_page_size.height());
275 291
276 thumbnails_fbo_size_ = params.thumbnails_page_size; 292 thumbnails_fbo_size_ = params.thumbnails_page_size;
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
591 *rgb_ptr++ = *rgba_ptr++; 607 *rgb_ptr++ = *rgba_ptr++;
592 solid = solid && (*rgba_ptr == 0xff); 608 solid = solid && (*rgba_ptr == 0xff);
593 rgba_ptr++; 609 rgba_ptr++;
594 } 610 }
595 *alpha_solid = solid; 611 *alpha_solid = solid;
596 612
597 done->Signal(); 613 done->Signal();
598 } 614 }
599 615
600 } // namespace content 616 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698