OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ui/gl/gl_surface_glx.h" | 5 #include "ui/gl/gl_surface_glx.h" |
6 | 6 |
7 extern "C" { | 7 extern "C" { |
8 #include <X11/Xlib.h> | 8 #include <X11/Xlib.h> |
9 } | 9 } |
10 #include <memory> | 10 #include <memory> |
(...skipping 12 matching lines...) Expand all Loading... |
23 #include "base/time/time.h" | 23 #include "base/time/time.h" |
24 #include "base/trace_event/trace_event.h" | 24 #include "base/trace_event/trace_event.h" |
25 #include "build/build_config.h" | 25 #include "build/build_config.h" |
26 #include "ui/events/platform/platform_event_source.h" | 26 #include "ui/events/platform/platform_event_source.h" |
27 #include "ui/gfx/x/x11_connection.h" | 27 #include "ui/gfx/x/x11_connection.h" |
28 #include "ui/gfx/x/x11_types.h" | 28 #include "ui/gfx/x/x11_types.h" |
29 #include "ui/gl/gl_bindings.h" | 29 #include "ui/gl/gl_bindings.h" |
30 #include "ui/gl/gl_implementation.h" | 30 #include "ui/gl/gl_implementation.h" |
31 #include "ui/gl/sync_control_vsync_provider.h" | 31 #include "ui/gl/sync_control_vsync_provider.h" |
32 | 32 |
33 namespace gfx { | 33 namespace gl { |
34 | 34 |
35 namespace { | 35 namespace { |
36 | 36 |
37 Display* g_display = nullptr; | 37 Display* g_display = nullptr; |
38 bool g_glx_context_create = false; | 38 bool g_glx_context_create = false; |
39 bool g_glx_create_context_robustness_supported = false; | 39 bool g_glx_create_context_robustness_supported = false; |
40 bool g_glx_texture_from_pixmap_supported = false; | 40 bool g_glx_texture_from_pixmap_supported = false; |
41 bool g_glx_oml_sync_control_supported = false; | 41 bool g_glx_oml_sync_control_supported = false; |
42 | 42 |
43 // Track support of glXGetMscRateOML separately from GLX_OML_sync_control as a | 43 // Track support of glXGetMscRateOML separately from GLX_OML_sync_control as a |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 found = true; | 108 found = true; |
109 break; | 109 break; |
110 } | 110 } |
111 } | 111 } |
112 if (found) { | 112 if (found) { |
113 return configs.get()[i]; | 113 return configs.get()[i]; |
114 } | 114 } |
115 return nullptr; | 115 return nullptr; |
116 } | 116 } |
117 | 117 |
118 class OMLSyncControlVSyncProvider | 118 class OMLSyncControlVSyncProvider : public gl::SyncControlVSyncProvider { |
119 : public gfx::SyncControlVSyncProvider { | |
120 public: | 119 public: |
121 explicit OMLSyncControlVSyncProvider(GLXWindow glx_window) | 120 explicit OMLSyncControlVSyncProvider(GLXWindow glx_window) |
122 : SyncControlVSyncProvider(), | 121 : SyncControlVSyncProvider(), |
123 glx_window_(glx_window) { | 122 glx_window_(glx_window) { |
124 } | 123 } |
125 | 124 |
126 ~OMLSyncControlVSyncProvider() override {} | 125 ~OMLSyncControlVSyncProvider() override {} |
127 | 126 |
128 protected: | 127 protected: |
129 bool GetSyncValues(int64_t* system_time, | 128 bool GetSyncValues(int64_t* system_time, |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 | 215 |
217 void Initialize() { | 216 void Initialize() { |
218 DCHECK(display_); | 217 DCHECK(display_); |
219 | 218 |
220 context_ = | 219 context_ = |
221 glXCreateNewContext(display_, config_, GLX_RGBA_TYPE, nullptr, True); | 220 glXCreateNewContext(display_, config_, GLX_RGBA_TYPE, nullptr, True); |
222 | 221 |
223 DCHECK(nullptr != context_); | 222 DCHECK(nullptr != context_); |
224 } | 223 } |
225 | 224 |
226 void GetVSyncParameters(const VSyncProvider::UpdateVSyncCallback& callback) { | 225 void GetVSyncParameters( |
| 226 const gfx::VSyncProvider::UpdateVSyncCallback& callback) { |
227 base::TimeTicks now; | 227 base::TimeTicks now; |
228 { | 228 { |
229 // Don't allow |window_| destruction while we're probing vsync. | 229 // Don't allow |window_| destruction while we're probing vsync. |
230 base::AutoLock locked(vsync_lock_); | 230 base::AutoLock locked(vsync_lock_); |
231 | 231 |
232 if (!context_ || cancel_vsync_flag_.IsSet()) | 232 if (!context_ || cancel_vsync_flag_.IsSet()) |
233 return; | 233 return; |
234 | 234 |
235 glXMakeContextCurrent(display_, glx_window_, glx_window_, context_); | 235 glXMakeContextCurrent(display_, glx_window_, glx_window_, context_); |
236 | 236 |
(...skipping 10 matching lines...) Expand all Loading... |
247 const base::TimeDelta kDefaultInterval = | 247 const base::TimeDelta kDefaultInterval = |
248 base::TimeDelta::FromSeconds(1) / 60; | 248 base::TimeDelta::FromSeconds(1) / 60; |
249 | 249 |
250 task_runner_->PostTask( | 250 task_runner_->PostTask( |
251 FROM_HERE, base::Bind(callback, now, kDefaultInterval)); | 251 FROM_HERE, base::Bind(callback, now, kDefaultInterval)); |
252 } | 252 } |
253 | 253 |
254 private: | 254 private: |
255 // For initialization of display_ in GLSurface::InitializeOneOff before | 255 // For initialization of display_ in GLSurface::InitializeOneOff before |
256 // the sandbox goes up. | 256 // the sandbox goes up. |
257 friend class gfx::GLSurfaceGLX; | 257 friend class gl::GLSurfaceGLX; |
258 | 258 |
259 static Display* display_; | 259 static Display* display_; |
260 | 260 |
261 GLXFBConfig config_; | 261 GLXFBConfig config_; |
262 GLXWindow glx_window_; | 262 GLXWindow glx_window_; |
263 GLXContext context_; | 263 GLXContext context_; |
264 | 264 |
265 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 265 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
266 | 266 |
267 base::CancellationFlag cancel_vsync_flag_; | 267 base::CancellationFlag cancel_vsync_flag_; |
(...skipping 23 matching lines...) Expand all Loading... |
291 cancel_vsync_flag_->Set(); | 291 cancel_vsync_flag_->Set(); |
292 } | 292 } |
293 | 293 |
294 // Hand-off |shim_| to be deleted on the |vsync_thread_|. | 294 // Hand-off |shim_| to be deleted on the |vsync_thread_|. |
295 vsync_thread_->message_loop()->DeleteSoon( | 295 vsync_thread_->message_loop()->DeleteSoon( |
296 FROM_HERE, | 296 FROM_HERE, |
297 shim_.release()); | 297 shim_.release()); |
298 } | 298 } |
299 | 299 |
300 void GetVSyncParameters( | 300 void GetVSyncParameters( |
301 const VSyncProvider::UpdateVSyncCallback& callback) override { | 301 const gfx::VSyncProvider::UpdateVSyncCallback& callback) override { |
302 if (kGetVSyncParametersMinSeconds > 0) { | 302 if (kGetVSyncParametersMinSeconds > 0) { |
303 base::TimeTicks now = base::TimeTicks::Now(); | 303 base::TimeTicks now = base::TimeTicks::Now(); |
304 base::TimeDelta delta = now - last_get_vsync_parameters_time_; | 304 base::TimeDelta delta = now - last_get_vsync_parameters_time_; |
305 if (delta.InSeconds() < kGetVSyncParametersMinSeconds) | 305 if (delta.InSeconds() < kGetVSyncParametersMinSeconds) |
306 return; | 306 return; |
307 last_get_vsync_parameters_time_ = now; | 307 last_get_vsync_parameters_time_ = now; |
308 } | 308 } |
309 | 309 |
310 // Only one outstanding request per surface. | 310 // Only one outstanding request per surface. |
311 if (!pending_callback_) { | 311 if (!pending_callback_) { |
312 pending_callback_.reset( | 312 pending_callback_.reset( |
313 new VSyncProvider::UpdateVSyncCallback(callback)); | 313 new gfx::VSyncProvider::UpdateVSyncCallback(callback)); |
314 vsync_thread_->message_loop()->PostTask( | 314 vsync_thread_->message_loop()->PostTask( |
315 FROM_HERE, | 315 FROM_HERE, |
316 base::Bind(&SGIVideoSyncProviderThreadShim::GetVSyncParameters, | 316 base::Bind(&SGIVideoSyncProviderThreadShim::GetVSyncParameters, |
317 base::Unretained(shim_.get()), | 317 base::Unretained(shim_.get()), |
318 base::Bind( | 318 base::Bind( |
319 &SGIVideoSyncVSyncProvider::PendingCallbackRunner, | 319 &SGIVideoSyncVSyncProvider::PendingCallbackRunner, |
320 AsWeakPtr()))); | 320 AsWeakPtr()))); |
321 } | 321 } |
322 } | 322 } |
323 | 323 |
324 private: | 324 private: |
325 void PendingCallbackRunner(const base::TimeTicks timebase, | 325 void PendingCallbackRunner(const base::TimeTicks timebase, |
326 const base::TimeDelta interval) { | 326 const base::TimeDelta interval) { |
327 DCHECK(pending_callback_); | 327 DCHECK(pending_callback_); |
328 pending_callback_->Run(timebase, interval); | 328 pending_callback_->Run(timebase, interval); |
329 pending_callback_.reset(); | 329 pending_callback_.reset(); |
330 } | 330 } |
331 | 331 |
332 scoped_refptr<SGIVideoSyncThread> vsync_thread_; | 332 scoped_refptr<SGIVideoSyncThread> vsync_thread_; |
333 | 333 |
334 // Thread shim through which the sync provider is accessed on |vsync_thread_|. | 334 // Thread shim through which the sync provider is accessed on |vsync_thread_|. |
335 std::unique_ptr<SGIVideoSyncProviderThreadShim> shim_; | 335 std::unique_ptr<SGIVideoSyncProviderThreadShim> shim_; |
336 | 336 |
337 std::unique_ptr<VSyncProvider::UpdateVSyncCallback> pending_callback_; | 337 std::unique_ptr<gfx::VSyncProvider::UpdateVSyncCallback> pending_callback_; |
338 | 338 |
339 // Raw pointers to sync primitives owned by the shim_. | 339 // Raw pointers to sync primitives owned by the shim_. |
340 // These will only be referenced before we post a task to destroy | 340 // These will only be referenced before we post a task to destroy |
341 // the shim_, so they are safe to access. | 341 // the shim_, so they are safe to access. |
342 base::CancellationFlag* cancel_vsync_flag_; | 342 base::CancellationFlag* cancel_vsync_flag_; |
343 base::Lock* vsync_lock_; | 343 base::Lock* vsync_lock_; |
344 | 344 |
345 base::TimeTicks last_get_vsync_parameters_time_; | 345 base::TimeTicks last_get_vsync_parameters_time_; |
346 | 346 |
347 DISALLOW_COPY_AND_ASSIGN(SGIVideoSyncVSyncProvider); | 347 DISALLOW_COPY_AND_ASSIGN(SGIVideoSyncVSyncProvider); |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
547 | 547 |
548 gfx::Size NativeViewGLSurfaceGLX::GetSize() { | 548 gfx::Size NativeViewGLSurfaceGLX::GetSize() { |
549 return size_; | 549 return size_; |
550 } | 550 } |
551 | 551 |
552 void* NativeViewGLSurfaceGLX::GetHandle() { | 552 void* NativeViewGLSurfaceGLX::GetHandle() { |
553 return reinterpret_cast<void*>(GetDrawableHandle()); | 553 return reinterpret_cast<void*>(GetDrawableHandle()); |
554 } | 554 } |
555 | 555 |
556 bool NativeViewGLSurfaceGLX::SupportsPostSubBuffer() { | 556 bool NativeViewGLSurfaceGLX::SupportsPostSubBuffer() { |
557 return gfx::g_driver_glx.ext.b_GLX_MESA_copy_sub_buffer; | 557 return gl::g_driver_glx.ext.b_GLX_MESA_copy_sub_buffer; |
558 } | 558 } |
559 | 559 |
560 void* NativeViewGLSurfaceGLX::GetConfig() { | 560 void* NativeViewGLSurfaceGLX::GetConfig() { |
561 if (!config_) | 561 if (!config_) |
562 config_ = GetConfigForWindow(g_display, window_); | 562 config_ = GetConfigForWindow(g_display, window_); |
563 return config_; | 563 return config_; |
564 } | 564 } |
565 | 565 |
566 gfx::SwapResult NativeViewGLSurfaceGLX::PostSubBuffer(int x, | 566 gfx::SwapResult NativeViewGLSurfaceGLX::PostSubBuffer(int x, |
567 int y, | 567 int y, |
568 int width, | 568 int width, |
569 int height) { | 569 int height) { |
570 DCHECK(gfx::g_driver_glx.ext.b_GLX_MESA_copy_sub_buffer); | 570 DCHECK(gl::g_driver_glx.ext.b_GLX_MESA_copy_sub_buffer); |
571 glXCopySubBufferMESA(g_display, GetDrawableHandle(), x, y, width, height); | 571 glXCopySubBufferMESA(g_display, GetDrawableHandle(), x, y, width, height); |
572 return gfx::SwapResult::SWAP_ACK; | 572 return gfx::SwapResult::SWAP_ACK; |
573 } | 573 } |
574 | 574 |
575 VSyncProvider* NativeViewGLSurfaceGLX::GetVSyncProvider() { | 575 gfx::VSyncProvider* NativeViewGLSurfaceGLX::GetVSyncProvider() { |
576 return vsync_provider_.get(); | 576 return vsync_provider_.get(); |
577 } | 577 } |
578 | 578 |
579 NativeViewGLSurfaceGLX::~NativeViewGLSurfaceGLX() { | 579 NativeViewGLSurfaceGLX::~NativeViewGLSurfaceGLX() { |
580 Destroy(); | 580 Destroy(); |
581 } | 581 } |
582 | 582 |
583 UnmappedNativeViewGLSurfaceGLX::UnmappedNativeViewGLSurfaceGLX( | 583 UnmappedNativeViewGLSurfaceGLX::UnmappedNativeViewGLSurfaceGLX( |
584 const gfx::Size& size) | 584 const gfx::Size& size) |
585 : size_(size), config_(nullptr), window_(0), glx_window_(0) { | 585 : size_(size), config_(nullptr), window_(0), glx_window_(0) { |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
638 void* UnmappedNativeViewGLSurfaceGLX::GetConfig() { | 638 void* UnmappedNativeViewGLSurfaceGLX::GetConfig() { |
639 if (!config_) | 639 if (!config_) |
640 config_ = GetConfigForWindow(g_display, window_); | 640 config_ = GetConfigForWindow(g_display, window_); |
641 return config_; | 641 return config_; |
642 } | 642 } |
643 | 643 |
644 UnmappedNativeViewGLSurfaceGLX::~UnmappedNativeViewGLSurfaceGLX() { | 644 UnmappedNativeViewGLSurfaceGLX::~UnmappedNativeViewGLSurfaceGLX() { |
645 Destroy(); | 645 Destroy(); |
646 } | 646 } |
647 | 647 |
648 } // namespace gfx | 648 } // namespace gl |
OLD | NEW |