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