| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/browser/renderer_host/accelerated_surface_container_touch.h" | 5 #include "chrome/browser/renderer_host/accelerated_surface_container_touch.h" |
| 6 | 6 |
| 7 #include <X11/Xlib.h> | 7 #include <X11/Xlib.h> |
| 8 #include <X11/extensions/Xcomposite.h> | 8 #include <X11/extensions/Xcomposite.h> |
| 9 | 9 |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "third_party/angle/include/EGL/egl.h" | 11 #include "third_party/angle/include/EGL/egl.h" |
| 12 #include "third_party/angle/include/EGL/eglext.h" | 12 #include "third_party/angle/include/EGL/eglext.h" |
| 13 #include "ui/gfx/gl/gl_bindings.h" | 13 #include "ui/gfx/gl/gl_bindings.h" |
| 14 #include "ui/gfx/gl/gl_implementation.h" | 14 #include "ui/gfx/gl/gl_implementation.h" |
| 15 #include "ui/gfx/gl/gl_surface_egl.h" | 15 #include "ui/gfx/gl/gl_surface_egl.h" |
| 16 #include "ui/gfx/gl/gl_surface_glx.h" |
| 16 #include "ui/gfx/rect.h" | 17 #include "ui/gfx/rect.h" |
| 17 #include "ui/gfx/gl/gl_surface_glx.h" | |
| 18 #include "ui/gfx/transform.h" | 18 #include "ui/gfx/transform.h" |
| 19 | 19 |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 class AcceleratedSurfaceContainerTouchEGL | 22 class AcceleratedSurfaceContainerTouchEGL |
| 23 : public AcceleratedSurfaceContainerTouch { | 23 : public AcceleratedSurfaceContainerTouch { |
| 24 public: | 24 public: |
| 25 AcceleratedSurfaceContainerTouchEGL(ui::CompositorGL* compositor, | 25 AcceleratedSurfaceContainerTouchEGL(const gfx::Size& size, |
| 26 const gfx::Size& size, | |
| 27 uint64 surface_handle); | 26 uint64 surface_handle); |
| 28 // TextureGL implementation | 27 // TextureGL implementation |
| 29 virtual void Draw(const ui::TextureDrawParams& params, | 28 virtual void Draw(const ui::TextureDrawParams& params, |
| 30 const gfx::Rect& clip_bounds_in_texture) OVERRIDE; | 29 const gfx::Rect& clip_bounds_in_texture) OVERRIDE; |
| 31 | 30 |
| 32 private: | 31 private: |
| 33 ~AcceleratedSurfaceContainerTouchEGL(); | 32 ~AcceleratedSurfaceContainerTouchEGL(); |
| 34 | 33 |
| 35 void* image_; | 34 void* image_; |
| 35 |
| 36 DISALLOW_COPY_AND_ASSIGN(AcceleratedSurfaceContainerTouchEGL); | 36 DISALLOW_COPY_AND_ASSIGN(AcceleratedSurfaceContainerTouchEGL); |
| 37 }; | 37 }; |
| 38 | 38 |
| 39 class AcceleratedSurfaceContainerTouchGLX | 39 class AcceleratedSurfaceContainerTouchGLX |
| 40 : public AcceleratedSurfaceContainerTouch { | 40 : public AcceleratedSurfaceContainerTouch { |
| 41 public: | 41 public: |
| 42 AcceleratedSurfaceContainerTouchGLX(ui::CompositorGL* compositor, | 42 AcceleratedSurfaceContainerTouchGLX(const gfx::Size& size, |
| 43 const gfx::Size& size, | |
| 44 uint64 surface_handle); | 43 uint64 surface_handle); |
| 45 // TextureGL implementation | 44 // TextureGL implementation |
| 46 virtual void Draw(const ui::TextureDrawParams& params, | 45 virtual void Draw(const ui::TextureDrawParams& params, |
| 47 const gfx::Rect& clip_bounds_in_texture) OVERRIDE; | 46 const gfx::Rect& clip_bounds_in_texture) OVERRIDE; |
| 48 | 47 |
| 49 private: | 48 private: |
| 50 ~AcceleratedSurfaceContainerTouchGLX(); | 49 ~AcceleratedSurfaceContainerTouchGLX(); |
| 51 | 50 |
| 52 XID pixmap_; | 51 XID pixmap_; |
| 53 XID glx_pixmap_; | 52 XID glx_pixmap_; |
| 53 |
| 54 DISALLOW_COPY_AND_ASSIGN(AcceleratedSurfaceContainerTouchGLX); | 54 DISALLOW_COPY_AND_ASSIGN(AcceleratedSurfaceContainerTouchGLX); |
| 55 }; | 55 }; |
| 56 | 56 |
| 57 class ScopedPtrXFree { | 57 class ScopedPtrXFree { |
| 58 public: | 58 public: |
| 59 void operator()(void* x) const { | 59 void operator()(void* x) const { |
| 60 ::XFree(x); | 60 ::XFree(x); |
| 61 } | 61 } |
| 62 }; | 62 }; |
| 63 | 63 |
| 64 AcceleratedSurfaceContainerTouchEGL::AcceleratedSurfaceContainerTouchEGL( | 64 AcceleratedSurfaceContainerTouchEGL::AcceleratedSurfaceContainerTouchEGL( |
| 65 ui::CompositorGL* compositor, | |
| 66 const gfx::Size& size, | 65 const gfx::Size& size, |
| 67 uint64 surface_handle) | 66 uint64 surface_handle) |
| 68 : AcceleratedSurfaceContainerTouch(compositor, size), | 67 : AcceleratedSurfaceContainerTouch(size), |
| 69 image_(NULL) { | 68 image_(NULL) { |
| 70 compositor_->MakeCurrent(); | 69 ui::SharedResources* instance = ui::SharedResources::GetInstance(); |
| 70 DCHECK(instance); |
| 71 instance->MakeSharedContextCurrent(); |
| 71 | 72 |
| 72 image_ = eglCreateImageKHR( | 73 image_ = eglCreateImageKHR( |
| 73 gfx::GLSurfaceEGL::GetHardwareDisplay(), EGL_NO_CONTEXT, | 74 gfx::GLSurfaceEGL::GetHardwareDisplay(), EGL_NO_CONTEXT, |
| 74 EGL_NATIVE_PIXMAP_KHR, reinterpret_cast<void*>(surface_handle), NULL); | 75 EGL_NATIVE_PIXMAP_KHR, reinterpret_cast<void*>(surface_handle), NULL); |
| 75 | 76 |
| 76 glGenTextures(1, &texture_id_); | 77 glGenTextures(1, &texture_id_); |
| 77 glBindTexture(GL_TEXTURE_2D, texture_id_); | 78 glBindTexture(GL_TEXTURE_2D, texture_id_); |
| 78 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | 79 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 79 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | 80 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 80 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 81 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 81 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 82 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 82 glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, image_); | 83 glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, image_); |
| 83 glFlush(); | 84 glFlush(); |
| 84 } | 85 } |
| 85 | 86 |
| 86 AcceleratedSurfaceContainerTouchEGL::~AcceleratedSurfaceContainerTouchEGL() { | 87 AcceleratedSurfaceContainerTouchEGL::~AcceleratedSurfaceContainerTouchEGL() { |
| 88 ui::SharedResources* instance = ui::SharedResources::GetInstance(); |
| 89 DCHECK(instance); |
| 90 instance->MakeSharedContextCurrent(); |
| 91 |
| 87 eglDestroyImageKHR(gfx::GLSurfaceEGL::GetHardwareDisplay(), image_); | 92 eglDestroyImageKHR(gfx::GLSurfaceEGL::GetHardwareDisplay(), image_); |
| 88 glFlush(); | 93 glFlush(); |
| 89 } | 94 } |
| 90 | 95 |
| 91 void AcceleratedSurfaceContainerTouchEGL::Draw( | 96 void AcceleratedSurfaceContainerTouchEGL::Draw( |
| 92 const ui::TextureDrawParams& params, | 97 const ui::TextureDrawParams& params, |
| 93 const gfx::Rect& clip_bounds_in_texture) { | 98 const gfx::Rect& clip_bounds_in_texture) { |
| 94 DCHECK(compositor_->program_no_swizzle()); | 99 ui::SharedResources* instance = ui::SharedResources::GetInstance(); |
| 100 DCHECK(instance); |
| 95 | 101 |
| 96 ui::TextureDrawParams modified_params = params; | 102 ui::TextureDrawParams modified_params = params; |
| 97 | 103 |
| 98 // Texture from GPU is flipped vertically. | 104 // Texture from GPU is flipped vertically. |
| 99 ui::Transform flipped; | 105 ui::Transform flipped; |
| 100 flipped.SetScaleY(-1.0); | 106 flipped.SetScaleY(-1.0); |
| 101 flipped.SetTranslateY(size_.height()); | 107 flipped.SetTranslateY(size_.height()); |
| 102 flipped.ConcatTransform(params.transform); | 108 flipped.ConcatTransform(params.transform); |
| 103 | 109 |
| 104 modified_params.transform = flipped; | 110 modified_params.transform = flipped; |
| 105 | 111 |
| 106 DrawInternal(*compositor_->program_no_swizzle(), | 112 DrawInternal(*instance->program_no_swizzle(), |
| 107 modified_params, | 113 modified_params, |
| 108 clip_bounds_in_texture); | 114 clip_bounds_in_texture); |
| 109 } | 115 } |
| 110 | 116 |
| 111 AcceleratedSurfaceContainerTouchGLX::AcceleratedSurfaceContainerTouchGLX( | 117 AcceleratedSurfaceContainerTouchGLX::AcceleratedSurfaceContainerTouchGLX( |
| 112 ui::CompositorGL* compositor, | |
| 113 const gfx::Size& size, | 118 const gfx::Size& size, |
| 114 uint64 surface_handle) | 119 uint64 surface_handle) |
| 115 : AcceleratedSurfaceContainerTouch(compositor, size), | 120 : AcceleratedSurfaceContainerTouch(size), |
| 116 pixmap_(0), | 121 pixmap_(0), |
| 117 glx_pixmap_(0) { | 122 glx_pixmap_(0) { |
| 123 ui::SharedResources* instance = ui::SharedResources::GetInstance(); |
| 124 DCHECK(instance); |
| 125 instance->MakeSharedContextCurrent(); |
| 126 |
| 118 // Create pixmap from window. | 127 // Create pixmap from window. |
| 119 Display* dpy = gfx::GLSurfaceGLX::GetDisplay(); | 128 Display* dpy = gfx::GLSurfaceGLX::GetDisplay(); |
| 120 int event_base, error_base; | 129 int event_base, error_base; |
| 121 if (XCompositeQueryExtension(dpy, &event_base, &error_base)) { | 130 if (XCompositeQueryExtension(dpy, &event_base, &error_base)) { |
| 122 int major = 0, minor = 2; | 131 int major = 0, minor = 2; |
| 123 XCompositeQueryVersion(dpy, &major, &minor); | 132 XCompositeQueryVersion(dpy, &major, &minor); |
| 124 if (major == 0 && minor < 2) { | 133 if (major == 0 && minor < 2) { |
| 125 LOG(ERROR) << "Pixmap from window not supported."; | 134 LOG(ERROR) << "Pixmap from window not supported."; |
| 126 return; | 135 return; |
| 127 } | 136 } |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 const int pixmapAttribs[] = { | 188 const int pixmapAttribs[] = { |
| 180 GLX_TEXTURE_TARGET_EXT, GLX_TEXTURE_2D_EXT, | 189 GLX_TEXTURE_TARGET_EXT, GLX_TEXTURE_2D_EXT, |
| 181 GLX_TEXTURE_FORMAT_EXT, GLX_TEXTURE_FORMAT_RGB_EXT, | 190 GLX_TEXTURE_FORMAT_EXT, GLX_TEXTURE_FORMAT_RGB_EXT, |
| 182 0 | 191 0 |
| 183 }; | 192 }; |
| 184 | 193 |
| 185 glx_pixmap_ = glXCreatePixmap( | 194 glx_pixmap_ = glXCreatePixmap( |
| 186 dpy, fbconfigs.get()[config], pixmap_, pixmapAttribs); | 195 dpy, fbconfigs.get()[config], pixmap_, pixmapAttribs); |
| 187 | 196 |
| 188 // Create texture. | 197 // Create texture. |
| 189 compositor_->MakeCurrent(); | |
| 190 glGenTextures(1, &texture_id_); | 198 glGenTextures(1, &texture_id_); |
| 191 glBindTexture(GL_TEXTURE_2D, texture_id_); | 199 glBindTexture(GL_TEXTURE_2D, texture_id_); |
| 192 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | 200 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 193 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | 201 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 194 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 202 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 195 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 203 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 196 } | 204 } |
| 197 | 205 |
| 198 AcceleratedSurfaceContainerTouchGLX::~AcceleratedSurfaceContainerTouchGLX() { | 206 AcceleratedSurfaceContainerTouchGLX::~AcceleratedSurfaceContainerTouchGLX() { |
| 207 ui::SharedResources* instance = ui::SharedResources::GetInstance(); |
| 208 DCHECK(instance); |
| 209 instance->MakeSharedContextCurrent(); |
| 210 |
| 199 Display* dpy = gfx::GLSurfaceGLX::GetDisplay(); | 211 Display* dpy = gfx::GLSurfaceGLX::GetDisplay(); |
| 200 if (glx_pixmap_) | 212 if (glx_pixmap_) |
| 201 glXDestroyGLXPixmap(dpy, glx_pixmap_); | 213 glXDestroyGLXPixmap(dpy, glx_pixmap_); |
| 202 if (pixmap_) | 214 if (pixmap_) |
| 203 XFreePixmap(dpy, pixmap_); | 215 XFreePixmap(dpy, pixmap_); |
| 204 } | 216 } |
| 205 | 217 |
| 206 void AcceleratedSurfaceContainerTouchGLX::Draw( | 218 void AcceleratedSurfaceContainerTouchGLX::Draw( |
| 207 const ui::TextureDrawParams& params, | 219 const ui::TextureDrawParams& params, |
| 208 const gfx::Rect& clip_bounds_in_texture) { | 220 const gfx::Rect& clip_bounds_in_texture) { |
| 209 DCHECK(compositor_->program_no_swizzle()); | 221 ui::SharedResources* instance = ui::SharedResources::GetInstance(); |
| 222 DCHECK(instance); |
| 223 |
| 210 Display* dpy = gfx::GLSurfaceGLX::GetDisplay(); | 224 Display* dpy = gfx::GLSurfaceGLX::GetDisplay(); |
| 211 | 225 |
| 212 glBindTexture(GL_TEXTURE_2D, texture_id_); | 226 glBindTexture(GL_TEXTURE_2D, texture_id_); |
| 213 glXBindTexImageEXT(dpy, glx_pixmap_, GLX_FRONT_LEFT_EXT, NULL); | 227 glXBindTexImageEXT(dpy, glx_pixmap_, GLX_FRONT_LEFT_EXT, NULL); |
| 214 DrawInternal(*compositor_->program_no_swizzle(), | 228 DrawInternal(*instance->program_no_swizzle(), |
| 215 params, | 229 params, |
| 216 clip_bounds_in_texture); | 230 clip_bounds_in_texture); |
| 217 glXReleaseTexImageEXT(dpy, glx_pixmap_, GLX_FRONT_LEFT_EXT); | 231 glXReleaseTexImageEXT(dpy, glx_pixmap_, GLX_FRONT_LEFT_EXT); |
| 218 } | 232 } |
| 219 | 233 |
| 220 } // namespace | 234 } // namespace |
| 221 | 235 |
| 222 AcceleratedSurfaceContainerTouch::AcceleratedSurfaceContainerTouch( | 236 AcceleratedSurfaceContainerTouch::AcceleratedSurfaceContainerTouch( |
| 223 ui::CompositorGL* compositor, | 237 const gfx::Size& size) : TextureGL(size) { |
| 224 const gfx::Size& size) : | |
| 225 TextureGL(compositor, size) { | |
| 226 } | 238 } |
| 227 | 239 |
| 228 // static | 240 // static |
| 229 AcceleratedSurfaceContainerTouch* | 241 AcceleratedSurfaceContainerTouch* |
| 230 AcceleratedSurfaceContainerTouch::CreateAcceleratedSurfaceContainer( | 242 AcceleratedSurfaceContainerTouch::CreateAcceleratedSurfaceContainer( |
| 231 ui::CompositorGL* compositor, | |
| 232 const gfx::Size& size, | 243 const gfx::Size& size, |
| 233 uint64 surface_handle) { | 244 uint64 surface_handle) { |
| 234 switch (gfx::GetGLImplementation()) { | 245 switch (gfx::GetGLImplementation()) { |
| 235 case gfx::kGLImplementationDesktopGL: | 246 case gfx::kGLImplementationDesktopGL: |
| 236 return new AcceleratedSurfaceContainerTouchGLX(compositor, | 247 return new AcceleratedSurfaceContainerTouchGLX(size, |
| 237 size, | |
| 238 surface_handle); | 248 surface_handle); |
| 239 case gfx::kGLImplementationEGLGLES2: | 249 case gfx::kGLImplementationEGLGLES2: |
| 240 return new AcceleratedSurfaceContainerTouchEGL(compositor, | 250 return new AcceleratedSurfaceContainerTouchEGL(size, |
| 241 size, | |
| 242 surface_handle); | 251 surface_handle); |
| 243 default: | 252 default: |
| 244 NOTREACHED(); | 253 NOTREACHED(); |
| 245 return NULL; | 254 return NULL; |
| 246 } | 255 } |
| 247 } | 256 } |
| 248 | 257 |
| 249 void AcceleratedSurfaceContainerTouch::SetCanvas( | 258 void AcceleratedSurfaceContainerTouch::SetCanvas( |
| 250 const SkCanvas& canvas, | 259 const SkCanvas& canvas, |
| 251 const gfx::Point& origin, | 260 const gfx::Point& origin, |
| 252 const gfx::Size& overall_size) { | 261 const gfx::Size& overall_size) { |
| 253 NOTREACHED(); | 262 NOTREACHED(); |
| 254 } | 263 } |
| OLD | NEW |