| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/gpu/gpu_backing_store_glx_context.h" | 5 #include "chrome/gpu/gpu_backing_store_glx_context.h" |
| 6 | 6 |
| 7 #include "app/gfx/gl/gl_bindings.h" |
| 7 #include "app/x11_util.h" | 8 #include "app/x11_util.h" |
| 8 #include "base/scoped_ptr.h" | 9 #include "base/scoped_ptr.h" |
| 9 #include "chrome/gpu/gpu_thread.h" | 10 #include "chrome/gpu/gpu_thread.h" |
| 10 | 11 |
| 11 // Must be last. | 12 // Must be last. |
| 12 #include <GL/glew.h> | |
| 13 #include <GL/glxew.h> | |
| 14 #include <X11/Xutil.h> | 13 #include <X11/Xutil.h> |
| 15 | 14 |
| 16 GpuBackingStoreGLXContext::GpuBackingStoreGLXContext(GpuThread* gpu_thread) | 15 GpuBackingStoreGLXContext::GpuBackingStoreGLXContext(GpuThread* gpu_thread) |
| 17 : gpu_thread_(gpu_thread), | 16 : gpu_thread_(gpu_thread), |
| 18 tried_to_init_(false), | 17 tried_to_init_(false), |
| 19 context_(NULL), | 18 context_(NULL), |
| 20 previous_window_id_(0), | 19 previous_window_id_(0), |
| 21 frame_buffer_for_scrolling_(0), | 20 frame_buffer_for_scrolling_(0), |
| 22 is_frame_buffer_bound_(false), | 21 is_frame_buffer_bound_(false), |
| 23 temp_scroll_texture_id_(0) { | 22 temp_scroll_texture_id_(0) { |
| 24 } | 23 } |
| 25 | 24 |
| 26 GpuBackingStoreGLXContext::~GpuBackingStoreGLXContext() { | 25 GpuBackingStoreGLXContext::~GpuBackingStoreGLXContext() { |
| 27 if (temp_scroll_texture_id_) { | 26 if (temp_scroll_texture_id_) { |
| 28 glDeleteTextures(1, &temp_scroll_texture_id_); | 27 glDeleteTextures(1, &temp_scroll_texture_id_); |
| 29 temp_scroll_texture_id_ = 0; | 28 temp_scroll_texture_id_ = 0; |
| 30 } | 29 } |
| 31 | 30 |
| 32 if (frame_buffer_for_scrolling_) | 31 if (frame_buffer_for_scrolling_) |
| 33 glDeleteFramebuffers(1, &frame_buffer_for_scrolling_); | 32 glDeleteFramebuffersEXT(1, &frame_buffer_for_scrolling_); |
| 34 | 33 |
| 35 if (context_) | 34 if (context_) |
| 36 glXDestroyContext(gpu_thread_->display(), context_); | 35 glXDestroyContext(gpu_thread_->display(), context_); |
| 37 } | 36 } |
| 38 | 37 |
| 39 GLXContext GpuBackingStoreGLXContext::BindContext(XID window_id) { | 38 GLXContext GpuBackingStoreGLXContext::BindContext(XID window_id) { |
| 40 DCHECK(!is_frame_buffer_bound_); | 39 DCHECK(!is_frame_buffer_bound_); |
| 41 | 40 |
| 42 if (tried_to_init_) { | 41 if (tried_to_init_) { |
| 43 if (!context_) | 42 if (!context_) |
| 44 return NULL; | 43 return NULL; |
| 45 if (!previous_window_id_ || previous_window_id_ != window_id) { | 44 if (!previous_window_id_ || previous_window_id_ != window_id) { |
| 46 bool success = ::glXMakeCurrent(gpu_thread_->display(), window_id, | 45 bool success = glXMakeCurrent(gpu_thread_->display(), window_id, |
| 47 context_); | 46 context_); |
| 48 DCHECK(success); | 47 DCHECK(success); |
| 49 } | 48 } |
| 50 previous_window_id_ = window_id; | 49 previous_window_id_ = window_id; |
| 51 return context_; | 50 return context_; |
| 52 } | 51 } |
| 53 tried_to_init_ = true; | 52 tried_to_init_ = true; |
| 54 | 53 |
| 55 int attrib_list[] = { GLX_RGBA, GLX_DOUBLEBUFFER, None }; | 54 int attrib_list[] = { GLX_RGBA, GLX_DOUBLEBUFFER, 0 }; |
| 56 scoped_ptr_malloc<XVisualInfo, ScopedPtrXFree> visual_info( | 55 scoped_ptr_malloc<XVisualInfo, ScopedPtrXFree> visual_info( |
| 57 ::glXChooseVisual(gpu_thread_->display(), 0, attrib_list)); | 56 glXChooseVisual(gpu_thread_->display(), 0, attrib_list)); |
| 58 if (!visual_info.get()) | 57 if (!visual_info.get()) |
| 59 return NULL; | 58 return NULL; |
| 60 | 59 |
| 61 context_ = ::glXCreateContext(gpu_thread_->display(), visual_info.get(), | 60 context_ = glXCreateContext(gpu_thread_->display(), visual_info.get(), |
| 62 NULL, True); | 61 NULL, True); |
| 63 bool success = ::glXMakeCurrent(gpu_thread_->display(), window_id, context_); | 62 bool success = glXMakeCurrent(gpu_thread_->display(), window_id, context_); |
| 64 DCHECK(success); | 63 DCHECK(success); |
| 65 glewInit(); | |
| 66 glewInitGL2Hack(); // Work around for I915. See gpu_video_layer_glx.cc. | |
| 67 return context_; | 64 return context_; |
| 68 } | 65 } |
| 69 | 66 |
| 70 bool GpuBackingStoreGLXContext::BindTextureForScrolling( | 67 bool GpuBackingStoreGLXContext::BindTextureForScrolling( |
| 71 XID window_id, | 68 XID window_id, |
| 72 const gfx::Size& size) { | 69 const gfx::Size& size) { |
| 73 DCHECK(!is_frame_buffer_bound_); | 70 DCHECK(!is_frame_buffer_bound_); |
| 74 BindContext(window_id); | 71 BindContext(window_id); |
| 75 | 72 |
| 76 // Create a new destination texture if the old one isn't properly sized. | 73 // Create a new destination texture if the old one isn't properly sized. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 88 // enough to fit the required size. | 85 // enough to fit the required size. |
| 89 glBindTexture(GL_TEXTURE_2D, temp_scroll_texture_id_); | 86 glBindTexture(GL_TEXTURE_2D, temp_scroll_texture_id_); |
| 90 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | 87 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 91 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | 88 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 92 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, size.width(), size.height(), | 89 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, size.width(), size.height(), |
| 93 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL); | 90 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL); |
| 94 glBindTexture(GL_TEXTURE_2D, 0); | 91 glBindTexture(GL_TEXTURE_2D, 0); |
| 95 } | 92 } |
| 96 | 93 |
| 97 if (!frame_buffer_for_scrolling_) | 94 if (!frame_buffer_for_scrolling_) |
| 98 glGenFramebuffers(1, &frame_buffer_for_scrolling_); | 95 glGenFramebuffersEXT(1, &frame_buffer_for_scrolling_); |
| 99 glBindFramebuffer(GL_FRAMEBUFFER, frame_buffer_for_scrolling_); | 96 glBindFramebufferEXT(GL_FRAMEBUFFER, frame_buffer_for_scrolling_); |
| 100 is_frame_buffer_bound_ = true; | 97 is_frame_buffer_bound_ = true; |
| 101 | 98 |
| 102 // Release our color attachment. | 99 // Release our color attachment. |
| 103 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, | 100 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, |
| 104 temp_scroll_texture_id_, 0); | 101 temp_scroll_texture_id_, 0); |
| 105 | 102 |
| 106 DCHECK(glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT) == | 103 DCHECK(glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT) == |
| 107 GL_FRAMEBUFFER_COMPLETE_EXT); | 104 GL_FRAMEBUFFER_COMPLETE_EXT); |
| 108 return true; | 105 return true; |
| 109 } | 106 } |
| 110 | 107 |
| 111 unsigned int GpuBackingStoreGLXContext::SwapTextureForScrolling( | 108 unsigned int GpuBackingStoreGLXContext::SwapTextureForScrolling( |
| 112 unsigned int old_texture, | 109 unsigned int old_texture, |
| 113 const gfx::Size& old_size) { | 110 const gfx::Size& old_size) { |
| 114 // Unbind the framebuffer, which we expect to be bound. | 111 // Unbind the framebuffer, which we expect to be bound. |
| 115 DCHECK(is_frame_buffer_bound_); | 112 DCHECK(is_frame_buffer_bound_); |
| 116 glBindFramebuffer(GL_FRAMEBUFFER, 0); | 113 glBindFramebufferEXT(GL_FRAMEBUFFER, 0); |
| 117 is_frame_buffer_bound_ = false; | 114 is_frame_buffer_bound_ = false; |
| 118 | 115 |
| 119 DCHECK(temp_scroll_texture_id_); | 116 DCHECK(temp_scroll_texture_id_); |
| 120 unsigned int new_texture = temp_scroll_texture_id_; | 117 unsigned int new_texture = temp_scroll_texture_id_; |
| 121 | 118 |
| 122 temp_scroll_texture_id_ = old_texture; | 119 temp_scroll_texture_id_ = old_texture; |
| 123 temp_scroll_texture_size_ = old_size; | 120 temp_scroll_texture_size_ = old_size; |
| 124 | 121 |
| 125 return new_texture; | 122 return new_texture; |
| 126 } | 123 } |
| OLD | NEW |